From b66c36812ff17914032318a14de25fa450e1fd76 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 20 Aug 2024 12:07:37 -0400 Subject: [PATCH] add unit test for failed to set outbound info --- changelog.md | 3 -- .../keeper/msg_server_migrate_tss_funds.go | 2 +- .../msg_server_migrate_tss_funds_test.go | 54 ++++++++++++++----- x/crosschain/types/errors.go | 5 +- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/changelog.md b/changelog.md index 2705b16899..5c6fdc217e 100644 --- a/changelog.md +++ b/changelog.md @@ -22,9 +22,6 @@ ### Tests * [2661](https://github.com/zeta-chain/node/pull/2661) - update connector and erc20Custody addresses in tss migration e2e tests - -### Tests - * [2726](https://github.com/zeta-chain/node/pull/2726) - add e2e tests for deposit and call, deposit and revert ### Fixes diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds.go b/x/crosschain/keeper/msg_server_migrate_tss_funds.go index 16797187b2..f1f625571a 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds.go @@ -109,7 +109,7 @@ func (k Keeper) initiateMigrateTSSFundsCCTX( // Set the CCTX and the nonce for the outbound migration err = k.SetObserverOutboundInfo(ctx, chainID, &cctx) if err != nil { - return errorsmod.Wrap(types.ErrCannotMigrateTssFunds, err.Error()) + return errorsmod.Wrap(types.ErrUnableToSetOutboundInfo, err.Error()) } // The migrate funds can be run again to update the migration cctx index if the migration fails 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/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") )