From fcf0691d7a9a48ee1b21349aaf703ad7307fa341 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 3 Jun 2024 09:34:01 +0200 Subject: [PATCH 1/4] deploy e2e test --- e2e/e2etests/test_deploy_contract.go | 86 ++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 e2e/e2etests/test_deploy_contract.go diff --git a/e2e/e2etests/test_deploy_contract.go b/e2e/e2etests/test_deploy_contract.go new file mode 100644 index 0000000000..2cf6ff0c49 --- /dev/null +++ b/e2e/e2etests/test_deploy_contract.go @@ -0,0 +1,86 @@ +package e2etests + +import ( + "fmt" + ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/zeta-chain/zetacore/e2e/contracts/testdapp" + "github.com/zeta-chain/zetacore/e2e/runner" + "github.com/zeta-chain/zetacore/e2e/utils" +) + +// deployFunc is a function that deploys a contract +type deployFunc func(r *runner.E2ERunner) (ethcommon.Address, error) + +// deployMap maps contract names to deploy functions +var deployMap = map[string]deployFunc{ + "testdapp_zevm": deployZEVMTestDApp, + "testdapp_evm": deployEVMTestDApp, +} + +// TestDeployContract deploys the specified contract +func TestDeployContract(r *runner.E2ERunner, args []string) { + availableContractNames := make([]string, 0, len(deployMap)) + for contractName := range deployMap { + availableContractNames = append(availableContractNames, contractName) + } + availableContractNamesMessage := fmt.Sprintf("Available contract names: %v", availableContractNames) + + if len(args) != 1 { + panic("TestDeployContract requires exactly one argument for the contract name. " + availableContractNamesMessage) + } + contractName := args[0] + + deployFunc, ok := deployMap[contractName] + if !ok { + panic(fmt.Sprintf("Unknown contract name: %s, %s", contractName, availableContractNamesMessage)) + } + + addr, err := deployFunc(r) + if err != nil { + panic(err) + } + + r.Logger.Print("%s deployed at %s", contractName, addr.Hex()) +} + +// deployZEVMTestDApp deploys the TestDApp contract on ZetaChain +func deployZEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) { + addr, tx, _, err := testdapp.DeployTestDApp( + r.ZEVMAuth, + r.ZEVMClient, + r.ConnectorZEVMAddr, + r.WZetaAddr, + ) + if err != nil { + return addr, err + } + + // Wait for the transaction to be mined + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) + if receipt.Status != 1 { + return addr, fmt.Errorf("contract deployment failed") + } + + return addr, nil +} + +// deployEVMTestDApp deploys the TestDApp contract on Ethereum +func deployEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) { + addr, tx, _, err := testdapp.DeployTestDApp( + r.EVMAuth, + r.EVMClient, + r.ConnectorEthAddr, + r.ZetaEthAddr, + ) + if err != nil { + return addr, err + } + + // Wait for the transaction to be mined + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + if receipt.Status != 1 { + return addr, fmt.Errorf("contract deployment failed") + } + + return addr, nil +} From 1a58fa23ebbe4c427fbc12a3a55e9547b50e897a Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 3 Jun 2024 09:34:11 +0200 Subject: [PATCH 2/4] add deploy e2e test to list --- e2e/e2etests/e2etests.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/e2e/e2etests/e2etests.go b/e2e/e2etests/e2etests.go index 83bc455502..348a2a7ef1 100644 --- a/e2e/e2etests/e2etests.go +++ b/e2e/e2etests/e2etests.go @@ -98,6 +98,12 @@ const ( TestUpdateBytecodeZRC20Name = "update_bytecode_zrc20" TestUpdateBytecodeConnectorName = "update_bytecode_connector" TestRateLimiterName = "rate_limiter" + + /* + Special tests + Not used to test functionalities but do various interactions with the netwoks + */ + TestDeploy = "deploy" ) // AllE2ETests is an ordered list of all e2e tests @@ -507,4 +513,15 @@ var AllE2ETests = []runner.E2ETest{ []runner.ArgDefinition{}, TestRateLimiter, ), + /* + Special tests + */ + runner.NewE2ETest( + TestDeploy, + "deploy a contract", + []runner.ArgDefinition{ + {Description: "contract name", DefaultValue: ""}, + }, + TestDeployContract, + ), } From 8e56705a687e090767cff9c9485b8ffbfc331932 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 3 Jun 2024 11:03:52 +0200 Subject: [PATCH 3/4] make generate --- e2e/e2etests/test_deploy_contract.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/e2e/e2etests/test_deploy_contract.go b/e2e/e2etests/test_deploy_contract.go index 2cf6ff0c49..860ae2e0dc 100644 --- a/e2e/e2etests/test_deploy_contract.go +++ b/e2e/e2etests/test_deploy_contract.go @@ -2,7 +2,9 @@ package e2etests import ( "fmt" + ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/zeta-chain/zetacore/e2e/contracts/testdapp" "github.com/zeta-chain/zetacore/e2e/runner" "github.com/zeta-chain/zetacore/e2e/utils" @@ -26,7 +28,9 @@ func TestDeployContract(r *runner.E2ERunner, args []string) { availableContractNamesMessage := fmt.Sprintf("Available contract names: %v", availableContractNames) if len(args) != 1 { - panic("TestDeployContract requires exactly one argument for the contract name. " + availableContractNamesMessage) + panic( + "TestDeployContract requires exactly one argument for the contract name. " + availableContractNamesMessage, + ) } contractName := args[0] From 132a29a287918e0a2ae011d85b7f9037b3083533 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 3 Jun 2024 11:09:33 +0200 Subject: [PATCH 4/4] changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index d4595d2891..1e2a568b14 100644 --- a/changelog.md +++ b/changelog.md @@ -47,6 +47,7 @@ * [2199](https://github.com/zeta-chain/node/pull/2199) - custom priority mempool unit tests * [2240](https://github.com/zeta-chain/node/pull/2240) - removed hard-coded Bitcoin regnet chainID in E2E withdraw tests * [2266](https://github.com/zeta-chain/node/pull/2266) - try fixing E2E test `crosschain_swap` failure `btc transaction not signed` +* [2299](https://github.com/zeta-chain/node/pull/2299) - add `zetae2e` command to deploy test contracts ### Fixes