From 6f705327bf18e97ca1e3c3b38abefd2184cc030a Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Mon, 6 Mar 2023 15:58:57 -0800 Subject: [PATCH 1/9] feat: add ecocredit batch metadata migration --- app/upgrades/v5_1/upgrade.go | 23 ++ app/upgrades/v5_1/upgrade_test.go | 44 ++++ x/ecocredit/migrations/v4/state.go | 134 ++++++++++ x/ecocredit/migrations/v4/state_test.go | 337 ++++++++++++++++++++++++ x/ecocredit/module/module.go | 2 +- 5 files changed, 539 insertions(+), 1 deletion(-) create mode 100644 app/upgrades/v5_1/upgrade.go create mode 100644 app/upgrades/v5_1/upgrade_test.go create mode 100644 x/ecocredit/migrations/v4/state.go create mode 100644 x/ecocredit/migrations/v4/state_test.go diff --git a/app/upgrades/v5_1/upgrade.go b/app/upgrades/v5_1/upgrade.go new file mode 100644 index 0000000000..5df9667d83 --- /dev/null +++ b/app/upgrades/v5_1/upgrade.go @@ -0,0 +1,23 @@ +package v5_1 //nolint:revive,stylecheck + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/regen-network/regen-ledger/v5/app/upgrades" +) + +const Name = "v5.1" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: Name, + CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // run in-place store migrations for ecocredit module + return mm.RunMigrations(ctx, cfg, fromVM) + } + }, + StoreUpgrades: storetypes.StoreUpgrades{}, +} diff --git a/app/upgrades/v5_1/upgrade_test.go b/app/upgrades/v5_1/upgrade_test.go new file mode 100644 index 0000000000..d0e1aa5aa6 --- /dev/null +++ b/app/upgrades/v5_1/upgrade_test.go @@ -0,0 +1,44 @@ +package v5_1_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + abci "github.com/tendermint/tendermint/abci/types" + + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/regen-network/regen-ledger/v5/app/testsuite" +) + +type UpgradeTestSuite struct { + testsuite.UpgradeTestSuite +} + +func TestUpgrade(t *testing.T) { + suite.Run(t, new(UpgradeTestSuite)) +} + +const upgradeHeight = 5 + +func (suite *UpgradeTestSuite) TestUpgrade() { + suite.Setup() + + suite.Ctx = suite.Ctx.WithBlockHeight(upgradeHeight - 1) + suite.Ctx = suite.Ctx.WithChainID("regen-1") + + plan := upgradetypes.Plan{Name: "v5.1", Height: upgradeHeight} + err := suite.App.UpgradeKeeper.ScheduleUpgrade(suite.Ctx, plan) + suite.Require().NoError(err) + + _, exists := suite.App.UpgradeKeeper.GetUpgradePlan(suite.Ctx) + suite.Require().True(exists) + + suite.Ctx = suite.Ctx.WithBlockHeight(upgradeHeight) + + suite.Require().NotPanics(func() { + beginBlockRequest := abci.RequestBeginBlock{} + suite.App.BeginBlocker(suite.Ctx, beginBlockRequest) + }) +} diff --git a/x/ecocredit/migrations/v4/state.go b/x/ecocredit/migrations/v4/state.go new file mode 100644 index 0000000000..2da6886588 --- /dev/null +++ b/x/ecocredit/migrations/v4/state.go @@ -0,0 +1,134 @@ +package v4 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + ecocreditv1 "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1" +) + +// MigrateState performs in-place store migrations from ConsensusVersion 3 to 4. +func MigrateState(sdkCtx sdk.Context, baseStore ecocreditv1.StateStore) error { + var batches []Batch + + if sdkCtx.ChainID() == "regen-1" { + batches = getMainnetBatches() + } + + for _, batch := range batches { + if err := migrateBatchMetadata(sdkCtx, baseStore, batch); err != nil { + return err + } + } + + return nil +} + +type Batch struct { + Denom string + NewMetadata string +} + +func getMainnetBatches() []Batch { + return []Batch{ + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-001 + { + Denom: "C01-001-20150101-20151231-001", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-002 + { + Denom: "C01-001-20150101-20151231-002", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-003 + { + Denom: "C01-001-20150101-20151231-003", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-004 + { + Denom: "C01-001-20150101-20151231-004", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-005 + { + Denom: "C01-001-20150101-20151231-005", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-001 + { + Denom: "C01-002-20190101-20191231-001", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-002 + { + Denom: "C01-002-20190101-20191231-002", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-003 + { + Denom: "C01-002-20190101-20191231-003", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-004 + { + Denom: "C01-002-20190101-20191231-004", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-003-20150701-20160630-001 + { + Denom: "C01-003-20150701-20160630-001", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-001-20180101-20181231-001 + { + Denom: "C02-001-20180101-20181231-001", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-003-20200630-20220629-001 + { + Denom: "C02-003-20200630-20220629-001", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-002-20211012-20241013-001 + { + Denom: "C02-002-20211012-20241013-001", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-004-20210102-20211207-001 + { + Denom: "C02-004-20210102-20211207-001", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-005 + { + Denom: "C01-002-20190101-20191231-005", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-006 + { + Denom: "C01-001-20150101-20151231-006", + NewMetadata: "regen1...", + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-006 + { + Denom: "C01-002-20190101-20191231-006", + NewMetadata: "regen1...", + }, + } +} + +func migrateBatchMetadata(ctx sdk.Context, baseStore ecocreditv1.StateStore, batch Batch) error { + b, err := baseStore.BatchTable().GetByDenom(ctx, batch.Denom) + if err != nil { + return err + } + + b.Metadata = batch.NewMetadata + + if err := baseStore.BatchTable().Update(ctx, b); err != nil { + return err + } + + return nil +} diff --git a/x/ecocredit/migrations/v4/state_test.go b/x/ecocredit/migrations/v4/state_test.go new file mode 100644 index 0000000000..64bff8e65a --- /dev/null +++ b/x/ecocredit/migrations/v4/state_test.go @@ -0,0 +1,337 @@ +package v4_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + dbm "github.com/tendermint/tm-db" + "google.golang.org/protobuf/types/known/timestamppb" + + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/cosmos/cosmos-sdk/orm/model/ormdb" + "github.com/cosmos/cosmos-sdk/orm/model/ormtable" + "github.com/cosmos/cosmos-sdk/orm/testing/ormtest" + "github.com/cosmos/cosmos-sdk/store" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + baseapi "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1" + "github.com/regen-network/regen-ledger/x/ecocredit/v3" + v4 "github.com/regen-network/regen-ledger/x/ecocredit/v3/migrations/v4" +) + +func TestMainnetMigrateBatchMetadata(t *testing.T) { + sdkCtx, baseStore := setup(t) + sdkCtx = sdkCtx.WithChainID("regen-1") + + // issuer is the same for all credit batches + issuer := sdk.MustAccAddressFromBech32("regen1v2ncquer9r2ytlkxh2djmmsq3e8we6rjc9snfn") + + // generic project key (we only need to test unchanged) + projectKey := uint64(1) + + // generic timestamp (we only need to test unchanged) + timestamp := timestamppb.Now() + + batches := []baseapi.Batch{ + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-001 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-001-20150101-20151231-001", + Metadata: "regen:13toVgyewRosPA4FVy4wWJgk7JGYc5K7TtE1nHaaHQJgvb6bBLtBBTC.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-002 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-001-20150101-20151231-002", + Metadata: "regen:13toVgbuejJuARiL27Js3Ek3bw3cFrpCN89agNL7pPksUjwQdLWnJRC.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-003 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-001-20150101-20151231-003", + Metadata: "regen:13toVgfKEu7dmUCsf6pfXKeWdNEaCAn8rhYB45gpJzoazQ1jEpRyapb.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-004 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-001-20150101-20151231-004", + Metadata: "regen:13toVhazYXg2LyQ7TXzEkBDsYi3wEyUzi56ZB6DgmbHGyLj9gUvfWHn.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-005 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-001-20150101-20151231-005", + Metadata: "regen:13toVgs8XiE5McGxNhf4hb4F6pxiRzQKXXwNNbbCs2VSDm8BWi94dQB.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-001 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-002-20190101-20191231-001", + Metadata: "regen:13toVgF84kQwSX11DdhDasYtMFU1Yb6qQwQvtv1rvH8pf5E8UTyajCX.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-002 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-002-20190101-20191231-002", + Metadata: "regen:13toVgR8xL6Nuyrotjaik7bqmkuWRnMvit8ka1fSBLnebzP7zUVbMJ3.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-003 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-002-20190101-20191231-003", + Metadata: "regen:13toVhAQCbMc2LJm44AV1enaqi27mRMkRjPJmVGdW11C4qcKuhrnGPA.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-004 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-002-20190101-20191231-004", + Metadata: "regen:13toVhJGk75xSgtrv831sgoEE6i3HhaWg7HtgtAxpFdk7Bp5Yz5Bz85.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-003-20150701-20160630-001 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-003-20150701-20160630-001", + Metadata: "regen:13toVhBNPukzs9mmH9j4yL7ZaAhBBbQ9D2M9Hiw2QkQR2MuFrmaUd5F.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-001-20180101-20181231-001 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C02-001-20180101-20181231-001", + Metadata: "regen:13toVgYscoLUM1ZVzavQv1wm4BBGRn36WGbtmr4Ppa8MrkKifYJxNUg.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-003-20200630-20220629-001 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C02-003-20200630-20220629-001", + Metadata: "regen:13toVfxW6oyujxDVKhFiUNK95FV92W1u5umcjED137HpnMcheqzzxUS.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-002-20211012-20241013-001 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C02-002-20211012-20241013-001", + Metadata: "regen:13toVh95YsiGdwkHXKeg2HtEXaiBn484JCK5wDAa6TijpZhUHkDjSBh.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-004-20210102-20211207-001 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C02-004-20210102-20211207-001", + Metadata: "regen:13toVgj1vCVsXxh713nC8joYfRgLRde8zryScve3PchGqQVWMqG85D9.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-005 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-002-20190101-20191231-005", + Metadata: "regen:13toVhUHUpYhfYLL2Pe4DhDrjFNmTQTnJBYsTQZDkZ9i9TboXgbDTJq.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-006 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-001-20150101-20151231-006", + Metadata: "regen:13toVgNQB7QfSsKEjFoRckAGLabSh8RoizLFtPxgkdswahbDuWiR2He.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-006 + { + Issuer: issuer, + ProjectKey: projectKey, + Denom: "C01-002-20190101-20191231-006", + Metadata: "regen:13toVgPD2BcAvUQ33EWf9CFQiuywRFoFeVoomKByrL68UGM6jpxtTiu.rdf", + StartDate: timestamp, + EndDate: timestamp, + IssuanceDate: timestamp, + Open: false, + }, + } + + // add batches to state + for _, batch := range batches { + require.NoError(t, baseStore.BatchTable().Insert(sdkCtx, &batch)) + } + + // execute state migrations + require.NoError(t, v4.MigrateState(sdkCtx, baseStore)) + + b1, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-001") + require.NoError(t, err) + require.Equal(t, b1.Metadata, "regen1...") + + b2, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-002") + require.NoError(t, err) + require.Equal(t, b2.Metadata, "regen1...") + + b3, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-003") + require.NoError(t, err) + require.Equal(t, b3.Metadata, "regen1...") + + b4, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-003") + require.NoError(t, err) + require.Equal(t, b4.Metadata, "regen1...") + + b5, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-004") + require.NoError(t, err) + require.Equal(t, b5.Metadata, "regen1...") + + b6, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-005") + require.NoError(t, err) + require.Equal(t, b6.Metadata, "regen1...") + + b7, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-001") + require.NoError(t, err) + require.Equal(t, b7.Metadata, "regen1...") + + b8, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-002") + require.NoError(t, err) + require.Equal(t, b8.Metadata, "regen1...") + + b9, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-003") + require.NoError(t, err) + require.Equal(t, b9.Metadata, "regen1...") + + b10, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-004") + require.NoError(t, err) + require.Equal(t, b10.Metadata, "regen1...") + + b11, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-003-20150701-20160630-001") + require.NoError(t, err) + require.Equal(t, b11.Metadata, "regen1...") + + b12, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-001-20180101-20181231-001") + require.NoError(t, err) + require.Equal(t, b12.Metadata, "regen1...") + + b13, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-003-20200630-20220629-001") + require.NoError(t, err) + require.Equal(t, b13.Metadata, "regen1...") + + b14, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-002-20211012-20241013-001") + require.NoError(t, err) + require.Equal(t, b14.Metadata, "regen1...") + + b15, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-004-20210102-20211207-001") + require.NoError(t, err) + require.Equal(t, b15.Metadata, "regen1...") + + b16, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-005") + require.NoError(t, err) + require.Equal(t, b16.Metadata, "regen1...") + + b17, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-006") + require.NoError(t, err) + require.Equal(t, b17.Metadata, "regen1...") + + // ensure all other fields are unchanged + for i := range batches { + b, err := baseStore.BatchTable().Get(sdkCtx, uint64(i+1)) + require.NoError(t, err) + + require.Equal(t, b.Issuer, issuer.Bytes()) + require.Equal(t, b.ProjectKey, projectKey) + require.Equal(t, b.StartDate.AsTime(), timestamp.AsTime()) + require.Equal(t, b.EndDate.AsTime(), timestamp.AsTime()) + require.Equal(t, b.IssuanceDate.AsTime(), timestamp.AsTime()) + require.Equal(t, b.Open, false) + } +} + +func setup(t *testing.T) (sdk.Context, baseapi.StateStore) { + ecocreditKey := sdk.NewKVStoreKey("ecocredit") + + db := dbm.NewMemDB() + cms := store.NewCommitMultiStore(db) + cms.MountStoreWithDB(ecocreditKey, storetypes.StoreTypeIAVL, db) + + require.NoError(t, cms.LoadLatestVersion()) + + ormCtx := ormtable.WrapContextDefault(ormtest.NewMemoryBackend()) + sdkCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()).WithContext(ormCtx) + + modDb, err := ormdb.NewModuleDB(&ecocredit.ModuleSchema, ormdb.ModuleDBOptions{}) + require.NoError(t, err) + + baseStore, err := baseapi.NewStateStore(modDb) + require.NoError(t, err) + + return sdkCtx, baseStore +} diff --git a/x/ecocredit/module/module.go b/x/ecocredit/module/module.go index b8595992fb..0cedb42ee0 100644 --- a/x/ecocredit/module/module.go +++ b/x/ecocredit/module/module.go @@ -42,7 +42,7 @@ var ( ) const ( - ConsensusVersion = 3 // ConsensusVersion is the module consensus version + ConsensusVersion = 4 // ConsensusVersion is the module consensus version ) // Module implements the AppModule interface. From 247079d0e69c2e3066e4bba55594c0cde682b9f6 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Tue, 7 Mar 2023 08:25:29 -0800 Subject: [PATCH 2/9] feat: add ecocredit batch metadata migration --- app/app.go | 6 ++++- x/ecocredit/migrations/v4/state.go | 34 ++++++++++++------------- x/ecocredit/migrations/v4/state_test.go | 34 ++++++++++++------------- x/ecocredit/module/module.go | 4 +++ x/ecocredit/server/migrations.go | 12 +++++++++ 5 files changed, 55 insertions(+), 35 deletions(-) diff --git a/app/app.go b/app/app.go index d014af2f2f..07a6e470ca 100644 --- a/app/app.go +++ b/app/app.go @@ -113,6 +113,7 @@ import ( regenupgrades "github.com/regen-network/regen-ledger/v5/app/upgrades" "github.com/regen-network/regen-ledger/v5/app/upgrades/v5_0" + "github.com/regen-network/regen-ledger/v5/app/upgrades/v5_1" "github.com/regen-network/regen-ledger/x/data/v2" datamodule "github.com/regen-network/regen-ledger/x/data/v2/module" "github.com/regen-network/regen-ledger/x/ecocredit/v3" @@ -193,7 +194,10 @@ var ( return perms }() - upgrades = []regenupgrades.Upgrade{v5_0.Upgrade} + upgrades = []regenupgrades.Upgrade{ + v5_0.Upgrade, + v5_1.Upgrade, + } ) func init() { diff --git a/x/ecocredit/migrations/v4/state.go b/x/ecocredit/migrations/v4/state.go index 2da6886588..f8e2d1010b 100644 --- a/x/ecocredit/migrations/v4/state.go +++ b/x/ecocredit/migrations/v4/state.go @@ -33,87 +33,87 @@ func getMainnetBatches() []Batch { // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-001 { Denom: "C01-001-20150101-20151231-001", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-002 { Denom: "C01-001-20150101-20151231-002", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-003 { Denom: "C01-001-20150101-20151231-003", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-004 { Denom: "C01-001-20150101-20151231-004", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-005 { Denom: "C01-001-20150101-20151231-005", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-001 { Denom: "C01-002-20190101-20191231-001", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-002 { Denom: "C01-002-20190101-20191231-002", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-003 { Denom: "C01-002-20190101-20191231-003", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-004 { Denom: "C01-002-20190101-20191231-004", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-003-20150701-20160630-001 { Denom: "C01-003-20150701-20160630-001", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-001-20180101-20181231-001 { Denom: "C02-001-20180101-20181231-001", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-003-20200630-20220629-001 { Denom: "C02-003-20200630-20220629-001", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-002-20211012-20241013-001 { Denom: "C02-002-20211012-20241013-001", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-004-20210102-20211207-001 { Denom: "C02-004-20210102-20211207-001", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-005 { Denom: "C01-002-20190101-20191231-005", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-006 { Denom: "C01-001-20150101-20151231-006", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-006 { Denom: "C01-002-20190101-20191231-006", - NewMetadata: "regen1...", + NewMetadata: "regen:", }, } } diff --git a/x/ecocredit/migrations/v4/state_test.go b/x/ecocredit/migrations/v4/state_test.go index 64bff8e65a..0284e07bf7 100644 --- a/x/ecocredit/migrations/v4/state_test.go +++ b/x/ecocredit/migrations/v4/state_test.go @@ -235,71 +235,71 @@ func TestMainnetMigrateBatchMetadata(t *testing.T) { b1, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-001") require.NoError(t, err) - require.Equal(t, b1.Metadata, "regen1...") + require.Equal(t, b1.Metadata, "regen:") b2, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-002") require.NoError(t, err) - require.Equal(t, b2.Metadata, "regen1...") + require.Equal(t, b2.Metadata, "regen:") b3, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-003") require.NoError(t, err) - require.Equal(t, b3.Metadata, "regen1...") + require.Equal(t, b3.Metadata, "regen:") b4, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-003") require.NoError(t, err) - require.Equal(t, b4.Metadata, "regen1...") + require.Equal(t, b4.Metadata, "regen:") b5, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-004") require.NoError(t, err) - require.Equal(t, b5.Metadata, "regen1...") + require.Equal(t, b5.Metadata, "regen:") b6, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-005") require.NoError(t, err) - require.Equal(t, b6.Metadata, "regen1...") + require.Equal(t, b6.Metadata, "regen:") b7, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-001") require.NoError(t, err) - require.Equal(t, b7.Metadata, "regen1...") + require.Equal(t, b7.Metadata, "regen:") b8, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-002") require.NoError(t, err) - require.Equal(t, b8.Metadata, "regen1...") + require.Equal(t, b8.Metadata, "regen:") b9, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-003") require.NoError(t, err) - require.Equal(t, b9.Metadata, "regen1...") + require.Equal(t, b9.Metadata, "regen:") b10, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-004") require.NoError(t, err) - require.Equal(t, b10.Metadata, "regen1...") + require.Equal(t, b10.Metadata, "regen:") b11, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-003-20150701-20160630-001") require.NoError(t, err) - require.Equal(t, b11.Metadata, "regen1...") + require.Equal(t, b11.Metadata, "regen:") b12, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-001-20180101-20181231-001") require.NoError(t, err) - require.Equal(t, b12.Metadata, "regen1...") + require.Equal(t, b12.Metadata, "regen:") b13, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-003-20200630-20220629-001") require.NoError(t, err) - require.Equal(t, b13.Metadata, "regen1...") + require.Equal(t, b13.Metadata, "regen:") b14, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-002-20211012-20241013-001") require.NoError(t, err) - require.Equal(t, b14.Metadata, "regen1...") + require.Equal(t, b14.Metadata, "regen:") b15, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-004-20210102-20211207-001") require.NoError(t, err) - require.Equal(t, b15.Metadata, "regen1...") + require.Equal(t, b15.Metadata, "regen:") b16, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-005") require.NoError(t, err) - require.Equal(t, b16.Metadata, "regen1...") + require.Equal(t, b16.Metadata, "regen:") b17, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-006") require.NoError(t, err) - require.Equal(t, b17.Metadata, "regen1...") + require.Equal(t, b17.Metadata, "regen:") // ensure all other fields are unchanged for i := range batches { diff --git a/x/ecocredit/module/module.go b/x/ecocredit/module/module.go index 0cedb42ee0..0d3bc0b7b5 100644 --- a/x/ecocredit/module/module.go +++ b/x/ecocredit/module/module.go @@ -135,6 +135,10 @@ func (m *Module) RegisterServices(cfg module.Configurator) { panic(err) } + if err := cfg.RegisterMigration(ecocredit.ModuleName, 3, migrator.Migrate3to4); err != nil { + panic(err) + } + m.Keeper = svr } diff --git a/x/ecocredit/server/migrations.go b/x/ecocredit/server/migrations.go index 641da4cf87..2cf9f725ac 100644 --- a/x/ecocredit/server/migrations.go +++ b/x/ecocredit/server/migrations.go @@ -3,6 +3,7 @@ package server import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + v4 "github.com/regen-network/regen-ledger/x/ecocredit/v3/migrations/v4" ecocreditv1 "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1" v3 "github.com/regen-network/regen-ledger/x/ecocredit/v3/migrations/v3" @@ -38,3 +39,14 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error { return nil } + +// Migrate3to4 migrates from version 3 to 4. +func (m Migrator) Migrate3to4(ctx sdk.Context) error { + + baseStore, _, _ := m.keeper.GetStateStores() + if err := v4.MigrateState(ctx, baseStore); err != nil { + return err + } + + return nil +} From 67d01d8fa938c170a80e7f73b54485078c92df26 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Tue, 7 Mar 2023 08:42:11 -0800 Subject: [PATCH 3/9] fix lint --- x/ecocredit/migrations/v4/state_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/ecocredit/migrations/v4/state_test.go b/x/ecocredit/migrations/v4/state_test.go index 0284e07bf7..1b22edf222 100644 --- a/x/ecocredit/migrations/v4/state_test.go +++ b/x/ecocredit/migrations/v4/state_test.go @@ -327,10 +327,10 @@ func setup(t *testing.T) (sdk.Context, baseapi.StateStore) { ormCtx := ormtable.WrapContextDefault(ormtest.NewMemoryBackend()) sdkCtx := sdk.NewContext(cms, tmproto.Header{}, false, log.NewNopLogger()).WithContext(ormCtx) - modDb, err := ormdb.NewModuleDB(&ecocredit.ModuleSchema, ormdb.ModuleDBOptions{}) + modDB, err := ormdb.NewModuleDB(&ecocredit.ModuleSchema, ormdb.ModuleDBOptions{}) require.NoError(t, err) - baseStore, err := baseapi.NewStateStore(modDb) + baseStore, err := baseapi.NewStateStore(modDB) require.NoError(t, err) return sdkCtx, baseStore From f0da29b7c23426b581f9f81bbf948871a0759555 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Tue, 7 Mar 2023 08:57:59 -0800 Subject: [PATCH 4/9] fix lint --- x/ecocredit/migrations/v4/state_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/ecocredit/migrations/v4/state_test.go b/x/ecocredit/migrations/v4/state_test.go index 1b22edf222..0688205db6 100644 --- a/x/ecocredit/migrations/v4/state_test.go +++ b/x/ecocredit/migrations/v4/state_test.go @@ -29,13 +29,13 @@ func TestMainnetMigrateBatchMetadata(t *testing.T) { // issuer is the same for all credit batches issuer := sdk.MustAccAddressFromBech32("regen1v2ncquer9r2ytlkxh2djmmsq3e8we6rjc9snfn") - // generic project key (we only need to test unchanged) + // generic project key (we only need to test unchanged after migration) projectKey := uint64(1) - // generic timestamp (we only need to test unchanged) + // generic timestamp (we only need to test unchanged after migration) timestamp := timestamppb.Now() - batches := []baseapi.Batch{ + batches := []*baseapi.Batch{ // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-001 { Issuer: issuer, @@ -227,7 +227,7 @@ func TestMainnetMigrateBatchMetadata(t *testing.T) { // add batches to state for _, batch := range batches { - require.NoError(t, baseStore.BatchTable().Insert(sdkCtx, &batch)) + require.NoError(t, baseStore.BatchTable().Insert(sdkCtx, batch)) } // execute state migrations From 70e90951c0c1a714038ad53f44f7a0847f481528 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Tue, 7 Mar 2023 08:59:58 -0800 Subject: [PATCH 5/9] fix import --- x/ecocredit/server/migrations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/ecocredit/server/migrations.go b/x/ecocredit/server/migrations.go index 2cf9f725ac..913a219921 100644 --- a/x/ecocredit/server/migrations.go +++ b/x/ecocredit/server/migrations.go @@ -3,10 +3,10 @@ package server import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - v4 "github.com/regen-network/regen-ledger/x/ecocredit/v3/migrations/v4" ecocreditv1 "github.com/regen-network/regen-ledger/api/v2/regen/ecocredit/v1" v3 "github.com/regen-network/regen-ledger/x/ecocredit/v3/migrations/v3" + v4 "github.com/regen-network/regen-ledger/x/ecocredit/v3/migrations/v4" ) // Migrator is a struct for handling in-place store migrations. From a07c63755e0a70545b5c84a287d331c6c1986139 Mon Sep 17 00:00:00 2001 From: Marie Gauthier Date: Thu, 16 Mar 2023 18:29:50 +0100 Subject: [PATCH 6/9] chore: add batches new metadata (#1831) --- x/ecocredit/migrations/v4/state.go | 34 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/x/ecocredit/migrations/v4/state.go b/x/ecocredit/migrations/v4/state.go index f8e2d1010b..80c8f6ec76 100644 --- a/x/ecocredit/migrations/v4/state.go +++ b/x/ecocredit/migrations/v4/state.go @@ -33,87 +33,87 @@ func getMainnetBatches() []Batch { // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-001 { Denom: "C01-001-20150101-20151231-001", - NewMetadata: "regen:", + NewMetadata: "regen:13toVg38ZRvFxPA2TBNnxGhabgogpJnv4LDm7YPgSuzuETiXz8GbnTF.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-002 { Denom: "C01-001-20150101-20151231-002", - NewMetadata: "regen:", + NewMetadata: "regen:13toVhTFtGtXxoHw7yy3QQVDGEpSQoVy4VARhtTWeuNQa5V25WUhagq.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-003 { Denom: "C01-001-20150101-20151231-003", - NewMetadata: "regen:", + NewMetadata: "regen:13toVghYySmmX9gm76MuwiPCC9AJy6Psb7wj6uj9JiBk4NvACGkpJDw.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-004 { Denom: "C01-001-20150101-20151231-004", - NewMetadata: "regen:", + NewMetadata: "regen:13toVgGhCxGuNrqKKugLY9thKAdLTgXHGxhbVutz2QLgtFmdZzPAKUB.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-005 { Denom: "C01-001-20150101-20151231-005", - NewMetadata: "regen:", + NewMetadata: "regen:13toVhaDUK1CHmqdZfKr6ZdF1L1ekTvUgjbEiGxWYqDWVZ937GUviFr.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-001 { Denom: "C01-002-20190101-20191231-001", - NewMetadata: "regen:", + NewMetadata: "regen:13toVgu5VbjKdfDKuwPfUoMeo2isi1ApbsCsaTCoyNknKnN9FE6j1hW.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-002 { Denom: "C01-002-20190101-20191231-002", - NewMetadata: "regen:", + NewMetadata: "regen:13toVgxDAxBev51DadD1he6gdkF6UPAoe25Y2xsSn3uDpzmHG3qGqRh.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-003 { Denom: "C01-002-20190101-20191231-003", - NewMetadata: "regen:", + NewMetadata: "regen:13toVgsTujvEeCS4hG9MXZii8eF9LBkrgzaw8mh2q54KfFtGFtH5DLi.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-004 { Denom: "C01-002-20190101-20191231-004", - NewMetadata: "regen:", + NewMetadata: "regen:13toVhKuR8NndSGZdciYTtCJf11hjYGwNvsWdjSPBmXNAqk8oL7u7XW.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-003-20150701-20160630-001 { Denom: "C01-003-20150701-20160630-001", - NewMetadata: "regen:", + NewMetadata: "regen:13toVhMT8c7hFZePMqa8raLBgCuLFo4MWbJ7QJRheFRC5dfPcmFZ4hk.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-001-20180101-20181231-001 { Denom: "C02-001-20180101-20181231-001", - NewMetadata: "regen:", + NewMetadata: "regen:13toVgpAwAm6fzYUUkD8UmioCYCP3GMbA3pdNkTM4wKeWc5UxmmCZW8.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-003-20200630-20220629-001 { Denom: "C02-003-20200630-20220629-001", - NewMetadata: "regen:", + NewMetadata: "regen:13toVh5g1AhGAWcTQCBXra1YfD2XJUbH35dvSLuEPAR8mQHJDY5ovVe.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-002-20211012-20241013-001 { Denom: "C02-002-20211012-20241013-001", - NewMetadata: "regen:", + NewMetadata: "regen:13toVhAukPXsjX5gMTADfUQzJQBjehJJoPwSavuU6GjyH5DtxZ5oVYS.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C02-004-20210102-20211207-001 { Denom: "C02-004-20210102-20211207-001", - NewMetadata: "regen:", + NewMetadata: "regen:13toVh1EoPoJJs1VSvmeQB3HHpXDgFBA19KqiP1tg4NByjWsFLJdjuq.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-005 { Denom: "C01-002-20190101-20191231-005", - NewMetadata: "regen:", + NewMetadata: "regen:13toVgwjqzxx3b9cRiRXBxrsUQB6D1WC4Kk8zZuXUfwnZ8WYtxRy4r5.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-001-20150101-20151231-006 { Denom: "C01-001-20150101-20151231-006", - NewMetadata: "regen:", + NewMetadata: "regen:13toVhaPG4MzeWcmoriPhQ5jRGx6ohhdzBPREoarrdqTRVCP8Xj7scM.rdf", }, // http://mainnet.regen.network:1317/regen/ecocredit/v1/batches/C01-002-20190101-20191231-006 { Denom: "C01-002-20190101-20191231-006", - NewMetadata: "regen:", + NewMetadata: "regen:13toVh3NyL4uDzLFcrf6rUFMQnV8af87tBdSzh1Dvsc8zgEx193Y7hr.rdf", }, } } From d3d734ed6135dae763c15878537a1d5a71eb55c7 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Thu, 16 Mar 2023 10:39:21 -0700 Subject: [PATCH 7/9] test: update test assertions using added metadata --- x/ecocredit/migrations/v4/state_test.go | 62 ++++++++++++------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/x/ecocredit/migrations/v4/state_test.go b/x/ecocredit/migrations/v4/state_test.go index 0688205db6..0ea843a4c2 100644 --- a/x/ecocredit/migrations/v4/state_test.go +++ b/x/ecocredit/migrations/v4/state_test.go @@ -235,71 +235,71 @@ func TestMainnetMigrateBatchMetadata(t *testing.T) { b1, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-001") require.NoError(t, err) - require.Equal(t, b1.Metadata, "regen:") + require.Equal(t, b1.Metadata, "regen:13toVg38ZRvFxPA2TBNnxGhabgogpJnv4LDm7YPgSuzuETiXz8GbnTF.rdf") b2, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-002") require.NoError(t, err) - require.Equal(t, b2.Metadata, "regen:") + require.Equal(t, b2.Metadata, "regen:13toVhTFtGtXxoHw7yy3QQVDGEpSQoVy4VARhtTWeuNQa5V25WUhagq.rdf") b3, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-003") require.NoError(t, err) - require.Equal(t, b3.Metadata, "regen:") + require.Equal(t, b3.Metadata, "regen:13toVghYySmmX9gm76MuwiPCC9AJy6Psb7wj6uj9JiBk4NvACGkpJDw.rdf") - b4, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-003") + b4, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-004") require.NoError(t, err) - require.Equal(t, b4.Metadata, "regen:") + require.Equal(t, b4.Metadata, "regen:13toVgGhCxGuNrqKKugLY9thKAdLTgXHGxhbVutz2QLgtFmdZzPAKUB.rdf") - b5, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-004") + b5, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-005") require.NoError(t, err) - require.Equal(t, b5.Metadata, "regen:") + require.Equal(t, b5.Metadata, "regen:13toVhaDUK1CHmqdZfKr6ZdF1L1ekTvUgjbEiGxWYqDWVZ937GUviFr.rdf") - b6, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-005") + b6, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-001") require.NoError(t, err) - require.Equal(t, b6.Metadata, "regen:") + require.Equal(t, b6.Metadata, "regen:13toVgu5VbjKdfDKuwPfUoMeo2isi1ApbsCsaTCoyNknKnN9FE6j1hW.rdf") - b7, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-001") + b7, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-002") require.NoError(t, err) - require.Equal(t, b7.Metadata, "regen:") + require.Equal(t, b7.Metadata, "regen:13toVgxDAxBev51DadD1he6gdkF6UPAoe25Y2xsSn3uDpzmHG3qGqRh.rdf") - b8, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-002") + b8, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-003") require.NoError(t, err) - require.Equal(t, b8.Metadata, "regen:") + require.Equal(t, b8.Metadata, "regen:13toVgsTujvEeCS4hG9MXZii8eF9LBkrgzaw8mh2q54KfFtGFtH5DLi.rdf") - b9, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-003") + b9, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-004") require.NoError(t, err) - require.Equal(t, b9.Metadata, "regen:") + require.Equal(t, b9.Metadata, "regen:13toVhKuR8NndSGZdciYTtCJf11hjYGwNvsWdjSPBmXNAqk8oL7u7XW.rdf") - b10, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-004") + b10, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-003-20150701-20160630-001") require.NoError(t, err) - require.Equal(t, b10.Metadata, "regen:") + require.Equal(t, b10.Metadata, "regen:13toVhMT8c7hFZePMqa8raLBgCuLFo4MWbJ7QJRheFRC5dfPcmFZ4hk.rdf") - b11, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-003-20150701-20160630-001") + b11, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-001-20180101-20181231-001") require.NoError(t, err) - require.Equal(t, b11.Metadata, "regen:") + require.Equal(t, b11.Metadata, "regen:13toVgpAwAm6fzYUUkD8UmioCYCP3GMbA3pdNkTM4wKeWc5UxmmCZW8.rdf") - b12, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-001-20180101-20181231-001") + b12, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-003-20200630-20220629-001") require.NoError(t, err) - require.Equal(t, b12.Metadata, "regen:") + require.Equal(t, b12.Metadata, "regen:13toVh5g1AhGAWcTQCBXra1YfD2XJUbH35dvSLuEPAR8mQHJDY5ovVe.rdf") - b13, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-003-20200630-20220629-001") + b13, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-002-20211012-20241013-001") require.NoError(t, err) - require.Equal(t, b13.Metadata, "regen:") + require.Equal(t, b13.Metadata, "regen:13toVhAukPXsjX5gMTADfUQzJQBjehJJoPwSavuU6GjyH5DtxZ5oVYS.rdf") - b14, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-002-20211012-20241013-001") + b14, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-004-20210102-20211207-001") require.NoError(t, err) - require.Equal(t, b14.Metadata, "regen:") + require.Equal(t, b14.Metadata, "regen:13toVh1EoPoJJs1VSvmeQB3HHpXDgFBA19KqiP1tg4NByjWsFLJdjuq.rdf") - b15, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C02-004-20210102-20211207-001") + b15, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-005") require.NoError(t, err) - require.Equal(t, b15.Metadata, "regen:") + require.Equal(t, b15.Metadata, "regen:13toVgwjqzxx3b9cRiRXBxrsUQB6D1WC4Kk8zZuXUfwnZ8WYtxRy4r5.rdf") - b16, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-005") + b16, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-006") require.NoError(t, err) - require.Equal(t, b16.Metadata, "regen:") + require.Equal(t, b16.Metadata, "regen:13toVhaPG4MzeWcmoriPhQ5jRGx6ohhdzBPREoarrdqTRVCP8Xj7scM.rdf") - b17, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-001-20150101-20151231-006") + b17, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20150101-20151231-006") require.NoError(t, err) - require.Equal(t, b17.Metadata, "regen:") + require.Equal(t, b17.Metadata, "regen:13toVh3NyL4uDzLFcrf6rUFMQnV8af87tBdSzh1Dvsc8zgEx193Y7hr.rdf") // ensure all other fields are unchanged for i := range batches { From 5ec614e6f407b2b69f35114d88ae0f6720c9053c Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Thu, 16 Mar 2023 10:45:51 -0700 Subject: [PATCH 8/9] test: fix start end date in batch check --- x/ecocredit/migrations/v4/state_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/ecocredit/migrations/v4/state_test.go b/x/ecocredit/migrations/v4/state_test.go index 0ea843a4c2..6d8892d68f 100644 --- a/x/ecocredit/migrations/v4/state_test.go +++ b/x/ecocredit/migrations/v4/state_test.go @@ -297,7 +297,7 @@ func TestMainnetMigrateBatchMetadata(t *testing.T) { require.NoError(t, err) require.Equal(t, b16.Metadata, "regen:13toVhaPG4MzeWcmoriPhQ5jRGx6ohhdzBPREoarrdqTRVCP8Xj7scM.rdf") - b17, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20150101-20151231-006") + b17, err := baseStore.BatchTable().GetByDenom(sdkCtx, "C01-002-20190101-20191231-006") require.NoError(t, err) require.Equal(t, b17.Metadata, "regen:13toVh3NyL4uDzLFcrf6rUFMQnV8af87tBdSzh1Dvsc8zgEx193Y7hr.rdf") From 0609bee6a954424be79f5f6a30c378a23f804a9d Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Tue, 21 Mar 2023 12:03:42 -0700 Subject: [PATCH 9/9] fix lint --- x/ecocredit/migrations/v4/state.go | 6 +----- x/ecocredit/server/migrations.go | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/x/ecocredit/migrations/v4/state.go b/x/ecocredit/migrations/v4/state.go index 80c8f6ec76..d0b6e4191c 100644 --- a/x/ecocredit/migrations/v4/state.go +++ b/x/ecocredit/migrations/v4/state.go @@ -126,9 +126,5 @@ func migrateBatchMetadata(ctx sdk.Context, baseStore ecocreditv1.StateStore, bat b.Metadata = batch.NewMetadata - if err := baseStore.BatchTable().Update(ctx, b); err != nil { - return err - } - - return nil + return baseStore.BatchTable().Update(ctx, b) } diff --git a/x/ecocredit/server/migrations.go b/x/ecocredit/server/migrations.go index 913a219921..d7c9677d1b 100644 --- a/x/ecocredit/server/migrations.go +++ b/x/ecocredit/server/migrations.go @@ -42,11 +42,6 @@ func (m Migrator) Migrate2to3(ctx sdk.Context) error { // Migrate3to4 migrates from version 3 to 4. func (m Migrator) Migrate3to4(ctx sdk.Context) error { - baseStore, _, _ := m.keeper.GetStateStores() - if err := v4.MigrateState(ctx, baseStore); err != nil { - return err - } - - return nil + return v4.MigrateState(ctx, baseStore) }