diff --git a/x/observer/keeper/msg_server_add_observer_test.go b/x/observer/keeper/msg_server_add_observer_test.go index b91018c190..960263399f 100644 --- a/x/observer/keeper/msg_server_add_observer_test.go +++ b/x/observer/keeper/msg_server_add_observer_test.go @@ -22,13 +22,13 @@ func TestMsgServer_AddObserver(t *testing.T) { }) authorityMock := keepertest.GetObserverAuthorityMock(t, k) admin := sample.AccAddress() + wctx := sdk.WrapSDKContext(ctx) + srv := keeper.NewMsgServerImpl(*k) + msg := types.MsgAddObserver{ Creator: admin, } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - wctx := sdk.WrapSDKContext(ctx) - - srv := keeper.NewMsgServerImpl(*k) res, err := srv.AddObserver(wctx, &msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) require.Nil(t, res) @@ -40,14 +40,14 @@ func TestMsgServer_AddObserver(t *testing.T) { }) authorityMock := keepertest.GetObserverAuthorityMock(t, k) admin := sample.AccAddress() + wctx := sdk.WrapSDKContext(ctx) + srv := keeper.NewMsgServerImpl(*k) + msg := types.MsgAddObserver{ Creator: admin, ZetaclientGranteePubkey: "invalid", } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - wctx := sdk.WrapSDKContext(ctx) - - srv := keeper.NewMsgServerImpl(*k) res, err := srv.AddObserver(wctx, &msg) require.Error(t, err) require.Equal(t, &types.MsgAddObserverResponse{}, res) @@ -60,20 +60,19 @@ func TestMsgServer_AddObserver(t *testing.T) { authorityMock := keepertest.GetObserverAuthorityMock(t, k) admin := sample.AccAddress() observerAddress := sdk.AccAddress(crypto.AddressHash([]byte("ObserverAddress"))) + wctx := sdk.WrapSDKContext(ctx) + + _, found := k.GetLastObserverCount(ctx) + require.False(t, found) + srv := keeper.NewMsgServerImpl(*k) + msg := types.MsgAddObserver{ Creator: admin, ZetaclientGranteePubkey: sample.PubKeyString(), AddNodeAccountOnly: false, ObserverAddress: observerAddress.String(), } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - wctx := sdk.WrapSDKContext(ctx) - - _, found := k.GetLastObserverCount(ctx) - require.False(t, found) - srv := keeper.NewMsgServerImpl(*k) - res, err := srv.AddObserver(wctx, &msg) require.NoError(t, err) require.Equal(t, &types.MsgAddObserverResponse{}, res) @@ -90,14 +89,7 @@ func TestMsgServer_AddObserver(t *testing.T) { authorityMock := keepertest.GetObserverAuthorityMock(t, k) admin := sample.AccAddress() observerAddress := sdk.AccAddress(crypto.AddressHash([]byte("ObserverAddress"))) - msg := types.MsgAddObserver{ - Creator: admin, - ZetaclientGranteePubkey: sample.PubKeyString(), - AddNodeAccountOnly: true, - ObserverAddress: observerAddress.String(), - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) wctx := sdk.WrapSDKContext(ctx) _, found := k.GetLastObserverCount(ctx) @@ -109,6 +101,13 @@ func TestMsgServer_AddObserver(t *testing.T) { _, found = k.GetNodeAccount(ctx, observerAddress.String()) require.False(t, found) + msg := types.MsgAddObserver{ + Creator: admin, + ZetaclientGranteePubkey: sample.PubKeyString(), + AddNodeAccountOnly: true, + ObserverAddress: observerAddress.String(), + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) res, err := srv.AddObserver(wctx, &msg) require.NoError(t, err) require.Equal(t, &types.MsgAddObserverResponse{}, res) diff --git a/x/observer/keeper/msg_server_disable_cctx_flags_test.go b/x/observer/keeper/msg_server_disable_cctx_flags_test.go index e91ebbeb87..74ec5cb14a 100644 --- a/x/observer/keeper/msg_server_disable_cctx_flags_test.go +++ b/x/observer/keeper/msg_server_disable_cctx_flags_test.go @@ -20,14 +20,14 @@ func TestMsgServer_MsgDisableCCTX(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgDisableCCTX{ Creator: admin, DisableOutbound: true, DisableInbound: true, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := srv.DisableCCTX(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -50,14 +50,14 @@ func TestMsgServer_MsgDisableCCTX(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgDisableCCTX{ Creator: admin, DisableOutbound: true, DisableInbound: true, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := srv.DisableCCTX(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -80,14 +80,14 @@ func TestMsgServer_MsgDisableCCTX(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgDisableCCTX{ Creator: admin, DisableOutbound: true, DisableInbound: false, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := srv.DisableCCTX(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -110,14 +110,14 @@ func TestMsgServer_MsgDisableCCTX(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgDisableCCTX{ Creator: admin, DisableOutbound: false, DisableInbound: true, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := srv.DisableCCTX(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -135,14 +135,14 @@ func TestMsgServer_MsgDisableCCTX(t *testing.T) { srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgDisableCCTX{ Creator: admin, DisableOutbound: true, DisableInbound: false, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - _, err := srv.DisableCCTX(sdk.WrapSDKContext(ctx), &msg) require.ErrorIs(t, authoritytypes.ErrUnauthorized, err) diff --git a/x/observer/keeper/msg_server_enable_cctx_flags_test.go b/x/observer/keeper/msg_server_enable_cctx_flags_test.go index 62ed9b773f..d09ea79262 100644 --- a/x/observer/keeper/msg_server_enable_cctx_flags_test.go +++ b/x/observer/keeper/msg_server_enable_cctx_flags_test.go @@ -20,14 +20,14 @@ func TestMsgServer_EnableCCTX(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := &types.MsgEnableCCTX{ Creator: admin, EnableInbound: true, EnableOutbound: true, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil) - _, err := srv.EnableCCTX(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) @@ -50,14 +50,14 @@ func TestMsgServer_EnableCCTX(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := &types.MsgEnableCCTX{ Creator: admin, EnableInbound: true, EnableOutbound: true, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil) - _, err := srv.EnableCCTX(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) @@ -80,14 +80,14 @@ func TestMsgServer_EnableCCTX(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := &types.MsgEnableCCTX{ Creator: admin, EnableInbound: true, EnableOutbound: false, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil) - _, err := srv.EnableCCTX(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) @@ -110,14 +110,14 @@ func TestMsgServer_EnableCCTX(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := &types.MsgEnableCCTX{ Creator: admin, EnableInbound: false, EnableOutbound: true, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, nil) - _, err := srv.EnableCCTX(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) @@ -135,12 +135,13 @@ func TestMsgServer_EnableCCTX(t *testing.T) { srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := &types.MsgEnableCCTX{ Creator: admin, EnableInbound: true, EnableOutbound: false, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, msg, authoritytypes.ErrUnauthorized) _, err := srv.EnableCCTX(sdk.WrapSDKContext(ctx), msg) diff --git a/x/observer/keeper/msg_server_remove_chain_params_test.go b/x/observer/keeper/msg_server_remove_chain_params_test.go index b877383714..fdcab1b72f 100644 --- a/x/observer/keeper/msg_server_remove_chain_params_test.go +++ b/x/observer/keeper/msg_server_remove_chain_params_test.go @@ -30,11 +30,6 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { // set admin admin := sample.AccAddress() - msg := types.MsgRemoveChainParams{ - Creator: admin, - ChainId: chain2, - } - // add chain params k.SetChainParamsList(ctx, types.ChainParamsList{ ChainParams: []*types.ChainParams{ @@ -45,6 +40,10 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { }) // remove chain params + msg := types.MsgRemoveChainParams{ + Creator: admin, + ChainId: chain2, + } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -56,12 +55,12 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { require.Equal(t, chain1, chainParamsList.ChainParams[0].ChainId) require.Equal(t, chain3, chainParamsList.ChainParams[1].ChainId) + // remove chain params msg2 := types.MsgRemoveChainParams{ Creator: admin, ChainId: chain1, } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg2, nil) - // remove chain params _, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &msg2) require.NoError(t, err) @@ -70,14 +69,13 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { require.True(t, found) require.Len(t, chainParamsList.ChainParams, 1) require.Equal(t, chain3, chainParamsList.ChainParams[0].ChainId) + + // remove chain params msg3 := types.MsgRemoveChainParams{ Creator: admin, ChainId: chain3, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg3, nil) - - // remove chain params _, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &msg3) require.NoError(t, err) @@ -94,14 +92,13 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgRemoveChainParams{ Creator: admin, ChainId: chains.ExternalChainList()[0].ChainId, } - - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - _, err := srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) }) @@ -111,21 +108,20 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { UseAuthorityMock: true, }) srv := keeper.NewMsgServerImpl(*k) + authorityMock := keepertest.GetObserverAuthorityMock(t, k) // set admin admin := sample.AccAddress() - msg := types.MsgRemoveChainParams{ - Creator: admin, - ChainId: chains.ExternalChainList()[0].ChainId, - } - - authorityMock := keepertest.GetObserverAuthorityMock(t, k) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) // not found if no chain params _, found := k.GetChainParamsList(ctx) require.False(t, found) + msg := types.MsgRemoveChainParams{ + Creator: admin, + ChainId: chains.ExternalChainList()[0].ChainId, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &msg) require.ErrorIs(t, err, types.ErrChainParamsNotFound) @@ -138,14 +134,12 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { }, }) + // not found if chain ID not in list msg2 := types.MsgRemoveChainParams{ Creator: admin, ChainId: chains.ExternalChainList()[3].ChainId, } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg2, nil) - - // not found if chain ID not in list _, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &msg2) require.ErrorIs(t, err, types.ErrChainParamsNotFound) }) diff --git a/x/observer/keeper/msg_server_reset_chain_nonces_test.go b/x/observer/keeper/msg_server_reset_chain_nonces_test.go index 28bfc0846b..c06cdb2c0a 100644 --- a/x/observer/keeper/msg_server_reset_chain_nonces_test.go +++ b/x/observer/keeper/msg_server_reset_chain_nonces_test.go @@ -22,16 +22,15 @@ func TestMsgServer_ResetChainNonces(t *testing.T) { srv := keeper.NewMsgServerImpl(*k) chainId := chains.GoerliLocalnet.ChainId admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgResetChainNonces{ Creator: admin, ChainId: chainId, ChainNonceLow: 1, ChainNonceHigh: 5, } - - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - _, err := srv.ResetChainNonces(sdk.WrapSDKContext(ctx), &msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) }) @@ -43,17 +42,16 @@ func TestMsgServer_ResetChainNonces(t *testing.T) { srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) chainId := chains.GoerliLocalnet.ChainId + msg := types.MsgResetChainNonces{ Creator: admin, ChainId: chainId, ChainNonceLow: 1, ChainNonceHigh: 5, } - - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := srv.ResetChainNonces(sdk.WrapSDKContext(ctx), &msg) require.ErrorIs(t, err, types.ErrTssNotFound) }) @@ -67,14 +65,14 @@ func TestMsgServer_ResetChainNonces(t *testing.T) { k.SetTSS(ctx, tss) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgResetChainNonces{ Creator: admin, ChainId: 999, ChainNonceLow: 1, ChainNonceHigh: 5, } - - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := srv.ResetChainNonces(sdk.WrapSDKContext(ctx), &msg) @@ -93,26 +91,7 @@ func TestMsgServer_ResetChainNonces(t *testing.T) { chainId := chains.GoerliLocalnet.ChainId nonceLow := 1 nonceHigh := 5 - - // Reset nonces to nonceLow and nonceHigh - msg := types.MsgResetChainNonces{ - Creator: admin, - ChainId: chainId, - ChainNonceLow: int64(nonceLow), - ChainNonceHigh: int64(nonceHigh), - } authorityMock := keepertest.GetObserverAuthorityMock(t, k) - // Reset nonces back to 0 - msg2 := types.MsgResetChainNonces{ - Creator: admin, - ChainId: chainId, - ChainNonceLow: 0, - ChainNonceHigh: 0, - } - - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg2, nil) - index := chains.GoerliLocalnet.ChainName.String() // check existing chain nonces @@ -122,6 +101,14 @@ func TestMsgServer_ResetChainNonces(t *testing.T) { require.False(t, found) // reset chain nonces + // Reset nonces to nonceLow and nonceHigh + msg := types.MsgResetChainNonces{ + Creator: admin, + ChainId: chainId, + ChainNonceLow: int64(nonceLow), + ChainNonceHigh: int64(nonceHigh), + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := srv.ResetChainNonces(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -140,6 +127,14 @@ func TestMsgServer_ResetChainNonces(t *testing.T) { require.Equal(t, int64(nonceHigh), pendingNonces.NonceHigh) // reset nonces back to 0 + // Reset nonces back to 0 + msg2 := types.MsgResetChainNonces{ + Creator: admin, + ChainId: chainId, + ChainNonceLow: 0, + ChainNonceHigh: 0, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg2, nil) _, err = srv.ResetChainNonces(sdk.WrapSDKContext(ctx), &msg2) require.NoError(t, err) diff --git a/x/observer/keeper/msg_server_update_chain_params_test.go b/x/observer/keeper/msg_server_update_chain_params_test.go index 048e63b6da..fa3ccaa7bf 100644 --- a/x/observer/keeper/msg_server_update_chain_params_test.go +++ b/x/observer/keeper/msg_server_update_chain_params_test.go @@ -28,19 +28,18 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { // set admin admin := sample.AccAddress() chainParams1 := sample.ChainParams(chain1) - msg := types.MsgUpdateChainParams{ - Creator: admin, - ChainParams: chainParams1, - } authorityMock := keepertest.GetObserverAuthorityMock(t, k) // check list initially empty _, found := k.GetChainParamsList(ctx) require.False(t, found) - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - // a new chain params can be added + msg := types.MsgUpdateChainParams{ + Creator: admin, + ChainParams: chainParams1, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) _, err := srv.UpdateChainParams(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -50,13 +49,13 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { require.Len(t, chainParamsList.ChainParams, 1) require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) chainParams2 := sample.ChainParams(chain2) + + // a new chian params can be added msg2 := types.MsgUpdateChainParams{ Creator: admin, ChainParams: chainParams2, } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg2, nil) - - // a new chian params can be added _, err = srv.UpdateChainParams(sdk.WrapSDKContext(ctx), &msg2) require.NoError(t, err) @@ -67,13 +66,13 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) require.Equal(t, chainParams2, chainParamsList.ChainParams[1]) chainParams3 := sample.ChainParams(chain3) + + // a new chain params can be added msg3 := types.MsgUpdateChainParams{ Creator: admin, ChainParams: chainParams3, } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg3, nil) - - // a new chain params can be added _, err = srv.UpdateChainParams(sdk.WrapSDKContext(ctx), &msg3) require.NoError(t, err) @@ -85,14 +84,13 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { require.Equal(t, chainParams2, chainParamsList.ChainParams[1]) require.Equal(t, chainParams3, chainParamsList.ChainParams[2]) + // chain params can be updated + chainParams2.ConfirmationCount = chainParams2.ConfirmationCount + 1 msg4 := types.MsgUpdateChainParams{ Creator: admin, ChainParams: chainParams2, } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg4, nil) - - // chain params can be updated - chainParams2.ConfirmationCount = chainParams2.ConfirmationCount + 1 _, err = srv.UpdateChainParams(sdk.WrapSDKContext(ctx), &msg4) require.NoError(t, err) @@ -110,16 +108,16 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { UseAuthorityMock: true, }) srv := keeper.NewMsgServerImpl(*k) - admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgUpdateChainParams{ Creator: admin, ChainParams: sample.ChainParams(chains.ExternalChainList()[0].ChainId), } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - _, err := srv.UpdateChainParams(sdk.WrapSDKContext(ctx), &msg) + require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) }) } diff --git a/x/observer/keeper/msg_server_update_gas_price_increase_flags_test.go b/x/observer/keeper/msg_server_update_gas_price_increase_flags_test.go index 936057510d..7fe99dc47d 100644 --- a/x/observer/keeper/msg_server_update_gas_price_increase_flags_test.go +++ b/x/observer/keeper/msg_server_update_gas_price_increase_flags_test.go @@ -21,15 +21,15 @@ func TestKeeper_UpdateGasPriceIncreaseFlags(t *testing.T) { srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() updatedFlags := sample.GasPriceIncreaseFlags() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + + // mock the authority keeper for authorization + msg := types.MsgUpdateGasPriceIncreaseFlags{ Creator: admin, GasPriceIncreaseFlags: updatedFlags, } - - // mock the authority keeper for authorization - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := srv.UpdateGasPriceIncreaseFlags(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -49,15 +49,15 @@ func TestKeeper_UpdateGasPriceIncreaseFlags(t *testing.T) { defaultCrosschainFlags := types.DefaultCrosschainFlags() k.SetCrosschainFlags(ctx, *defaultCrosschainFlags) updatedFlags := sample.GasPriceIncreaseFlags() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + msg := types.MsgUpdateGasPriceIncreaseFlags{ Creator: admin, GasPriceIncreaseFlags: updatedFlags, } - - // mock the authority keeper for authorization - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := srv.UpdateGasPriceIncreaseFlags(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err) @@ -74,6 +74,10 @@ func TestKeeper_UpdateGasPriceIncreaseFlags(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + authorityMock := keepertest.GetObserverAuthorityMock(t, k) + + // mock the authority keeper for authorization + msg := types.MsgUpdateGasPriceIncreaseFlags{ Creator: admin, GasPriceIncreaseFlags: types.GasPriceIncreaseFlags{ @@ -82,11 +86,7 @@ func TestKeeper_UpdateGasPriceIncreaseFlags(t *testing.T) { GasPriceIncreasePercent: 1, }, } - - // mock the authority keeper for authorization - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err := srv.UpdateGasPriceIncreaseFlags(sdk.WrapSDKContext(ctx), &msg) require.ErrorContains(t, err, "epoch length must be positive") @@ -101,15 +101,14 @@ func TestKeeper_UpdateGasPriceIncreaseFlags(t *testing.T) { }) srv := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() + + // mock the authority keeper for authorization + authorityMock := keepertest.GetObserverAuthorityMock(t, k) msg := types.MsgUpdateGasPriceIncreaseFlags{ Creator: admin, GasPriceIncreaseFlags: sample.GasPriceIncreaseFlags(), } - - // mock the authority keeper for authorization - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - _, err := srv.UpdateGasPriceIncreaseFlags(sdk.WrapSDKContext(ctx), &msg) require.ErrorContains(t, err, "sender not authorized") }) diff --git a/x/observer/keeper/msg_server_update_keygen_test.go b/x/observer/keeper/msg_server_update_keygen_test.go index 6f3522540a..966f4a2588 100644 --- a/x/observer/keeper/msg_server_update_keygen_test.go +++ b/x/observer/keeper/msg_server_update_keygen_test.go @@ -20,13 +20,13 @@ func TestMsgServer_UpdateKeygen(t *testing.T) { }) authorityMock := keepertest.GetObserverAuthorityMock(t, k) admin := sample.AccAddress() + wctx := sdk.WrapSDKContext(ctx) + + srv := keeper.NewMsgServerImpl(*k) msg := types.MsgUpdateKeygen{ Creator: admin, } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, authoritytypes.ErrUnauthorized) - wctx := sdk.WrapSDKContext(ctx) - - srv := keeper.NewMsgServerImpl(*k) res, err := srv.UpdateKeygen(wctx, &msg) require.ErrorIs(t, err, authoritytypes.ErrUnauthorized) require.Nil(t, res) @@ -38,13 +38,14 @@ func TestMsgServer_UpdateKeygen(t *testing.T) { }) authorityMock := keepertest.GetObserverAuthorityMock(t, k) admin := sample.AccAddress() + + wctx := sdk.WrapSDKContext(ctx) + srv := keeper.NewMsgServerImpl(*k) + msg := types.MsgUpdateKeygen{ Creator: admin, } keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - wctx := sdk.WrapSDKContext(ctx) - - srv := keeper.NewMsgServerImpl(*k) res, err := srv.UpdateKeygen(wctx, &msg) require.Error(t, err) require.Nil(t, res) @@ -56,18 +57,19 @@ func TestMsgServer_UpdateKeygen(t *testing.T) { }) authorityMock := keepertest.GetObserverAuthorityMock(t, k) admin := sample.AccAddress() - msg := types.MsgUpdateKeygen{ - Creator: admin, - Block: 2, - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) wctx := sdk.WrapSDKContext(ctx) item := types.Keygen{ BlockNumber: 10, } k.SetKeygen(ctx, item) srv := keeper.NewMsgServerImpl(*k) + + msg := types.MsgUpdateKeygen{ + Creator: admin, + Block: 2, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) res, err := srv.UpdateKeygen(wctx, &msg) require.Error(t, err) require.Nil(t, res) @@ -79,11 +81,7 @@ func TestMsgServer_UpdateKeygen(t *testing.T) { }) authorityMock := keepertest.GetObserverAuthorityMock(t, k) admin := sample.AccAddress() - msg := types.MsgUpdateKeygen{ - Creator: admin, - Block: ctx.BlockHeight() + 30, - } - keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) + wctx := sdk.WrapSDKContext(ctx) item := types.Keygen{ BlockNumber: 10, @@ -97,6 +95,11 @@ func TestMsgServer_UpdateKeygen(t *testing.T) { GranteePubkey: granteePubKey, }) + msg := types.MsgUpdateKeygen{ + Creator: admin, + Block: ctx.BlockHeight() + 30, + } + keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) res, err := srv.UpdateKeygen(wctx, &msg) require.NoError(t, err) require.Equal(t, &types.MsgUpdateKeygenResponse{}, res) diff --git a/x/observer/keeper/msg_server_update_observer_test.go b/x/observer/keeper/msg_server_update_observer_test.go index d0bcd08201..2a4308590f 100644 --- a/x/observer/keeper/msg_server_update_observer_test.go +++ b/x/observer/keeper/msg_server_update_observer_test.go @@ -362,6 +362,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.SetLastObserverCount(ctx, &types.LastObserverCount{ Count: count, }) + authorityMock := keepertest.GetObserverAuthorityMock(t, k) msg := types.MsgUpdateObserver{ Creator: admin, @@ -369,9 +370,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_AdminUpdate, } - authorityMock := keepertest.GetObserverAuthorityMock(t, k) keepertest.MockCheckAuthorization(&authorityMock.Mock, &msg, nil) - _, err = srv.UpdateObserver(sdk.WrapSDKContext(ctx), &msg) require.NoError(t, err)