Skip to content

Commit

Permalink
Vesting and tests updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dawid-kruk committed Feb 16, 2024
1 parent bd2f9f4 commit 17bebcd
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
**Vesting Parameters Modification**

- modified the vesting parameters of Valdiator round pool and VC round pool from free 5%, lockup 18 months, and vesting 18 months to free 8%, lockup 4 months, and vesting 10 months.
- modified the vesting parameters of Early-bird (private) round pool lockup none, and vesting 9 months to lockup 2 months, and vesting 7 months.
- modified the vesting parameters of Public round pool lockup none, and vesting 6 months to lockup 1 month, and vesting 5 months.

**Community Pool Reduction**

Expand Down
32 changes: 32 additions & 0 deletions app/upgrades/v131/vesting_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
const (
VcRoundTypeName = "VC round"
ValidatorRoundTypeName = "Valdiator round"
PublicRoundTypeName = "Public round"
EarlyBirdRoundTypeName = "Early-bird round"
)

func ModifyVestingTypes(ctx sdk.Context, appKeepers cfeupgradetypes.AppKeepers) error {
Expand All @@ -27,6 +29,18 @@ func ModifyVestingTypes(ctx sdk.Context, appKeepers cfeupgradetypes.AppKeepers)
return nil
}

_, err = appKeepers.GetC4eVestingKeeper().MustGetVestingType(ctx, PublicRoundTypeName)
if err != nil {
ctx.Logger().Info("vesting type not found", "vestingType", PublicRoundTypeName)
return nil
}

_, err = appKeepers.GetC4eVestingKeeper().MustGetVestingType(ctx, EarlyBirdRoundTypeName)
if err != nil {
ctx.Logger().Info("vesting type not found", "vestingType", EarlyBirdRoundTypeName)
return nil
}

vcRoundPoolType := cfevestingtypes.VestingType{
Name: VcRoundTypeName,
Free: sdk.MustNewDecFromStr("0.08"),
Expand All @@ -43,5 +57,23 @@ func ModifyVestingTypes(ctx sdk.Context, appKeepers cfeupgradetypes.AppKeepers)
}
appKeepers.GetC4eVestingKeeper().SetVestingType(ctx, validatorRoundType)

publicRoundType := cfevestingtypes.VestingType{
Name: PublicRoundTypeName,
Free: sdk.MustNewDecFromStr("0.2"),
LockupPeriod: 30 * 24 * time.Hour,
VestingPeriod: 152 * 24 * time.Hour,
}

appKeepers.GetC4eVestingKeeper().SetVestingType(ctx, publicRoundType)

earlyBirdRoundType := cfevestingtypes.VestingType{
Name: EarlyBirdRoundTypeName,
Free: sdk.MustNewDecFromStr("0.15"),
LockupPeriod: 61 * 24 * time.Hour,
VestingPeriod: 213 * 24 * time.Hour,
}

appKeepers.GetC4eVestingKeeper().SetVestingType(ctx, earlyBirdRoundType)

return nil
}
217 changes: 197 additions & 20 deletions app/upgrades/v131/vesting_updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,101 +12,278 @@ import (
v131 "github.com/chain4energy/c4e-chain/app/upgrades/v131"
)

const (
VcRoundTypeName = "VC round"
ValidatorRoundTypeName = "Valdiator round"
)
func TestModifyVestingTypesVCRoundNotFound(t *testing.T) {
testHelper := testapp.SetupTestAppWithHeight(t, 1000)

validatorRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Validator round",
Free: sdk.MustNewDecFromStr("0.05"),
LockupPeriod: 274 * 24 * time.Hour,
VestingPeriod: 548 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, validatorRoundTypeBefore)

publicRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Public round",
Free: sdk.MustNewDecFromStr("0.2"),
LockupPeriod: 0,
VestingPeriod: 183 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, publicRoundTypeBefore)

earlyBirdRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Early-bird round",
Free: sdk.MustNewDecFromStr("0.15"),
LockupPeriod: 0,
VestingPeriod: 274 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, earlyBirdRoundTypeBefore)

vestingTypesBefore := testHelper.C4eVestingUtils.GetC4eVestingKeeper().GetAllVestingTypes(testHelper.Context)
require.NotNil(t, vestingTypesBefore)
require.Equal(t, 3, len(vestingTypesBefore.VestingTypes))

