Add support for permanent locked vesting accounts (#8520)

* add basics for permanent locked vesting account support

* remove sdk.Msg support for PermanentLockedVestingAccount

* add tests for PermanentLockedVestingAccount

* remove unecessary tests

* drop unecessary create vesting acct msgs

* Update x/auth/vesting/types/vesting_account.go

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Update x/auth/vesting/types/vesting_account.go

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Update x/auth/vesting/types/vesting_account.go

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Update x/auth/vesting/types/vesting_account_test.go

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Review changes

* Factorize init function

* Factorize more

* Comments

* Fix build after rename

Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
Co-authored-by: Aaron Craelius <aaron@regen.network>
This commit is contained in:
Cory 2021-04-21 09:18:28 -07:00 committed by GitHub
parent 045c45f550
commit 603e89541f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 502 additions and 122 deletions

View File

@ -581,6 +581,7 @@
- [DelayedVestingAccount](#cosmos.vesting.v1beta1.DelayedVestingAccount)
- [Period](#cosmos.vesting.v1beta1.Period)
- [PeriodicVestingAccount](#cosmos.vesting.v1beta1.PeriodicVestingAccount)
- [PermanentLockedAccount](#cosmos.vesting.v1beta1.PermanentLockedAccount)
- [Scalar Value Types](#scalar-value-types)
@ -8192,6 +8193,23 @@ periodically vests by unlocking coins during each specified period.
<a name="cosmos.vesting.v1beta1.PermanentLockedAccount"></a>
### PermanentLockedAccount
PermanentLockedAccount implements the VestingAccount interface. It does
not ever release coins, locking them indefinitely. Coins in this account can
still be used for delegating and for governance votes even while locked.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `base_vesting_account` | [BaseVestingAccount](#cosmos.vesting.v1beta1.BaseVestingAccount) | | |
<!-- end messages -->
<!-- end enums -->

View File

@ -71,3 +71,13 @@ message PeriodicVestingAccount {
int64 start_time = 2 [(gogoproto.moretags) = "yaml:\"start_time\""];
repeated Period vesting_periods = 3 [(gogoproto.moretags) = "yaml:\"vesting_periods\"", (gogoproto.nullable) = false];
}
// PermanentLockedAccount implements the VestingAccount interface. It does
// not ever release coins, locking them indefinitely. Coins in this account can
// still be used for delegating and for governance votes even while locked.
message PermanentLockedAccount {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
BaseVestingAccount base_vesting_account = 1 [(gogoproto.embed) = true];
}

View File

@ -12,7 +12,8 @@ import (
type VestingAccount interface {
types.AccountI
// LockedCoins returns the set of coins that are not spendable (i.e. locked).
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
// defined as the vesting coins that are not delegated.
//
// To get spendable coins of a vesting account, first the total balance must
// be retrieved and the locked tokens can be subtracted from the total balance.

View File

@ -17,6 +17,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&ContinuousVestingAccount{}, "cosmos-sdk/ContinuousVestingAccount", nil)
cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil)
cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount", nil)
cdc.RegisterConcrete(&PermanentLockedAccount{}, "cosmos-sdk/PermanentLockedAccount", nil)
}
// RegisterInterface associates protoName with AccountI and VestingAccount
@ -28,6 +29,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&ContinuousVestingAccount{},
&DelayedVestingAccount{},
&PeriodicVestingAccount{},
&PermanentLockedAccount{},
)
registry.RegisterImplementations(
@ -36,6 +38,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&DelayedVestingAccount{},
&ContinuousVestingAccount{},
&PeriodicVestingAccount{},
&PermanentLockedAccount{},
)
registry.RegisterImplementations(
@ -44,6 +47,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&DelayedVestingAccount{},
&ContinuousVestingAccount{},
&PeriodicVestingAccount{},
&PermanentLockedAccount{},
)
registry.RegisterImplementations(

View File

@ -5,6 +5,5 @@ import (
)
var (
app = simapp.Setup(false)
appCodec = simapp.MakeTestEncodingConfig().Marshaler
app = simapp.Setup(false)
)

View File

@ -238,12 +238,52 @@ func (m *PeriodicVestingAccount) XXX_DiscardUnknown() {
var xxx_messageInfo_PeriodicVestingAccount proto.InternalMessageInfo
// PermanentLockedAccount implements the VestingAccount interface. It does
// not ever release coins, locking them indefinitely. Coins in this account can
// still be used for delegating and for governance votes even while locked.
type PermanentLockedAccount struct {
*BaseVestingAccount `protobuf:"bytes,1,opt,name=base_vesting_account,json=baseVestingAccount,proto3,embedded=base_vesting_account" json:"base_vesting_account,omitempty"`
}
func (m *PermanentLockedAccount) Reset() { *m = PermanentLockedAccount{} }
func (*PermanentLockedAccount) ProtoMessage() {}
func (*PermanentLockedAccount) Descriptor() ([]byte, []int) {
return fileDescriptor_89e80273ca606d6e, []int{5}
}
func (m *PermanentLockedAccount) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *PermanentLockedAccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_PermanentLockedAccount.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *PermanentLockedAccount) XXX_Merge(src proto.Message) {
xxx_messageInfo_PermanentLockedAccount.Merge(m, src)
}
func (m *PermanentLockedAccount) XXX_Size() int {
return m.Size()
}
func (m *PermanentLockedAccount) XXX_DiscardUnknown() {
xxx_messageInfo_PermanentLockedAccount.DiscardUnknown(m)
}
var xxx_messageInfo_PermanentLockedAccount proto.InternalMessageInfo
func init() {
proto.RegisterType((*BaseVestingAccount)(nil), "cosmos.vesting.v1beta1.BaseVestingAccount")
proto.RegisterType((*ContinuousVestingAccount)(nil), "cosmos.vesting.v1beta1.ContinuousVestingAccount")
proto.RegisterType((*DelayedVestingAccount)(nil), "cosmos.vesting.v1beta1.DelayedVestingAccount")
proto.RegisterType((*Period)(nil), "cosmos.vesting.v1beta1.Period")
proto.RegisterType((*PeriodicVestingAccount)(nil), "cosmos.vesting.v1beta1.PeriodicVestingAccount")
proto.RegisterType((*PermanentLockedAccount)(nil), "cosmos.vesting.v1beta1.PermanentLockedAccount")
}
func init() {
@ -251,44 +291,45 @@ func init() {
}
var fileDescriptor_89e80273ca606d6e = []byte{
// 593 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x95, 0xbf, 0x6f, 0xd3, 0x40,
0x14, 0xc7, 0x7d, 0x49, 0x08, 0xe5, 0x02, 0x4d, 0x6b, 0x9a, 0x60, 0x3a, 0xd8, 0x91, 0xc5, 0x10,
0x21, 0xe1, 0x90, 0xc2, 0x94, 0x0d, 0x17, 0x21, 0x55, 0x65, 0x40, 0x16, 0x62, 0x60, 0x89, 0xfc,
0xe3, 0x70, 0x4e, 0xc4, 0xbe, 0xc8, 0x77, 0xa9, 0xc8, 0x1f, 0x80, 0x84, 0xd4, 0x05, 0x24, 0x06,
0xc6, 0x2e, 0x2c, 0xfc, 0x11, 0xcc, 0x1d, 0x23, 0x26, 0xa6, 0x80, 0x92, 0xff, 0x20, 0x7f, 0x01,
0xf2, 0xdd, 0xd9, 0x01, 0x17, 0x88, 0xca, 0x80, 0xd4, 0x29, 0x79, 0xf7, 0xde, 0xfb, 0xde, 0xe7,
0xbd, 0x7b, 0x77, 0x86, 0xb7, 0x7c, 0x42, 0x23, 0x42, 0x3b, 0x47, 0x88, 0x32, 0x1c, 0x87, 0x9d,
0xa3, 0xae, 0x87, 0x98, 0xdb, 0xcd, 0x6c, 0x6b, 0x94, 0x10, 0x46, 0xd4, 0xa6, 0x88, 0xb2, 0xb2,
0x55, 0x19, 0xb5, 0xbb, 0x13, 0x92, 0x90, 0xf0, 0x90, 0x4e, 0xfa, 0x4f, 0x44, 0xef, 0xea, 0x52,
0xd3, 0x73, 0x29, 0xca,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d, 0xff, 0x13, 0x94, 0x28, 0xd1, 0xd6, 0xe5, 0xf5, 0x6a, 0x0a,
0xf9, 0x82, 0x88, 0xe9, 0x6c, 0xca, 0x15, 0x11, 0x4e, 0x57, 0xa7, 0x66, 0x1f, 0x9e, 0xce, 0x75,
0x30, 0x9d, 0xeb, 0xe0, 0xfb, 0x5c, 0x07, 0x6f, 0x17, 0xba, 0x32, 0x5d, 0xe8, 0xca, 0xd7, 0x85,
0xae, 0x3c, 0xef, 0xfe, 0xb5, 0xf3, 0xaf, 0xe4, 0x2b, 0x2d, 0x3f, 0x0f, 0xfc, 0x20, 0xbc, 0x2a,
0x7f, 0xa7, 0xef, 0xfd, 0x08, 0x00, 0x00, 0xff, 0xff, 0x97, 0xc5, 0xe2, 0xb4, 0x3d, 0x06, 0x00,
// 609 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x95, 0x3f, 0x6f, 0xd3, 0x40,
0x18, 0xc6, 0x7d, 0x4d, 0x08, 0xe5, 0x0a, 0xfd, 0x63, 0xda, 0x60, 0x3a, 0xd8, 0x91, 0xc5, 0x10,
0x21, 0xe1, 0xd0, 0xc2, 0xd4, 0x0d, 0x17, 0x21, 0x55, 0xed, 0x80, 0x2c, 0xc4, 0xc0, 0x12, 0x9d,
0xed, 0xc3, 0xb1, 0x1a, 0xdf, 0x45, 0xbe, 0x4b, 0x45, 0x3e, 0x00, 0x08, 0xa9, 0x0b, 0x48, 0x0c,
0x8c, 0x5d, 0x58, 0xf8, 0x10, 0xcc, 0x1d, 0x23, 0x26, 0xa6, 0x80, 0x92, 0x6f, 0x90, 0x4f, 0x80,
0x7c, 0x77, 0x76, 0x8a, 0x0b, 0x44, 0x65, 0x00, 0x31, 0x25, 0x77, 0xef, 0xfb, 0x3e, 0xf7, 0x7b,
0x5f, 0x3f, 0xa7, 0x83, 0xb7, 0x02, 0xca, 0x12, 0xca, 0x5a, 0x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0x55, 0xf1, 0xd4, 0x4a, 0x0f, 0x60,
0x0d, 0x25, 0x02, 0x61, 0xee, 0x9d, 0xba, 0x9b, 0x19, 0xe6, 0x42, 0xa6, 0x50, 0xd2, 0x3b, 0x55,
0x41, 0xf3, 0x61, 0x01, 0xd6, 0x25, 0x4d, 0x1c, 0xfc, 0x2f, 0x1f, 0x55, 0x8f, 0xe0, 0x4a, 0x0e,
0xd5, 0x13, 0xec, 0x4c, 0x5d, 0x75, 0xf3, 0x57, 0x50, 0xb2, 0x45, 0xd7, 0x54, 0xd7, 0xab, 0x2e,
0xe5, 0x4b, 0x22, 0xb6, 0xb7, 0xac, 0x76, 0x64, 0x3a, 0x3b, 0xf3, 0xd5, 0x5e, 0x01, 0x31, 0xa7,
0x04, 0x11, 0x4c, 0xf8, 0x01, 0x0d, 0x0e, 0x71, 0xf8, 0x4f, 0xec, 0xe3, 0xee, 0x9f, 0x8e, 0x4d,
0x30, 0x1c, 0x9b, 0xe0, 0xdb, 0xd8, 0x04, 0x6f, 0x26, 0xa6, 0x36, 0x9c, 0x98, 0xda, 0x97, 0x89,
0xa9, 0x3d, 0xdb, 0xfa, 0xad, 0x05, 0x5e, 0xa8, 0xe7, 0x42, 0xbd, 0x53, 0xc2, 0x11, 0x7e, 0x4d,
0x3c, 0x18, 0xf7, 0xbe, 0x07, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0xd5, 0x07, 0xc6, 0x06, 0x00,
0x00,
}
@ -545,6 +586,41 @@ func (m *PeriodicVestingAccount) MarshalToSizedBuffer(dAtA []byte) (int, error)
return len(dAtA) - i, nil
}
func (m *PermanentLockedAccount) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *PermanentLockedAccount) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *PermanentLockedAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.BaseVestingAccount != nil {
{
size, err := m.BaseVestingAccount.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintVesting(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintVesting(dAtA []byte, offset int, v uint64) int {
offset -= sovVesting(v)
base := offset
@ -659,6 +735,19 @@ func (m *PeriodicVestingAccount) Size() (n int) {
return n
}
func (m *PermanentLockedAccount) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.BaseVestingAccount != nil {
l = m.BaseVestingAccount.Size()
n += 1 + l + sovVesting(uint64(l))
}
return n
}
func sovVesting(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
@ -1305,6 +1394,92 @@ func (m *PeriodicVestingAccount) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *PermanentLockedAccount) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowVesting
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: PermanentLockedAccount: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: PermanentLockedAccount: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field BaseVestingAccount", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowVesting
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthVesting
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthVesting
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.BaseVestingAccount == nil {
m.BaseVestingAccount = &BaseVestingAccount{}
}
if err := m.BaseVestingAccount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipVesting(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthVesting
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipVesting(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0

View File

@ -261,7 +261,8 @@ func (cva ContinuousVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coi
return cva.OriginalVesting.Sub(cva.GetVestedCoins(blockTime))
}
// LockedCoins returns the set of coins that are not spendable (i.e. locked).
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
// defined as the vesting coins that are not delegated.
func (cva ContinuousVestingAccount) LockedCoins(blockTime time.Time) sdk.Coins {
return cva.BaseVestingAccount.LockedCoinsFromVesting(cva.GetVestingCoins(blockTime))
}
@ -386,7 +387,8 @@ func (pva PeriodicVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins
return pva.OriginalVesting.Sub(pva.GetVestedCoins(blockTime))
}
// LockedCoins returns the set of coins that are not spendable (i.e. locked).
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
// defined as the vesting coins that are not delegated.
func (pva PeriodicVestingAccount) LockedCoins(blockTime time.Time) sdk.Coins {
return pva.BaseVestingAccount.LockedCoinsFromVesting(pva.GetVestingCoins(blockTime))
}
@ -496,7 +498,8 @@ func (dva DelayedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins
return dva.OriginalVesting.Sub(dva.GetVestedCoins(blockTime))
}
// LockedCoins returns the set of coins that are not spendable (i.e. locked).
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
// defined as the vesting coins that are not delegated.
func (dva DelayedVestingAccount) LockedCoins(blockTime time.Time) sdk.Coins {
return dva.BaseVestingAccount.LockedCoinsFromVesting(dva.GetVestingCoins(blockTime))
}
@ -523,6 +526,73 @@ func (dva DelayedVestingAccount) String() string {
return out.(string)
}
//-----------------------------------------------------------------------------
// Permanent Locked Vesting Account
var _ vestexported.VestingAccount = (*PermanentLockedAccount)(nil)
var _ authtypes.GenesisAccount = (*PermanentLockedAccount)(nil)
// NewPermanentLockedAccount returns a PermanentLockedAccount
func NewPermanentLockedAccount(baseAcc *authtypes.BaseAccount, coins sdk.Coins) *PermanentLockedAccount {
baseVestingAcc := &BaseVestingAccount{
BaseAccount: baseAcc,
OriginalVesting: coins,
EndTime: 0, // ensure EndTime is set to 0, as PermanentLockedAccount's do not have an EndTime
}
return &PermanentLockedAccount{baseVestingAcc}
}
// GetVestedCoins returns the total amount of vested coins for a permanent locked vesting
// account. All coins are only vested once the schedule has elapsed.
func (plva PermanentLockedAccount) GetVestedCoins(_ time.Time) sdk.Coins {
return nil
}
// GetVestingCoins returns the total number of vesting coins for a permanent locked
// vesting account.
func (plva PermanentLockedAccount) GetVestingCoins(_ time.Time) sdk.Coins {
return plva.OriginalVesting
}
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
// defined as the vesting coins that are not delegated.
func (plva PermanentLockedAccount) LockedCoins(_ time.Time) sdk.Coins {
return plva.BaseVestingAccount.LockedCoinsFromVesting(plva.OriginalVesting)
}
// TrackDelegation tracks a desired delegation amount by setting the appropriate
// values for the amount of delegated vesting, delegated free, and reducing the
// overall amount of base coins.
func (plva *PermanentLockedAccount) TrackDelegation(blockTime time.Time, balance, amount sdk.Coins) {
plva.BaseVestingAccount.TrackDelegation(balance, plva.OriginalVesting, amount)
}
// GetStartTime returns zero since a permanent locked vesting account has no start time.
func (plva PermanentLockedAccount) GetStartTime() int64 {
return 0
}
// GetEndTime returns a vesting account's end time, we return 0 to denote that
// a permanently locked vesting account has no end time.
func (plva PermanentLockedAccount) GetEndTime() int64 {
return 0
}
// Validate checks for errors on the account fields
func (plva PermanentLockedAccount) Validate() error {
if plva.EndTime > 0 {
return errors.New("permanently vested accounts cannot have an end-time")
}
return plva.BaseVestingAccount.Validate()
}
func (plva PermanentLockedAccount) String() string {
out, _ := plva.MarshalYAML()
return out.(string)
}
type getPK interface {
GetPubKey() cryptotypes.PubKey
}

View File

@ -23,9 +23,7 @@ func TestGetVestedCoinsContVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix())
// require no coins vested in the very beginning of the vesting schedule
@ -49,9 +47,7 @@ func TestGetVestingCoinsContVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix())
// require all coins vesting in the beginning of the vesting schedule
@ -71,10 +67,7 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix())
// require that all original coins are locked at the end of the vesting
@ -89,19 +82,13 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) {
// require that all vested coins (50%) are spendable
lockedCoins = cva.LockedCoins(now.Add(12 * time.Hour))
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, lockedCoins)
// require that all vested coins (50%) are spendable plus any received
lockedCoins = cva.LockedCoins(now.Add(12 * time.Hour))
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, lockedCoins)
}
func TestTrackDelegationContVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require the ability to delegate all vesting coins
cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix())
@ -138,9 +125,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require the ability to undelegate all vesting coins
cva := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix())
@ -186,9 +171,7 @@ func TestGetVestedCoinsDelVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require no coins are vested until schedule maturation
dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix())
@ -204,9 +187,7 @@ func TestGetVestingCoinsDelVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require all coins vesting at the beginning of the schedule
dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix())
@ -222,9 +203,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require that all coins are locked in the beginning of the vesting
// schedule
@ -241,12 +220,6 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) {
lockedCoins = dva.LockedCoins(now.Add(12 * time.Hour))
require.True(t, lockedCoins.IsEqual(origCoins))
// receive some coins
// require that only received coins are spendable since the account is still
// vesting
lockedCoins = dva.LockedCoins(now.Add(12 * time.Hour))
require.True(t, lockedCoins.IsEqual(origCoins))
// delegate some locked coins
// require that locked is reduced
delegatedAmount := sdk.NewCoins(sdk.NewInt64Coin(stakeDenom, 50))
@ -259,9 +232,7 @@ func TestTrackDelegationDelVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require the ability to delegate all vesting coins
dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix())
@ -296,9 +267,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require the ability to undelegate all vesting coins
dva := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix())
@ -349,9 +318,7 @@ func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) {
types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}},
}
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods)
// require no coins vested at the beginning of the vesting schedule
@ -394,10 +361,7 @@ func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) {
types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}},
}
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{
sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods)
// require all coins vesting at the beginning of the vesting schedule
@ -434,10 +398,7 @@ func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) {
types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}},
}
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{
sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods)
// require that there exist no spendable coins at the beginning of the
@ -453,11 +414,6 @@ func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) {
// require that all still vesting coins (50%) are locked
lockedCoins = pva.LockedCoins(now.Add(12 * time.Hour))
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, lockedCoins)
// receive some coins
// require that all still vesting coins (50% of original) are locked plus any received
lockedCoins = pva.LockedCoins(now.Add(12 * time.Hour))
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, lockedCoins)
}
func TestTrackDelegationPeriodicVestingAcc(t *testing.T) {
@ -469,9 +425,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) {
types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}},
}
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require the ability to delegate all vesting coins
pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods)
@ -527,9 +481,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}},
}
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
bacc, origCoins := initBaseAccount()
// require the ability to undelegate all vesting coins at the beginning of vesting
pva := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods)
@ -578,6 +530,135 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}, pva.DelegatedVesting)
}
func TestGetVestedCoinsPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(1000 * 24 * time.Hour)
bacc, origCoins := initBaseAccount()
// require no coins are vested
plva := types.NewPermanentLockedAccount(bacc, origCoins)
vestedCoins := plva.GetVestedCoins(now)
require.Nil(t, vestedCoins)
// require no coins be vested at end time
vestedCoins = plva.GetVestedCoins(endTime)
require.Nil(t, vestedCoins)
}
func TestGetVestingCoinsPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(1000 * 24 * time.Hour)
bacc, origCoins := initBaseAccount()
// require all coins vesting at the beginning of the schedule
plva := types.NewPermanentLockedAccount(bacc, origCoins)
vestingCoins := plva.GetVestingCoins(now)
require.Equal(t, origCoins, vestingCoins)
// require all coins vesting at the end time
vestingCoins = plva.GetVestingCoins(endTime)
require.Equal(t, origCoins, vestingCoins)
}
func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(1000 * 24 * time.Hour)
bacc, origCoins := initBaseAccount()
// require that all coins are locked in the beginning of the vesting
// schedule
plva := types.NewPermanentLockedAccount(bacc, origCoins)
lockedCoins := plva.LockedCoins(now)
require.True(t, lockedCoins.IsEqual(origCoins))
// require that all coins are still locked at end time
lockedCoins = plva.LockedCoins(endTime)
require.True(t, lockedCoins.IsEqual(origCoins))
// delegate some locked coins
// require that locked is reduced
delegatedAmount := sdk.NewCoins(sdk.NewInt64Coin(stakeDenom, 50))
plva.TrackDelegation(now.Add(12*time.Hour), origCoins, delegatedAmount)
lockedCoins = plva.LockedCoins(now.Add(12 * time.Hour))
require.True(t, lockedCoins.IsEqual(origCoins.Sub(delegatedAmount)))
}
func TestTrackDelegationPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(1000 * 24 * time.Hour)
bacc, origCoins := initBaseAccount()
// require the ability to delegate all vesting coins
plva := types.NewPermanentLockedAccount(bacc, origCoins)
plva.TrackDelegation(now, origCoins, origCoins)
require.Equal(t, origCoins, plva.DelegatedVesting)
require.Nil(t, plva.DelegatedFree)
// require the ability to delegate all vested coins at endTime
plva = types.NewPermanentLockedAccount(bacc, origCoins)
plva.TrackDelegation(endTime, origCoins, origCoins)
require.Equal(t, origCoins, plva.DelegatedVesting)
require.Nil(t, plva.DelegatedFree)
// require no modifications when delegation amount is zero or not enough funds
plva = types.NewPermanentLockedAccount(bacc, origCoins)
require.Panics(t, func() {
plva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)})
})
require.Nil(t, plva.DelegatedVesting)
require.Nil(t, plva.DelegatedFree)
}
func TestTrackUndelegationPermLockedVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(1000 * 24 * time.Hour)
bacc, origCoins := initBaseAccount()
// require the ability to undelegate all vesting coins
plva := types.NewPermanentLockedAccount(bacc, origCoins)
plva.TrackDelegation(now, origCoins, origCoins)
plva.TrackUndelegation(origCoins)
require.Nil(t, plva.DelegatedFree)
require.Nil(t, plva.DelegatedVesting)
// require the ability to undelegate all vesting coins at endTime
plva = types.NewPermanentLockedAccount(bacc, origCoins)
plva.TrackDelegation(endTime, origCoins, origCoins)
plva.TrackUndelegation(origCoins)
require.Nil(t, plva.DelegatedFree)
require.Nil(t, plva.DelegatedVesting)
// require no modifications when the undelegation amount is zero
plva = types.NewPermanentLockedAccount(bacc, origCoins)
require.Panics(t, func() {
plva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)})
})
require.Nil(t, plva.DelegatedFree)
require.Nil(t, plva.DelegatedVesting)
// delegate to two validators
plva = types.NewPermanentLockedAccount(bacc, origCoins)
plva.TrackDelegation(now, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)})
plva.TrackDelegation(now, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)})
// undelegate from one validator that got slashed 50%
plva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)})
require.Nil(t, plva.DelegatedFree)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 75)}, plva.DelegatedVesting)
// undelegate from the other validator that did not get slashed
plva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)})
require.Nil(t, plva.DelegatedFree)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}, plva.DelegatedVesting)
}
func TestGenesisAccountValidate(t *testing.T) {
pubkey := secp256k1.GenPrivKey().PubKey()
addr := sdk.AccAddress(pubkey.Address())
@ -633,6 +714,16 @@ func TestGenesisAccountValidate(t *testing.T) {
0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 25)}}}),
true,
},
{
"valid permanent locked vesting account",
types.NewPermanentLockedAccount(baseAcc, initialVesting),
false,
},
{
"invalid positive end time for permanently locked vest account",
&types.PermanentLockedAccount{BaseVestingAccount: baseVestingWithCoins},
true,
},
}
for _, tt := range tests {
@ -645,11 +736,7 @@ func TestGenesisAccountValidate(t *testing.T) {
}
func TestContinuousVestingAccountMarshal(t *testing.T) {
pubkey := secp256k1.GenPrivKey().PubKey()
addr := sdk.AccAddress(pubkey.Address())
coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5))
baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50)
baseAcc, coins := initBaseAccount()
baseVesting := types.NewBaseVestingAccount(baseAcc, coins, time.Now().Unix())
acc := types.NewContinuousVestingAccountRaw(baseVesting, baseVesting.EndTime)
@ -667,11 +754,7 @@ func TestContinuousVestingAccountMarshal(t *testing.T) {
}
func TestPeriodicVestingAccountMarshal(t *testing.T) {
pubkey := secp256k1.GenPrivKey().PubKey()
addr := sdk.AccAddress(pubkey.Address())
coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5))
baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50)
baseAcc, coins := initBaseAccount()
acc := types.NewPeriodicVestingAccount(baseAcc, coins, time.Now().Unix(), types.Periods{types.Period{3600, coins}})
bz, err := app.AccountKeeper.MarshalAccount(acc)
@ -688,11 +771,7 @@ func TestPeriodicVestingAccountMarshal(t *testing.T) {
}
func TestDelayedVestingAccountMarshal(t *testing.T) {
pubkey := secp256k1.GenPrivKey().PubKey()
addr := sdk.AccAddress(pubkey.Address())
coins := sdk.NewCoins(sdk.NewInt64Coin("test", 5))
baseAcc := authtypes.NewBaseAccount(addr, pubkey, 10, 50)
baseAcc, coins := initBaseAccount()
acc := types.NewDelayedVestingAccount(baseAcc, coins, time.Now().Unix())
bz, err := app.AccountKeeper.MarshalAccount(acc)
@ -707,3 +786,27 @@ func TestDelayedVestingAccountMarshal(t *testing.T) {
_, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2])
require.NotNil(t, err)
}
func TestPermanentLockedAccountMarshal(t *testing.T) {
baseAcc, coins := initBaseAccount()
acc := types.NewPermanentLockedAccount(baseAcc, coins)
bz, err := app.AccountKeeper.MarshalAccount(acc)
require.Nil(t, err)
acc2, err := app.AccountKeeper.UnmarshalAccount(bz)
require.Nil(t, err)
require.IsType(t, &types.PermanentLockedAccount{}, acc2)
require.Equal(t, acc.String(), acc2.String())
// error on bad bytes
_, err = app.AccountKeeper.UnmarshalAccount(bz[:len(bz)/2])
require.NotNil(t, err)
}
func initBaseAccount() (*authtypes.BaseAccount, sdk.Coins) {
_, _, addr := testdata.KeyTestPubAddr()
origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)}
bacc := authtypes.NewBaseAccountWithAddress(addr)
return bacc, origCoins
}