Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Mar 18, 2022
1 parent d7fab63 commit d757314
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 7 additions & 3 deletions x/feemarket/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
// the base fee key prefix used in version 1
KeyPrefixBaseFeeV1 = []byte{2}
)

// Migrator is a struct for handling in-place store migrations.
type Migrator struct {
keeper Keeper
Expand All @@ -20,12 +25,11 @@ func NewMigrator(keeper Keeper) Migrator {

func (m Migrator) Migrate1to2(ctx sdk.Context) error {
store := ctx.KVStore(m.keeper.storeKey)
baseFeeKeyPrefix := []byte{2}
bz := store.Get(baseFeeKeyPrefix)
bz := store.Get(KeyPrefixBaseFeeV1)
if len(bz) > 0 {
baseFee := new(big.Int).SetBytes(bz)
m.keeper.SetBaseFee(ctx, baseFee)
}
store.Delete(baseFeeKeyPrefix)
store.Delete(KeyPrefixBaseFeeV1)
return nil
}
18 changes: 18 additions & 0 deletions x/feemarket/keeper/migrations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package keeper_test

import (
"math/big"

"github.com/tharsis/ethermint/x/feemarket/keeper"
)

func (suite *KeeperTestSuite) TestMigration1To2() {
suite.SetupTest()
storeKey := suite.app.GetKey("feemarket")
store := suite.ctx.KVStore(storeKey)
baseFee := big.NewInt(1000)
store.Set(keeper.KeyPrefixBaseFeeV1, baseFee.Bytes())
m := keeper.NewMigrator(suite.app.FeeMarketKeeper)
suite.Require().NoError(m.Migrate1to2(suite.ctx))
suite.Require().Equal(baseFee, suite.app.FeeMarketKeeper.GetBaseFee(suite.ctx))
}

0 comments on commit d757314

Please sign in to comment.