Skip to content

Commit

Permalink
chore: add duplicate issuer validation (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleem1314 authored Apr 8, 2022
1 parent 987d33b commit 21d4003
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions x/ecocredit/core/msg_create_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ func (m *MsgCreateClass) ValidateBasic() error {
if len(m.CreditTypeAbbrev) == 0 {
return sdkerrors.ErrInvalidRequest.Wrap("must specify a credit type abbreviation")
}

duplicateMap := make(map[string]bool)
for _, issuer := range m.Issuers {

if _, err := sdk.AccAddressFromBech32(issuer); err != nil {
return sdkerrors.ErrInvalidRequest.Wrap(err.Error())
}

if _, ok := duplicateMap[issuer]; ok {
return sdkerrors.ErrInvalidRequest.Wrapf("duplicate issuer %s", issuer)
}
duplicateMap[issuer] = true
}

if m.Fee != nil {
Expand Down
10 changes: 10 additions & 0 deletions x/ecocredit/core/msg_create_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ func TestMsgCreateClass(t *testing.T) {
},
expErr: true,
},
"invalid duplicate issuer": {
src: MsgCreateClass{
Admin: addr1.String(),
Issuers: []string{addr1.String(), addr2.String(), addr1.String()},
CreditTypeAbbrev: "C",
Metadata: "hello",
Fee: validFee,
},
expErr: true,
},
}

for msg, test := range tests {
Expand Down

0 comments on commit 21d4003

Please sign in to comment.