Skip to content

Commit

Permalink
test: add E2E testing for V2 contract migration (#2763)
Browse files Browse the repository at this point in the history
* rename migration into tss migration

* rename post tss migration

* initialize migration function body

* update contract version used

* migration test

* remove migration as test

* add migration option

* generate

* make some fixes

* make generate

* fix gateway address

* fixes

* add some fixes

* Update contrib/localnet/orchestrator/start-zetae2e.sh

Co-authored-by: skosito <[email protected]>

* comments

* changelog

* fix config file

* Update cmd/zetae2e/local/tss_migration.go

Co-authored-by: Dmitry S <[email protected]>

* Update e2e/txserver/authority.go

Co-authored-by: Dmitry S <[email protected]>

* refactor bitcoin error

* fix approval functions

---------

Co-authored-by: skosito <[email protected]>
Co-authored-by: Dmitry S <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2024
1 parent 7b34d1d commit 47a0609
Show file tree
Hide file tree
Showing 29 changed files with 732 additions and 216 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
TSS_MIGRATION_TESTS: ${{ steps.matrix-conditionals.outputs.TSS_MIGRATION_TESTS }}
SOLANA_TESTS: ${{ steps.matrix-conditionals.outputs.SOLANA_TESTS }}
V2_TESTS: ${{ steps.matrix-conditionals.outputs.V2_TESTS }}
V2_MIGRATION_TESTS: ${{ steps.matrix-conditionals.outputs.V2_MIGRATION_TESTS }}
steps:
# use api rather than event context to avoid race conditions (label added after push)
- id: matrix-conditionals
Expand All @@ -62,6 +63,7 @@ jobs:
core.setOutput('TSS_MIGRATION_TESTS', labels.includes('TSS_MIGRATION_TESTS'));
core.setOutput('SOLANA_TESTS', labels.includes('SOLANA_TESTS'));
core.setOutput('V2_TESTS', labels.includes('V2_TESTS')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
core.setOutput('V2_MIGRATION_TESTS', labels.includes('V2_MIGRATION_TESTS')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
} else if (context.eventName === 'merge_group') {
core.setOutput('DEFAULT_TESTS', true);
core.setOutput('UPGRADE_LIGHT_TESTS', true);
Expand All @@ -76,6 +78,7 @@ jobs:
core.setOutput('PERFORMANCE_TESTS', true);
core.setOutput('STATEFUL_DATA_TESTS', true);
core.setOutput('V2_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
core.setOutput('V2_MIGRATION_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
} else if (context.eventName === 'schedule') {
core.setOutput('DEFAULT_TESTS', true);
core.setOutput('UPGRADE_TESTS', true);
Expand All @@ -87,6 +90,7 @@ jobs:
core.setOutput('TSS_MIGRATION_TESTS', true);
core.setOutput('SOLANA_TESTS', true);
core.setOutput('V2_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
core.setOutput('V2_MIGRATION_TESTS', true); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
} else if (context.eventName === 'workflow_dispatch') {
const makeTargets = context.payload.inputs['make-targets'].split(',');
core.setOutput('DEFAULT_TESTS', makeTargets.includes('default-test'));
Expand All @@ -99,6 +103,7 @@ jobs:
core.setOutput('TSS_MIGRATION_TESTS', makeTargets.includes('tss-migration-test'));
core.setOutput('SOLANA_TESTS', makeTargets.includes('solana-test'));
core.setOutput('V2_TESTS', makeTargets.includes('v2-test')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
core.setOutput('V2_MIGRATION_TESTS', makeTargets.includes('v2-migration-test')); // for v2 tests, TODO: remove this once we fully migrate to v2 (https://github.com/zeta-chain/node/issues/2627)
}
e2e:
Expand Down Expand Up @@ -140,6 +145,9 @@ jobs:
- make-target: "start-v2-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.V2_TESTS == 'true' }}
- make-target: "start-upgrade-v2-migration-test"
runs-on: ubuntu-20.04
run: ${{ needs.matrix-conditionals.outputs.V2_MIGRATION_TESTS == 'true' }}
name: ${{ matrix.make-target }}
uses: ./.github/workflows/reusable-e2e.yml
with:
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ start-upgrade-test-admin: zetanode-upgrade
export E2E_ARGS="--skip-regular --test-admin" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile upgrade -f docker-compose.yml -f docker-compose-upgrade.yml up -d

# this test upgrades from v18 and execute the v2 contracts migration process
# this tests is part of upgrade test part because it should run the upgrade from v18 to fully replicate the upgrade process
start-upgrade-v2-migration-test: zetanode-upgrade
@echo "--> Starting v2 migration upgrade test"
export LOCALNET_MODE=upgrade && \
export UPGRADE_HEIGHT=90 && \
export E2E_ARGS="--test-v2-migration" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile upgrade -f docker-compose.yml -f docker-compose-upgrade.yml up -d


start-upgrade-import-mainnet-test: zetanode-upgrade
@echo "--> Starting import-data upgrade test"
export LOCALNET_MODE=upgrade && \
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [2661](https://github.com/zeta-chain/node/pull/2661) - update connector and erc20Custody addresses in tss migration e2e tests
* [2726](https://github.com/zeta-chain/node/pull/2726) - add e2e tests for deposit and call, deposit and revert
* [2703](https://github.com/zeta-chain/node/pull/2703) - add e2e tests for stateful precompiled contracts
* [2763](https://github.com/zeta-chain/node/pull/2763) - add V2 contracts migration test

### Fixes

Expand Down
16 changes: 16 additions & 0 deletions cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ additional_accounts:
bech32_address: "zeta1k4f0l2e9qqjccxnstwj0uaarxvn44lj990she9"
evm_address: "0xb552FFAb2500258C1A705Ba4Fe77A333275AFE45"
private_key: "bd6b74387f11b31d21e87c2ae7a23ec269aee08a355dad6c508a6fceb79d1f48"
user_v2_ether:
bech32_address: "zeta1erlqlpl5da7a9r3emzw60kax9fxc3h0r3z7c5e"
evm_address: "0xC8fe0F87f46F7Dd28e39D89Da7Dba62A4D88dde3"
private_key: "11c25af71c82602a681ce622bf76f4f0fbc3b7f23ce935db6249d1517322f436"
user_v2_erc20:
bech32_address: "zeta12wp6syndml6jd32m7f9mn2wscsxz6cff8nczl4"
evm_address: "0x5383A8126ddff526C55bF24Bb9a9D0c40c2d6129"
private_key: "77b0e4dcc29c5c47b6999dabd42abcfdf7750ccc86d6659c1373ec1ea3b4af6c"
user_v2_ether_revert:
bech32_address: "zeta1m7m5xd79x9qmlyfpqxcwuac04r3dewfpdcfw5e"
evm_address: "0xdFb74337c53141bf912101b0Ee770FA8e2DCB921"
private_key: "be7098604cc40f95d68298a3b4ae13972ac8a3df271ba19ddf169070d30e8ba8"
user_v2_erc20_revert:
bech32_address: "zeta1nry9yeg6njhjrp2ctppa8558vqxal9fxk69zxg"
evm_address: "0x98c852651A9CAF2185585843d3D287600Ddf9526"
private_key: "bf9456c679bb5a952a9a137fcfc920e0413efdb97c36de1e57455763084230cb"
policy_accounts:
emergency_policy_account:
bech32_address: "zeta16m2cnrdwtgweq4njc6t470vl325gw4kp6s7tap"
Expand Down
74 changes: 17 additions & 57 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
flagSkipBitcoinSetup = "skip-bitcoin-setup"
flagSkipHeaderProof = "skip-header-proof"
flagTestV2 = "test-v2"
flagTestV2Migration = "test-v2-migration"
flagSkipTrackerCheck = "skip-tracker-check"
flagSkipPrecompiles = "skip-precompiles"
)
Expand Down Expand Up @@ -76,12 +77,15 @@ func NewLocalCmd() *cobra.Command {
cmd.Flags().Bool(flagSkipHeaderProof, false, "set to true to skip header proof tests")
cmd.Flags().Bool(flagTestTSSMigration, false, "set to true to include a migration test at the end")
cmd.Flags().Bool(flagTestV2, false, "set to true to run tests for v2 contracts")
cmd.Flags().Bool(flagTestV2Migration, false, "set to true to run tests for v2 contracts migration test")
cmd.Flags().Bool(flagSkipTrackerCheck, false, "set to true to skip tracker check at the end of the tests")
cmd.Flags().Bool(flagSkipPrecompiles, false, "set to true to skip stateful precompiled contracts test")

return cmd
}

// TODO: simplify this file: put the different type of tests in separate files
// https://github.com/zeta-chain/node/issues/2762
func localE2ETest(cmd *cobra.Command, _ []string) {
// fetch flags
var (
Expand All @@ -102,6 +106,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
skipTrackerCheck = must(cmd.Flags().GetBool(flagSkipTrackerCheck))
testTSSMigration = must(cmd.Flags().GetBool(flagTestTSSMigration))
testV2 = must(cmd.Flags().GetBool(flagTestV2))
testV2Migration = must(cmd.Flags().GetBool(flagTestV2Migration))
skipPrecompiles = must(cmd.Flags().GetBool(flagSkipPrecompiles))
)

Expand Down Expand Up @@ -235,6 +240,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
os.Exit(0)
}

// run the v2 migration
if testV2Migration {
deployerRunner.RunV2Migration()
}

// run tests
var eg errgroup.Group

Expand Down Expand Up @@ -338,7 +348,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {

// TestMigrateChainSupportName tests EVM chain migration. Currently this test doesn't work with Anvil because pre-EIP1559 txs are not supported
// See issue below for details
// TODO: renenable this test as per the issue below
// TODO: reenable this test as per the issue below
// https://github.com/zeta-chain/node/issues/1980
// e2etests.TestMigrateChainSupportName,
))
Expand All @@ -363,65 +373,15 @@ 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()

//// Test happy paths for gas token workflow
eg.Go(v2TestRoutine(conf, "eth", conf.AdditionalAccounts.UserEther, color.FgHiGreen, deployerRunner, verbose,
e2etests.TestV2ETHDepositName,
e2etests.TestV2ETHDepositAndCallName,
e2etests.TestV2ETHWithdrawName,
e2etests.TestV2ETHWithdrawAndCallName,
e2etests.TestV2ZEVMToEVMCallName,
e2etests.TestV2EVMToZEVMCallName,
))

//// Test happy paths for erc20 token workflow
eg.Go(v2TestRoutine(conf, "erc20", conf.AdditionalAccounts.UserERC20, color.FgHiBlue, deployerRunner, verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM
e2etests.TestV2ERC20DepositName,
e2etests.TestV2ERC20DepositAndCallName,
e2etests.TestV2ERC20WithdrawName,
e2etests.TestV2ERC20WithdrawAndCallName,
))
// note: not run in testV2Migration because it is already run in the migration process
deployerRunner.UpdateChainParamsV2Contracts()
}

// Test revert cases for gas token workflow
eg.Go(
v2TestRoutine(
conf,
"eth-revert",
conf.AdditionalAccounts.UserZetaTest,
color.FgHiYellow,
deployerRunner,
verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM and withdraw
e2etests.TestV2ETHDepositAndCallRevertName,
e2etests.TestV2ETHDepositAndCallRevertWithCallName,
e2etests.TestV2ETHWithdrawAndCallRevertName,
e2etests.TestV2ETHWithdrawAndCallRevertWithCallName,
),
)

// Test revert cases for erc20 token workflow
eg.Go(
v2TestRoutine(
conf,
"erc20-revert",
conf.AdditionalAccounts.UserBitcoin,
color.FgHiRed,
deployerRunner,
verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM
e2etests.TestV2ERC20DepositName, // necessary to have assets to withdraw
e2etests.TestOperationAddLiquidityETHName, // liquidity with gas and ERC20 are necessary for reverts
e2etests.TestOperationAddLiquidityERC20Name,
e2etests.TestV2ERC20DepositAndCallRevertName,
e2etests.TestV2ERC20DepositAndCallRevertWithCallName,
e2etests.TestV2ERC20WithdrawAndCallRevertName,
e2etests.TestV2ERC20WithdrawAndCallRevertWithCallName,
),
)
if testV2 || testV2Migration {
startV2Tests(&eg, conf, deployerRunner, verbose)
}

// while tests are executed, monitor blocks in parallel to check if system txs are on top and they have biggest priority
Expand Down
63 changes: 0 additions & 63 deletions cmd/zetae2e/local/migration.go

This file was deleted.

55 changes: 54 additions & 1 deletion cmd/zetae2e/local/tss_migration.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package local

import (
"fmt"
"os"
"time"

"github.com/fatih/color"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/config"
Expand All @@ -12,6 +14,57 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

// tssMigrationTestRoutine runs TSS migration related e2e tests
func tssMigrationTestRoutine(
conf config.Config,
deployerRunner *runner.E2ERunner,
verbose bool,
testNames ...string,
) func() error {
return func() (err error) {
account := conf.AdditionalAccounts.UserMigration
// initialize runner for migration test
tssMigrationTestRunner, err := initTestRunner(
"tssMigration",
conf,
deployerRunner,
account,
runner.NewLogger(verbose, color.FgHiGreen, "migration"),
runner.WithZetaTxServer(deployerRunner.ZetaTxServer),
)
if err != nil {
return err
}

tssMigrationTestRunner.Logger.Print("🏃 starting TSS migration tests")
startTime := time.Now()

if len(testNames) == 0 {
tssMigrationTestRunner.Logger.Print("🍾 TSS migration tests completed in %s", time.Since(startTime).String())
return nil
}
// run TSS migration test
testsToRun, err := tssMigrationTestRunner.GetE2ETestsToRunByName(
e2etests.AllE2ETests,
testNames...,
)
if err != nil {
return fmt.Errorf("TSS migration tests failed: %v", err)
}

if err := tssMigrationTestRunner.RunE2ETests(testsToRun); err != nil {
return fmt.Errorf("TSS migration tests failed: %v", err)
}
if err := tssMigrationTestRunner.CheckBtcTSSBalance(); err != nil {
return err
}

tssMigrationTestRunner.Logger.Print("🍾 TSS migration tests completed in %s", time.Since(startTime).String())

return nil
}
}

func TSSMigration(deployerRunner *runner.E2ERunner, logger *runner.Logger, verbose bool, conf config.Config) {
migrationStartTime := time.Now()
logger.Print("🏁 starting tss migration")
Expand All @@ -30,7 +83,7 @@ func TSSMigration(deployerRunner *runner.E2ERunner, logger *runner.Logger, verbo
// Run migration
// migrationRoutine runs migration e2e test , which migrates funds from the older TSS to the new one
// The zetaclient restarts required for this process are managed by the background workers in zetaclient (TSSListener)
fn := migrationRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTSSName)
fn := tssMigrationTestRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTSSName)

if err := fn(); err != nil {
logger.Print("❌ %v", err)
Expand Down
Loading

0 comments on commit 47a0609

Please sign in to comment.