mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 08:15:19 +00:00
message test
This commit is contained in:
parent
71742d2eef
commit
2327b01ed4
@ -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())
|
||||
} else {
|
||||
require.Error(t, tc.msg.ValidateBasic())
|
||||
}
|
||||
})
|
||||
if tc.expectPass {
|
||||
require.NoError(t, tc.msg.ValidateBasic(), tc.name)
|
||||
} else {
|
||||
require.Error(t, tc.msg.ValidateBasic(), tc.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user