diff --git a/testutil/keeper/authority.go b/testutil/keeper/authority.go index faf4d79829..1e61bf9881 100644 --- a/testutil/keeper/authority.go +++ b/testutil/keeper/authority.go @@ -74,13 +74,9 @@ func AuthorityKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { return &k, ctx } -// MockIsAuthorized mocks the IsAuthorized method of an authority keeper mock -func MockIsAuthorized(m *mock.Mock, address string, policyType types.PolicyType, isAuthorized bool) { - m.On("IsAuthorized", mock.Anything, address, policyType).Return(isAuthorized).Once() -} - -func MockCheckAuthorization(m *mock.Mock, msg sdk.Msg, isAuthorized error) { - m.On("CheckAuthorization", mock.Anything, msg).Return(isAuthorized).Once() +// MockCheckAuthorization mocks the CheckAuthorization method of the authority keeper. +func MockCheckAuthorization(m *mock.Mock, msg sdk.Msg, authorizationResult error) { + m.On("CheckAuthorization", mock.Anything, msg).Return(authorizationResult).Once() } func SetAdminPolicies(ctx sdk.Context, ak *keeper.Keeper) string { diff --git a/x/authority/keeper/msg_server_add_authorization.go b/x/authority/keeper/msg_server_add_authorization.go index ee65edb96a..3c3247fc4e 100644 --- a/x/authority/keeper/msg_server_add_authorization.go +++ b/x/authority/keeper/msg_server_add_authorization.go @@ -17,6 +17,7 @@ func (k msgServer) AddAuthorization( ) (*types.MsgAddAuthorizationResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + // check if the caller is authorized to add an authorization err := k.CheckAuthorization(ctx, msg) if err != nil { return nil, errorsmod.Wrap(types.ErrUnauthorized, err.Error()) diff --git a/x/authority/keeper/msg_server_remove_authorization.go b/x/authority/keeper/msg_server_remove_authorization.go index 0f785667a4..671406429c 100644 --- a/x/authority/keeper/msg_server_remove_authorization.go +++ b/x/authority/keeper/msg_server_remove_authorization.go @@ -18,6 +18,7 @@ func (k msgServer) RemoveAuthorization( ) (*types.MsgRemoveAuthorizationResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + // check if the caller is authorized to remove an authorization err := k.CheckAuthorization(ctx, msg) if err != nil { return nil, errorsmod.Wrap(types.ErrUnauthorized, err.Error()) diff --git a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go index 6699d16cfd..505776c89f 100644 --- a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go +++ b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go @@ -20,11 +20,6 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { msgServer := crosschainkeeper.NewMsgServerImpl(*k) admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - msg := crosschaintypes.MsgAbortStuckCCTX{ - Creator: admin, - CctxIndex: sample.GetCctxIndexFromString("cctx_index"), - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) // create a cctx cctx := sample.CrossChainTx(t, "cctx_index") @@ -35,6 +30,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { k.SetCrossChainTx(ctx, *cctx) // abort the cctx + msg := crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.AbortStuckCCTX(ctx, &msg) require.NoError(t, err) @@ -51,13 +51,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { msgServer := crosschainkeeper.NewMsgServerImpl(*k) admin := sample.AccAddress() - msg := crosschaintypes.MsgAbortStuckCCTX{ - Creator: admin, - CctxIndex: sample.GetCctxIndexFromString("cctx_index"), - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - // create a cctx cctx := sample.CrossChainTx(t, "cctx_index") cctx.CctxStatus = &crosschaintypes.Status{ @@ -67,6 +61,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { k.SetCrossChainTx(ctx, *cctx) // abort the cctx + msg := crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.AbortStuckCCTX(ctx, &msg) require.NoError(t, err) @@ -83,12 +82,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { msgServer := crosschainkeeper.NewMsgServerImpl(*k) admin := sample.AccAddress() - msg := crosschaintypes.MsgAbortStuckCCTX{ - Creator: admin, - CctxIndex: sample.GetCctxIndexFromString("cctx_index"), - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) // create a cctx cctx := sample.CrossChainTx(t, "cctx_index") @@ -99,6 +93,12 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { k.SetCrossChainTx(ctx, *cctx) // abort the cctx + msg := crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), + } + + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.AbortStuckCCTX(ctx, &msg) require.NoError(t, err) @@ -115,12 +115,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { msgServer := crosschainkeeper.NewMsgServerImpl(*k) admin := sample.AccAddress() - msg := crosschaintypes.MsgAbortStuckCCTX{ - Creator: admin, - CctxIndex: sample.GetCctxIndexFromString("cctx_index"), - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) // create a cctx cctx := sample.CrossChainTx(t, "cctx_index") @@ -131,6 +126,12 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { k.SetCrossChainTx(ctx, *cctx) // abort the cctx + msg := crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), + } + + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AbortStuckCCTX(ctx, &msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) }) @@ -143,14 +144,13 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + + // abort the cctx msg := crosschaintypes.MsgAbortStuckCCTX{ Creator: admin, CctxIndex: sample.GetCctxIndexFromString("cctx_index"), } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - - // abort the cctx _, err := msgServer.AbortStuckCCTX(ctx, &msg) require.ErrorIs(t, err, crosschaintypes.ErrCannotFindCctx) }) @@ -163,11 +163,6 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { admin := sample.AccAddress() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - msg := crosschaintypes.MsgAbortStuckCCTX{ - Creator: admin, - CctxIndex: sample.GetCctxIndexFromString("cctx_index"), - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) // create a cctx cctx := sample.CrossChainTx(t, "cctx_index") @@ -178,6 +173,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { k.SetCrossChainTx(ctx, *cctx) // abort the cctx + msg := crosschaintypes.MsgAbortStuckCCTX{ + Creator: admin, + CctxIndex: sample.GetCctxIndexFromString("cctx_index"), + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.AbortStuckCCTX(ctx, &msg) require.ErrorIs(t, err, crosschaintypes.ErrStatusNotPending) }) diff --git a/x/crosschain/keeper/msg_server_add_inbound_tracker_test.go b/x/crosschain/keeper/msg_server_add_inbound_tracker_test.go index cd1688e816..9d135d513d 100644 --- a/x/crosschain/keeper/msg_server_add_inbound_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_inbound_tracker_test.go @@ -32,6 +32,10 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) txHash := "string" chainID := getValidEthChainID() + + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + msg := types.MsgAddInboundTracker{ Creator: nonAdmin, ChainId: chainID, @@ -41,11 +45,7 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { BlockHash: "", TxIndex: 0, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) - observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - _, err := msgServer.AddInboundTracker(ctx, &msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) _, found := k.GetInboundTracker(ctx, chainID, txHash) @@ -60,6 +60,10 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) txHash := "string" chainID := getValidEthChainID() + + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(nil) + msg := types.MsgAddInboundTracker{ Creator: sample.AccAddress(), ChainId: chainID + 1, @@ -69,10 +73,6 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { BlockHash: "", TxIndex: 0, } - - observerMock := keepertest.GetCrosschainObserverMock(t, k) - observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(nil) - _, err := msgServer.AddInboundTracker(ctx, &msg) require.ErrorIs(t, err, observertypes.ErrSupportedChains) _, found := k.GetInboundTracker(ctx, chainID, txHash) @@ -91,6 +91,12 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) txHash := "string" chainID := getValidEthChainID() + + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + + setSupportedChain(ctx, zk, chainID) + msg := types.MsgAddInboundTracker{ Creator: admin, ChainId: chainID, @@ -100,14 +106,9 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { BlockHash: "", TxIndex: 0, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) - observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - - setSupportedChain(ctx, zk, chainID) - _, err := msgServer.AddInboundTracker(ctx, &msg) + require.NoError(t, err) _, found := k.GetInboundTracker(ctx, chainID, txHash) require.True(t, found) @@ -125,6 +126,10 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { observerMock := keepertest.GetCrosschainObserverMock(t, k) txHash := "string" chainID := getValidEthChainID() + + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) + msg := types.MsgAddInboundTracker{ Creator: admin, ChainId: chainID, @@ -134,11 +139,7 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { BlockHash: "", TxIndex: 0, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) - observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) - _, err := msgServer.AddInboundTracker(ctx, &msg) require.NoError(t, err) _, found := k.GetInboundTracker(ctx, chainID, txHash) @@ -159,6 +160,12 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { admin := sample.AccAddress() txHash := "string" chainID := getValidEthChainID() + + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(nil, errors.New("error")) + msg := types.MsgAddInboundTracker{ Creator: admin, ChainId: chainID, @@ -168,13 +175,7 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { BlockHash: "", TxIndex: 0, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) - observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(nil, errors.New("error")) - _, err := msgServer.AddInboundTracker(ctx, &msg) require.ErrorIs(t, err, types.ErrProofVerificationFail) }) @@ -193,6 +194,13 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) txHash := "string" chainID := getValidEthChainID() + + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(sample.Bytes(), nil) + observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(nil, false) + msg := types.MsgAddInboundTracker{ Creator: admin, ChainId: chainID, @@ -202,14 +210,7 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { BlockHash: "", TxIndex: 0, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) - observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(sample.Bytes(), nil) - observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything).Return(nil, false) - _, err := msgServer.AddInboundTracker(ctx, &msg) require.ErrorIs(t, err, types.ErrUnsupportedChain) }) @@ -229,17 +230,7 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { admin := sample.AccAddress() txHash := "string" chainID := getValidEthChainID() - msg := types.MsgAddInboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: txHash, - CoinType: coin.CoinType_Zeta, - Proof: &proofs.Proof{}, - BlockHash: "", - TxIndex: 0, - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). @@ -250,6 +241,16 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { setSupportedChain(ctx, zk, chainID) + msg := types.MsgAddInboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AddInboundTracker(ctx, &msg) require.ErrorIs(t, err, observertypes.ErrTssNotFound) }) @@ -269,17 +270,7 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { admin := sample.AccAddress() txHash := "string" chainID := getValidEthChainID() - msg := types.MsgAddInboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: txHash, - CoinType: coin.CoinType_Zeta, - Proof: &proofs.Proof{}, - BlockHash: "", - TxIndex: 0, - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything). @@ -294,6 +285,16 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { setSupportedChain(ctx, zk, chainID) + msg := types.MsgAddInboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Zeta, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AddInboundTracker(ctx, &msg) require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) }) @@ -311,21 +312,11 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { ethTx, ethTxBytes := sample.EthTx(t, chainID, tssAddress, 42) admin := sample.AccAddress() txHash := ethTx.Hash().Hex() - msg := types.MsgAddInboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: txHash, - CoinType: coin.CoinType_Gas, // use coin types gas: the receiver must be the tss address - Proof: &proofs.Proof{}, - BlockHash: "", - TxIndex: 0, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) observerMock := keepertest.GetCrosschainObserverMock(t, k) lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) observerMock.On("GetChainParamsByChainID", mock.Anything, mock.Anything). @@ -336,6 +327,16 @@ func TestMsgServer_AddToInboundTracker(t *testing.T) { lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(ethTxBytes, nil) + msg := types.MsgAddInboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + CoinType: coin.CoinType_Gas, // use coin types gas: the receiver must be the tss address + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AddInboundTracker(ctx, &msg) require.NoError(t, err) _, found := k.GetInboundTracker(ctx, chainID, txHash) diff --git a/x/crosschain/keeper/msg_server_add_outbound_tracker_test.go b/x/crosschain/keeper/msg_server_add_outbound_tracker_test.go index 770e14fe83..f01f5cf7d5 100644 --- a/x/crosschain/keeper/msg_server_add_outbound_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_outbound_tracker_test.go @@ -35,6 +35,14 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { admin := sample.AccAddress() chainID := getEthereumChainID() hash := sample.Hash().Hex() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + msg := types.MsgAddOutboundTracker{ Creator: admin, ChainId: chainID, @@ -44,15 +52,7 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { TxIndex: 0, Nonce: 0, } - - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - observerMock := keepertest.GetCrosschainObserverMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) - observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) - keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) - _, err := msgServer.AddOutboundTracker(ctx, &msg) require.NoError(t, err) tracker, found := k.GetOutboundTracker(ctx, chainID, 0) @@ -73,6 +73,11 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { admin := sample.AccAddress() chainID := getEthereumChainID() hash := sample.Hash().Hex() + + observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) + observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) + keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) + msg := types.MsgAddOutboundTracker{ Creator: admin, ChainId: chainID, @@ -82,12 +87,7 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { TxIndex: 0, Nonce: 0, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) - observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(true) - keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) - _, err := msgServer.AddOutboundTracker(ctx, &msg) require.NoError(t, err) tracker, found := k.GetOutboundTracker(ctx, chainID, 0) @@ -109,17 +109,7 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { chainID := getEthereumChainID() existinghHash := sample.Hash().Hex() newHash := sample.Hash().Hex() - msg := types.MsgAddOutboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: newHash, - Proof: nil, - BlockHash: "", - TxIndex: 0, - Nonce: 42, - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) @@ -134,6 +124,16 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { }, }) + msg := types.MsgAddOutboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: newHash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.AddOutboundTracker(ctx, &msg) require.NoError(t, err) tracker, found := k.GetOutboundTracker(ctx, chainID, 42) @@ -244,17 +244,7 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { admin := sample.AccAddress() chainID := getEthereumChainID() newHash := sample.Hash().Hex() - msg := types.MsgAddOutboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: newHash, - Proof: nil, - BlockHash: "", - TxIndex: 0, - Nonce: 42, - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) @@ -272,6 +262,16 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { HashList: hashes, }) + msg := types.MsgAddOutboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: newHash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.AddOutboundTracker(ctx, &msg) require.ErrorIs(t, err, types.ErrMaxTxOutTrackerHashesReached) }) @@ -287,20 +287,10 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { chainID := getEthereumChainID() existinghHash := sample.Hash().Hex() - msg := types.MsgAddOutboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: existinghHash, - Proof: nil, - BlockHash: "", - TxIndex: 0, - Nonce: 42, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) observerMock := keepertest.GetCrosschainObserverMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) @@ -315,6 +305,16 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { }, }) + msg := types.MsgAddOutboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: existinghHash, + Proof: nil, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.AddOutboundTracker(ctx, &msg) require.NoError(t, err) tracker, found := k.GetOutboundTracker(ctx, chainID, 42) @@ -335,21 +335,11 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { chainID := getEthereumChainID() ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) txHash := ethTx.Hash().Hex() - msg := types.MsgAddOutboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: txHash, - Proof: &proofs.Proof{}, - BlockHash: "", - TxIndex: 0, - Nonce: 42, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) observerMock := keepertest.GetCrosschainObserverMock(t, k) lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) @@ -359,6 +349,16 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(ethTxBytes, nil) + msg := types.MsgAddOutboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AddOutboundTracker(ctx, &msg) require.NoError(t, err) tracker, found := k.GetOutboundTracker(ctx, chainID, 42) @@ -379,21 +379,11 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { chainID := getEthereumChainID() ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) txHash := ethTx.Hash().Hex() - msg := types.MsgAddOutboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: txHash, - Proof: &proofs.Proof{}, - BlockHash: "", - TxIndex: 0, - Nonce: 42, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) observerMock := keepertest.GetCrosschainObserverMock(t, k) lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) @@ -418,6 +408,16 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { }, }) + msg := types.MsgAddOutboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AddOutboundTracker(ctx, &msg) require.NoError(t, err) tracker, found := k.GetOutboundTracker(ctx, chainID, 42) @@ -439,27 +439,27 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { chainID := getEthereumChainID() ethTx, ethTxBytes, _ := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) txHash := ethTx.Hash().Hex() - msg := types.MsgAddOutboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: txHash, - Proof: &proofs.Proof{}, - BlockHash: "", - TxIndex: 0, - Nonce: 42, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) observerMock := keepertest.GetCrosschainObserverMock(t, k) lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(ethTxBytes, errors.New("error")) + msg := types.MsgAddOutboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AddOutboundTracker(ctx, &msg) require.ErrorIs(t, err, types.ErrProofVerificationFail) }) @@ -476,21 +476,11 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { chainID := getEthereumChainID() ethTx, ethTxBytes, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) txHash := ethTx.Hash().Hex() - msg := types.MsgAddOutboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: txHash, - Proof: &proofs.Proof{}, - BlockHash: "", - TxIndex: 0, - Nonce: 42, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) observerMock := keepertest.GetCrosschainObserverMock(t, k) lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) @@ -500,6 +490,16 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { Eth: tssAddress.Hex(), }, errors.New("error")) + msg := types.MsgAddOutboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AddOutboundTracker(ctx, &msg) require.ErrorIs(t, err, observertypes.ErrTssNotFound) }) @@ -516,21 +516,10 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { chainID := getEthereumChainID() ethTx, _, tssAddress := sample.EthTxSigned(t, chainID, sample.EthAddress(), 42) txHash := ethTx.Hash().Hex() - msg := types.MsgAddOutboundTracker{ - Creator: admin, - ChainId: chainID, - TxHash: txHash, - Proof: &proofs.Proof{}, - BlockHash: "", - TxIndex: 0, - Nonce: 42, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) observerMock := keepertest.GetCrosschainObserverMock(t, k) lightclientMock := keepertest.GetCrosschainLightclientMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) observerMock.On("GetSupportedChainFromChainID", mock.Anything, mock.Anything).Return(&chains.Chain{}) observerMock.On("IsNonTombstonedObserver", mock.Anything, mock.Anything).Return(false) keepertest.MockCctxByNonce(t, ctx, *k, observerMock, types.CctxStatus_PendingOutbound, false) @@ -542,6 +531,16 @@ func TestMsgServer_AddToOutboundTracker(t *testing.T) { lightclientMock.On("VerifyProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(sample.Bytes(), nil) + msg := types.MsgAddOutboundTracker{ + Creator: admin, + ChainId: chainID, + TxHash: txHash, + Proof: &proofs.Proof{}, + BlockHash: "", + TxIndex: 0, + Nonce: 42, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.AddOutboundTracker(ctx, &msg) require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) }) 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 383eac8d1f..7cc346d15c 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go @@ -94,19 +94,20 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) + msgServer := keeper.NewMsgServerImpl(*k) indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) gp, found := k.GetMedianGasPriceInUint(ctx, chain.ChainId) require.True(t, found) + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.NoError(t, err) hash := crypto.Keccak256Hash([]byte(indexString)) @@ -126,19 +127,20 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) { admin := sample.AccAddress() chain := getValidBTCChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) msgServer := keeper.NewMsgServerImpl(*k) indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) gp, found := k.GetMedianGasPriceInUint(ctx, chain.ChainId) require.True(t, found) + + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.NoError(t, err) hash := crypto.Keccak256Hash([]byte(indexString)) @@ -158,17 +160,17 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + + msgServer := keeper.NewMsgServerImpl(*k) + msg := crosschaintypes.MsgMigrateTssFunds{ Creator: admin, ChainId: chain.ChainId, Amount: amount, } - - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - - msgServer := keeper.NewMsgServerImpl(*k) - _, err := msgServer.MigrateTssFunds(ctx, &msg) require.Error(t, err) }) @@ -182,19 +184,19 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("IsInboundEnabled", mock.Anything).Return(true) msgServer := keeper.NewMsgServerImpl(*k) + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.Error(t, err) }) @@ -208,14 +210,8 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("IsInboundEnabled", mock.Anything).Return(false) @@ -223,6 +219,12 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.Error(t, err) }) @@ -236,14 +238,8 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("IsInboundEnabled", mock.Anything).Return(false) @@ -252,6 +248,12 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.Error(t, err) }) @@ -265,14 +267,8 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("IsInboundEnabled", mock.Anything).Return(false) @@ -282,6 +278,12 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.Error(t, err) }) @@ -295,14 +297,8 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("IsInboundEnabled", mock.Anything).Return(false) @@ -314,6 +310,13 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { observerMock.On("GetAllTSS", mock.Anything).Return([]observertypes.TSS{tss2}) msgServer := keeper.NewMsgServerImpl(*k) + + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.Error(t, err) }) @@ -327,14 +330,8 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) observerMock := keepertest.GetCrosschainObserverMock(t, k) observerMock.On("IsInboundEnabled", mock.Anything).Return(false) @@ -349,6 +346,12 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.Error(t, err) }) @@ -361,18 +364,18 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + + msgServer := keeper.NewMsgServerImpl(*k) + + indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) + msg := crosschaintypes.MsgMigrateTssFunds{ Creator: admin, ChainId: chain.ChainId, Amount: amount, } - - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - - msgServer := keeper.NewMsgServerImpl(*k) - - indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.NoError(t, err) hash := crypto.Keccak256Hash([]byte(indexString)) @@ -392,18 +395,17 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("100") + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msgServer := keeper.NewMsgServerImpl(*k) + indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) + msg := crosschaintypes.MsgMigrateTssFunds{ Creator: admin, ChainId: chain.ChainId, Amount: amount, } - - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - - msgServer := keeper.NewMsgServerImpl(*k) - - indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.ErrorContains(t, err, crosschaintypes.ErrCannotMigrateTssFunds.Error()) hash := crypto.Keccak256Hash([]byte(indexString)) @@ -420,18 +422,17 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msgServer := keeper.NewMsgServerImpl(*k) + indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, false, true) + msg := crosschaintypes.MsgMigrateTssFunds{ Creator: admin, ChainId: chain.ChainId, Amount: amount, } - - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - - msgServer := keeper.NewMsgServerImpl(*k) - - indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, false, true) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.ErrorContains(t, err, "no new tss address has been generated") hash := crypto.Keccak256Hash([]byte(indexString)) @@ -448,15 +449,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - msgServer := keeper.NewMsgServerImpl(*k) indexString, tssPubkey := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) @@ -466,6 +459,13 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Tss: tssPubkey, }) + + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) require.ErrorContains(t, err, "cannot migrate funds when there are pending nonces") @@ -483,14 +483,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - msgServer := keeper.NewMsgServerImpl(*k) indexString, tssPubkey := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) @@ -507,6 +500,13 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, MigrationCctxIndex: existingCctx.Index, }) + + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) require.ErrorContains(t, err, "cannot migrate funds while there are pending migrations") @@ -528,14 +528,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { admin := sample.AccAddress() chain := getValidEthChain() amount := sdkmath.NewUintFromString("10000000000000000000") - msg := crosschaintypes.MsgMigrateTssFunds{ - Creator: admin, - ChainId: chain.ChainId, - Amount: amount, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) @@ -546,6 +539,14 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { newTss.FinalizedZetaHeight = currentTss.FinalizedZetaHeight - 10 newTss.KeyGenZetaHeight = currentTss.KeyGenZetaHeight - 10 k.GetObserverKeeper().SetTSSHistory(ctx, newTss) + + msg := crosschaintypes.MsgMigrateTssFunds{ + Creator: admin, + ChainId: chain.ChainId, + Amount: amount, + } + + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.MigrateTssFunds(ctx, &msg) require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) require.ErrorContains(t, err, "current tss is the latest") diff --git a/x/crosschain/keeper/msg_server_refund_aborted_tx_test.go b/x/crosschain/keeper/msg_server_refund_aborted_tx_test.go index a81310f215..bf3678ecaf 100644 --- a/x/crosschain/keeper/msg_server_refund_aborted_tx_test.go +++ b/x/crosschain/keeper/msg_server_refund_aborted_tx_test.go @@ -45,13 +45,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.Sender, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -73,6 +67,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { "foobar", ) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.Sender, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.NoError(t, err) @@ -93,13 +93,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.Sender, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -116,6 +110,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { ) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.Sender, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.NoError(t, err) @@ -136,13 +136,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.Sender, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -160,6 +154,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { ) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.Sender, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.NoError(t, err) @@ -180,14 +180,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.Sender, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -205,6 +198,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { ) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.Sender, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.Error(t, err) }) @@ -217,14 +216,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.Sender, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -242,6 +234,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { ) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.Sender, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.Error(t, err) }) @@ -255,13 +253,8 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") refundAddress := sample.EthAddress() - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: refundAddress.String(), - } + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -275,6 +268,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { k.SetZetaAccounting(ctx, crosschaintypes.ZetaAccounting{AbortedZetaAmount: cctx.InboundParams.Amount}) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: refundAddress.String(), + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.NoError(t, err) @@ -295,13 +294,8 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { chainID := getValidEthChainID() asset := sample.EthAddress().String() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.Sender, - } + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -325,6 +319,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { "bar", ) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.Sender, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.NoError(t, err) @@ -350,14 +350,8 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { cctx.CctxStatus.IsAbortRefunded = false cctx.InboundParams.SenderChainId = chainID cctx.InboundParams.CoinType = coin.CoinType_Gas - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.TxOrigin, - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -374,6 +368,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { "foobar", ) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.TxOrigin, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.NoError(t, err) @@ -394,14 +394,8 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: "invalid-address", - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -415,6 +409,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { k.SetZetaAccounting(ctx, crosschaintypes.ZetaAccounting{AbortedZetaAmount: cctx.InboundParams.Amount}) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: "invalid-address", + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.ErrorContains(t, err, "invalid refund address") }) @@ -427,14 +427,8 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: "0x0000000000000000000000000000000000000000", - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -448,6 +442,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { k.SetZetaAccounting(ctx, crosschaintypes.ZetaAccounting{AbortedZetaAmount: cctx.InboundParams.Amount}) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: "0x0000000000000000000000000000000000000000", + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.ErrorContains(t, err, "invalid refund address") }) @@ -461,12 +461,6 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { chainID := getValidEthChainID() authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: "", - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -479,6 +473,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { k.SetCrossChainTx(ctx, *cctx) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: "", + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.ErrorContains(t, err, "CCTX is not aborted") c, found := k.GetCrossChainTx(ctx, cctx.Index) @@ -494,13 +494,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: "", - } authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -512,6 +506,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { cctx.InboundParams.CoinType = coin.CoinType_Gas deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: "", + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.ErrorContains(t, err, "cannot find cctx") }) @@ -524,13 +524,8 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidBtcChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: "", - } + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -552,6 +547,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { "foobar", ) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: "", + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.ErrorContains(t, err, "refund address is required") }) @@ -564,14 +565,8 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.Sender, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -583,6 +578,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { k.SetCrossChainTx(ctx, *cctx) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.Sender, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.ErrorContains(t, err, "unable to find zeta accounting") }) @@ -595,14 +596,7 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() cctx := sample.CrossChainTx(t, "sample-index") - msg := crosschaintypes.MsgRefundAbortedCCTX{ - Creator: admin, - CctxIndex: cctx.Index, - RefundAddress: cctx.InboundParams.Sender, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) msgServer := keeper.NewMsgServerImpl(*k) k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) @@ -624,6 +618,12 @@ func TestMsgServer_RefundAbortedCCTX(t *testing.T) { "foobar", ) + msg := crosschaintypes.MsgRefundAbortedCCTX{ + Creator: admin, + CctxIndex: cctx.Index, + RefundAddress: cctx.InboundParams.Sender, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) _, err := msgServer.RefundAbortedCCTX(ctx, &msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) }) diff --git a/x/crosschain/keeper/msg_server_remove_outbound_tracker_test.go b/x/crosschain/keeper/msg_server_remove_outbound_tracker_test.go index b3c4e2eb34..e4a5a4eb6b 100644 --- a/x/crosschain/keeper/msg_server_remove_outbound_tracker_test.go +++ b/x/crosschain/keeper/msg_server_remove_outbound_tracker_test.go @@ -23,14 +23,14 @@ func TestMsgServer_RemoveFromOutboundTracker(t *testing.T) { }) admin := sample.AccAddress() + + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msgServer := keeper.NewMsgServerImpl(*k) + msg := types.MsgRemoveOutboundTracker{ Creator: admin, } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - - msgServer := keeper.NewMsgServerImpl(*k) - res, err := msgServer.RemoveOutboundTracker(ctx, &msg) require.Error(t, err) require.Empty(t, res) @@ -49,16 +49,15 @@ func TestMsgServer_RemoveFromOutboundTracker(t *testing.T) { }) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msgServer := keeper.NewMsgServerImpl(*k) + msg := types.MsgRemoveOutboundTracker{ Creator: admin, ChainId: 1, Nonce: 1, } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - - msgServer := keeper.NewMsgServerImpl(*k) - res, err := msgServer.RemoveOutboundTracker(ctx, &msg) require.NoError(t, err) require.Empty(t, res) diff --git a/x/crosschain/keeper/msg_server_update_rate_limiter_flags_test.go b/x/crosschain/keeper/msg_server_update_rate_limiter_flags_test.go index 0b998e04c1..6872479973 100644 --- a/x/crosschain/keeper/msg_server_update_rate_limiter_flags_test.go +++ b/x/crosschain/keeper/msg_server_update_rate_limiter_flags_test.go @@ -20,17 +20,16 @@ func TestMsgServer_UpdateRateLimiterFlags(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() flags := sample.RateLimiterFlags() - msg := types.NewMsgUpdateRateLimiterFlags( - admin, - flags, - ) authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil) - _, found := k.GetRateLimiterFlags(ctx) require.False(t, found) + msg := types.NewMsgUpdateRateLimiterFlags( + admin, + flags, + ) + keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil) _, err := msgServer.UpdateRateLimiterFlags(ctx, msg) require.NoError(t, err) @@ -46,14 +45,13 @@ func TestMsgServer_UpdateRateLimiterFlags(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() flags := sample.RateLimiterFlags() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msg := types.NewMsgUpdateRateLimiterFlags( admin, flags, ) - - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, authoritytypes.ErrUnauthorized) - _, err := msgServer.UpdateRateLimiterFlags(ctx, msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) }) diff --git a/x/crosschain/keeper/msg_server_update_tss_test.go b/x/crosschain/keeper/msg_server_update_tss_test.go index f2d60fa76b..7999475b0b 100644 --- a/x/crosschain/keeper/msg_server_update_tss_test.go +++ b/x/crosschain/keeper/msg_server_update_tss_test.go @@ -20,15 +20,15 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { }) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + + msgServer := keeper.NewMsgServerImpl(*k) + msg := crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: "", } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - - msgServer := keeper.NewMsgServerImpl(*k) - _, err := msgServer.UpdateTssAddress(ctx, &msg) require.Error(t, err) }) @@ -39,15 +39,14 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { }) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msgServer := keeper.NewMsgServerImpl(*k) + msg := crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: "", } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - - msgServer := keeper.NewMsgServerImpl(*k) - _, err := msgServer.UpdateTssAddress(ctx, &msg) require.Error(t, err) }) @@ -60,14 +59,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { admin := sample.AccAddress() tssOld := sample.Tss() tssNew := sample.Tss() - msg := crosschaintypes.MsgUpdateTssAddress{ - Creator: admin, - TssPubkey: tssNew.TssPubkey, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - msgServer := keeper.NewMsgServerImpl(*k) k.GetObserverKeeper().SetTSSHistory(ctx, tssOld) @@ -88,6 +80,12 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx)), ) + + msg := crosschaintypes.MsgUpdateTssAddress{ + Creator: admin, + TssPubkey: tssNew.TssPubkey, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.UpdateTssAddress(ctx, &msg) require.NoError(t, err) tss, found := k.GetObserverKeeper().GetTSS(ctx) @@ -105,13 +103,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { admin := sample.AccAddress() tssOld := sample.Tss() tssNew := sample.Tss() - msg := crosschaintypes.MsgUpdateTssAddress{ - Creator: admin, - TssPubkey: tssNew.TssPubkey, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) @@ -132,6 +124,12 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx)), ) + + msg := crosschaintypes.MsgUpdateTssAddress{ + Creator: admin, + TssPubkey: tssNew.TssPubkey, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.UpdateTssAddress(ctx, &msg) require.ErrorContains(t, err, "tss pubkey has not been generated") require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) @@ -152,13 +150,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { admin := sample.AccAddress() tssOld := sample.Tss() - msg := crosschaintypes.MsgUpdateTssAddress{ - Creator: admin, - TssPubkey: tssOld.TssPubkey, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) @@ -179,6 +171,12 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx)), ) + + msg := crosschaintypes.MsgUpdateTssAddress{ + Creator: admin, + TssPubkey: tssOld.TssPubkey, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.UpdateTssAddress(ctx, &msg) require.ErrorContains(t, err, "no new tss address has been generated") require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) @@ -200,14 +198,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { admin := sample.AccAddress() tssOld := sample.Tss() tssNew := sample.Tss() - msg := crosschaintypes.MsgUpdateTssAddress{ - Creator: admin, - TssPubkey: tssNew.TssPubkey, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - msgServer := keeper.NewMsgServerImpl(*k) k.GetObserverKeeper().SetTSSHistory(ctx, tssOld) @@ -225,8 +216,13 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { cctx := sample.CrossChainTx(t, index) cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined k.SetCrossChainTx(ctx, *cctx) - require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), 1) + + msg := crosschaintypes.MsgUpdateTssAddress{ + Creator: admin, + TssPubkey: tssNew.TssPubkey, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.UpdateTssAddress(ctx, &msg) require.ErrorContains(t, err, "cannot update tss address not enough migrations have been created and completed") require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) @@ -245,13 +241,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { admin := sample.AccAddress() tssOld := sample.Tss() tssNew := sample.Tss() - msg := crosschaintypes.MsgUpdateTssAddress{ - Creator: admin, - TssPubkey: tssNew.TssPubkey, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) msgServer := keeper.NewMsgServerImpl(*k) @@ -275,6 +265,12 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx)), ) + + msg := crosschaintypes.MsgUpdateTssAddress{ + Creator: admin, + TssPubkey: tssNew.TssPubkey, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.UpdateTssAddress(ctx, &msg) require.ErrorContains(t, err, "cannot update tss address while there are pending migrations") require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) @@ -293,14 +289,7 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { admin := sample.AccAddress() tssOld := sample.Tss() tssNew := sample.Tss() - msg := crosschaintypes.MsgUpdateTssAddress{ - Creator: admin, - TssPubkey: tssNew.TssPubkey, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - msgServer := keeper.NewMsgServerImpl(*k) k.GetObserverKeeper().SetTSSHistory(ctx, tssOld) @@ -320,6 +309,12 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx)), ) + + msg := crosschaintypes.MsgUpdateTssAddress{ + Creator: admin, + TssPubkey: tssNew.TssPubkey, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.UpdateTssAddress(ctx, &msg) require.ErrorContains(t, err, "migration cross chain tx not found") require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) diff --git a/x/crosschain/keeper/msg_server_whitelist_erc20_test.go b/x/crosschain/keeper/msg_server_whitelist_erc20_test.go index 922cbf36c8..397fd7aac1 100644 --- a/x/crosschain/keeper/msg_server_whitelist_erc20_test.go +++ b/x/crosschain/keeper/msg_server_whitelist_erc20_test.go @@ -31,18 +31,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { admin := sample.AccAddress() erc20Address := sample.EthAddress().Hex() - msg := types.MsgWhitelistERC20{ - Creator: admin, - Erc20Address: erc20Address, - ChainId: chainID, - Name: "foo", - Symbol: "FOO", - Decimals: 18, - GasLimit: 100000, - } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper) setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foobar", "FOOBAR") @@ -53,6 +42,16 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Prices: []uint64{1}, }) + msg := types.MsgWhitelistERC20{ + Creator: admin, + Erc20Address: erc20Address, + ChainId: chainID, + Name: "foo", + Symbol: "FOO", + Decimals: 18, + GasLimit: 100000, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) res, err := msgServer.WhitelistERC20(ctx, &msg) require.NoError(t, err) require.NotNil(t, res) @@ -73,6 +72,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { gasLimit, err := zk.FungibleKeeper.QueryGasLimit(ctx, ethcommon.HexToAddress(zrc20)) require.NoError(t, err) require.Equal(t, uint64(100000), gasLimit.Uint64()) + msgNew := types.MsgWhitelistERC20{ Creator: admin, Erc20Address: sample.EthAddress().Hex(), @@ -82,7 +82,6 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msgNew, nil) // Ensure that whitelist a new erc20 create a cctx with a different index @@ -101,6 +100,8 @@ func TestKeeper_WhitelistERC20(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msg := types.MsgWhitelistERC20{ Creator: admin, Erc20Address: sample.EthAddress().Hex(), @@ -110,10 +111,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, } - - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - _, err := msgServer.WhitelistERC20(ctx, &msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) }) @@ -127,6 +125,8 @@ func TestKeeper_WhitelistERC20(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName) admin := sample.AccAddress() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msg := types.MsgWhitelistERC20{ Creator: admin, Erc20Address: "invalid", @@ -136,7 +136,6 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := msgServer.WhitelistERC20(ctx, &msg) @@ -154,6 +153,13 @@ func TestKeeper_WhitelistERC20(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() asset := sample.EthAddress().Hex() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + + fc := sample.ForeignCoins(t, sample.EthAddress().Hex()) + fc.Asset = asset + fc.ForeignChainId = chainID + zk.FungibleKeeper.SetForeignCoins(ctx, fc) + msg := types.MsgWhitelistERC20{ Creator: admin, Erc20Address: asset, @@ -163,15 +169,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, } - - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - - fc := sample.ForeignCoins(t, sample.EthAddress().Hex()) - fc.Asset = asset - fc.ForeignChainId = chainID - zk.FungibleKeeper.SetForeignCoins(ctx, fc) - _, err := msgServer.WhitelistERC20(ctx, &msg) require.ErrorIs(t, err, fungibletypes.ErrForeignCoinAlreadyExist) }) @@ -187,6 +185,8 @@ func TestKeeper_WhitelistERC20(t *testing.T) { admin := sample.AccAddress() chainID := getValidEthChainID() erc20Address := sample.EthAddress().Hex() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + msg := types.MsgWhitelistERC20{ Creator: admin, Erc20Address: erc20Address, @@ -196,9 +196,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := msgServer.WhitelistERC20(ctx, &msg) require.ErrorIs(t, err, types.ErrCannotFindTSSKeys) }) @@ -213,6 +211,10 @@ func TestKeeper_WhitelistERC20(t *testing.T) { admin := sample.AccAddress() erc20Address := sample.EthAddress().Hex() + authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) + + k.GetObserverKeeper().SetTssAndUpdateNonce(ctx, sample.Tss()) + msg := types.MsgWhitelistERC20{ Creator: admin, Erc20Address: erc20Address, @@ -222,11 +224,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, } - authorityMock := keepertest.GetCrosschainAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - - k.GetObserverKeeper().SetTssAndUpdateNonce(ctx, sample.Tss()) - _, err := msgServer.WhitelistERC20(ctx, &msg) require.ErrorIs(t, err, types.ErrInvalidChainID) })