Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add a test to deploy contracts #2299

Merged
merged 6 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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

Expand Down
17 changes: 17 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
),
}
90 changes: 90 additions & 0 deletions e2e/e2etests/test_deploy_contract.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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
}
Loading