Skip to content

Commit

Permalink
additional test-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nivasan1 committed Jul 24, 2024
1 parent 5e3d51a commit 9ec5a76
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion protocol/app/ante/market_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down
92 changes: 86 additions & 6 deletions protocol/app/ante/market_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
},
Expand All @@ -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{
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 9ec5a76

Please sign in to comment.