Skip to content

Commit

Permalink
chore: backport #838 (#869)
Browse files Browse the repository at this point in the history
Co-authored-by: Chenyao Yu <4844716+chenyaoy@users.noreply.github.com>
  • Loading branch information
aljo242 and chenyaoy authored Dec 11, 2024
1 parent 2341cdd commit 855e377
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 188 deletions.
176 changes: 88 additions & 88 deletions api/slinky/marketmap/v1/tx.pulsar.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions proto/slinky/marketmap/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ message MsgRemoveMarketAuthoritiesResponse {}
// MsgRemoveMarkets defines the Msg/RemoveMarkets request type. It contains the
// new markets to be removed from the market map.
message MsgRemoveMarkets {
option (cosmos.msg.v1.signer) = "admin";
option (cosmos.msg.v1.signer) = "authority";

// Admin defines the authority that is the x/marketmap
// Admin account. This account is set in the module parameters.
string admin = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// Authority is the signer of this transaction. This authority must be
// authorized by the module to execute the message.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Markets is the list of markets to remove.
repeated string markets = 2;
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/slinky_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ func (s *SlinkyIntegrationSuite) RemoveMarket(
}

msg := &mmtypes.MsgRemoveMarkets{
Admin: s.user.FormattedAddress(),
Markets: marketString,
Authority: s.user.FormattedAddress(),
Markets: marketString,
}

tx := CreateTx(s.T(), s.chain, s.user, gasPrice, msg)
Expand Down
10 changes: 3 additions & 7 deletions x/marketmap/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,9 @@ func (ms msgServer) RemoveMarkets(

ctx := sdk.UnwrapSDKContext(goCtx)

params, err := ms.k.GetParams(ctx)
if err != nil {
return nil, err
}

if msg.Admin != params.Admin {
return nil, fmt.Errorf("request admin %s does not match module admin %s", msg.Admin, params.Admin)
// perform basic msg validity checks
if err := ms.verifyMarketAuthorities(ctx, msg); err != nil {
return nil, fmt.Errorf("unable to verify market authorities: %w", err)
}

deletedMarkets := make([]string, 0, len(msg.Markets))
Expand Down
34 changes: 17 additions & 17 deletions x/marketmap/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {

s.Run("unable to process for invalid authority", func() {
msg := &types.MsgRemoveMarkets{
Admin: "invalid",
Authority: "invalid",
}
resp, err := msgServer.RemoveMarkets(s.ctx, msg)
s.Require().Error(err)
Expand All @@ -540,8 +540,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {

s.Run("only remove existing markets - no error", func() {
msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{"BTC/USD", "ETH/USDT"},
Authority: s.marketAuthorities[0],
Markets: []string{"BTC/USD", "ETH/USDT"},
}
resp, err := msgServer.RemoveMarkets(s.ctx, msg)
s.Require().NoError(err)
Expand All @@ -550,8 +550,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {

s.Run("unable to remove non-existent market - single", func() {
msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{"BTC/USD"},
Authority: s.marketAuthorities[0],
Markets: []string{"BTC/USD"},
}
resp, err := msgServer.RemoveMarkets(s.ctx, msg)
s.Require().NoError(err)
Expand All @@ -563,8 +563,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
copyBTC.Ticker.Enabled = false

msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String()},
}

err := s.keeper.CreateMarket(s.ctx, copyBTC)
Expand All @@ -587,8 +587,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
s.Require().NoError(err)

msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String()},
}

resp, err := msgServer.RemoveMarkets(s.ctx, msg)
Expand Down Expand Up @@ -638,13 +638,13 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
s.Require().NoError(err)

msgRemoveBTC := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String()},
}

msgRemoveETH := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyETH.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyETH.Ticker.String()},
}

resp, err := msgServer.RemoveMarkets(s.ctx, msgRemoveBTC)
Expand Down Expand Up @@ -673,8 +673,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
s.Require().NoError(err)

msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String(), copyETH.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String(), copyETH.Ticker.String()},
}

resp, err := msgServer.RemoveMarkets(s.ctx, msg)
Expand Down Expand Up @@ -713,8 +713,8 @@ func (s *KeeperTestSuite) TestMsgServerRemoveMarkets() {
s.Require().NoError(err)

msg := &types.MsgRemoveMarkets{
Admin: s.admin,
Markets: []string{copyBTC.Ticker.String(), copyETH.Ticker.String()},
Authority: s.marketAuthorities[0],
Markets: []string{copyBTC.Ticker.String(), copyETH.Ticker.String()},
}

resp, err := msgServer.RemoveMarkets(s.ctx, msg)
Expand Down
2 changes: 1 addition & 1 deletion x/marketmap/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (m *MsgRemoveMarketAuthorities) ValidateBasic() error {
// whether the signer is a valid acc-address.
func (m *MsgRemoveMarkets) ValidateBasic() error {
// validate signer address
if _, err := sdk.AccAddressFromBech32(m.Admin); err != nil {
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {
return err
}

Expand Down
18 changes: 9 additions & 9 deletions x/marketmap/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,39 +528,39 @@ func TestValidateBasicMsgRemoveMarkets(t *testing.T) {
{
"if the Authority is not an acc-address - fail",
types.MsgRemoveMarkets{
Admin: "invalid",
Authority: "invalid",
},
false,
},
{
name: "invalid message (no markets) - fail",
msg: types.MsgRemoveMarkets{
Markets: nil,
Admin: sample.Address(rng),
Markets: nil,
Authority: sample.Address(rng),
},
expectPass: false,
},
{
name: "valid message - single market",
msg: types.MsgRemoveMarkets{
Markets: []string{"USDT/USD"},
Admin: sample.Address(rng),
Markets: []string{"USDT/USD"},
Authority: sample.Address(rng),
},
expectPass: true,
},
{
name: "valid message - multiple markets",
msg: types.MsgRemoveMarkets{
Markets: []string{"USDT/USD", "ETH/USD"},
Admin: sample.Address(rng),
Markets: []string{"USDT/USD", "ETH/USD"},
Authority: sample.Address(rng),
},
expectPass: true,
},
{
name: "invalid message (duplicate markets",
msg: types.MsgRemoveMarkets{
Markets: []string{"USDT/USD", "USDT/USD"},
Admin: sample.Address(rng),
Markets: []string{"USDT/USD", "USDT/USD"},
Authority: sample.Address(rng),
},
expectPass: false,
},
Expand Down
120 changes: 60 additions & 60 deletions x/marketmap/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 855e377

Please sign in to comment.