diff --git a/protocol/app/ante/market_update.go b/protocol/app/ante/market_update.go index c3aa2314d57..243dcd8dc2f 100644 --- a/protocol/app/ante/market_update.go +++ b/protocol/app/ante/market_update.go @@ -163,7 +163,7 @@ func (d ValidateMarketUpdateDecorator) doMarketsUpdateEnabledValues(ctx sdk.Cont // if market exists, it should not change the enabled value if mmMarket.Ticker.Enabled != market.Ticker.Enabled { return fmt.Errorf( - "market should not change enabled value from %t to %t", + "market should not change enabled value from %t to %t", mmMarket.Ticker.Enabled, market.Ticker.Enabled, ) } diff --git a/protocol/app/ante/market_update_test.go b/protocol/app/ante/market_update_test.go index 861f98afd67..38e948ffa38 100644 --- a/protocol/app/ante/market_update_test.go +++ b/protocol/app/ante/market_update_test.go @@ -459,6 +459,22 @@ func TestValidateMarketUpdateDecorator_AnteHandle(t *testing.T) { }, wantErr: true, }, + { + name: "reject a single update-markets message with a new market that's enabled", + args: args{ + msgs: []sdk.Msg{ + &mmtypes.MsgUpdateMarkets{ + Authority: constants.BobAccAddress.String(), + UpdateMarkets: []mmtypes.Market{ + testMarketWithEnabled, + }, + }, + }, + simulate: false, + marketMapMarkets: []mmtypes.Market{testMarket}, // existing mm market is disabled + }, + wantErr: true, + }, { name: "reject a single message with a new market that's enabled - simulate", args: args{ @@ -470,7 +486,54 @@ func TestValidateMarketUpdateDecorator_AnteHandle(t *testing.T) { }, }, }, - simulate: true, + simulate: true, + marketMapMarkets: []mmtypes.Market{testMarket}, // existing mm market is disabled + }, + wantErr: true, + }, + { + name: "reject a single message with a new market that's enabled, but doesn't exist in x/marketmap", + args: args{ + msgs: []sdk.Msg{ + &mmtypes.MsgUpsertMarkets{ + Authority: constants.BobAccAddress.String(), + Markets: []mmtypes.Market{ + testMarketWithEnabled, + }, + }, + }, + simulate: false, + }, + wantErr: true, + }, + { + name: "reject a single update-markets message with a new market that's enabled, but doesn't exist in x/marketmap", + args: args{ + msgs: []sdk.Msg{ + &mmtypes.MsgUpdateMarkets{ + Authority: constants.BobAccAddress.String(), + UpdateMarkets: []mmtypes.Market{ + testMarketWithEnabled, + }, + }, + }, + simulate: false, + }, + wantErr: true, + }, + { + name: "reject a single message with a new market that's enabled, but doesn't exist in x/marketmap - simulate", + args: args{ + msgs: []sdk.Msg{ + &mmtypes.MsgUpsertMarkets{ + Authority: constants.BobAccAddress.String(), + Markets: []mmtypes.Market{ + testMarketWithEnabled, + }, + }, + }, + simulate: true, + marketMapMarkets: []mmtypes.Market{testMarket}, // existing mm market is disabled }, wantErr: true, }, @@ -491,6 +554,23 @@ func TestValidateMarketUpdateDecorator_AnteHandle(t *testing.T) { }, wantErr: true, }, + { + name: "reject single update markets message disabling a market", + args: args{ + msgs: []sdk.Msg{ + &mmtypes.MsgUpsertMarkets{ + Authority: constants.BobAccAddress.String(), + Markets: []mmtypes.Market{ + testMarket, + }, + }, + }, + simulate: false, + marketMapMarkets: []mmtypes.Market{testMarketWithEnabled}, + marketParams: []prices_types.MarketParam{testMarketParams}, + }, + wantErr: true, + }, { name: "reject single message disabling a market - simulate", args: args{ @@ -514,6 +594,11 @@ func TestValidateMarketUpdateDecorator_AnteHandle(t *testing.T) { tApp := testapp.NewTestAppBuilder(t).Build() ctx := tApp.InitChain() + // setup initial market-map markets + for _, market := range tt.args.marketMapMarkets { + require.NoError(t, tApp.App.MarketMapKeeper.CreateMarket(ctx, market)) + } + for _, mp := range tt.args.marketParams { marketID := rand.Uint32() mp.Id = marketID @@ -525,11 +610,6 @@ func TestValidateMarketUpdateDecorator_AnteHandle(t *testing.T) { require.NoError(t, err) } - // setup initial market-map markets - for _, market := range tt.args.marketMapMarkets { - require.NoError(t, tApp.App.MarketMapKeeper.CreateMarket(ctx, market)) - } - // setup initial perps based on test for _, pair := range tt.args.marketPerps { marketID := rand.Uint32()