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) {
addr := sdk.AccAddress([]byte("someName"))
addr, err := sdk.AccAddressFromBech32(testAccAddress1)
require.NoError(t, err)
tests := []struct {
name string
msg MsgPlaceBid
expectPass bool
}{
{"normal",
{
"normal",
NewMsgPlaceBid(1, addr, c("token", 10)),
true,
},
{
"zero id",
NewMsgPlaceBid(0, addr, c("token", 10)),
true},
{"emptyAddr",
NewMsgPlaceBid(0, sdk.AccAddress{}, c("token", 10)),
false},
{"negativeAmount",
NewMsgPlaceBid(0, addr, sdk.Coin{Denom: "token", Amount: sdk.NewInt(-10)}),
false},
{"zeroAmount",
NewMsgPlaceBid(0, addr, c("token", 0)),
true},
false,
},
{
"empty address ",
NewMsgPlaceBid(1, nil, c("token", 10)),
false,
},
{
"invalid address",
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 {
t.Run(tc.name, func(t *testing.T) {
if tc.expectPass {
require.NoError(t, tc.msg.ValidateBasic())
require.NoError(t, tc.msg.ValidateBasic(), tc.name)
} else {
require.Error(t, tc.msg.ValidateBasic())
require.Error(t, tc.msg.ValidateBasic(), tc.name)
}
})
}
}