Skip to content

Commit

Permalink
[1658]: Update MsgMarketManageReqAttrsRequest validation to make sure…
Browse files Browse the repository at this point in the history
… the market id isn't zero. Fix some other unit tests that broke a while back when I took out some colons from the error messages.
  • Loading branch information
SpicyLemon committed Sep 15, 2023
1 parent 5d83522 commit a6d0805
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
4 changes: 4 additions & 0 deletions x/exchange/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ func (m MsgMarketManageReqAttrsRequest) ValidateBasic() error {
errs = append(errs, fmt.Errorf("invalid administrator %q: %w", m.Administrator, err))
}

if m.MarketId == 0 {
errs = append(errs, fmt.Errorf("invalid market id: cannot be zero"))
}

if m.HasUpdates() {
errs = append(errs,
ValidateAddRemoveReqAttrs("create-ask", m.CreateAskToAdd, m.CreateAskToRemove),
Expand Down
59 changes: 43 additions & 16 deletions x/exchange/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ func TestAllMsgsGetSigners(t *testing.T) {
// TODO[1658]: Add MsgMarketUpdateEnabledRequest once it's actually been defined.
// TODO[1658]: Add MsgMarketUpdateUserSettleRequest once it's actually been defined.
// TODO[1658]: Add MsgMarketManagePermissionsRequest once it's actually been defined.
// TODO[1658]: Add MsgMarketManageReqAttrsRequest once it's actually been defined.
func(signer string) sdk.Msg {
return &MsgMarketManageReqAttrsRequest{Administrator: signer}
},
func(signer string) sdk.Msg {
return &MsgGovCreateMarketRequest{Authority: signer}
},
Expand Down Expand Up @@ -423,6 +425,7 @@ func TestMsgMarketManageReqAttrsRequest_ValidateBasic(t *testing.T) {
name: "no admin",
msg: MsgMarketManageReqAttrsRequest{
Administrator: "",
MarketId: 1,
CreateAskToAdd: []string{"abc"},
},
expErr: []string{"invalid administrator", "empty address string is not allowed"},
Expand All @@ -431,19 +434,32 @@ func TestMsgMarketManageReqAttrsRequest_ValidateBasic(t *testing.T) {
name: "bad admin",
msg: MsgMarketManageReqAttrsRequest{
Administrator: "not1valid",
MarketId: 1,
CreateAskToAdd: []string{"abc"},
},
expErr: []string{"invalid administrator", "decoding bech32 failed"},
},
{
name: "no updates",
msg: MsgMarketManageReqAttrsRequest{Administrator: goodAdmin},
name: "market id zero",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
CreateAskToAdd: []string{"abc"},
},
expErr: []string{"invalid market id: cannot be zero"},
},
{
name: "no updates",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
},
expErr: []string{"no updates"},
},
{
name: "invalid create ask to add entry",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateAskToAdd: []string{"in-valid-attr"},
},
expErr: []string{"invalid create-ask to add required attribute \"in-valid-attr\""},
Expand All @@ -452,13 +468,15 @@ func TestMsgMarketManageReqAttrsRequest_ValidateBasic(t *testing.T) {
name: "invalid create ask to remove entry",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateAskToRemove: []string{"in-valid-attr"},
},
},
{
name: "invalid create bid to add entry",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateBidToAdd: []string{"in-valid-attr"},
},
expErr: []string{"invalid create-bid to add required attribute \"in-valid-attr\""},
Expand All @@ -467,13 +485,15 @@ func TestMsgMarketManageReqAttrsRequest_ValidateBasic(t *testing.T) {
name: "invalid create bid to remove entry",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateBidToRemove: []string{"in-valid-attr"},
},
},
{
name: "add and remove same create ask entry",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateAskToAdd: []string{"abc", "def", "ghi"},
CreateAskToRemove: []string{"jkl", "abc"},
},
Expand All @@ -483,6 +503,7 @@ func TestMsgMarketManageReqAttrsRequest_ValidateBasic(t *testing.T) {
name: "add and remove same create bid entry",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateBidToAdd: []string{"abc", "def", "ghi"},
CreateBidToRemove: []string{"jkl", "abc"},
},
Expand All @@ -492,6 +513,7 @@ func TestMsgMarketManageReqAttrsRequest_ValidateBasic(t *testing.T) {
name: "add to create-ask the same as remove from create-bid",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateAskToAdd: []string{"abc", "def", "ghi"},
CreateBidToRemove: []string{"jkl", "abc"},
},
Expand All @@ -500,6 +522,7 @@ func TestMsgMarketManageReqAttrsRequest_ValidateBasic(t *testing.T) {
name: "add to create-bid the same as remove from create-ask",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateBidToAdd: []string{"abc", "def", "ghi"},
CreateAskToRemove: []string{"jkl", "abc"},
},
Expand All @@ -508,31 +531,35 @@ func TestMsgMarketManageReqAttrsRequest_ValidateBasic(t *testing.T) {
name: "add one to and remove one from each",
msg: MsgMarketManageReqAttrsRequest{
Administrator: goodAdmin,
MarketId: 1,
CreateAskToAdd: []string{"to-add.ask"},
CreateAskToRemove: []string{"to-remove.ask"},
CreateBidToAdd: []string{"to-add.bid"},
CreateBidToRemove: []string{"to-remove.bid"},
},
},
{
name: "no admin and no updates",
name: "no admin and no market id and no updates",
msg: MsgMarketManageReqAttrsRequest{},
expErr: []string{
"invalid administrator",
"invalid market id",
"no updates",
},
},
{
name: "multiple errors",
msg: MsgMarketManageReqAttrsRequest{
Administrator: "not1valid",
MarketId: 0,
CreateAskToAdd: []string{"bad-ask-attr", "dup-ask"},
CreateAskToRemove: []string{"dup-ask"},
CreateBidToAdd: []string{"bad-bid-attr", "dup-bid"},
CreateBidToRemove: []string{"dup-bid"},
},
expErr: []string{
"invalid administrator",
"invalid market id",
"invalid create-ask to add required attribute \"bad-ask-attr\"",
"cannot add and remove the same create-ask required attributes \"dup-ask\"",
"invalid create-bid to add required attribute \"bad-bid-attr\"",
Expand Down Expand Up @@ -695,7 +722,7 @@ func TestMsgGovManageFeesRequest_ValidateBasic(t *testing.T) {
AddFeeCreateAskFlat: []sdk.Coin{coin(1, "nhash")},
RemoveFeeCreateAskFlat: []sdk.Coin{coin(1, "nhash")},
},
expErr: []string{"cannot add and remove the same create-ask flat fee options: 1nhash"},
expErr: []string{"cannot add and remove the same create-ask flat fee options 1nhash"},
},
{
name: "invalid add create-bid flat",
Expand All @@ -712,7 +739,7 @@ func TestMsgGovManageFeesRequest_ValidateBasic(t *testing.T) {
AddFeeCreateBidFlat: []sdk.Coin{coin(1, "nhash")},
RemoveFeeCreateBidFlat: []sdk.Coin{coin(1, "nhash")},
},
expErr: []string{"cannot add and remove the same create-bid flat fee options: 1nhash"},
expErr: []string{"cannot add and remove the same create-bid flat fee options 1nhash"},
},
{
name: "invalid add seller settlement flat",
Expand All @@ -729,7 +756,7 @@ func TestMsgGovManageFeesRequest_ValidateBasic(t *testing.T) {
AddFeeSellerSettlementFlat: []sdk.Coin{coin(1, "nhash")},
RemoveFeeSellerSettlementFlat: []sdk.Coin{coin(1, "nhash")},
},
expErr: []string{"cannot add and remove the same seller settlement flat fee options: 1nhash"},
expErr: []string{"cannot add and remove the same seller settlement flat fee options 1nhash"},
},
{
name: "invalid add seller settlement ratio",
Expand All @@ -746,7 +773,7 @@ func TestMsgGovManageFeesRequest_ValidateBasic(t *testing.T) {
AddFeeSellerSettlementRatios: []FeeRatio{ratio(2, "nhash", 1, "nhash")},
RemoveFeeSellerSettlementRatios: []FeeRatio{ratio(2, "nhash", 1, "nhash")},
},
expErr: []string{"cannot add and remove the same seller settlement fee ratios: 2nhash:1nhash"},
expErr: []string{"cannot add and remove the same seller settlement fee ratios 2nhash:1nhash"},
},
{
name: "invalid add buyer settlement flat",
Expand All @@ -763,7 +790,7 @@ func TestMsgGovManageFeesRequest_ValidateBasic(t *testing.T) {
AddFeeBuyerSettlementFlat: []sdk.Coin{coin(1, "nhash")},
RemoveFeeBuyerSettlementFlat: []sdk.Coin{coin(1, "nhash")},
},
expErr: []string{"cannot add and remove the same buyer settlement flat fee options: 1nhash"},
expErr: []string{"cannot add and remove the same buyer settlement flat fee options 1nhash"},
},
{
name: "invalid add buyer settlement ratio",
Expand All @@ -780,7 +807,7 @@ func TestMsgGovManageFeesRequest_ValidateBasic(t *testing.T) {
AddFeeBuyerSettlementRatios: []FeeRatio{ratio(2, "nhash", 1, "nhash")},
RemoveFeeBuyerSettlementRatios: []FeeRatio{ratio(2, "nhash", 1, "nhash")},
},
expErr: []string{"cannot add and remove the same buyer settlement fee ratios: 2nhash:1nhash"},
expErr: []string{"cannot add and remove the same buyer settlement fee ratios 2nhash:1nhash"},
},
{
name: "multiple errors",
Expand All @@ -802,17 +829,17 @@ func TestMsgGovManageFeesRequest_ValidateBasic(t *testing.T) {
expErr: []string{
"invalid authority", "empty address string is not allowed",
`invalid create-ask flat fee to add option "0nhash": amount cannot be zero`,
"cannot add and remove the same create-ask flat fee options: 0nhash",
"cannot add and remove the same create-ask flat fee options 0nhash",
`invalid create-bid flat fee to add option "0nhash": amount cannot be zero`,
"cannot add and remove the same create-bid flat fee options: 0nhash",
"cannot add and remove the same create-bid flat fee options 0nhash",
`invalid seller settlement flat fee to add option "0nhash": amount cannot be zero`,
"cannot add and remove the same seller settlement flat fee options: 0nhash",
"cannot add and remove the same seller settlement flat fee options 0nhash",
`seller fee ratio fee amount "2nhash" cannot be greater than price amount "1nhash"`,
"cannot add and remove the same seller settlement fee ratios: 1nhash:2nhash",
"cannot add and remove the same seller settlement fee ratios 1nhash:2nhash",
`invalid buyer settlement flat fee to add option "0nhash": amount cannot be zero`,
"cannot add and remove the same buyer settlement flat fee options: 0nhash",
"cannot add and remove the same buyer settlement flat fee options 0nhash",
`buyer fee ratio fee amount "2nhash" cannot be greater than price amount "1nhash"`,
"cannot add and remove the same buyer settlement fee ratios: 1nhash:2nhash",
"cannot add and remove the same buyer settlement fee ratios 1nhash:2nhash",
},
},
}
Expand Down

0 comments on commit a6d0805

Please sign in to comment.