From 6c39cd519a9590425734d95fa292a2d1c3b85222 Mon Sep 17 00:00:00 2001 From: kevin-yuhh Date: Tue, 18 Jul 2023 11:51:44 +0800 Subject: [PATCH 1/7] migrate oracle certik prefix to shentu --- x/oracle/keeper/migrations.go | 7 ++ x/oracle/keeper/task.go | 2 +- x/oracle/legacy/v280/store.go | 162 +++++++++++++++++++++++++++++ x/oracle/legacy/v280/store_test.go | 157 ++++++++++++++++++++++++++++ x/oracle/module.go | 7 +- 5 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 x/oracle/legacy/v280/store.go create mode 100644 x/oracle/legacy/v280/store_test.go diff --git a/x/oracle/keeper/migrations.go b/x/oracle/keeper/migrations.go index 69f3f802f..7bf05da7c 100644 --- a/x/oracle/keeper/migrations.go +++ b/x/oracle/keeper/migrations.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + v280 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v280" v2 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v2" ) @@ -21,3 +22,9 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error { v2.UpdateParams(ctx, m.keeper.paramSpace) return v2.MigrateTaskStore(ctx, m.keeper.storeKey, m.keeper.cdc) } + +// Migrate2to3 migrates from version 2 to 3. +func (m Migrator) Migrate2to3(ctx sdk.Context) error { + v280.MigrateAllTaskStore(ctx, m.keeper.storeKey, m.keeper.cdc) + return v280.MigrateOperatorStore(ctx, m.keeper.storeKey, m.keeper.cdc) +} diff --git a/x/oracle/keeper/task.go b/x/oracle/keeper/task.go index b70039a01..b8080a82a 100644 --- a/x/oracle/keeper/task.go +++ b/x/oracle/keeper/task.go @@ -93,7 +93,7 @@ func (k Keeper) GetTask(ctx sdk.Context, taskID []byte) (task types.TaskI, err e return } -//remove ID of the task from closingBlockStore because it has been handled in shortcut +// DeleteFromClosingTaskIDs remove ID of the task from closingBlockStore because it has been handled in shortcut func (k Keeper) DeleteFromClosingTaskIDs(ctx sdk.Context, task types.TaskI) { taskIDs := k.GetClosingTaskIDs(ctx, task) for i := range taskIDs { diff --git a/x/oracle/legacy/v280/store.go b/x/oracle/legacy/v280/store.go new file mode 100644 index 000000000..47d35cb62 --- /dev/null +++ b/x/oracle/legacy/v280/store.go @@ -0,0 +1,162 @@ +package v280 + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/shentufoundation/shentu/v2/common" + "github.com/shentufoundation/shentu/v2/x/oracle/types" +) + +func MigrateAllTaskStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { + store := ctx.KVStore(storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.TaskStoreKeyPrefix) + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + var oldTask types.TaskI + + err := cdc.UnmarshalInterface(iterator.Value(), &oldTask) + if err != nil { + return err + } + + switch task := oldTask.(type) { + case *types.Task: + if err = MigrateTaskStore(task, store, iterator.Key(), cdc); err != nil { + return err + } + case *types.TxTask: + if err = MigrateTxTaskStore(task, store, iterator.Key(), cdc); err != nil { + return err + } + default: + return fmt.Errorf("err kvstore") + } + + } + return nil +} + +func MigrateTaskStore(task *types.Task, store store.KVStore, key []byte, cdc codec.BinaryCodec) error { + shentuAddr, err := common.PrefixToShentu(task.Creator) + if err != nil { + return err + } + + newTask := types.Task{ + Contract: task.Contract, + Function: task.Function, + BeginBlock: task.BeginBlock, + Bounty: task.Bounty, + Description: task.Description, + Expiration: task.Expiration, + Creator: shentuAddr, + Responses: nil, + Result: task.Result, + ExpireHeight: task.ExpireHeight, + WaitingBlocks: task.WaitingBlocks, + Status: task.Status, + } + + for _, response := range task.Responses { + operator, err := common.PrefixToShentu(response.Operator) + if err != nil { + return err + } + newResponse := types.Response{ + Operator: operator, + Score: response.Score, + Weight: response.Weight, + Reward: response.Reward, + } + newTask.Responses = append(newTask.Responses, newResponse) + } + // delete old task + store.Delete(key) + // set task + bz, err := cdc.MarshalInterface(&newTask) + if err != nil { + return err + } + store.Set(types.TaskStoreKey(newTask.GetID()), bz) + return nil +} + +func MigrateTxTaskStore(task *types.TxTask, store store.KVStore, key []byte, cdc codec.BinaryCodec) error { + shentuAddr, err := common.PrefixToShentu(task.Creator) + if err != nil { + return err + } + + newTask := types.TxTask{ + AtxHash: task.AtxHash, + Creator: shentuAddr, + Bounty: task.Bounty, + ValidTime: task.ValidTime, + Expiration: task.Expiration, + Responses: nil, + Score: task.Score, + Status: task.Status, + } + + for _, response := range task.Responses { + operator, err := common.PrefixToShentu(response.Operator) + if err != nil { + return err + } + newResponse := types.Response{ + Operator: operator, + Score: response.Score, + Weight: response.Weight, + Reward: response.Reward, + } + newTask.Responses = append(newTask.Responses, newResponse) + } + // delete old task + store.Delete(key) + // set task + bz, err := cdc.MarshalInterface(&newTask) + if err != nil { + return err + } + store.Set(types.TaskStoreKey(newTask.GetID()), bz) + return nil +} + +func MigrateOperatorStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { + store := ctx.KVStore(storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.OperatorStoreKeyPrefix) + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + var oldOperator types.Operator + cdc.MustUnmarshalLengthPrefixed(iterator.Value(), &oldOperator) + + shentuOperatorAddress, err := common.PrefixToShentu(oldOperator.Address) + if err != nil { + return err + } + shentuProposal, err := common.PrefixToShentu(oldOperator.Proposer) + if err != nil { + return err + } + + newOperator := types.Operator{ + Address: shentuOperatorAddress, + Proposer: shentuProposal, + Collateral: oldOperator.Collateral, + AccumulatedRewards: oldOperator.AccumulatedRewards, + Name: oldOperator.Name, + } + + store.Delete(iterator.Value()) + bz := cdc.MustMarshalLengthPrefixed(&newOperator) + addr := sdk.MustAccAddressFromBech32(shentuOperatorAddress) + store.Set(types.OperatorStoreKey(addr), bz) + } + return nil +} diff --git a/x/oracle/legacy/v280/store_test.go b/x/oracle/legacy/v280/store_test.go new file mode 100644 index 000000000..bf15158cc --- /dev/null +++ b/x/oracle/legacy/v280/store_test.go @@ -0,0 +1,157 @@ +package v280_test + +import ( + "encoding/hex" + "github.com/stretchr/testify/require" + "math/rand" + "testing" + "time" + + "github.com/tendermint/tendermint/crypto/ed25519" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + + shentuapp "github.com/shentufoundation/shentu/v2/app" + "github.com/shentufoundation/shentu/v2/common" + v280 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v280" + oracletypes "github.com/shentufoundation/shentu/v2/x/oracle/types" +) + +func Test_MigrateAllTaskStore(t *testing.T) { + app := shentuapp.Setup(false) + cfg := sdk.GetConfig() + cfg.SetBech32PrefixForAccount(common.Bech32PrefixAccAddr, common.Bech32PrefixAccPub) + ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now().UTC()}) + cdc := shentuapp.MakeEncodingConfig().Marshaler + + store := ctx.KVStore(app.GetKey(oracletypes.StoreKey)) + operator, _ := common.PrefixToCertik(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()).String()) + // mock old data + + response := oracletypes.Response{ + Operator: operator, + Weight: sdk.NewInt(50), + Reward: nil, + } + + tasks := make(map[string]oracletypes.TaskI) + for i := 0; i < 10; i++ { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + beginBlock := r.Int63n(100) + waitingBlocks := r.Int63n(10) + 1 + expireHeight := beginBlock + waitingBlocks + status := r.Intn(4) + creator, _ := common.PrefixToCertik(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()).String()) + + task := oracletypes.Task{ + Contract: simtypes.RandStringOfLength(r, 10), + Function: simtypes.RandStringOfLength(r, 5), + BeginBlock: beginBlock, + Bounty: nil, + Description: simtypes.RandStringOfLength(r, 5), + Expiration: time.Time{}, + Creator: creator, + Responses: nil, + Result: simtypes.RandomAmount(r, sdk.NewInt(100)), + ExpireHeight: expireHeight, + WaitingBlocks: waitingBlocks, + Status: oracletypes.TaskStatus(status), + } + task.AddResponse(response) + tasks[string(oracletypes.NewTaskID(task.Contract, task.Function))] = &task + + bz, err := cdc.MarshalInterface(&task) + if err != nil { + panic(err) + } + store.Set(oracletypes.TaskStoreKey(task.GetID()), bz) + + txTask := oracletypes.TxTask{ + AtxHash: []byte(hex.EncodeToString([]byte(simtypes.RandStringOfLength(r, 10)))), + Bounty: nil, + ValidTime: time.Time{}, + Expiration: time.Time{}, + Creator: creator, + Responses: nil, + Status: oracletypes.TaskStatus(status), + Score: r.Int63n(100), + } + txTask.AddResponse(response) + tasks[string(txTask.GetID())] = &txTask + + bz, err = cdc.MarshalInterface(&txTask) + if err != nil { + panic(err) + } + store.Set(oracletypes.TaskStoreKey(txTask.GetID()), bz) + } + + err := v280.MigrateAllTaskStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) + require.Nil(t, err) + + app.OracleKeeper.IteratorAllTasks(ctx, func(task oracletypes.TaskI) bool { + creator := task.GetCreator() + _, _, err := bech32.DecodeAndConvert(creator) + require.NoError(t, err) + + tk, ok := tasks[string(task.GetID())] + require.True(t, ok) + shentuAddr, err := common.PrefixToShentu(tk.GetCreator()) + require.NoError(t, err) + require.Equal(t, shentuAddr, task.GetCreator()) + + require.Equal(t, tk.GetBounty(), task.GetBounty()) + require.Equal(t, tk.GetScore(), task.GetScore()) + return false + }) + +} + +func Test_MigrateOperator(t *testing.T) { + app := shentuapp.Setup(false) + cfg := sdk.GetConfig() + cfg.SetBech32PrefixForAccount(common.Bech32PrefixAccAddr, common.Bech32PrefixAccPub) + ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now().UTC()}) + cdc := shentuapp.MakeEncodingConfig().Marshaler + + store := ctx.KVStore(app.GetKey(oracletypes.StoreKey)) + // mock old data + for i := 0; i < 10; i++ { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + operatorAddr, _ := common.PrefixToCertik(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()).String()) + proposerAddr, _ := common.PrefixToCertik(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()).String()) + + operator := oracletypes.Operator{ + Address: operatorAddr, + Proposer: proposerAddr, + Collateral: nil, + AccumulatedRewards: nil, + Name: simtypes.RandStringOfLength(r, 10), + } + + bz := cdc.MustMarshalLengthPrefixed(&operator) + _, addrBz, err := bech32.DecodeAndConvert(operatorAddr) + if err != nil { + panic(err) + } + addr := sdk.AccAddress(addrBz) + store.Set(oracletypes.OperatorStoreKey(addr), bz) + } + + err := v280.MigrateOperatorStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) + require.Nil(t, err) + + app.OracleKeeper.IterateAllOperators(ctx, func(operator oracletypes.Operator) bool { + hrp, _, err := bech32.DecodeAndConvert(operator.Address) + require.NoError(t, err) + require.Equal(t, hrp, "shentu") + + hrp, _, err = bech32.DecodeAndConvert(operator.Proposer) + require.NoError(t, err) + require.Equal(t, hrp, "shentu") + return false + }) +} diff --git a/x/oracle/module.go b/x/oracle/module.go index 86243fe49..3756265fd 100644 --- a/x/oracle/module.go +++ b/x/oracle/module.go @@ -112,7 +112,7 @@ func (am AppModule) Name() string { return types.ModuleName } -// RegisterInvariants registers the this module invariants. +// RegisterInvariants registers this module invariants. func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { keeper.RegisterInvariants(ir, am.keeper) } @@ -142,6 +142,11 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err != nil { panic(err) } + + err = cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3) + if err != nil { + panic(err) + } } // InitGenesis performs genesis initialization for the oracle module. From f867ffcb970666a49ce802227d0a81bed42dd970 Mon Sep 17 00:00:00 2001 From: kevin-yuhh Date: Tue, 25 Jul 2023 10:28:30 +0800 Subject: [PATCH 2/7] update ConsensusVersion --- x/oracle/module.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/oracle/module.go b/x/oracle/module.go index 3756265fd..c776a7fd3 100644 --- a/x/oracle/module.go +++ b/x/oracle/module.go @@ -164,7 +164,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 2 } +func (AppModule) ConsensusVersion() uint64 { return 3 } // BeginBlock implements the Cosmos SDK BeginBlock module function. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { From 205e10c246c091f074ff5669016019d4c2257665 Mon Sep 17 00:00:00 2001 From: kevin-yuhh Date: Tue, 25 Jul 2023 15:35:51 +0800 Subject: [PATCH 3/7] update operator migration --- x/oracle/legacy/v280/store.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/x/oracle/legacy/v280/store.go b/x/oracle/legacy/v280/store.go index 47d35cb62..5258db453 100644 --- a/x/oracle/legacy/v280/store.go +++ b/x/oracle/legacy/v280/store.go @@ -133,28 +133,22 @@ func MigrateOperatorStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.Bina defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - var oldOperator types.Operator - cdc.MustUnmarshalLengthPrefixed(iterator.Value(), &oldOperator) + var operator types.Operator + cdc.MustUnmarshalLengthPrefixed(iterator.Value(), &operator) - shentuOperatorAddress, err := common.PrefixToShentu(oldOperator.Address) + shentuOperatorAddress, err := common.PrefixToShentu(operator.Address) if err != nil { return err } - shentuProposal, err := common.PrefixToShentu(oldOperator.Proposer) + shentuProposal, err := common.PrefixToShentu(operator.Proposer) if err != nil { return err } - newOperator := types.Operator{ - Address: shentuOperatorAddress, - Proposer: shentuProposal, - Collateral: oldOperator.Collateral, - AccumulatedRewards: oldOperator.AccumulatedRewards, - Name: oldOperator.Name, - } + operator.Address = shentuOperatorAddress + operator.Proposer = shentuProposal - store.Delete(iterator.Value()) - bz := cdc.MustMarshalLengthPrefixed(&newOperator) + bz := cdc.MustMarshalLengthPrefixed(&operator) addr := sdk.MustAccAddressFromBech32(shentuOperatorAddress) store.Set(types.OperatorStoreKey(addr), bz) } From 443b4808d97c9723bf32402734c68a63bd8dfc5f Mon Sep 17 00:00:00 2001 From: kevin-yuhh Date: Tue, 25 Jul 2023 18:46:09 +0800 Subject: [PATCH 4/7] add oracle withdraw migration --- x/oracle/keeper/migrations.go | 3 +-- x/oracle/legacy/v280/store.go | 36 +++++++++++++++++++++++++++++ x/oracle/legacy/v280/store_test.go | 37 ++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/x/oracle/keeper/migrations.go b/x/oracle/keeper/migrations.go index 7bf05da7c..bdcc6ea91 100644 --- a/x/oracle/keeper/migrations.go +++ b/x/oracle/keeper/migrations.go @@ -25,6 +25,5 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error { // Migrate2to3 migrates from version 2 to 3. func (m Migrator) Migrate2to3(ctx sdk.Context) error { - v280.MigrateAllTaskStore(ctx, m.keeper.storeKey, m.keeper.cdc) - return v280.MigrateOperatorStore(ctx, m.keeper.storeKey, m.keeper.cdc) + return v280.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) } diff --git a/x/oracle/legacy/v280/store.go b/x/oracle/legacy/v280/store.go index 5258db453..c01b986e4 100644 --- a/x/oracle/legacy/v280/store.go +++ b/x/oracle/legacy/v280/store.go @@ -154,3 +154,39 @@ func MigrateOperatorStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.Bina } return nil } + +func MigrateWithdrawStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { + store := ctx.KVStore(storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.WithdrawStoreKeyPrefix) + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + var withdraw types.Withdraw + cdc.MustUnmarshalLengthPrefixed(iterator.Value(), &withdraw) + + shentuAddr, err := common.PrefixToShentu(withdraw.Address) + if err != nil { + return err + } + + withdraw.Address = shentuAddr + + bz := cdc.MustMarshalLengthPrefixed(&withdraw) + withdrawAddr := sdk.MustAccAddressFromBech32(shentuAddr) + store.Set(types.WithdrawStoreKey(withdrawAddr, withdraw.DueBlock), bz) + } + return nil +} + +func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { + if err := MigrateAllTaskStore(ctx, storeKey, cdc); err != nil { + return err + } + if err := MigrateOperatorStore(ctx, storeKey, cdc); err != nil { + return err + } + if err := MigrateWithdrawStore(ctx, storeKey, cdc); err != nil { + return err + } + return nil +} diff --git a/x/oracle/legacy/v280/store_test.go b/x/oracle/legacy/v280/store_test.go index bf15158cc..42a1c411a 100644 --- a/x/oracle/legacy/v280/store_test.go +++ b/x/oracle/legacy/v280/store_test.go @@ -155,3 +155,40 @@ func Test_MigrateOperator(t *testing.T) { return false }) } + +func Test_MigrateWithdraw(t *testing.T) { + app := shentuapp.Setup(false) + cfg := sdk.GetConfig() + cfg.SetBech32PrefixForAccount(common.Bech32PrefixAccAddr, common.Bech32PrefixAccPub) + ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now().UTC()}) + cdc := shentuapp.MakeEncodingConfig().Marshaler + + store := ctx.KVStore(app.GetKey(oracletypes.StoreKey)) + // mock old data + for i := 0; i < 10; i++ { + withdrawsAddr, _ := common.PrefixToCertik(sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes()).String()) + + withdraw := oracletypes.Withdraw{ + Address: withdrawsAddr, + Amount: nil, + DueBlock: rand.Int63(), + } + + bz := cdc.MustMarshalLengthPrefixed(&withdraw) + withdrawAcc, err := sdk.AccAddressFromBech32(withdrawsAddr) + if err != nil { + panic(err) + } + store.Set(oracletypes.WithdrawStoreKey(withdrawAcc, withdraw.DueBlock), bz) + } + + err := v280.MigrateWithdrawStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) + require.Nil(t, err) + + app.OracleKeeper.IterateAllWithdraws(ctx, func(withdraw oracletypes.Withdraw) bool { + hrp, _, err := bech32.DecodeAndConvert(withdraw.Address) + require.NoError(t, err) + require.Equal(t, hrp, "shentu") + return false + }) +} From ca4c07c0624c2932eb96ff95711acad67db449f4 Mon Sep 17 00:00:00 2001 From: kevin-yuhh Date: Wed, 2 Aug 2023 15:40:48 +0800 Subject: [PATCH 5/7] sort imports --- x/oracle/keeper/migrations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/oracle/keeper/migrations.go b/x/oracle/keeper/migrations.go index bdcc6ea91..595b7f128 100644 --- a/x/oracle/keeper/migrations.go +++ b/x/oracle/keeper/migrations.go @@ -2,9 +2,9 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - v280 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v280" v2 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v2" + v280 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v280" ) // Migrator is a struct for handling in-place store migrations. From f8cff4f12c4b9a6083e3ae34cf1b0b395db8ad46 Mon Sep 17 00:00:00 2001 From: kevin-yuhh Date: Thu, 3 Aug 2023 15:13:14 +0800 Subject: [PATCH 6/7] change v280 to v3 --- x/oracle/keeper/migrations.go | 4 ++-- x/oracle/legacy/{v280 => v3}/store.go | 2 +- x/oracle/legacy/{v280 => v3}/store_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename x/oracle/legacy/{v280 => v3}/store.go (99%) rename x/oracle/legacy/{v280 => v3}/store_test.go (98%) diff --git a/x/oracle/keeper/migrations.go b/x/oracle/keeper/migrations.go index 595b7f128..b1ce2720c 100644 --- a/x/oracle/keeper/migrations.go +++ b/x/oracle/keeper/migrations.go @@ -4,7 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" v2 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v2" - v280 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v280" + v3 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v3" ) // Migrator is a struct for handling in-place store migrations. @@ -25,5 +25,5 @@ func (m Migrator) Migrate1to2(ctx sdk.Context) error { // Migrate2to3 migrates from version 2 to 3. func (m Migrator) Migrate2to3(ctx sdk.Context) error { - return v280.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) + return v3.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc) } diff --git a/x/oracle/legacy/v280/store.go b/x/oracle/legacy/v3/store.go similarity index 99% rename from x/oracle/legacy/v280/store.go rename to x/oracle/legacy/v3/store.go index c01b986e4..cea07ea21 100644 --- a/x/oracle/legacy/v280/store.go +++ b/x/oracle/legacy/v3/store.go @@ -1,4 +1,4 @@ -package v280 +package v3 import ( "fmt" diff --git a/x/oracle/legacy/v280/store_test.go b/x/oracle/legacy/v3/store_test.go similarity index 98% rename from x/oracle/legacy/v280/store_test.go rename to x/oracle/legacy/v3/store_test.go index 42a1c411a..a472cb62b 100644 --- a/x/oracle/legacy/v280/store_test.go +++ b/x/oracle/legacy/v3/store_test.go @@ -1,4 +1,4 @@ -package v280_test +package v3_test import ( "encoding/hex" @@ -16,7 +16,7 @@ import ( shentuapp "github.com/shentufoundation/shentu/v2/app" "github.com/shentufoundation/shentu/v2/common" - v280 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v280" + v280 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v3" oracletypes "github.com/shentufoundation/shentu/v2/x/oracle/types" ) From 7bde959665031cef428ec88bfeed52e21050e3ae Mon Sep 17 00:00:00 2001 From: kevin-yuhh Date: Fri, 4 Aug 2023 00:01:00 +0800 Subject: [PATCH 7/7] add v3 --- x/oracle/legacy/v3/store_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/oracle/legacy/v3/store_test.go b/x/oracle/legacy/v3/store_test.go index a472cb62b..1bd851bfb 100644 --- a/x/oracle/legacy/v3/store_test.go +++ b/x/oracle/legacy/v3/store_test.go @@ -16,7 +16,7 @@ import ( shentuapp "github.com/shentufoundation/shentu/v2/app" "github.com/shentufoundation/shentu/v2/common" - v280 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v3" + v3 "github.com/shentufoundation/shentu/v2/x/oracle/legacy/v3" oracletypes "github.com/shentufoundation/shentu/v2/x/oracle/types" ) @@ -89,7 +89,7 @@ func Test_MigrateAllTaskStore(t *testing.T) { store.Set(oracletypes.TaskStoreKey(txTask.GetID()), bz) } - err := v280.MigrateAllTaskStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) + err := v3.MigrateAllTaskStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) require.Nil(t, err) app.OracleKeeper.IteratorAllTasks(ctx, func(task oracletypes.TaskI) bool { @@ -141,7 +141,7 @@ func Test_MigrateOperator(t *testing.T) { store.Set(oracletypes.OperatorStoreKey(addr), bz) } - err := v280.MigrateOperatorStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) + err := v3.MigrateOperatorStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) require.Nil(t, err) app.OracleKeeper.IterateAllOperators(ctx, func(operator oracletypes.Operator) bool { @@ -182,7 +182,7 @@ func Test_MigrateWithdraw(t *testing.T) { store.Set(oracletypes.WithdrawStoreKey(withdrawAcc, withdraw.DueBlock), bz) } - err := v280.MigrateWithdrawStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) + err := v3.MigrateWithdrawStore(ctx, app.GetKey(oracletypes.StoreKey), cdc) require.Nil(t, err) app.OracleKeeper.IterateAllWithdraws(ctx, func(withdraw oracletypes.Withdraw) bool {