Skip to content

Commit

Permalink
test withdraw and call
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Aug 9, 2024
1 parent f2288b7 commit a5ec5ab
Show file tree
Hide file tree
Showing 23 changed files with 177 additions and 54 deletions.
9 changes: 6 additions & 3 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,18 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
eg.Go(solanaTestRoutine(conf, deployerRunner, verbose, solanaTests...))
}
if testV2 {
// update the ERC20 custody contract for v2 tests
deployerRunner.UpdateChainParamsERC20CustodyContract()

eg.Go(v2TestRoutine(conf, deployerRunner, verbose,
e2etests.TestV2ETHDepositName,
//e2etests.TestV2ETHDepositAndCallName,
//e2etests.TestV2ETHWithdrawName,
e2etests.TestV2ETHWithdrawAndCallName,
//e2etests.TestV2ERC20DepositName,
//e2etests.TestV2ETHWithdrawAndCallName,
e2etests.TestV2ERC20DepositName,
//e2etests.TestV2ERC20DepositAndCallName,
//e2etests.TestV2ERC20WithdrawName,
//e2etests.TestV2ERC20WithdrawAndCallName,
e2etests.TestV2ERC20WithdrawAndCallName,
//e2etests.TestV2ZEVMToEVMCallName,
//e2etests.TestV2EVMToZEVMCallName,
))
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_v2_erc20_deposit.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package e2etests

import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_v2_erc20_deposit_and_call.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package e2etests

import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
Expand Down
3 changes: 2 additions & 1 deletion e2e/e2etests/test_v2_erc20_withdraw.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package e2etests

import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
"math/big"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

func TestV2ERC20Withdraw(r *runner.E2ERunner, args []string) {
Expand All @@ -17,6 +17,7 @@ func TestV2ERC20Withdraw(r *runner.E2ERunner, args []string) {
require.True(r, ok, "Invalid amount specified for TestV2ERC20Withdraw")

r.ApproveERC20ZRC20(r.GatewayZEVMAddr)
r.ApproveETHZRC20(r.GatewayZEVMAddr)

// perform the withdraw
tx := r.V2ERC20Withdraw(r.EVMAddress(), amount)
Expand Down
9 changes: 7 additions & 2 deletions e2e/e2etests/test_v2_erc20_withdraw_and_call.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package e2etests

import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
"math/big"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

const payloadMessageWithdrawERC20 = "this is a test ERC20 withdraw and call payload"
Expand All @@ -21,9 +21,14 @@ func TestV2ERC20WithdrawAndCall(r *runner.E2ERunner, args []string) {
r.AssertTestDAppEVMValues(false, payloadMessageWithdrawETH, amount)

r.ApproveERC20ZRC20(r.GatewayZEVMAddr)
r.ApproveETHZRC20(r.GatewayZEVMAddr)

// perform the withdraw
tx := r.V2ERC20WithdrawAndCall(r.EVMAddress(), amount, r.EncodeERC20Call(r.ERC20ZRC20Addr, amount, payloadMessageWithdrawERC20))
tx := r.V2ERC20WithdrawAndCall(
r.TestDAppV2EVMAddr,
amount,
r.EncodeERC20Call(r.ERC20Addr, amount, payloadMessageWithdrawERC20),
)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_v2_eth_deposit.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package e2etests

import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_v2_eth_deposit_and_call.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package e2etests

import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_v2_eth_withdraw.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package e2etests

import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
"math/big"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

func TestV2ETHWithdraw(r *runner.E2ERunner, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_v2_eth_withdraw_and_call.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package e2etests

import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
"math/big"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

const payloadMessageWithdrawETH = "this is a test ETH withdraw and call payload"
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_v2_evm_to_zevm_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package e2etests

import (
"github.com/stretchr/testify/require"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

func TestV2EVMToZEVMCall(r *runner.E2ERunner, args []string) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_v2_zevm_to_evm_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package e2etests

import (
"github.com/stretchr/testify/require"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

func TestV2ZEVMToEVMCall(r *runner.E2ERunner, args []string) {
Expand Down
12 changes: 9 additions & 3 deletions e2e/runner/testdapp.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package runner

import (
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/pkg/contracts/testdappv2"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/pkg/contracts/testdappv2"
)

// AssertTestDAppZEVMValues is a function that asserts the values of the test dapp on the ZEVM
Expand All @@ -21,7 +22,12 @@ func (r *E2ERunner) AssertTestDAppEVMValues(equals bool, message string, amount
r.assertTestDAppValues(r.TestDAppV2EVM, equals, message, amount)
}

func (r *E2ERunner) assertTestDAppValues(testDApp *testdappv2.TestDAppV2, equals bool, message string, amount *big.Int) {
func (r *E2ERunner) assertTestDAppValues(
testDApp *testdappv2.TestDAppV2,
equals bool,
message string,
amount *big.Int,
) {
// check the payload was received on the contract
actualMessage, err := testDApp.LastMessage(&bind.CallOpts{})
require.NoError(r, err)
Expand Down
41 changes: 40 additions & 1 deletion e2e/runner/v2_setup_zeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/pkg/contracts/erc1967proxy"
"github.com/zeta-chain/zetacore/pkg/contracts/testdappv2"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

// SetZEVMContractsV2 set contracts for the ZEVM
Expand Down Expand Up @@ -39,7 +40,12 @@ func (r *E2ERunner) SetZEVMContractsV2() {
require.NoError(r, err)

// Deploy the proxy contract
r.Logger.Info("Deploying proxy with %s and %s, address: %s", r.WZetaAddr.Hex(), r.Account.EVMAddress().Hex(), gatewayZEVMAddr.Hex())
r.Logger.Info(
"Deploying proxy with %s and %s, address: %s",
r.WZetaAddr.Hex(),
r.Account.EVMAddress().Hex(),
gatewayZEVMAddr.Hex(),
)
proxyAddress, txProxy, _, err := erc1967proxy.DeployERC1967Proxy(
r.ZEVMAuth,
r.ZEVMClient,
Expand Down Expand Up @@ -68,3 +74,36 @@ func (r *E2ERunner) SetZEVMContractsV2() {
ensureTxReceipt(txProxy, "Gateway proxy deployment failed")
ensureTxReceipt(txTestDAppV2, "TestDAppV2 deployment failed")
}

// UpdateChainParamsERC20CustodyContract update the erc20 custody contract in the chain params
// this operation is used when transitioning to new smart contract architecture where a new ERC20 custody contract is deployed
func (r *E2ERunner) UpdateChainParamsERC20CustodyContract() {
res, err := r.ObserverClient.GetChainParams(r.Ctx, &observertypes.QueryGetChainParamsRequest{})
require.NoError(r, err)

evmChainID, err := r.EVMClient.ChainID(r.Ctx)

Check failure on line 84 in e2e/runner/v2_setup_zeta.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

// find old chain params
var (
chainParams *observertypes.ChainParams
found bool
)
for _, cp := range res.ChainParams.ChainParams {
if cp.ChainId == evmChainID.Int64() {
chainParams = cp
found = true
break
}
}
require.True(r, found, "Chain params not found for chain id %d", evmChainID)

// update with the new ERC20 custody contract address
chainParams.Erc20CustodyContractAddress = r.ERC20CustodyV2Addr.Hex()

// update the chain params
_, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, observertypes.NewMsgUpdateChainParams(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName),
chainParams,
))
require.NoError(r, err)
}
4 changes: 2 additions & 2 deletions e2e/runner/v2_zevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (r *E2ERunner) V2ETHWithdrawAndCall(

// V2ERC20Withdraw calls Withdraw of Gateway with erc20 token on ZEVM
func (r *E2ERunner) V2ERC20Withdraw(receiver ethcommon.Address, amount *big.Int) *ethtypes.Transaction {
tx, err := r.GatewayZEVM.Withdraw(r.ZEVMAuth, receiver.Bytes(), amount, r.ERC20Addr)
tx, err := r.GatewayZEVM.Withdraw(r.ZEVMAuth, receiver.Bytes(), amount, r.ERC20ZRC20Addr)
require.NoError(r, err)

return tx
Expand All @@ -42,7 +42,7 @@ func (r *E2ERunner) V2ERC20WithdrawAndCall(
amount *big.Int,
payload []byte,
) *ethtypes.Transaction {
tx, err := r.GatewayZEVM.WithdrawAndCall(r.ZEVMAuth, receiver.Bytes(), amount, r.ERC20Addr, payload)
tx, err := r.GatewayZEVM.WithdrawAndCall(r.ZEVMAuth, receiver.Bytes(), amount, r.ERC20ZRC20Addr, payload)
require.NoError(r, err)

return tx
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/evm_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"github.com/pkg/errors"
"math/big"

errorsmod "cosmossdk.io/errors"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/pkg/errors"
connectorzevm "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/zevm/zetaconnectorzevm.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/zrc20.sol"

Expand Down
5 changes: 4 additions & 1 deletion x/crosschain/keeper/v2_zevm_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ func (k Keeper) newWithdrawalInbound(

// for simple withdraw without call, we use the specified gas limit in the zrc20 contract
if len(event.Message) == 0 {
gasLimitQueried, err := k.fungibleKeeper.QueryGasLimit(ctx, ethcommon.HexToAddress(foreignCoin.Zrc20ContractAddress))
gasLimitQueried, err := k.fungibleKeeper.QueryGasLimit(
ctx,
ethcommon.HexToAddress(foreignCoin.Zrc20ContractAddress),
)
if err != nil {
return nil, errors.Wrap(err, "cannot query gas limit")

Check warning on line 134 in x/crosschain/keeper/v2_zevm_inbound.go

View check run for this annotation

Codecov / codecov/patch

x/crosschain/keeper/v2_zevm_inbound.go#L128-L134

Added lines #L128 - L134 were not covered by tests
}
Expand Down
4 changes: 3 additions & 1 deletion zetaclient/chains/bitcoin/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ func (signer *Signer) TryProcessOutbound(
cancelTx,
)
if err != nil {
logger.Warn().Err(err).Msgf("SignConnectorOnReceive error: nonce %d chain %d", outboundTssNonce, params.ReceiverChainId)
logger.Warn().
Err(err).
Msgf("SignConnectorOnReceive error: nonce %d chain %d", outboundTssNonce, params.ReceiverChainId)

Check warning on line 437 in zetaclient/chains/bitcoin/signer/signer.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/signer/signer.go#L435-L437

Added lines #L435 - L437 were not covered by tests
return
}
logger.Info().
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/evm/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package observer
import (
"context"
"fmt"
erc20custodyv2 "github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol"
"math"
"math/big"
"strings"
Expand All @@ -18,6 +17,7 @@ import (
"github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zeta.non-eth.sol"
zetaconnectoreth "github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zetaconnector.eth.sol"
"github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zetaconnector.non-eth.sol"
erc20custodyv2 "github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"

"github.com/zeta-chain/zetacore/pkg/bg"
Expand Down
4 changes: 2 additions & 2 deletions zetaclient/chains/evm/observer/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"encoding/hex"
"fmt"
erc20custodyv2 "github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"
"math/big"
"strings"
"time"
Expand All @@ -18,6 +16,8 @@ import (
"github.com/rs/zerolog/log"
"github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/v1/pkg/contracts/evm/zetaconnector.non-eth.sol"
erc20custodyv2 "github.com/zeta-chain/protocol-contracts/v2/pkg/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"

"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
Expand Down
Loading

0 comments on commit a5ec5ab

Please sign in to comment.