Skip to content

Commit

Permalink
update message logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Jan 10, 2024
1 parent b9e098a commit a54a814
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
7 changes: 1 addition & 6 deletions x/observer/keeper/msg_server_update_crosschain_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ import (
func (k msgServer) UpdateCrosschainFlags(goCtx context.Context, msg *types.MsgUpdateCrosschainFlags) (*types.MsgUpdateCrosschainFlagsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

requiredGroup := types.Policy_Type_group1
if msg.IsInboundEnabled || msg.IsOutboundEnabled || msg.GasPriceIncreaseFlags != nil {
requiredGroup = types.Policy_Type_group2
}

// check permission
if msg.Creator != k.GetParams(ctx).GetAdminPolicyAccount(requiredGroup) {
if msg.Creator != k.GetParams(ctx).GetAdminPolicyAccount(msg.GetRequiredGroup()) {
return &types.MsgUpdateCrosschainFlagsResponse{}, types.ErrNotAuthorizedPolicy
}

Expand Down
33 changes: 31 additions & 2 deletions x/observer/keeper/msg_server_update_crosschain_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
require.Equal(t, uint32(42), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent)
require.True(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled)
require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)

setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group2)

// can update flags again
Expand All @@ -71,7 +72,7 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
},
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: false,
IsBtcTypeChainEnabled: true,
},
})
require.NoError(t, err)
Expand All @@ -84,7 +85,8 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval)
require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent)
require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled)
require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)
require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)

// group 1 should be able to disable inbound and outbound
setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1)

Expand All @@ -103,6 +105,33 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) {
require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength)
require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval)
require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent)
require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled)
require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)

// group 1 should be able to disable header verification
setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1)

// if gas price increase flags is nil, it should not be updated
_, err = srv.UpdateCrosschainFlags(sdk.WrapSDKContext(ctx), &types.MsgUpdateCrosschainFlags{
Creator: admin,
IsInboundEnabled: false,
IsOutboundEnabled: false,
BlockHeaderVerificationFlags: &types.BlockHeaderVerificationFlags{
IsEthTypeChainEnabled: false,
IsBtcTypeChainEnabled: false,
},
})
require.NoError(t, err)

flags, found = k.GetCrosschainFlags(ctx)
require.True(t, found)
require.False(t, flags.IsInboundEnabled)
require.False(t, flags.IsOutboundEnabled)
require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength)
require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval)
require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent)
require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled)
require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled)

// if flags are not defined, default should be used
k.RemoveCrosschainFlags(ctx)
Expand Down

0 comments on commit a54a814

Please sign in to comment.