diff --git a/protocol/testing/e2e/gov/prices_test.go b/protocol/testing/e2e/gov/prices_test.go index 89f2b996b8..ad341b83b3 100644 --- a/protocol/testing/e2e/gov/prices_test.go +++ b/protocol/testing/e2e/gov/prices_test.go @@ -67,6 +67,20 @@ func TestUpdateMarketParam(t *testing.T) { }, expectedProposalStatus: govtypesv1.ProposalStatus_PROPOSAL_STATUS_FAILED, }, + "Failure: new pair name does not exist in marketmap": { + msg: &pricestypes.MsgUpdateMarketParam{ + Authority: lib.GovModuleAddress.String(), + MarketParam: pricestypes.MarketParam{ + Id: MODIFIED_MARKET_PARAM.Id, + Pair: "nonexistent-pair", + Exponent: MODIFIED_MARKET_PARAM.Exponent, + MinExchanges: MODIFIED_MARKET_PARAM.MinExchanges, + MinPriceChangePpm: MODIFIED_MARKET_PARAM.MinPriceChangePpm, + ExchangeConfigJson: MODIFIED_MARKET_PARAM.ExchangeConfigJson, + }, + }, + expectedProposalStatus: govtypesv1.ProposalStatus_PROPOSAL_STATUS_FAILED, + }, "Failure: exponent is updated": { msg: &pricestypes.MsgUpdateMarketParam{ Authority: lib.GovModuleAddress.String(), diff --git a/protocol/x/prices/keeper/msg_server_update_market_param_test.go b/protocol/x/prices/keeper/msg_server_update_market_param_test.go index b04959a7a6..5e837330e8 100644 --- a/protocol/x/prices/keeper/msg_server_update_market_param_test.go +++ b/protocol/x/prices/keeper/msg_server_update_market_param_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/lib/slinky" "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" keepertest "github.com/dydxprotocol/v4-chain/protocol/testutil/keeper" @@ -26,7 +27,7 @@ func TestUpdateMarketParam(t *testing.T) { msg *pricestypes.MsgUpdateMarketParam expectedErr string }{ - "Succeeds: update all parameters except exponent": { + "Succeeds: update all parameters except exponent and pair": { msg: &pricestypes.MsgUpdateMarketParam{ Authority: lib.GovModuleAddress.String(), MarketParam: pricestypes.MarketParam{ @@ -39,6 +40,19 @@ func TestUpdateMarketParam(t *testing.T) { }, }, }, + "Succeeds: update pair name": { + msg: &pricestypes.MsgUpdateMarketParam{ + Authority: lib.GovModuleAddress.String(), + MarketParam: pricestypes.MarketParam{ + Id: testMarketParam.Id, + Pair: "NEWMARKET-USD", + Exponent: testMarketParam.Exponent, + MinExchanges: 72, + MinPriceChangePpm: 2_023, + ExchangeConfigJson: `{"exchanges":[{"exchangeName":"XYZ","ticker":"PIKACHU"}]}`, + }, + }, + }, "Succeeds: update min price change ppm only": { msg: &pricestypes.MsgUpdateMarketParam{ Authority: lib.GovModuleAddress.String(), @@ -122,6 +136,20 @@ func TestUpdateMarketParam(t *testing.T) { }, expectedErr: "Market exponent cannot be updated", }, + "Failure: new pair name does not exist in marketmap": { + msg: &pricestypes.MsgUpdateMarketParam{ + Authority: lib.GovModuleAddress.String(), + MarketParam: pricestypes.MarketParam{ + Id: testMarketParam.Id, + Pair: "nonexistent-pair", + Exponent: testMarketParam.Exponent, + MinExchanges: testMarketParam.MinExchanges, + MinPriceChangePpm: testMarketParam.MinPriceChangePpm, + ExchangeConfigJson: "{}", + }, + }, + expectedErr: "NONEXISTENT/PAIR: Ticker not found in market map", + }, "Failure: empty authority": { msg: &pricestypes.MsgUpdateMarketParam{ Authority: "", @@ -144,12 +172,22 @@ func TestUpdateMarketParam(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { - ctx, pricesKeeper, _, _, mockTimeProvider, _, _ := keepertest.PricesKeepers(t) + ctx, pricesKeeper, _, _, mockTimeProvider, _, marketMapKeeper := keepertest.PricesKeepers(t) mockTimeProvider.On("Now").Return(constants.TimeT) msgServer := keeper.NewMsgServerImpl(pricesKeeper) initialMarketParam, err := keepertest.CreateTestMarket(t, ctx, pricesKeeper, testMarketParam, testMarketPrice) require.NoError(t, err) + // Create new pair in marketmap if test is expected to succeed + if (initialMarketParam.Pair != tc.msg.MarketParam.Pair) && tc.expectedErr == "" { + keepertest.CreateMarketsInMarketMapFromParams( + t, + ctx, + marketMapKeeper, + []pricestypes.MarketParam{tc.msg.MarketParam}, + ) + } + _, err = msgServer.UpdateMarketParam(ctx, tc.msg) if tc.expectedErr != "" { require.ErrorContains(t, err, tc.expectedErr) @@ -163,6 +201,21 @@ func TestUpdateMarketParam(t *testing.T) { updatedMarketParam, exists := pricesKeeper.GetMarketParam(ctx, tc.msg.MarketParam.Id) require.True(t, exists) require.Equal(t, tc.msg.MarketParam, updatedMarketParam) + + // If pair name changed, verify that old pair is disabled in the marketmap and new pair is enabled + if initialMarketParam.Pair != updatedMarketParam.Pair { + oldCp, err := slinky.MarketPairToCurrencyPair(initialMarketParam.Pair) + require.NoError(t, err) + oldMarket, err := marketMapKeeper.GetMarket(ctx, oldCp.String()) + require.NoError(t, err) + require.False(t, oldMarket.Ticker.Enabled) + + newCp, err := slinky.MarketPairToCurrencyPair(updatedMarketParam.Pair) + require.NoError(t, err) + market, err := marketMapKeeper.GetMarket(ctx, newCp.String()) + require.NoError(t, err) + require.True(t, market.Ticker.Enabled) + } } }) }