err := v131.ModifyVestingTypes(testHelper.Context, testHelper.App)
require.NoError(t, err)

vestingTypesAfter := testHelper.C4eVestingUtils.GetC4eVestingKeeper().GetAllVestingTypes(testHelper.Context)
require.Equal(t, 3, len(vestingTypesAfter.VestingTypes))

for _, vtBefore := range vestingTypesBefore.VestingTypes {
vtAfter, found := findVestingTypeByName(vestingTypesAfter.VestingTypes, vtBefore.Name)
require.True(t, found)
require.EqualValues(t, vtBefore, vtAfter)
}

testHelper.ValidateGenesisAndInvariants()
}

func TestModifyVestingTypesPublicRoundNotFound(t *testing.T) {
testHelper := testapp.SetupTestAppWithHeight(t, 1000)

vcRoundTypeBefore := cfevestingtypes.VestingType{
Name: "VC round",
Free: sdk.MustNewDecFromStr("0.05"),
LockupPeriod: 548 * 24 * time.Hour,
VestingPeriod: 548 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, vcRoundTypeBefore)

validatorRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Validator round",
Free: sdk.MustNewDecFromStr("0.05"),
LockupPeriod: 274 * 24 * time.Hour,
VestingPeriod: 548 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, validatorRoundTypeBefore)

earlyBirdRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Early-bird round",
Free: sdk.MustNewDecFromStr("0.15"),
LockupPeriod: 0,
VestingPeriod: 274 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, earlyBirdRoundTypeBefore)

vestingTypesBefore := testHelper.C4eVestingUtils.GetC4eVestingKeeper().GetAllVestingTypes(testHelper.Context)
require.NotNil(t, vestingTypesBefore)
require.Equal(t, 3, len(vestingTypesBefore.VestingTypes))

err := v131.ModifyVestingTypes(testHelper.Context, testHelper.App)
require.NoError(t, err)

vestingTypesAfter := testHelper.C4eVestingUtils.GetC4eVestingKeeper().GetAllVestingTypes(testHelper.Context)
require.Equal(t, 3, len(vestingTypesAfter.VestingTypes))

for _, vtBefore := range vestingTypesBefore.VestingTypes {
vtAfter, found := findVestingTypeByName(vestingTypesAfter.VestingTypes, vtBefore.Name)
require.True(t, found)
require.EqualValues(t, vtBefore, vtAfter)
}

testHelper.ValidateGenesisAndInvariants()
}

func TestModifyVestingTypesVcRoundTypeNameNotFound(t *testing.T) {
func TestModifyVestingTypesEarlyBirdRoundNotFound(t *testing.T) {
testHelper := testapp.SetupTestAppWithHeight(t, 1000)

vcRoundTypeBefore := cfevestingtypes.VestingType{
Name: "VC round",
Free: sdk.MustNewDecFromStr("0.05"),
LockupPeriod: 548 * 24 * time.Hour,
VestingPeriod: 548 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, vcRoundTypeBefore)

validatorRoundTypeBefore := cfevestingtypes.VestingType{
Name: ValidatorRoundTypeName,
Name: "Validator round",
Free: sdk.MustNewDecFromStr("0.05"),
LockupPeriod: 274 * 24 * time.Hour,
VestingPeriod: 548 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, validatorRoundTypeBefore)

publicRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Public round",
Free: sdk.MustNewDecFromStr("0.2"),
LockupPeriod: 0,
VestingPeriod: 183 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, publicRoundTypeBefore)

vestingTypesBefore := testHelper.C4eVestingUtils.GetC4eVestingKeeper().GetAllVestingTypes(testHelper.Context)
require.NotNil(t, vestingTypesBefore)
require.Equal(t, 1, len(vestingTypesBefore.VestingTypes))
require.Equal(t, 3, len(vestingTypesBefore.VestingTypes))

err := v131.ModifyVestingTypes(testHelper.Context, testHelper.App)
require.NoError(t, err)

vestingTypesAfter := testHelper.C4eVestingUtils.GetC4eVestingKeeper().GetAllVestingTypes(testHelper.Context)
require.Equal(t, 1, len(vestingTypesAfter.VestingTypes))
require.Equal(t, 3, len(vestingTypesAfter.VestingTypes))

for _, vtBefore := range vestingTypesBefore.VestingTypes {
vtAfter, found := findVestingTypeByName(vestingTypesAfter.VestingTypes, vtBefore.Name)
require.True(t, found)
require.EqualValues(t, vtBefore, vtAfter)
}

require.Equal(t, vestingTypesBefore, vestingTypesAfter)
testHelper.ValidateGenesisAndInvariants()
}

