Skip to content

Commit f4366ad

Browse files
authored
test(e2e): add a test to deploy contracts (#2299)
* deploy e2e test * add deploy e2e test to list * make generate * changelog
1 parent 833a253 commit f4366ad

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* [2199](https://github.com/zeta-chain/node/pull/2199) - custom priority mempool unit tests
4949
* [2240](https://github.com/zeta-chain/node/pull/2240) - removed hard-coded Bitcoin regnet chainID in E2E withdraw tests
5050
* [2266](https://github.com/zeta-chain/node/pull/2266) - try fixing E2E test `crosschain_swap` failure `btc transaction not signed`
51+
* [2299](https://github.com/zeta-chain/node/pull/2299) - add `zetae2e` command to deploy test contracts
5152

5253
### Fixes
5354

e2e/e2etests/e2etests.go

+17
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ const (
9898
TestUpdateBytecodeZRC20Name = "update_bytecode_zrc20"
9999
TestUpdateBytecodeConnectorName = "update_bytecode_connector"
100100
TestRateLimiterName = "rate_limiter"
101+
102+
/*
103+
Special tests
104+
Not used to test functionalities but do various interactions with the netwoks
105+
*/
106+
TestDeploy = "deploy"
101107
)
102108

103109
// AllE2ETests is an ordered list of all e2e tests
@@ -507,4 +513,15 @@ var AllE2ETests = []runner.E2ETest{
507513
[]runner.ArgDefinition{},
508514
TestRateLimiter,
509515
),
516+
/*
517+
Special tests
518+
*/
519+
runner.NewE2ETest(
520+
TestDeploy,
521+
"deploy a contract",
522+
[]runner.ArgDefinition{
523+
{Description: "contract name", DefaultValue: ""},
524+
},
525+
TestDeployContract,
526+
),
510527
}

e2e/e2etests/test_deploy_contract.go

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package e2etests
2+
3+
import (
4+
"fmt"
5+
6+
ethcommon "github.com/ethereum/go-ethereum/common"
7+
8+
"github.com/zeta-chain/zetacore/e2e/contracts/testdapp"
9+
"github.com/zeta-chain/zetacore/e2e/runner"
10+
"github.com/zeta-chain/zetacore/e2e/utils"
11+
)
12+
13+
// deployFunc is a function that deploys a contract
14+
type deployFunc func(r *runner.E2ERunner) (ethcommon.Address, error)
15+
16+
// deployMap maps contract names to deploy functions
17+
var deployMap = map[string]deployFunc{
18+
"testdapp_zevm": deployZEVMTestDApp,
19+
"testdapp_evm": deployEVMTestDApp,
20+
}
21+
22+
// TestDeployContract deploys the specified contract
23+
func TestDeployContract(r *runner.E2ERunner, args []string) {
24+
availableContractNames := make([]string, 0, len(deployMap))
25+
for contractName := range deployMap {
26+
availableContractNames = append(availableContractNames, contractName)
27+
}
28+
availableContractNamesMessage := fmt.Sprintf("Available contract names: %v", availableContractNames)
29+
30+
if len(args) != 1 {
31+
panic(
32+
"TestDeployContract requires exactly one argument for the contract name. " + availableContractNamesMessage,
33+
)
34+
}
35+
contractName := args[0]
36+
37+
deployFunc, ok := deployMap[contractName]
38+
if !ok {
39+
panic(fmt.Sprintf("Unknown contract name: %s, %s", contractName, availableContractNamesMessage))
40+
}
41+
42+
addr, err := deployFunc(r)
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
r.Logger.Print("%s deployed at %s", contractName, addr.Hex())
48+
}
49+
50+
// deployZEVMTestDApp deploys the TestDApp contract on ZetaChain
51+
func deployZEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) {
52+
addr, tx, _, err := testdapp.DeployTestDApp(
53+
r.ZEVMAuth,
54+
r.ZEVMClient,
55+
r.ConnectorZEVMAddr,
56+
r.WZetaAddr,
57+
)
58+
if err != nil {
59+
return addr, err
60+
}
61+
62+
// Wait for the transaction to be mined
63+
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
64+
if receipt.Status != 1 {
65+
return addr, fmt.Errorf("contract deployment failed")
66+
}
67+
68+
return addr, nil
69+
}
70+
71+
// deployEVMTestDApp deploys the TestDApp contract on Ethereum
72+
func deployEVMTestDApp(r *runner.E2ERunner) (ethcommon.Address, error) {
73+
addr, tx, _, err := testdapp.DeployTestDApp(
74+
r.EVMAuth,
75+
r.EVMClient,
76+
r.ConnectorEthAddr,
77+
r.ZetaEthAddr,
78+
)
79+
if err != nil {
80+
return addr, err
81+
}
82+
83+
// Wait for the transaction to be mined
84+
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout)
85+
if receipt.Status != 1 {
86+
return addr, fmt.Errorf("contract deployment failed")
87+
}
88+
89+
return addr, nil
90+
}

0 commit comments

Comments
 (0)