diff --git a/app/test_helpers.go b/app/test_helpers.go index 888800ae4b..37a77e9d8d 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -9,6 +9,9 @@ import ( "testing" "time" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/crypto-org-chain/cronos/x/cronos" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" @@ -58,10 +61,27 @@ var DefaultConsensusParams = &abci.ConsensusParams{ }, } -func setup(withGenesis bool, invCheckPeriod uint) (*App, GenesisState) { +// ExperimentalAppOptions is a stub implementing AppOptions +type ExperimentalAppOptions struct{} + +// Get implements AppOptions +func (ao ExperimentalAppOptions) Get(o string) interface{} { + if o == cronos.ExperimentalFlag { + return true + } + return nil +} + +func setup(withGenesis bool, invCheckPeriod uint, experimental bool) (*App, GenesisState) { db := dbm.NewMemDB() encCdc := MakeEncodingConfig() - app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, EmptyAppOptions{}) + var appOption servertypes.AppOptions + if experimental { + appOption = ExperimentalAppOptions{} + } else { + appOption = EmptyAppOptions{} + } + app := New(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, invCheckPeriod, encCdc, appOption) if withGenesis { return app, NewDefaultGenesisState(encCdc.Marshaler) } @@ -69,8 +89,8 @@ func setup(withGenesis bool, invCheckPeriod uint) (*App, GenesisState) { } // Setup initializes a new App. A Nop logger is set in App. -func Setup(isCheckTx bool, cronosAdmin string) *App { - app, genesisState := setup(!isCheckTx, 5) +func Setup(isCheckTx bool, cronosAdmin string, experimental bool) *App { + app, genesisState := setup(!isCheckTx, 5, experimental) // set cronos_admin for test cronosGen := cronostypes.DefaultGenesis() @@ -105,7 +125,7 @@ func Setup(isCheckTx bool, cronosAdmin string) *App { // of one consensus engine unit (10^6) in the default token of the simapp from first genesis // account. A Nop logger is set in App. func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *App { - app, genesisState := setup(true, 5) + app, genesisState := setup(true, 5, true) // set genesis accounts authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis) @@ -185,7 +205,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs // SetupWithGenesisAccounts initializes a new App with the provided genesis // accounts and possible balances. func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *App { - app, genesisState := setup(true, 0) + app, genesisState := setup(true, 0, true) authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis) diff --git a/x/cronos/handler_test.go b/x/cronos/handler_test.go index 1251d6b874..5d26adf108 100644 --- a/x/cronos/handler_test.go +++ b/x/cronos/handler_test.go @@ -35,7 +35,7 @@ func (suite *CronosTestSuite) SetupTest() { privKey, err := ethsecp256k1.GenerateKey() suite.Require().NoError(err) suite.address = sdk.AccAddress(privKey.PubKey().Address()) - suite.app = app.Setup(false, suite.address.String()) + suite.app = app.Setup(false, suite.address.String(), true) suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{Height: 1, ChainID: app.TestAppChainID, Time: time.Now().UTC()}) suite.handler = cronos.NewHandler(suite.app.CronosKeeper) diff --git a/x/cronos/keeper/keeper_test.go b/x/cronos/keeper/keeper_test.go index a298708f46..960dc54fe3 100644 --- a/x/cronos/keeper/keeper_test.go +++ b/x/cronos/keeper/keeper_test.go @@ -54,7 +54,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { require.NoError(t, err) consAddress := sdk.ConsAddress(priv.PubKey().Address()) - suite.app = app.Setup(checkTx, sdk.AccAddress(suite.address.Bytes()).String()) + suite.app = app.Setup(checkTx, sdk.AccAddress(suite.address.Bytes()).String(), true) suite.ctx = suite.app.NewContext(checkTx, tmproto.Header{ Height: 1, ChainID: app.TestAppChainID,