Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Sep 20, 2024
1 parent 999f504 commit b099577
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
10 changes: 5 additions & 5 deletions protocol/app/ante/market_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (d ValidateMarketUpdateDecorator) AnteHandle(
return ctx, fmt.Errorf("unrecognized message type: %T", msg)
}

if contains := d.doMarketsContainRestrictedMarket(ctx, markets); contains {
return ctx, ErrNoCrossMarketUpdates
if contains, ticker := d.doMarketsContainRestrictedMarket(ctx, markets); contains {
return ctx, fmt.Errorf("%w: %s", ErrNoCrossMarketUpdates, ticker)
}

// check if the market updates are safe
Expand All @@ -95,7 +95,7 @@ func (d ValidateMarketUpdateDecorator) AnteHandle(
func (d ValidateMarketUpdateDecorator) doMarketsContainRestrictedMarket(
ctx sdk.Context,
markets []mmtypes.Market,
) bool {
) (bool, string) {
// Grab all the perpetuals markets
perps := d.perpKeeper.GetAllPerpetuals(ctx)
restrictedMap := make(map[string]bool, len(perps))
Expand Down Expand Up @@ -123,11 +123,11 @@ func (d ValidateMarketUpdateDecorator) doMarketsContainRestrictedMarket(

restricted, found := restrictedMap[ticker]
if found && restricted {
return true
return true, ticker
}
}

return false
return false, ""
}

// doMarketsUpdateEnabledValues checks if the given markets updates are safe, specifically:
Expand Down
49 changes: 49 additions & 0 deletions protocol/app/ante/market_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ var (
},
}

testUSDTUSDMarket = mmtypes.Market{
Ticker: mmtypes.Ticker{
CurrencyPair: types.CurrencyPair{
Base: "USDT",
Quote: "USD",
},
Decimals: 1,
MinProviderCount: 1,
Enabled: true,
Metadata_JSON: "",
},
ProviderConfigs: []mmtypes.ProviderConfig{
{
Name: "test_provider",
OffChainTicker: "USDT/USD",
},
},
}

enabledTestMarketWithProviderConfig = mmtypes.Market{
Ticker: mmtypes.Ticker{
CurrencyPair: types.CurrencyPair{
Expand Down Expand Up @@ -725,6 +744,36 @@ func TestValidateMarketUpdateDecorator_AnteHandle(t *testing.T) {
},
wantErr: false,
},
{
name: "always reject USDT/USD - simulate",
args: args{
msgs: []sdk.Msg{
&mmtypes.MsgUpsertMarkets{
Authority: constants.BobAccAddress.String(),
Markets: []mmtypes.Market{
testUSDTUSDMarket,
},
},
},
simulate: true,
},
wantErr: true,
},
{
name: "always reject USDT/USD",
args: args{
msgs: []sdk.Msg{
&mmtypes.MsgUpdateMarkets{
Authority: constants.BobAccAddress.String(),
UpdateMarkets: []mmtypes.Market{
testUSDTUSDMarket,
},
},
},
simulate: false,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit b099577

Please sign in to comment.