Skip to content

Commit

Permalink
test(msgs): UpdateParams, MsgPayout
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Jun 2, 2024
1 parent 676ed60 commit 09e412b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
2 changes: 0 additions & 2 deletions x/manifest/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func (ms msgServer) UpdateParams(ctx context.Context, req *types.MsgUpdateParams
return nil, ms.k.Params.Set(ctx, req.Params)
}

// PayoutStakeholders implements types.MsgServer.
func (ms msgServer) Payout(ctx context.Context, req *types.MsgPayout) (*types.MsgPayoutResponse, error) {
if ms.k.authority != req.Authority {
return nil, fmt.Errorf("invalid authority; expected %s, got %s", ms.k.authority, req.Authority)
Expand All @@ -45,7 +44,6 @@ func (ms msgServer) Payout(ctx context.Context, req *types.MsgPayout) (*types.Ms
return nil, ms.k.PayoutStakeholders(ctx, req.PayoutPairs)
}

// BurnHeldBalance implements types.MsgServer.
func (ms msgServer) BurnHeldBalance(ctx context.Context, msg *types.MsgBurnHeldBalance) (*types.MsgBurnHeldBalanceResponse, error) {
addr, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions x/manifest/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ func (msg *MsgPayout) Validate() error {
return fmt.Errorf("coin cannot be zero for address: %s", addr)
}

if coin.IsNegative() {
return fmt.Errorf("coin cannot be negative for address: %s", addr)
}

if err := coin.Validate(); err != nil {
return errors.Wrapf(err, "invalid coin: %v for address: %s", coin, addr)
}
Expand Down
83 changes: 83 additions & 0 deletions x/manifest/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestMsgUpdateParams(t *testing.T) {
_, _, acc := testdata.KeyTestPubAddr()

type tc struct {
name string
msg *MsgUpdateParams
success bool
}

for _, c := range []tc{
{
name: "success; valid update params",
msg: NewMsgUpdateParams(acc),
success: true,
},
{
name: "fail; bad address",
msg: &MsgUpdateParams{
Authority: "bad",
Params: NewParams(),
},
},
} {
c := c
t.Run(c.name, func(t *testing.T) {
if c.success {
require.NoError(t, c.msg.Validate())
} else {
require.Error(t, c.msg.Validate())
}
})
}
}

func TestMsgBurn(t *testing.T) {
_, _, acc := testdata.KeyTestPubAddr()

Expand Down Expand Up @@ -49,3 +83,52 @@ func TestMsgBurn(t *testing.T) {
})
}
}

func TestMsgPayout(t *testing.T) {
_, _, authority := testdata.KeyTestPubAddr()
_, _, acc := testdata.KeyTestPubAddr()

type tc struct {
name string
msg *MsgPayout
success bool
}

for _, c := range []tc{
{
name: "fail; no payouts",
msg: NewMsgPayout(authority, []PayoutPair{}),
},
{
name: "fail; bad payout address",
msg: NewMsgPayout(authority, []PayoutPair{
{
Address: "bad",
Coin: sdk.NewCoin("stake", sdkmath.NewInt(5)),
},
}),
},
{
name: "fail; 0 payout coins",
msg: NewMsgPayout(authority, []PayoutPair{
NewPayoutPair(acc, "stake", 0),
}),
},
{
name: "success; payout",
msg: NewMsgPayout(authority, []PayoutPair{
NewPayoutPair(acc, "stake", 5),
}),
success: true,
},
} {
c := c
t.Run(c.name, func(t *testing.T) {
if c.success {
require.NoError(t, c.msg.Validate())
} else {
require.Error(t, c.msg.Validate())
}
})
}
}

0 comments on commit 09e412b

Please sign in to comment.