Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ValidateDenom for MsgSend, MsgRetire, and MsgCancel #554

Merged
merged 7 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions x/ecocredit/client/testsuite/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,8 @@ func (s *IntegrationTestSuite) TestTxSend() {
},
s.commonTxFlags()...,
),
expectErr: true,
errInTxResponse: true,
expectedErrMsg: "abcde is not a valid credit batch denom",
expectErr: true,
expectedErrMsg: "denomination didn't match the format",
},
{
name: "invalid tradable amount",
Expand Down Expand Up @@ -930,9 +929,8 @@ func (s *IntegrationTestSuite) TestTxRetire() {
},
s.commonTxFlags()...,
),
expectErr: true,
errInTxResponse: true,
expectedErrMsg: "abcde is not a valid credit batch denom",
expectErr: true,
expectedErrMsg: "denomination didn't match the format",
aleem1314 marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: "invalid amount",
Expand Down
13 changes: 7 additions & 6 deletions x/ecocredit/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func (m *MsgSend) ValidateBasic() error {
}

for _, credit := range m.Credits {
if credit.BatchDenom == "" {
return sdkerrors.ErrInvalidRequest.Wrap("batch denom should not be empty")
if err := ValidateDenom(credit.BatchDenom); err != nil {
return err
}

if _, err := math.NewNonNegativeDecFromString(credit.TradableAmount); err != nil {
Expand Down Expand Up @@ -210,9 +210,10 @@ func (m *MsgRetire) ValidateBasic() error {
}

for _, credit := range m.Credits {
if credit.BatchDenom == "" {
return sdkerrors.ErrInvalidRequest.Wrap("batch denom should not be empty")
if err := ValidateDenom(credit.BatchDenom); err != nil {
return err
}

if _, err := math.NewPositiveDecFromString(credit.Amount); err != nil {
return err
}
Expand Down Expand Up @@ -252,8 +253,8 @@ func (m *MsgCancel) ValidateBasic() error {
}

for _, credit := range m.Credits {
if credit.BatchDenom == "" {
return sdkerrors.ErrInvalidRequest.Wrap("batch denom should not be empty")
if err := ValidateDenom(credit.BatchDenom); err != nil {
return err
}

if _, err := math.NewPositiveDecFromString(credit.Amount); err != nil {
Expand Down
28 changes: 14 additions & 14 deletions x/ecocredit/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func TestMsgSend(t *testing.T) {
Recipient: addr2.String(),
Credits: []*MsgSend_SendCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
TradableAmount: "10",
RetiredAmount: "10",
RetirementLocation: "ST-UVW XY Z12",
Expand Down Expand Up @@ -505,7 +505,7 @@ func TestMsgSend(t *testing.T) {
Recipient: addr2.String(),
Credits: []*MsgSend_SendCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
TradableAmount: "10",
RetiredAmount: "0",
},
Expand Down Expand Up @@ -567,7 +567,7 @@ func TestMsgRetire(t *testing.T) {
Holder: addr1.String(),
Credits: []*MsgRetire_RetireCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "10",
},
},
Expand All @@ -579,7 +579,7 @@ func TestMsgRetire(t *testing.T) {
src: MsgRetire{
Credits: []*MsgRetire_RetireCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "10",
},
},
Expand All @@ -592,7 +592,7 @@ func TestMsgRetire(t *testing.T) {
Holder: "wrongHolder",
Credits: []*MsgRetire_RetireCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "10",
},
},
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestMsgRetire(t *testing.T) {
Holder: addr1.String(),
Credits: []*MsgRetire_RetireCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
},
},
Location: "AB-CDE FG1 345",
Expand All @@ -636,7 +636,7 @@ func TestMsgRetire(t *testing.T) {
Holder: addr1.String(),
Credits: []*MsgRetire_RetireCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "abc",
},
},
Expand All @@ -649,7 +649,7 @@ func TestMsgRetire(t *testing.T) {
Holder: addr1.String(),
Credits: []*MsgRetire_RetireCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "10",
},
},
Expand All @@ -661,7 +661,7 @@ func TestMsgRetire(t *testing.T) {
Holder: addr1.String(),
Credits: []*MsgRetire_RetireCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "10",
},
},
Expand Down Expand Up @@ -695,7 +695,7 @@ func TestMsgCancel(t *testing.T) {
Holder: addr1.String(),
Credits: []*MsgCancel_CancelCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "10",
},
},
Expand All @@ -706,7 +706,7 @@ func TestMsgCancel(t *testing.T) {
src: MsgCancel{
Credits: []*MsgCancel_CancelCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "10",
},
},
Expand All @@ -718,7 +718,7 @@ func TestMsgCancel(t *testing.T) {
Holder: "wrongHolder",
Credits: []*MsgCancel_CancelCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "10",
},
},
Expand Down Expand Up @@ -747,7 +747,7 @@ func TestMsgCancel(t *testing.T) {
Holder: addr1.String(),
Credits: []*MsgCancel_CancelCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
},
},
},
Expand All @@ -758,7 +758,7 @@ func TestMsgCancel(t *testing.T) {
Holder: addr1.String(),
Credits: []*MsgCancel_CancelCredits{
{
BatchDenom: "some_denom",
BatchDenom: "A00-00000000-00000000-000",
Amount: "abc",
},
},
Expand Down