func TestModifyVestingTypesvalidatorRoundTypeBeforeNotFound(t *testing.T) {
func TestModifyVestingTypesValidatorRoundNotFound(t *testing.T) {
testHelper := testapp.SetupTestAppWithHeight(t, 1000)

vcRoundTypeBefore := cfevestingtypes.VestingType{
Name: VcRoundTypeName,
Name: "VC round",
Free: sdk.MustNewDecFromStr("0.05"),
LockupPeriod: 548 * 24 * time.Hour,
VestingPeriod: 548 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, vcRoundTypeBefore)

publicRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Public round",
Free: sdk.MustNewDecFromStr("0.2"),
LockupPeriod: 0,
VestingPeriod: 183 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, publicRoundTypeBefore)

earlyBirdRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Early-bird round",
Free: sdk.MustNewDecFromStr("0.15"),
LockupPeriod: 0,
VestingPeriod: 274 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, earlyBirdRoundTypeBefore)

vestingTypesBefore := testHelper.C4eVestingUtils.GetC4eVestingKeeper().GetAllVestingTypes(testHelper.Context)
require.NotNil(t, vestingTypesBefore)
require.Equal(t, 1, len(vestingTypesBefore.VestingTypes))
require.Equal(t, 3, len(vestingTypesBefore.VestingTypes))

err := v131.ModifyVestingTypes(testHelper.Context, testHelper.App)
require.NoError(t, err)

vestingTypesAfter := testHelper.C4eVestingUtils.GetC4eVestingKeeper().GetAllVestingTypes(testHelper.Context)
require.Equal(t, 1, len(vestingTypesAfter.VestingTypes))
require.Equal(t, 3, len(vestingTypesAfter.VestingTypes))

for _, vtBefore := range vestingTypesBefore.VestingTypes {
vtAfter, found := findVestingTypeByName(vestingTypesAfter.VestingTypes, vtBefore.Name)
require.True(t, found)
require.EqualValues(t, vtBefore, vtAfter)
}

require.Equal(t, vestingTypesBefore, vestingTypesAfter)
testHelper.ValidateGenesisAndInvariants()
}

func findVestingTypeByName(vestingTypes []*cfevestingtypes.VestingType, name string) (*cfevestingtypes.VestingType, bool) {
for _, vt := range vestingTypes {
if vt.Name == name {
return vt, true
}
}
return &cfevestingtypes.VestingType{}, false
}

func TestModifyVestingTypesVestingTypeExists(t *testing.T) {
testHelper := testapp.SetupTestAppWithHeight(t, 1000)

vcRoundTypeBefore := cfevestingtypes.VestingType{
Name: VcRoundTypeName,
Name: "VC round",
Free: sdk.MustNewDecFromStr("0.05"),
LockupPeriod: 548 * 24 * time.Hour,
VestingPeriod: 548 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, vcRoundTypeBefore)

validatorRoundTypeBefore := cfevestingtypes.VestingType{
Name: ValidatorRoundTypeName,
Name: "Valdiator round",
Free: sdk.MustNewDecFromStr("0.05"),
LockupPeriod: 274 * 24 * time.Hour,
VestingPeriod: 548 * 24 * time.Hour,
}
testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, validatorRoundTypeBefore)

publicRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Public round",
Free: sdk.MustNewDecFromStr("0.2"),
LockupPeriod: 0,
VestingPeriod: 183 * 24 * time.Hour,
}

testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, publicRoundTypeBefore)

earyBirdRoundTypeBefore := cfevestingtypes.VestingType{
Name: "Early-bird round",
Free: sdk.MustNewDecFromStr("0.15"),
LockupPeriod: 0,
VestingPeriod: 274 * 24 * time.Hour,
}

testHelper.App.CfevestingKeeper.SetVestingType(testHelper.Context, earyBirdRoundTypeBefore)

