Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Modify 'Update' module's keeper due to the iparam refactor #301

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace))
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Getter(), app.RegisterCodespace(slashing.DefaultCodespace))
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection)
app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper, app.iparamsKeeper.GovSetter())
app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper)
app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.iparamsKeeper.GovSetter(), app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace))

// register message routes
Expand Down
19 changes: 13 additions & 6 deletions modules/upgrade/keep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package upgrade

import (
"fmt"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/irisnet/irishub/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"strings"
"testing"
"github.com/irisnet/irishub/modules/upgrade/params"
)

func TestUpdateKeeper(t *testing.T) {
ctx, keeper := createTestInput(t)
ctx, keeper, _ := createTestInput(t)
router := baseapp.NewRouter()
router.AddRoute("main", []*sdk.KVStoreKey{sdk.NewKVStoreKey("main")}, nil)
router.AddRoute("acc", []*sdk.KVStoreKey{sdk.NewKVStoreKey("acc")}, nil)
Expand Down Expand Up @@ -124,7 +125,7 @@ func TestSwitchKeeper(t *testing.T) {
}

func TestSetKVStoreKeylist(t *testing.T) {
ctx, keeper := createTestInput(t)
ctx, keeper, paramKeeper := createTestInput(t)

router := baseapp.NewRouter()
router.AddRoute("main-0", []*sdk.KVStoreKey{sdk.NewKVStoreKey("main")}, nil)
Expand All @@ -133,6 +134,10 @@ func TestSetKVStoreKeylist(t *testing.T) {
router.AddRoute("stake-0", []*sdk.KVStoreKey{sdk.NewKVStoreKey("stake")}, nil)
router.AddRoute("upgrade-0", []*sdk.KVStoreKey{sdk.NewKVStoreKey("upgrade")}, nil)


upgradeparams.ProposalAcceptHeightParameter.SetReadWriter(paramKeeper.Setter())
upgradeparams.CurrentUpgradeProposalIdParameter.SetReadWriter(paramKeeper.Setter())

InitGenesis(ctx, keeper, router)
keeper.SetKVStoreKeylist(ctx)
}
Expand All @@ -153,7 +158,7 @@ func getModuleList(router baseapp.Router) ModuleLifeTimeList {
}

func TestKeeper_InitGenesis_commidID(t *testing.T) {
ctx, keeper := createTestInput(t)
ctx, keeper, paramKeeper := createTestInput(t)
router := baseapp.NewRouter()
router.AddRoute("main", []*sdk.KVStoreKey{sdk.NewKVStoreKey("main")}, nil)
router.AddRoute("acc", []*sdk.KVStoreKey{sdk.NewKVStoreKey("acc")}, nil)
Expand All @@ -169,6 +174,8 @@ func TestKeeper_InitGenesis_commidID(t *testing.T) {
InitGenesis_commitID(ctx, keeper)
fmt.Println(keeper.GetKVStoreKeylist(ctx))

keeper.SetCurrentProposalAcceptHeight(ctx, 1234234000)
fmt.Println(keeper.GetCurrentProposalAcceptHeight(ctx))
upgradeparams.ProposalAcceptHeightParameter.SetReadWriter(paramKeeper.Setter())

upgradeparams.SetProposalAcceptHeight(ctx, 1234234000)
fmt.Println(upgradeparams.GetProposalAcceptHeight(ctx))
}
5 changes: 1 addition & 4 deletions modules/upgrade/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/irisnet/irishub/modules/iparams"
"math"
)

Expand All @@ -18,15 +17,13 @@ type Keeper struct {
cdc *wire.Codec
// The ValidatorSet to get information about validators
sk stake.Keeper
params iparams.GovSetter
}

func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, sk stake.Keeper, ps iparams.GovSetter) Keeper {
func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, sk stake.Keeper) Keeper {
keeper := Keeper{
storeKey: key,
cdc: cdc,
sk: sk,
params: ps,
}
return keeper
}
Expand Down
16 changes: 10 additions & 6 deletions modules/upgrade/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"encoding/hex"
"github.com/irisnet/irishub/modules/iparams"
"github.com/cosmos/cosmos-sdk/x/params"
)

var (
Expand Down Expand Up @@ -54,18 +54,20 @@ func createTestCodec() *wire.Codec {
return cdc
}

func createTestInput(t *testing.T) (sdk.Context, Keeper) {
func createTestInput(t *testing.T) (sdk.Context, Keeper, params.Keeper) {
keyAcc := sdk.NewKVStoreKey("acc")
keyStake := sdk.NewKVStoreKey("stake")
keyUpdate := sdk.NewKVStoreKey("update")
keyParams := sdk.NewKVStoreKey("params")
keyIparams := sdk.NewKVStoreKey("iparams")

db := dbm.NewMemDB()
ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(keyAcc, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyStake, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyUpdate, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams,sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyIparams, sdk.StoreTypeIAVL, db)

err := ms.LoadLatestVersion()
require.Nil(t, err)
Expand All @@ -74,7 +76,9 @@ func createTestInput(t *testing.T) (sdk.Context, Keeper) {
accountMapper := auth.NewAccountMapper(cdc, keyAcc, auth.ProtoBaseAccount)
ck := bank.NewKeeper(accountMapper)
sk := stake.NewKeeper(cdc, keyStake, ck, stake.DefaultCodespace)
pk := iparams.NewKeeper(cdc,keyParams)
keeper := NewKeeper(cdc, keyUpdate, sk,pk.GovSetter())
return ctx, keeper

keeper := NewKeeper(cdc, keyUpdate, sk)
paramKeeper := params.NewKeeper(wire.NewCodec(), keyParams)

return ctx, keeper, paramKeeper
}