Skip to content

Commit

Permalink
duplicate address check
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jun 3, 2024
1 parent 2615b2d commit 21de617
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions interchaintest/mainfest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ func TestManifestModule(t *testing.T) {
})

t.Run("fail: invalid payout addr", func(t *testing.T) {
_, err = helpers.ManifestStakeholderPayout(t, ctx, appChain, poaAdmin, []manifesttypes.PayoutPair{
manifesttypes.NewPayoutPair(sdk.MustAccAddressFromBech32(uaddr), Denom, 1),
manifesttypes.NewPayoutPair(sdk.MustAccAddressFromBech32(uaddr), Denom, 2),
})
require.Error(t, err)
})

t.Run("fail: duplicate address payout", func(t *testing.T) {
_, err = helpers.ManifestStakeholderPayout(t, ctx, appChain, poaAdmin, []manifesttypes.PayoutPair{
{
Address: "abcdefg",
Expand Down
9 changes: 9 additions & 0 deletions x/manifest/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ func TestPerformPayout(t *testing.T) {
},
shouldFail: true,
},
{
name: "fail; duplicate address",
sender: authority.String(),
payouts: []types.PayoutPair{
types.NewPayoutPair(acc, "umfx", 1),
types.NewPayoutPair(acc, "umfx", 1),
},
shouldFail: true,
},
{
name: "fail; payout to bad address",
sender: authority.String(),
Expand Down
11 changes: 11 additions & 0 deletions x/manifest/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (msg *MsgPayout) Validate() error {
return fmt.Errorf("payouts cannot be empty")
}

dupCheck := make([]string, 0, len(msg.PayoutPairs))

for _, p := range msg.PayoutPairs {
p := p

Expand All @@ -110,6 +112,15 @@ func (msg *MsgPayout) Validate() error {
if err := coin.Validate(); err != nil {
return errors.Wrapf(err, "invalid coin: %v for address: %s", coin, addr)

Check warning on line 113 in x/manifest/types/msgs.go

View check run for this annotation

Codecov / codecov/patch

x/manifest/types/msgs.go#L113

Added line #L113 was not covered by tests
}

for _, d := range dupCheck {
d := d
if d == addr {
return fmt.Errorf("duplicate address: %s", addr)
}
}

dupCheck = append(dupCheck, addr)
}

return nil
Expand Down
7 changes: 7 additions & 0 deletions x/manifest/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func TestMsgPayout(t *testing.T) {
},
}),
},
{
name: "fail; duplicate address",
msg: NewMsgPayout(authority, []PayoutPair{
NewPayoutPair(acc, "stake", 1),
NewPayoutPair(acc, "stake", 2),
}),
},
{
name: "fail; 0 payout coins",
msg: NewMsgPayout(authority, []PayoutPair{
Expand Down

0 comments on commit 21de617

Please sign in to comment.