err := v131.ModifyVestingTypes(testHelper.Context, testHelper.App)
require.NoError(t, err)

vcRoundTypeAfter, err := testHelper.C4eVestingUtils.GetC4eVestingKeeper().MustGetVestingType(testHelper.Context, VcRoundTypeName)
vcRoundTypeAfter, err := testHelper.C4eVestingUtils.GetC4eVestingKeeper().MustGetVestingType(testHelper.Context, "VC round")
require.Nil(t, err)
expectedVcRoundType := &cfevestingtypes.VestingType{
Name: VcRoundTypeName,
Name: "VC round",
Free: sdk.MustNewDecFromStr("0.08"),
LockupPeriod: 122 * 24 * time.Hour,
VestingPeriod: 305 * 24 * time.Hour,
}
require.EqualValues(t, expectedVcRoundType, vcRoundTypeAfter)

validatorRoundTypeAfter, err := testHelper.C4eVestingUtils.GetC4eVestingKeeper().MustGetVestingType(testHelper.Context, ValidatorRoundTypeName)
validatorRoundTypeAfter, err := testHelper.C4eVestingUtils.GetC4eVestingKeeper().MustGetVestingType(testHelper.Context, "Valdiator round")
require.Nil(t, err)
expectedValidatorRoundType := &cfevestingtypes.VestingType{
Name: ValidatorRoundTypeName,
Name: "Valdiator round",
Free: sdk.MustNewDecFromStr("0.08"),
LockupPeriod: 122 * 24 * time.Hour,
VestingPeriod: 305 * 24 * time.Hour,
}
require.EqualValues(t, expectedValidatorRoundType, validatorRoundTypeAfter)

publicRoundTypeFAfter, err := testHelper.C4eVestingUtils.GetC4eVestingKeeper().MustGetVestingType(testHelper.Context, "Public round")
require.Nil(t, err)
expectedPublicRoundType := &cfevestingtypes.VestingType{
Name: "Public round",
Free: sdk.MustNewDecFromStr("0.2"),
LockupPeriod: 30 * 24 * time.Hour,
VestingPeriod: 152 * 24 * time.Hour,
}
require.EqualValues(t, expectedPublicRoundType, publicRoundTypeFAfter)

earlyBirdRoundTypeAfter, err := testHelper.C4eVestingUtils.GetC4eVestingKeeper().MustGetVestingType(testHelper.Context, "Early-bird round")
require.Nil(t, err)
expectedEarlyBirdRoundType := &cfevestingtypes.VestingType{
Name: "Early-bird round",
Free: sdk.MustNewDecFromStr("0.15"),
LockupPeriod: 61 * 24 * time.Hour,
VestingPeriod: 213 * 24 * time.Hour,
}
require.EqualValues(t, expectedEarlyBirdRoundType, earlyBirdRoundTypeAfter)

testHelper.ValidateGenesisAndInvariants()
}
23 changes: 21 additions & 2 deletions tests/e2e/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *MainnetMigrationSetupSuite) TestMainnetMigration() {

// verify vesting types
vestingTypes := node.QueryVestingTypes()
s.Equal(5, len(vestingTypes))
s.Equal(7, len(vestingTypes))

s.ElementsMatch(createMainnetVestingTypes(), vestingTypes)

Expand Down Expand Up @@ -204,5 +204,24 @@ func createMainnetVestingTypes() []types.GenesisVestingType {
VestingPeriod: 30,
Free: sdk.MustNewDecFromStr("0.000000000000000000"),
}
return []types.GenesisVestingType{vt1, vt2, vt3, vt4, vt5}

vt6 := types.GenesisVestingType{
Name: "Early-bird round",
LockupPeriod: 61,
LockupPeriodUnit: "day",
VestingPeriod: 213,
VestingPeriodUnit: "day",
Free: sdk.MustNewDecFromStr("0.150000000000000000"),
}

vt7 := types.GenesisVestingType{
Name: "Public round",
LockupPeriod: 30,
LockupPeriodUnit: "day",
VestingPeriod: 152,
VestingPeriodUnit: "day",
Free: sdk.MustNewDecFromStr("0.200000000000000000"),
}

return []types.GenesisVestingType{vt1, vt2, vt3, vt4, vt5, vt6, vt7}
}
Loading

0 comments on commit 17bebcd

Please sign in to comment.