Skip to content

Commit

Permalink
add unit test for failed to set outbound info
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Aug 20, 2024
1 parent 6f63131 commit b66c368
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
3 changes: 0 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/msg_server_migrate_tss_funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 41 additions & 13 deletions x/crosschain/keeper/msg_server_migrate_tss_funds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
})
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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())
})
}
5 changes: 3 additions & 2 deletions x/crosschain/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

0 comments on commit b66c368

Please sign in to comment.