github.com/Finschia/finschia-sdk@v0.48.1/x/distribution/types/msg_test.go (about) 1 package types 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 sdk "github.com/Finschia/finschia-sdk/types" 9 ) 10 11 // test ValidateBasic for MsgSetWithdrawAddress 12 func TestMsgSetWithdrawAddress(t *testing.T) { 13 tests := []struct { 14 delegatorAddr sdk.AccAddress 15 withdrawAddr sdk.AccAddress 16 expectPass bool 17 }{ 18 {delAddr1, delAddr2, true}, 19 {delAddr1, delAddr1, true}, 20 {emptyDelAddr, delAddr1, false}, 21 {delAddr1, emptyDelAddr, false}, 22 {emptyDelAddr, emptyDelAddr, false}, 23 } 24 25 for i, tc := range tests { 26 msg := NewMsgSetWithdrawAddress(tc.delegatorAddr, tc.withdrawAddr) 27 if tc.expectPass { 28 require.Nil(t, msg.ValidateBasic(), "test index: %v", i) 29 } else { 30 require.NotNil(t, msg.ValidateBasic(), "test index: %v", i) 31 } 32 } 33 } 34 35 // test ValidateBasic for MsgWithdrawDelegatorReward 36 func TestMsgWithdrawDelegatorReward(t *testing.T) { 37 tests := []struct { 38 delegatorAddr sdk.AccAddress 39 validatorAddr sdk.ValAddress 40 expectPass bool 41 }{ 42 {delAddr1, valAddr1, true}, 43 {emptyDelAddr, valAddr1, false}, 44 {delAddr1, emptyValAddr, false}, 45 {emptyDelAddr, emptyValAddr, false}, 46 } 47 for i, tc := range tests { 48 msg := NewMsgWithdrawDelegatorReward(tc.delegatorAddr, tc.validatorAddr) 49 if tc.expectPass { 50 require.Nil(t, msg.ValidateBasic(), "test index: %v", i) 51 } else { 52 require.NotNil(t, msg.ValidateBasic(), "test index: %v", i) 53 } 54 } 55 } 56 57 // test ValidateBasic for MsgWithdrawValidatorCommission 58 func TestMsgWithdrawValidatorCommission(t *testing.T) { 59 tests := []struct { 60 validatorAddr sdk.ValAddress 61 expectPass bool 62 }{ 63 {valAddr1, true}, 64 {emptyValAddr, false}, 65 } 66 for i, tc := range tests { 67 msg := NewMsgWithdrawValidatorCommission(tc.validatorAddr) 68 if tc.expectPass { 69 require.Nil(t, msg.ValidateBasic(), "test index: %v", i) 70 } else { 71 require.NotNil(t, msg.ValidateBasic(), "test index: %v", i) 72 } 73 } 74 } 75 76 // test ValidateBasic for MsgDepositIntoCommunityPool 77 func TestMsgDepositIntoCommunityPool(t *testing.T) { 78 tests := []struct { 79 amount sdk.Coins 80 depositor sdk.AccAddress 81 expectPass bool 82 }{ 83 {sdk.NewCoins(sdk.NewInt64Coin("uatom", 10000)), sdk.AccAddress{}, false}, 84 {sdk.Coins{sdk.NewInt64Coin("uatom", 10), sdk.NewInt64Coin("uatom", 10)}, delAddr1, false}, 85 {sdk.NewCoins(sdk.NewInt64Coin("uatom", 1000)), delAddr1, true}, 86 } 87 for i, tc := range tests { 88 msg := NewMsgFundCommunityPool(tc.amount, tc.depositor) 89 if tc.expectPass { 90 require.Nil(t, msg.ValidateBasic(), "test index: %v", i) 91 } else { 92 require.NotNil(t, msg.ValidateBasic(), "test index: %v", i) 93 } 94 } 95 }