2019-10-10 08:53:30 -07:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-09-25 01:41:16 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
2019-10-10 08:53:30 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
pk1 = ed25519.GenPrivKey().PubKey()
|
|
|
|
pk2 = ed25519.GenPrivKey().PubKey()
|
|
|
|
addr1 = sdk.ValAddress(pk1.Address())
|
|
|
|
addr2 = sdk.ValAddress(pk2.Address())
|
|
|
|
)
|
|
|
|
|
|
|
|
// require invalid vesting account fails validation
|
|
|
|
func TestValidateGenesisInvalidAccounts(t *testing.T) {
|
|
|
|
acc1 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr1))
|
2020-01-30 13:31:16 -08:00
|
|
|
acc1Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150))
|
2020-02-18 04:50:13 -08:00
|
|
|
baseVestingAcc := NewBaseVestingAccount(acc1, acc1Balance, 1548775410)
|
2020-01-30 13:31:16 -08:00
|
|
|
|
2019-10-10 08:53:30 -07:00
|
|
|
// invalid delegated vesting
|
2020-01-30 13:31:16 -08:00
|
|
|
baseVestingAcc.DelegatedVesting = acc1Balance.Add(acc1Balance...)
|
2019-10-10 08:53:30 -07:00
|
|
|
|
|
|
|
acc2 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr2))
|
2020-01-30 13:31:16 -08:00
|
|
|
// acc2Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150))
|
2019-10-10 08:53:30 -07:00
|
|
|
|
2020-05-20 12:21:00 -07:00
|
|
|
genAccs := make([]authtypes.GenesisAccount, 2)
|
2019-10-10 08:53:30 -07:00
|
|
|
genAccs[0] = baseVestingAcc
|
2020-02-18 04:50:13 -08:00
|
|
|
genAccs[1] = acc2
|
2019-10-10 08:53:30 -07:00
|
|
|
|
|
|
|
require.Error(t, authtypes.ValidateGenAccounts(genAccs))
|
2020-01-30 13:31:16 -08:00
|
|
|
baseVestingAcc.DelegatedVesting = acc1Balance
|
2019-10-10 08:53:30 -07:00
|
|
|
genAccs[0] = baseVestingAcc
|
|
|
|
require.NoError(t, authtypes.ValidateGenAccounts(genAccs))
|
|
|
|
// invalid start time
|
|
|
|
genAccs[0] = NewContinuousVestingAccountRaw(baseVestingAcc, 1548888000)
|
|
|
|
require.Error(t, authtypes.ValidateGenAccounts(genAccs))
|
|
|
|
}
|