From 17bebcd1151f1240f854582a4451624db1eb87d2 Mon Sep 17 00:00:00 2001 From: Dawid Kruk Date: Fri, 16 Feb 2024 11:25:32 +0100 Subject: [PATCH] Vesting and tests updates --- CHANGELOG.md | 2 + app/upgrades/v131/vesting_updates.go | 32 +++ app/upgrades/v131/vesting_updates_test.go | 217 ++++++++++++++++-- tests/e2e/migration_test.go | 23 +- .../mainnet-v1.3.1-migration-app-state.json | 16 ++ x/cfeclaim/types/user_entry.go | 4 - 6 files changed, 268 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ce7232b..cfed86ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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** diff --git a/app/upgrades/v131/vesting_updates.go b/app/upgrades/v131/vesting_updates.go index f1231b29..dade1c3d 100644 --- a/app/upgrades/v131/vesting_updates.go +++ b/app/upgrades/v131/vesting_updates.go @@ -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 { @@ -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"), @@ -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 } diff --git a/app/upgrades/v131/vesting_updates_test.go b/app/upgrades/v131/vesting_updates_test.go index b1f56b86..c413eadd 100644 --- a/app/upgrades/v131/vesting_updates_test.go +++ b/app/upgrades/v131/vesting_updates_test.go @@ -12,66 +12,204 @@ 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, @@ -79,34 +217,73 @@ func TestModifyVestingTypesVestingTypeExists(t *testing.T) { 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() } diff --git a/tests/e2e/migration_test.go b/tests/e2e/migration_test.go index d99814d6..25efd7b9 100644 --- a/tests/e2e/migration_test.go +++ b/tests/e2e/migration_test.go @@ -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) @@ -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} } diff --git a/tests/e2e/resources/mainnet-v1.3.1-migration-app-state.json b/tests/e2e/resources/mainnet-v1.3.1-migration-app-state.json index 610cff13..200d0263 100644 --- a/tests/e2e/resources/mainnet-v1.3.1-migration-app-state.json +++ b/tests/e2e/resources/mainnet-v1.3.1-migration-app-state.json @@ -394,6 +394,22 @@ "vesting_period": "548", "vesting_period_unit": "day", "free": "0.050000000000000000" + }, + { + "name": "Early-bird round", + "lockup_period": "0", + "lockup_period_unit": "day", + "vesting_period": "274", + "vesting_period_unit": "day", + "free": "0.150000000000000000" + }, + { + "name": "Public round", + "lockup_period": "0", + "lockup_period_unit": "day", + "vesting_period": "183", + "vesting_period_unit": "day", + "free": "0.200000000000000000" } ] }, diff --git a/x/cfeclaim/types/user_entry.go b/x/cfeclaim/types/user_entry.go index d4baf424..3885a10d 100644 --- a/x/cfeclaim/types/user_entry.go +++ b/x/cfeclaim/types/user_entry.go @@ -14,10 +14,6 @@ func (m *UserEntry) Validate() error { return err } - if len(m.ClaimRecords) == 0 { - return fmt.Errorf("at least one campaign record is required") - } - campaignIDMap := make(map[uint64]struct{}) for _, elem := range m.ClaimRecords { if _, ok := campaignIDMap[elem.CampaignId]; ok {