diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index f5030b1152..4390bd1ede 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -168,6 +168,7 @@ jobs: - make-target: "start-tss-migration-test" runs-on: ubuntu-20.04 run: ${{ needs.matrix-conditionals.outputs.TSS_MIGRATION_TESTS == 'true' }} + timeout-minutes: 40 - make-target: "start-solana-test" runs-on: ubuntu-20.04 run: ${{ needs.matrix-conditionals.outputs.SOLANA_TESTS == 'true' }} diff --git a/Makefile b/Makefile index 51931ea89b..6328a808a1 100644 --- a/Makefile +++ b/Makefile @@ -262,7 +262,8 @@ start-stress-test: zetanode cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile stress -f docker-compose.yml up -d start-tss-migration-test: zetanode - @echo "--> Starting migration test" + @echo "--> Starting tss migration test" + export LOCALNET_MODE=tss-migrate && \ export E2E_ARGS="--test-tss-migration" && \ cd contrib/localnet/ && $(DOCKER_COMPOSE) up -d diff --git a/changelog.md b/changelog.md index d6791e1659..98a09fb06e 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,7 @@ ### Tests +* [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 ### Fixes diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 3d923b32a8..ca345a86ca 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -9,7 +9,6 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" - "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config" @@ -439,7 +438,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) { logger.Print("โœ… e2e tests completed in %s", time.Since(testStartTime).String()) if testTSSMigration { - runTSSMigrationTest(deployerRunner, logger, verbose, conf) + TSSMigration(deployerRunner, logger, verbose, conf) } // Verify that there are no trackers left over after tests complete if !skipTrackerCheck { @@ -496,48 +495,6 @@ func waitKeygenHeight( } } -func runTSSMigrationTest(deployerRunner *runner.E2ERunner, logger *runner.Logger, verbose bool, conf config.Config) { - migrationStartTime := time.Now() - logger.Print("๐Ÿ starting tss migration") - - response, err := deployerRunner.CctxClient.LastZetaHeight( - deployerRunner.Ctx, - &crosschaintypes.QueryLastZetaHeightRequest{}, - ) - require.NoError(deployerRunner, err) - err = deployerRunner.ZetaTxServer.UpdateKeygen(response.Height) - require.NoError(deployerRunner, err) - - // Generate new TSS - waitKeygenHeight(deployerRunner.Ctx, deployerRunner.CctxClient, deployerRunner.ObserverClient, logger, 0) - - // migration test is a blocking thread, we cannot run other tests in parallel - // The migration test migrates funds to a new TSS and then updates the TSS address on zetacore. - // The necessary restarts are done by the zetaclient supervisor - fn := migrationTestRoutine(conf, deployerRunner, verbose, e2etests.TestMigrateTSSName) - - if err := fn(); err != nil { - logger.Print("โŒ %v", err) - logger.Print("โŒ tss migration failed") - os.Exit(1) - } - - logger.Print("โœ… migration completed in %s ", time.Since(migrationStartTime).String()) - logger.Print("๐Ÿ starting post migration tests") - - tests := []string{ - e2etests.TestBitcoinWithdrawSegWitName, - e2etests.TestEtherWithdrawName, - } - fn = postMigrationTestRoutine(conf, deployerRunner, verbose, tests...) - - if err := fn(); err != nil { - logger.Print("โŒ %v", err) - logger.Print("โŒ post migration tests failed") - os.Exit(1) - } -} - func must[T any](v T, err error) T { return testutil.Must(v, err) } diff --git a/cmd/zetae2e/local/migration.go b/cmd/zetae2e/local/migration.go index d6fab1b709..27d9682990 100644 --- a/cmd/zetae2e/local/migration.go +++ b/cmd/zetae2e/local/migration.go @@ -11,8 +11,8 @@ import ( "github.com/zeta-chain/zetacore/e2e/runner" ) -// migrationTestRoutine runs migration related e2e tests -func migrationTestRoutine( +// migrationRoutine runs migration related e2e tests +func migrationRoutine( conf config.Config, deployerRunner *runner.E2ERunner, verbose bool, diff --git a/cmd/zetae2e/local/post_migration.go b/cmd/zetae2e/local/post_migration.go deleted file mode 100644 index f339ce0bc1..0000000000 --- a/cmd/zetae2e/local/post_migration.go +++ /dev/null @@ -1,58 +0,0 @@ -package local - -import ( - "time" - - "github.com/fatih/color" - "github.com/pkg/errors" - - "github.com/zeta-chain/zetacore/e2e/config" - "github.com/zeta-chain/zetacore/e2e/e2etests" - "github.com/zeta-chain/zetacore/e2e/runner" -) - -// postMigrationTestRoutine runs post migration tests -func postMigrationTestRoutine( - conf config.Config, - deployerRunner *runner.E2ERunner, - verbose bool, - testNames ...string, -) func() error { - return func() (err error) { - account := conf.AdditionalAccounts.UserBitcoin - // initialize runner for post migration test - postMigrationRunner, err := initTestRunner( - "postMigration", - conf, - deployerRunner, - account, - runner.NewLogger(verbose, color.FgMagenta, "postMigrationRunner"), - ) - if err != nil { - return err - } - - postMigrationRunner.Logger.Print("๐Ÿƒ starting postMigration tests") - startTime := time.Now() - - testsToRun, err := postMigrationRunner.GetE2ETestsToRunByName( - e2etests.AllE2ETests, - testNames..., - ) - if err != nil { - return errors.Wrap(err, "postMigrationRunner tests failed") - } - - if err := postMigrationRunner.RunE2ETests(testsToRun); err != nil { - return errors.Wrap(err, "postMigrationRunner tests failed") - } - - if err := postMigrationRunner.CheckBtcTSSBalance(); err != nil { - return err - } - - postMigrationRunner.Logger.Print("๐Ÿพ PostMigration tests completed in %s", time.Since(startTime).String()) - - return err - } -} diff --git a/cmd/zetae2e/local/tss_migration.go b/cmd/zetae2e/local/tss_migration.go new file mode 100644 index 0000000000..a7acf80daa --- /dev/null +++ b/cmd/zetae2e/local/tss_migration.go @@ -0,0 +1,43 @@ +package local + +import ( + "os" + "time" + + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/e2e/config" + "github.com/zeta-chain/zetacore/e2e/e2etests" + "github.com/zeta-chain/zetacore/e2e/runner" + crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" +) + +func TSSMigration(deployerRunner *runner.E2ERunner, logger *runner.Logger, verbose bool, conf config.Config) { + migrationStartTime := time.Now() + logger.Print("๐Ÿ starting tss migration") + + response, err := deployerRunner.CctxClient.LastZetaHeight( + deployerRunner.Ctx, + &crosschaintypes.QueryLastZetaHeightRequest{}, + ) + require.NoError(deployerRunner, err) + err = deployerRunner.ZetaTxServer.UpdateKeygen(response.Height) + require.NoError(deployerRunner, err) + + // Generate new TSS + waitKeygenHeight(deployerRunner.Ctx, deployerRunner.CctxClient, deployerRunner.ObserverClient, logger, 0) + + // 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) + + if err := fn(); err != nil { + logger.Print("โŒ %v", err) + logger.Print("โŒ tss migration failed") + os.Exit(1) + } + deployerRunner.UpdateTssAddressForConnector() + deployerRunner.UpdateTssAddressForErc20custody() + logger.Print("โœ… migration completed in %s ", time.Since(migrationStartTime).String()) +} diff --git a/contrib/localnet/orchestrator/start-zetae2e.sh b/contrib/localnet/orchestrator/start-zetae2e.sh index 4ee8192c6d..c3adda9753 100644 --- a/contrib/localnet/orchestrator/start-zetae2e.sh +++ b/contrib/localnet/orchestrator/start-zetae2e.sh @@ -107,6 +107,45 @@ fi ### Run zetae2e command depending on the option passed +# Mode migrate is used to run the e2e tests before and after the TSS migration +# It runs the e2e tests with the migrate flag which triggers a TSS migration at the end of the tests. Once the migrationis done the first e2e test is complete +# The second e2e test is run after the migration to ensure the network is still working as expected with the new tss address +if [ "$LOCALNET_MODE" == "tss-migrate" ]; then + if [[ ! -f deployed.yml ]]; then + zetae2e local $E2E_ARGS --setup-only --config config.yml --config-out deployed.yml --skip-header-proof + if [ $? -ne 0 ]; then + echo "e2e setup failed" + exit 1 + fi + else + echo "skipping e2e setup because it has already been completed" + fi + + echo "running e2e test before migrating TSS" + zetae2e local $E2E_ARGS --skip-setup --config deployed.yml --skip-header-proof + if [ $? -ne 0 ]; then + echo "first e2e failed" + exit 1 + fi + + echo "waiting 10 seconds for node to restart" + sleep 10 + + zetae2e local --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof + ZETAE2E_EXIT_CODE=$? + if [ $ZETAE2E_EXIT_CODE -eq 0 ]; then + echo "E2E passed after migration" + exit 0 + else + echo "E2E failed after migration" + exit 1 + fi +fi + + +# Mode upgrade is used to run the e2e tests before and after the upgrade +# It runs the e2e tests , waits for the upgrade height to be reached, and then runs the e2e tests again once the ungrade is done. +# The second e2e test is run after the upgrade to ensure the network is still working as expected with the new version if [ "$LOCALNET_MODE" == "upgrade" ]; then # Run the e2e tests, then restart zetaclientd at upgrade height and run the e2e tests again @@ -185,8 +224,7 @@ if [ "$LOCALNET_MODE" == "upgrade" ]; then fi else - - # Run the e2e tests normally + # If no mode is passed, run the e2e tests normally echo "running e2e setup..." if [[ ! -f deployed.yml ]]; then diff --git a/e2e/e2etests/test_crosschain_swap.go b/e2e/e2etests/test_crosschain_swap.go index 798958a652..f41d3d8372 100644 --- a/e2e/e2etests/test_crosschain_swap.go +++ b/e2e/e2etests/test_crosschain_swap.go @@ -15,6 +15,8 @@ import ( ) func TestCrosschainSwap(r *runner.E2ERunner, _ []string) { + stop := r.MineBlocksIfLocalBitcoin() + defer stop() r.ZEVMAuth.GasLimit = 10000000 // TODO: move into setup and skip it if already initialized @@ -23,7 +25,7 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) { // if the tx fails due to already initialized, it will be ignored _, err := r.UniswapV2Factory.CreatePair(r.ZEVMAuth, r.ERC20ZRC20Addr, r.BTCZRC20Addr) if err != nil { - r.Logger.Print("โ„น๏ธcreate pair error") + r.Logger.Print("โ„น๏ธ create pair error") } txERC20ZRC20Approve, err := r.ERC20ZRC20.Approve(r.ZEVMAuth, r.UniswapV2RouterAddr, big.NewInt(1e18)) @@ -90,10 +92,6 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) { _, err = r.GenerateToAddressIfLocalBitcoin(10, r.BTCDeployerAddress) require.NoError(r, err) - // mine blocks if testing on regnet - stop := r.MineBlocksIfLocalBitcoin() - defer stop() - // cctx1 index acts like the inboundHash for the second cctx (the one that withdraws BTC) cctx2 := utils.WaitCctxMinedByInboundHash(r.Ctx, cctx1.Index, r.CctxClient, r.Logger, r.CctxTimeout) @@ -145,7 +143,9 @@ func TestCrosschainSwap(r *runner.E2ERunner, _ []string) { r.Logger.Info("memo length %d", len(memo)) amount := 0.1 - txid, err := r.SendToTSSFromDeployerWithMemo(amount, utxos[1:2], memo) + utxos, err = r.ListDeployerUTXOs() + require.NoError(r, err) + txid, err := r.SendToTSSFromDeployerWithMemo(amount, utxos[0:1], memo) require.NoError(r, err) cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, txid.String(), r.CctxClient, r.Logger, r.CctxTimeout) diff --git a/e2e/e2etests/test_message_passing_external_chains_revert_fail.go b/e2e/e2etests/test_message_passing_external_chains_revert_fail.go index 8504aaca56..47957e5678 100644 --- a/e2e/e2etests/test_message_passing_external_chains_revert_fail.go +++ b/e2e/e2etests/test_message_passing_external_chains_revert_fail.go @@ -65,7 +65,6 @@ func TestMessagePassingRevertFailExternalChains(r *runner.E2ERunner, args []stri r.Logger.Info(" Zeta Value: %d", sentLog.ZetaValueAndGas) } } - // expect revert tx to fail cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, receipt.TxHash.String(), r.CctxClient, r.Logger, r.CctxTimeout) receipt, err = r.EVMClient.TransactionReceipt(r.Ctx, ethcommon.HexToHash(cctx.GetCurrentOutboundParam().Hash)) diff --git a/e2e/e2etests/test_migrate_tss.go b/e2e/e2etests/test_migrate_tss.go index c1bb79c062..cc7286360b 100644 --- a/e2e/e2etests/test_migrate_tss.go +++ b/e2e/e2etests/test_migrate_tss.go @@ -159,7 +159,6 @@ func TestMigrateTSS(r *runner.E2ERunner, _ []string) { require.LessOrEqual(r, btcTSSBalanceNew*1e8, btcTSSBalanceOld*1e8) // ETH - r.TSSAddress = common.HexToAddress(newTss.Eth) ethTSSBalanceNew, err := r.EVMClient.BalanceAt(context.Background(), r.TSSAddress, nil) require.NoError(r, err) diff --git a/e2e/e2etests/test_zrc20_swap.go b/e2e/e2etests/test_zrc20_swap.go index 14febbe800..3008904306 100644 --- a/e2e/e2etests/test_zrc20_swap.go +++ b/e2e/e2etests/test_zrc20_swap.go @@ -19,7 +19,7 @@ func TestZRC20Swap(r *runner.E2ERunner, _ []string) { // if the tx fails due to already initialized, it will be ignored tx, err := r.UniswapV2Factory.CreatePair(r.ZEVMAuth, r.ERC20ZRC20Addr, r.ETHZRC20Addr) if err != nil { - r.Logger.Print("โ„น๏ธcreate pair error") + r.Logger.Print("โ„น๏ธ create pair error") } else { utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) } diff --git a/e2e/runner/admin_evm.go b/e2e/runner/admin_evm.go new file mode 100644 index 0000000000..8b357a01f5 --- /dev/null +++ b/e2e/runner/admin_evm.go @@ -0,0 +1,38 @@ +package runner + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/stretchr/testify/require" + + "github.com/zeta-chain/zetacore/e2e/utils" +) + +func (r *E2ERunner) UpdateTssAddressForConnector() { + require.NoError(r, r.SetTSSAddresses()) + + tx, err := r.ConnectorEth.UpdateTssAddress(r.EVMAuth, r.TSSAddress) + require.NoError(r, err) + r.Logger.Info(fmt.Sprintf("TSS Address Update Tx: %s", tx.Hash().String())) + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + utils.RequireTxSuccessful(r, receipt) + + tssAddressOnConnector, err := r.ConnectorEth.TssAddress(&bind.CallOpts{Context: r.Ctx}) + require.NoError(r, err) + require.Equal(r, r.TSSAddress, tssAddressOnConnector) +} + +func (r *E2ERunner) UpdateTssAddressForErc20custody() { + require.NoError(r, r.SetTSSAddresses()) + + tx, err := r.ERC20Custody.UpdateTSSAddress(r.EVMAuth, r.TSSAddress) + require.NoError(r, err) + r.Logger.Info(fmt.Sprintf("TSS ERC20 Address Update Tx: %s", tx.Hash().String())) + receipt := utils.MustWaitForTxReceipt(r.Ctx, r.EVMClient, tx, r.Logger, r.ReceiptTimeout) + utils.RequireTxSuccessful(r, receipt) + + tssAddressOnCustody, err := r.ERC20Custody.TSSAddress(&bind.CallOpts{Context: r.Ctx}) + require.NoError(r, err) + require.Equal(r, r.TSSAddress, tssAddressOnCustody) +} diff --git a/e2e/utils/zetacore.go b/e2e/utils/zetacore.go index 9122860d75..b69d9fbc32 100644 --- a/e2e/utils/zetacore.go +++ b/e2e/utils/zetacore.go @@ -19,8 +19,11 @@ const ( EmergencyPolicyName = "emergency" AdminPolicyName = "admin" OperationalPolicyName = "operational" + // The timeout was increased from 4 to 6 , which allows for a higher success in test runs + // However this needs to be researched as to why the increase in timeout was needed. + // https://github.com/zeta-chain/node/issues/2690 - DefaultCctxTimeout = 6 * time.Minute + DefaultCctxTimeout = 8 * time.Minute ) // WaitCctxMinedByInboundHash waits until cctx is mined; returns the cctxIndex (the last one) diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds.go b/x/crosschain/keeper/msg_server_migrate_tss_funds.go index 7d48b48cdb..f1f625571a 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds.go @@ -106,6 +106,12 @@ func (k Keeper) initiateMigrateTSSFundsCCTX( return err } + // Set the CCTX and the nonce for the outbound migration + err = k.SetObserverOutboundInfo(ctx, chainID, &cctx) + if err != nil { + return errorsmod.Wrap(types.ErrUnableToSetOutboundInfo, err.Error()) + } + // The migrate funds can be run again to update the migration cctx index if the migration fails // This should be used after carefully calculating the amount again existingMigrationInfo, found := k.zetaObserverKeeper.GetFundMigrator(ctx, chainID) diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go index a715fcf4e6..93e9a8fb98 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go @@ -26,6 +26,7 @@ func setupTssMigrationParams( amount sdkmath.Uint, setNewTss bool, setCurrentTSS bool, + setChainNonces bool, ) (string, string) { zk.ObserverKeeper.SetCrosschainFlags(ctx, observertypes.CrosschainFlags{ IsInboundEnabled: false, @@ -70,10 +71,12 @@ func setupTssMigrationParams( PriorityFees: []uint64{100, 300, 200}, MedianIndex: 1, }) - k.GetObserverKeeper().SetChainNonces(ctx, observertypes.ChainNonces{ - ChainId: chain.ChainId, - Nonce: 1, - }) + if setChainNonces { + k.GetObserverKeeper().SetChainNonces(ctx, observertypes.ChainNonces{ + ChainId: chain.ChainId, + Nonce: 1, + }) + } indexString := crosschaintypes.GetTssMigrationCCTXIndexString( currentTss.TssPubkey, newTss.TssPubkey, @@ -98,7 +101,7 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) - indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true) + indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true, true) gp, priorityFee, found := k.GetMedianGasValues(ctx, chain.ChainId) require.True(t, found) msg := crosschaintypes.MsgMigrateTssFunds{ @@ -134,7 +137,7 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) { authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) msgServer := keeper.NewMsgServerImpl(*k) - indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true) + indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true, true) gp, priorityFee, found := k.GetMedianGasValues(ctx, chain.ChainId) require.True(t, found) @@ -373,7 +376,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) - indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true) + indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true, true) msg := crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -405,7 +408,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) msgServer := keeper.NewMsgServerImpl(*k) - indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true) + indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true, true) msg := crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -433,7 +436,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) msgServer := keeper.NewMsgServerImpl(*k) - indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, false, true) + indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, false, true, true) msg := crosschaintypes.MsgMigrateTssFunds{ Creator: admin, @@ -460,7 +463,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) msgServer := keeper.NewMsgServerImpl(*k) - indexString, tssPubkey := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true) + indexString, tssPubkey := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true, true) k.GetObserverKeeper().SetPendingNonces(ctx, observertypes.PendingNonces{ NonceLow: 1, NonceHigh: 10, @@ -483,7 +486,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { require.False(t, found) }) - t.Run("unable to migrate funds when a pending cctx is presnt in migration info", func(t *testing.T) { + t.Run("unable to migrate funds when a pending cctx is present in migration info", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ UseAuthorityMock: true, }) @@ -494,7 +497,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) msgServer := keeper.NewMsgServerImpl(*k) - indexString, tssPubkey := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true) + indexString, tssPubkey := setupTssMigrationParams(zk, k, ctx, chain, amount, true, true, true) k.GetObserverKeeper().SetPendingNonces(ctx, observertypes.PendingNonces{ NonceLow: 1, NonceHigh: 1, @@ -541,7 +544,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) - indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, false, false) + indexString, _ := setupTssMigrationParams(zk, k, ctx, chain, amount, false, false, true) currentTss, found := k.GetObserverKeeper().GetTSS(ctx) require.True(t, found) newTss := sample.Tss() @@ -565,4 +568,29 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { require.False(t, found) }, ) + + t.Run("unable to process migration if SetObserverOutboundInfo fails", func(t *testing.T) { + k, ctx, _, zk := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseAuthorityMock: true, + }) + + admin := sample.AccAddress() + chain := getValidEthChain() + amount := sdkmath.NewUintFromString("10000000000000000000") + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + + msgServer := keeper.NewMsgServerImpl(*k) + + _, _ = setupTssMigrationParams(zk, k, ctx, chain, amount, true, true, false) + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) + keepertest.MockGetChainListEmpty(&authorityMock.Mock) + + _, err := msgServer.MigrateTssFunds(ctx, &msg) + require.ErrorContains(t, err, crosschaintypes.ErrUnableToSetOutboundInfo.Error()) + }) } diff --git a/x/crosschain/types/cmd_cctxs.go b/x/crosschain/types/cmd_cctxs.go index 3f416c6d7d..5ba7495d22 100644 --- a/x/crosschain/types/cmd_cctxs.go +++ b/x/crosschain/types/cmd_cctxs.go @@ -250,7 +250,7 @@ func MigrateFundCmdCCTX( gasLimit, gasPrice, priorityFee.MulUint64(2).String(), - newTSSPubKey, + currentTSSPubKey, ), nil } diff --git a/x/crosschain/types/errors.go b/x/crosschain/types/errors.go index 279442d2c7..40182fe313 100644 --- a/x/crosschain/types/errors.go +++ b/x/crosschain/types/errors.go @@ -55,6 +55,7 @@ var ( 1156, "migration tx from an old tss address detected", ) - ErrValidatingInbound = errorsmod.Register(ModuleName, 1157, "unable to validate inbound") - ErrInvalidGasLimit = errorsmod.Register(ModuleName, 1158, "invalid gas limit") + ErrValidatingInbound = errorsmod.Register(ModuleName, 1157, "unable to validate inbound") + ErrInvalidGasLimit = errorsmod.Register(ModuleName, 1158, "invalid gas limit") + ErrUnableToSetOutboundInfo = errorsmod.Register(ModuleName, 1159, "unable to set outbound info") )