From 2327b01ed4ffdec2a173ec0d7809dab1ebd49040 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Tue, 12 May 2020 16:37:08 -0400 Subject: [PATCH] message test --- x/auction/types/msg_test.go | 56 ++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/x/auction/types/msg_test.go b/x/auction/types/msg_test.go index 7ac2909c..948ac22b 100644 --- a/x/auction/types/msg_test.go +++ b/x/auction/types/msg_test.go @@ -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) + } } }