Skip to content

Commit

Permalink
R4R: Merge from v1.0.0 (#2125)
Browse files Browse the repository at this point in the history
* refactor guardian module

* apply comment from github

* Revert: refactor guardian module (6c463ef)

* delete useless file

* use simapp

* optimize the code

* apply comment from github

* replace testing with suite

* add test

* add cli test

* repair error when merge from v1.0.0-refactor
  • Loading branch information
Zhiqiang Zhang authored and chengwenxi committed Dec 10, 2019
1 parent 944d5e8 commit 607747f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
keys := sdk.NewKVStoreKeys(
bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey,
mint.StoreKey, distr.StoreKey, slashing.StoreKey, gov.StoreKey,
params.StoreKey, evidence.StoreKey,
params.StoreKey, evidence.StoreKey, guardian.StoreKey,
)
tKeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)

Expand Down Expand Up @@ -177,7 +177,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b

// create guardian keeper with guardian router
app.guardianKeeper = guardian.NewKeeper(
app.cdc, keys[evidence.StoreKey], guardian.DefaultCodespace,
app.cdc, keys[guardian.StoreKey], guardian.DefaultCodespace,
)

// register the proposal types
Expand Down
16 changes: 8 additions & 8 deletions modules/guardian/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (suite *KeeperTestSuite) TestAddProfiler() {
suite.cdc.MustUnmarshalBinaryLengthPrefixed(profilersIterator.Value(), &profiler)
profilers = append(profilers, profiler)
}
require.Equal(suite.T(), 1, len(profilers))
require.True(suite.T(), profiler.Equal(profilers[0]))
require.Equal(suite.T(), 2, len(profilers))
require.Contains(suite.T(), profilers, profiler)
}

func (suite *KeeperTestSuite) TestDeleteProfiler() {
Expand Down Expand Up @@ -97,8 +97,8 @@ func (suite *KeeperTestSuite) TestAddTrustee() {
suite.cdc.MustUnmarshalBinaryLengthPrefixed(trusteesIterator.Value(), &trustee)
trustees = append(trustees, trustee)
}
require.Equal(suite.T(), 1, len(trustees))
require.True(suite.T(), trustee.Equal(trustees[0]))
require.Equal(suite.T(), 2, len(trustees))
require.Contains(suite.T(), trustees, trustee)
}

func (suite *KeeperTestSuite) TestDeleteTrustee() {
Expand All @@ -125,8 +125,8 @@ func (suite *KeeperTestSuite) TestQueryProfilers() {

err := suite.cdc.UnmarshalJSON(res, &profilers)
require.NoError(suite.T(), err)
require.Len(suite.T(), profilers, 1)
require.Equal(suite.T(), profiler, profilers[0])
require.Len(suite.T(), profilers, 2)
require.Contains(suite.T(), profilers, profiler)
}

func (suite *KeeperTestSuite) TestQueryTrustees() {
Expand All @@ -140,8 +140,8 @@ func (suite *KeeperTestSuite) TestQueryTrustees() {

err := suite.cdc.UnmarshalJSON(res, &trustees)
require.NoError(suite.T(), err)
require.Len(suite.T(), trustees, 1)
require.Equal(suite.T(), trustee, trustees[0])
require.Len(suite.T(), trustees, 2)
require.Contains(suite.T(), trustees, trustee)
}

func newPubKey(pk string) (res crypto.PubKey) {
Expand Down
10 changes: 6 additions & 4 deletions simapp/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package simapp

import (
"github.com/irisnet/irishub/modules/guardian"
"io"
"os"

Expand All @@ -24,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/irisnet/irishub/modules/guardian"
"github.com/irisnet/irishub/modules/mint"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
Expand Down Expand Up @@ -56,6 +56,7 @@ var (
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
evidence.AppModuleBasic{},
guardian.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -131,7 +132,7 @@ func NewSimApp(
keys := sdk.NewKVStoreKeys(
bam.MainStoreKey, auth.StoreKey, staking.StoreKey, supply.StoreKey, mint.StoreKey,
distr.StoreKey, slashing.StoreKey, gov.StoreKey, params.StoreKey,
evidence.StoreKey,
evidence.StoreKey, guardian.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)

Expand Down Expand Up @@ -188,7 +189,7 @@ func NewSimApp(
)

app.GuardianKeeper = guardian.NewKeeper(
app.cdc, keys[evidence.StoreKey], guardian.DefaultCodespace,
app.cdc, keys[guardian.StoreKey], guardian.DefaultCodespace,
)

evidenceRouter := evidence.NewRouter()
Expand Down Expand Up @@ -226,6 +227,7 @@ func NewSimApp(
slashing.NewAppModule(app.SlashingKeeper, app.StakingKeeper),
staking.NewAppModule(app.StakingKeeper, app.AccountKeeper, app.SupplyKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
guardian.NewAppModule(app.GuardianKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -239,7 +241,7 @@ func NewSimApp(
app.mm.SetOrderInitGenesis(
auth.ModuleName, distr.ModuleName, staking.ModuleName, bank.ModuleName,
slashing.ModuleName, gov.ModuleName, mint.ModuleName, supply.ModuleName,
crisis.ModuleName, genutil.ModuleName, evidence.ModuleName,
crisis.ModuleName, genutil.ModuleName, evidence.ModuleName, guardian.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down

0 comments on commit 607747f

Please sign in to comment.