message test

This commit is contained in:
Federico Kunze 2020-05-12 16:37:08 -04:00
parent 71742d2eef
commit 2327b01ed4
No known key found for this signature in database
GPG Key ID: 655F93A970080A30

View File

@ -9,34 +9,52 @@ import (
) )
func TestMsgPlaceBid_ValidateBasic(t *testing.T) { func TestMsgPlaceBid_ValidateBasic(t *testing.T) {
addr := sdk.AccAddress([]byte("someName")) addr, err := sdk.AccAddressFromBech32(testAccAddress1)
require.NoError(t, err)
tests := []struct { tests := []struct {
name string name string
msg MsgPlaceBid msg MsgPlaceBid
expectPass bool expectPass bool
}{ }{
{"normal", {
"normal",
NewMsgPlaceBid(1, addr, c("token", 10)),
true,
},
{
"zero id",
NewMsgPlaceBid(0, addr, c("token", 10)), NewMsgPlaceBid(0, addr, c("token", 10)),
true}, false,
{"emptyAddr", },
NewMsgPlaceBid(0, sdk.AccAddress{}, c("token", 10)), {
false}, "empty address ",
{"negativeAmount", NewMsgPlaceBid(1, nil, c("token", 10)),
NewMsgPlaceBid(0, addr, sdk.Coin{Denom: "token", Amount: sdk.NewInt(-10)}), false,
false}, },
{"zeroAmount", {
NewMsgPlaceBid(0, addr, c("token", 0)), "invalid address",
true}, NewMsgPlaceBid(1, addr[:10], c("token", 10)),
false,
},
{
"negative amount",
NewMsgPlaceBid(1, addr, sdk.Coin{Denom: "token", Amount: sdk.NewInt(-10)}),
false,
},
{
"zero amount",
NewMsgPlaceBid(1, addr, c("token", 0)),
true,
},
} }
for _, tc := range tests { for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if tc.expectPass { if tc.expectPass {
require.NoError(t, tc.msg.ValidateBasic()) require.NoError(t, tc.msg.ValidateBasic(), tc.name)
} else { } else {
require.Error(t, tc.msg.ValidateBasic()) require.Error(t, tc.msg.ValidateBasic(), tc.name)
} }
})
} }
} }