2018-10-05 03:41:38 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// test ValidateBasic for MsgSetWithdrawAddress
|
2018-10-05 03:41:38 -07:00
|
|
|
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 i, tc := range tests {
|
|
|
|
msg := NewMsgSetWithdrawAddress(tc.delegatorAddr, tc.withdrawAddr)
|
|
|
|
if tc.expectPass {
|
|
|
|
require.Nil(t, msg.ValidateBasic(), "test index: %v", i)
|
|
|
|
} else {
|
|
|
|
require.NotNil(t, msg.ValidateBasic(), "test index: %v", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// test ValidateBasic for MsgWithdrawDelegatorReward
|
2018-10-05 03:41:38 -07:00
|
|
|
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 i, tc := range tests {
|
|
|
|
msg := NewMsgWithdrawDelegatorReward(tc.delegatorAddr, tc.validatorAddr)
|
|
|
|
if tc.expectPass {
|
|
|
|
require.Nil(t, msg.ValidateBasic(), "test index: %v", i)
|
|
|
|
} else {
|
|
|
|
require.NotNil(t, msg.ValidateBasic(), "test index: %v", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:38:05 -08:00
|
|
|
// test ValidateBasic for MsgWithdrawValidatorCommission
|
|
|
|
func TestMsgWithdrawValidatorCommission(t *testing.T) {
|
2018-10-05 03:41:38 -07:00
|
|
|
tests := []struct {
|
|
|
|
validatorAddr sdk.ValAddress
|
|
|
|
expectPass bool
|
|
|
|
}{
|
|
|
|
{valAddr1, true},
|
|
|
|
{emptyValAddr, false},
|
|
|
|
}
|
|
|
|
for i, tc := range tests {
|
2019-01-16 13:38:05 -08:00
|
|
|
msg := NewMsgWithdrawValidatorCommission(tc.validatorAddr)
|
2018-10-05 03:41:38 -07:00
|
|
|
if tc.expectPass {
|
|
|
|
require.Nil(t, msg.ValidateBasic(), "test index: %v", i)
|
|
|
|
} else {
|
|
|
|
require.NotNil(t, msg.ValidateBasic(), "test index: %v", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|