From e223eadb363302393d792d0e8f3b822f4913d102 Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Fri, 28 Sep 2018 19:04:04 -0400 Subject: [PATCH] types msg tests --- x/distribution/types/msg_test.go | 93 +++++++++++++++++++++ x/distribution/types/test_utils.go | 27 ++++++ x/distribution/types/validator_info_test.go | 9 ++ 3 files changed, 129 insertions(+) create mode 100644 x/distribution/types/msg_test.go create mode 100644 x/distribution/types/test_utils.go create mode 100644 x/distribution/types/validator_info_test.go diff --git a/x/distribution/types/msg_test.go b/x/distribution/types/msg_test.go new file mode 100644 index 000000000..24af43b2e --- /dev/null +++ b/x/distribution/types/msg_test.go @@ -0,0 +1,93 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// test ValidateBasic for MsgCreateValidator +func TestMsgSetWithdrawAddress(t *testing.T) { + tests := []struct { + delegatorAddr sdk.AccAddress + withdrawAddr sdk.AccAddress + expectPass bool + }{ + {delAddr1, delAddr2, true}, + {delAddr1, delAddr1, true}, + {emptyDelAddr, delAddr1, false}, + {delAddr1, emptyDelAddr, false}, + {emptyDelAddr, emptyDelAddr, false}, + } + + for _, tc := range tests { + msg := NewMsgSetWithdrawAddress(tc.delegatorAddr, tc.withdrawAddr) + if tc.expectPass { + require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) + } else { + require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) + } + } +} + +// test ValidateBasic for MsgEditValidator +func TestMsgWithdrawDelegatorReward(t *testing.T) { + tests := []struct { + delegatorAddr sdk.AccAddress + validatorAddr sdk.ValAddress + expectPass bool + }{ + {delAddr1, valAddr1, true}, + {emptyDelAddr, valAddr1, false}, + {delAddr1, emptyValAddr, false}, + {emptyDelAddr, emptyValAddr, false}, + } + for _, tc := range tests { + msg := NewMsgWithdrawDelegatorReward(tc.delegatorAddr, tc.validatorAddr) + if tc.expectPass { + require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) + } else { + require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) + } + } +} + +// test ValidateBasic and GetSigners for MsgCreateValidatorOnBehalfOf +func TestMsgWithdrawDelegatorRewardsAll(t *testing.T) { + tests := []struct { + delegatorAddr sdk.AccAddress + expectPass bool + }{ + {delAddr, true}, + {emptyDelAddr, false}, + } + for _, tc := range tests { + msg := NewMsgWithdrawDelegatorRewardsAll(tc.delegatorAddr) + if tc.expectPass { + require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) + } else { + require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) + } + } +} + +// test ValidateBasic for MsgDelegate +func TestMsgWithdrawValidatorRewardsAll(t *testing.T) { + tests := []struct { + validatorAddr sdk.ValAddress + expectPass bool + }{ + {valAddr1, true}, + {emptyValAddr, false}, + } + for _, tc := range tests { + msg := NewMsgWithdrawValidatorRewardsAll(tc.validatorAddr) + if tc.expectPass { + require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) + } else { + require.NotNil(t, msg.ValidateBasic(), "test: %v", tc.name) + } + } +} diff --git a/x/distribution/types/test_utils.go b/x/distribution/types/test_utils.go new file mode 100644 index 000000000..3ea78cd79 --- /dev/null +++ b/x/distribution/types/test_utils.go @@ -0,0 +1,27 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/ed25519" +) + +var ( + delPk1 = ed25519.GenPrivKey().PubKey() + delPk2 = ed25519.GenPrivKey().PubKey() + delPk3 = ed25519.GenPrivKey().PubKey() + delAddr1 = sdk.AccAddress(delPk1.Address()) + delAddr2 = sdk.AccAddress(delPk2.Address()) + delAddr3 = sdk.AccAddress(delPk3.Address()) + emptyDelAddr sdk.AccAddress + + valPk1 = ed25519.GenPrivKey().PubKey() + valPk2 = ed25519.GenPrivKey().PubKey() + valPk3 = ed25519.GenPrivKey().PubKey() + valAddr1 = sdk.ValAddress(delPk1.Address()) + valAddr2 = sdk.ValAddress(delPk2.Address()) + valAddr3 = sdk.ValAddress(delPk3.Address()) + emptyValAddr sdk.ValAddress + + emptyPubkey crypto.PubKey +) diff --git a/x/distribution/types/validator_info_test.go b/x/distribution/types/validator_info_test.go new file mode 100644 index 000000000..a18464be1 --- /dev/null +++ b/x/distribution/types/validator_info_test.go @@ -0,0 +1,9 @@ +package types + +import "testing" + +func TestTakeFeePoolRewards(t *testing.T) { +} + +func WithdrawCommission(t *testing.T) { +}