From 7371a54386365a4c648c8aafd3520a674879c3bf Mon Sep 17 00:00:00 2001 From: yys Date: Mon, 15 Jun 2020 12:51:46 +0900 Subject: [PATCH] fix alias & add market/treasury wasm interface --- app/app.go | 13 ++- app/app_test.go | 15 +++- x/wasm/alias.go | 113 ++++++++++++++----------- x/wasm/internal/keeper/keeper.go | 4 +- x/wasm/internal/types/msg_binding.go | 4 +- x/wasm/internal/types/query_binding.go | 4 +- x/wasm/test_utils.go | 3 +- 7 files changed, 91 insertions(+), 65 deletions(-) diff --git a/app/app.go b/app/app.go index 4e70d972b..be09e2298 100644 --- a/app/app.go +++ b/app/app.go @@ -43,7 +43,9 @@ import ( wasmconfig "github.com/terra-project/core/x/wasm/config" bankwasm "github.com/terra-project/core/x/bank/wasm" + marketwasm "github.com/terra-project/core/x/market/wasm" stakingwasm "github.com/terra-project/core/x/staking/wasm" + treasurywasm "github.com/terra-project/core/x/treasury/wasm" ) const appName = "TerraApp" @@ -227,16 +229,19 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest // create wasm keeper with msg parser & querier app.wasmKeeper = wasm.NewKeeper(app.cdc, keys[wasm.StoreKey], app.subspaces[wasm.ModuleName], - app.accountKeeper, app.bankKeeper, app.supplyKeeper, app.treasuryKeeper, bApp.Router(), wasm.FeatureStaking, wasmConfig) + app.accountKeeper, app.bankKeeper, app.supplyKeeper, app.treasuryKeeper, bApp.Router(), wasm.DefaultFeatures, wasmConfig) app.wasmKeeper.RegisterMsgParsers(map[string]wasm.WasmMsgParserInterface{ wasm.WasmMsgParserRouteBank: bankwasm.NewWasmMsgParser(), wasm.WasmMsgParserRouteStaking: stakingwasm.NewWasmMsgParser(), + wasm.WasmMsgParserRouteMarket: marketwasm.NewWasmMsgParser(), wasm.WasmMsgParserRouteWasm: wasm.NewWasmMsgParser(), }) app.wasmKeeper.RegisterQueriers(map[string]wasm.WasmQuerierInterface{ - wasm.WasmQueryRouteBank: bankwasm.NewWasmQuerier(app.bankKeeper), - wasm.WasmQueryRouteStaking: stakingwasm.NewWasmQuerier(app.stakingKeeper), - wasm.WasmQueryRouteWasm: wasm.NewWasmQuerier(app.wasmKeeper), + wasm.WasmQueryRouteBank: bankwasm.NewWasmQuerier(app.bankKeeper), + wasm.WasmQueryRouteStaking: stakingwasm.NewWasmQuerier(app.stakingKeeper), + wasm.WasmQueryRouteMarket: marketwasm.NewWasmQuerier(app.marketKeeper), + wasm.WasmQueryRouteTreasury: treasurywasm.NewWasmQuerier(app.treasuryKeeper), + wasm.WasmQueryRouteWasm: wasm.NewWasmQuerier(app.wasmKeeper), }) // register the proposal types diff --git a/app/app_test.go b/app/app_test.go index ca98ed606..e2942cad3 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -1,25 +1,31 @@ package app import ( + "io/ioutil" "os" "testing" + "github.com/spf13/viper" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" wasmconfig "github.com/terra-project/core/x/wasm/config" ) func TestTerraExport(t *testing.T) { - db := dbm.NewMemDB() + tempDir, err := ioutil.TempDir("", "wasmtest") + require.NoError(t, err) + viper.Set(flags.FlagHome, tempDir) + db := dbm.NewMemDB() tapp := NewTerraApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, map[int64]bool{}, wasmconfig.DefaultConfig()) - err := setGenesis(tapp) + err = setGenesis(tapp) require.NoError(t, err) // Making a new app object with the db, so that initchain hasn't been called @@ -32,7 +38,6 @@ func TestTerraExport(t *testing.T) { } func setGenesis(tapp *TerraApp) error { - genesisState := ModuleBasics.DefaultGenesis() stateBytes, err := codec.MarshalJSONIndent(tapp.Codec(), genesisState) if err != nil { @@ -52,6 +57,10 @@ func setGenesis(tapp *TerraApp) error { // ensure that black listed addresses are properly set in bank keeper func TestBlackListedAddrs(t *testing.T) { + tempDir, err := ioutil.TempDir("", "wasmtest") + require.NoError(t, err) + viper.Set(flags.FlagHome, tempDir) + db := dbm.NewMemDB() app := NewTerraApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0, map[int64]bool{}, wasmconfig.DefaultConfig()) diff --git a/x/wasm/alias.go b/x/wasm/alias.go index 4d47280f1..b97085530 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -1,8 +1,8 @@ // nolint // autogenerated code using github.com/rigelrozanski/multitool // aliases generated for the following subdirectories: -// ALIASGEN: github.com/terra-project/core/x/wasm/internal/types/ -// ALIASGEN: github.com/terra-project/core/x/wasm/internal/keeper/ +// ALIASGEN: core/x/wasm/internal/keeper +// ALIASGEN: core/x/wasm/internal/types package wasm import ( @@ -11,34 +11,48 @@ import ( ) const ( - ModuleName = types.ModuleName - StoreKey = types.StoreKey - TStoreKey = types.TStoreKey - QuerierRoute = types.QuerierRoute - RouterKey = types.RouterKey - WasmMsgParserRouteBank = types.WasmMsgParserRouteBank - WasmMsgParserRouteStaking = types.WasmMsgParserRouteStaking - WasmMsgParserRouteWasm = types.WasmMsgParserRouteWasm - DefaultParamspace = types.DefaultParamspace - QueryGetByteCode = types.QueryGetByteCode - QueryGetCodeInfo = types.QueryGetCodeInfo - QueryGetContractInfo = types.QueryGetContractInfo - QueryRawStore = types.QueryRawStore - QueryContractStore = types.QueryContractStore - WasmQueryRouteBank = types.WasmQueryRouteBank - WasmQueryRouteStaking = types.WasmQueryRouteStaking - WasmQueryRouteWasm = types.WasmQueryRouteWasm + DefaultFeatures = types.DefaultFeatures + ModuleName = types.ModuleName + StoreKey = types.StoreKey + TStoreKey = types.TStoreKey + QuerierRoute = types.QuerierRoute + RouterKey = types.RouterKey + WasmMsgParserRouteBank = types.WasmMsgParserRouteBank + WasmMsgParserRouteStaking = types.WasmMsgParserRouteStaking + WasmMsgParserRouteMarket = types.WasmMsgParserRouteMarket + WasmMsgParserRouteWasm = types.WasmMsgParserRouteWasm + DefaultParamspace = types.DefaultParamspace + EnforcedMaxContractSize = types.EnforcedMaxContractSize + EnforcedMaxContractGas = types.EnforcedMaxContractGas + EnforcedMaxContractMsgSize = types.EnforcedMaxContractMsgSize + DefaultMaxContractSize = types.DefaultMaxContractSize + DefaultMaxContractGas = types.DefaultMaxContractGas + DefaultMaxContractMsgSize = types.DefaultMaxContractMsgSize + DefaultGasMultiplier = types.DefaultGasMultiplier + QueryGetByteCode = types.QueryGetByteCode + QueryGetCodeInfo = types.QueryGetCodeInfo + QueryGetContractInfo = types.QueryGetContractInfo + QueryRawStore = types.QueryRawStore + QueryContractStore = types.QueryContractStore + WasmQueryRouteBank = types.WasmQueryRouteBank + WasmQueryRouteStaking = types.WasmQueryRouteStaking + WasmQueryRouteMarket = types.WasmQueryRouteMarket + WasmQueryRouteTreasury = types.WasmQueryRouteTreasury + WasmQueryRouteWasm = types.WasmQueryRouteWasm ) var ( // functions aliases + NewKeeper = keeper.NewKeeper + NewQuerier = keeper.NewQuerier + NewWasmMsgParser = keeper.NewWasmMsgParser + NewWasmQuerier = keeper.NewWasmQuerier RegisterCodec = types.RegisterCodec - EncodeSdkCoin = types.EncodeSdkCoin - EncodeSdkCoins = types.EncodeSdkCoins - FeatureStaking = types.DefaultFeatures ParseResult = types.ParseResult ParseToCoin = types.ParseToCoin ParseToCoins = types.ParseToCoins + EncodeSdkCoin = types.EncodeSdkCoin + EncodeSdkCoins = types.EncodeSdkCoins NewCodeInfo = types.NewCodeInfo NewContractInfo = types.NewContractInfo NewWasmAPIParams = types.NewWasmAPIParams @@ -52,49 +66,48 @@ var ( NewMsgStoreCode = types.NewMsgStoreCode NewMsgInstantiateContract = types.NewMsgInstantiateContract NewMsgExecuteContract = types.NewMsgExecuteContract + NewModuleMsgParser = types.NewModuleMsgParser DefaultParams = types.DefaultParams ParamKeyTable = types.ParamKeyTable NewQueryCodeIDParams = types.NewQueryCodeIDParams NewQueryContractAddressParams = types.NewQueryContractAddressParams NewQueryRawStoreParams = types.NewQueryRawStoreParams NewQueryContractParams = types.NewQueryContractParams - NewWasmMsgParser = keeper.NewWasmMsgParser - NewWasmQuerier = keeper.NewWasmQuerier - NewKeeper = keeper.NewKeeper - NewQuerier = keeper.NewQuerier - CreateTestInput = keeper.CreateTestInput + NewModuleQuerier = types.NewModuleQuerier // variable aliases - ModuleCdc = types.ModuleCdc - ErrStoreCodeFailed = types.ErrStoreCodeFailed - ErrAccountExists = types.ErrAccountExists - ErrInstantiateFailed = types.ErrInstantiateFailed - ErrExecuteFailed = types.ErrExecuteFailed - ErrGasLimit = types.ErrGasLimit - ErrInvalidGenesis = types.ErrInvalidGenesis - ErrNotFound = types.ErrNotFound - ErrInvalidMsg = types.ErrInvalidMsg - ErrNoRegisteredQuerier = types.ErrNoRegisteredQuerier - ErrNoRegisteredParser = types.ErrNoRegisteredParser - LastCodeIDKey = types.LastCodeIDKey - LastInstanceIDKey = types.LastInstanceIDKey - CodeKey = types.CodeKey - ContractInfoKey = types.ContractInfoKey - ContractStoreKey = types.ContractStoreKey - ParamStoreKeyMaxContractSize = types.ParamStoreKeyMaxContractSize - ParamStoreKeyMaxContractGas = types.ParamStoreKeyMaxContractGas - ParamStoreKeyGasMultiplier = types.ParamStoreKeyGasMultiplier - DefaultMaxContractSize = types.DefaultMaxContractSize - DefaultMaxContractGas = types.DefaultMaxContractGas - DefaultGasMultiplier = types.DefaultGasMultiplier + ModuleCdc = types.ModuleCdc + ErrStoreCodeFailed = types.ErrStoreCodeFailed + ErrAccountExists = types.ErrAccountExists + ErrInstantiateFailed = types.ErrInstantiateFailed + ErrExecuteFailed = types.ErrExecuteFailed + ErrGasLimit = types.ErrGasLimit + ErrInvalidGenesis = types.ErrInvalidGenesis + ErrNotFound = types.ErrNotFound + ErrInvalidMsg = types.ErrInvalidMsg + ErrNoRegisteredQuerier = types.ErrNoRegisteredQuerier + ErrNoRegisteredParser = types.ErrNoRegisteredParser + LastCodeIDKey = types.LastCodeIDKey + LastInstanceIDKey = types.LastInstanceIDKey + CodeKey = types.CodeKey + ContractInfoKey = types.ContractInfoKey + ContractStoreKey = types.ContractStoreKey + ParamStoreKeyMaxContractSize = types.ParamStoreKeyMaxContractSize + ParamStoreKeyMaxContractGas = types.ParamStoreKeyMaxContractGas + ParamStoreKeyMaxContractMsgSize = types.ParamStoreKeyMaxContractMsgSize + ParamStoreKeyGasMultiplier = types.ParamStoreKeyGasMultiplier ) type ( + Keeper = keeper.Keeper + WasmMsgParser = keeper.WasmMsgParser + WasmQuerier = keeper.WasmQuerier Model = types.Model CodeInfo = types.CodeInfo ContractInfo = types.ContractInfo AccountKeeper = types.AccountKeeper BankKeeper = types.BankKeeper + TreasuryKeeper = types.TreasuryKeeper GenesisState = types.GenesisState Code = types.Code Contract = types.Contract @@ -112,6 +125,4 @@ type ( WasmQuerierInterface = types.WasmQuerierInterface Querier = types.Querier WasmCustomQuery = types.WasmCustomQuery - Keeper = keeper.Keeper - InitMsg = keeper.InitMsg ) diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index 16907402d..c4beaac83 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -72,8 +72,8 @@ func NewKeeper(cdc *codec.Codec, storeKey sdk.StoreKey, router: router, queryGasLimit: wasmConfig.ContractQueryGasLimit, cacheSize: wasmConfig.CacheSize, - msgParser: types.NewMsgParser(), - querier: types.NewQuerier(), + msgParser: types.NewModuleMsgParser(), + querier: types.NewModuleQuerier(), } } diff --git a/x/wasm/internal/types/msg_binding.go b/x/wasm/internal/types/msg_binding.go index c0b71a108..8ce89d6a9 100644 --- a/x/wasm/internal/types/msg_binding.go +++ b/x/wasm/internal/types/msg_binding.go @@ -32,8 +32,8 @@ type WasmCustomMsg struct { // MsgParser - holds multiple module msg parsers type MsgParser map[string]WasmMsgParserInterface -// NewMsgParser returns wasm msg parser -func NewMsgParser() MsgParser { +// NewModuleMsgParser returns wasm msg parser +func NewModuleMsgParser() MsgParser { return make(MsgParser) } diff --git a/x/wasm/internal/types/query_binding.go b/x/wasm/internal/types/query_binding.go index 636505ee1..a3dc3efb8 100644 --- a/x/wasm/internal/types/query_binding.go +++ b/x/wasm/internal/types/query_binding.go @@ -21,8 +21,8 @@ type Querier struct { Queriers map[string]WasmQuerierInterface } -// NewQuerier return wasm querier -func NewQuerier() Querier { +// NewModuleQuerier return wasm querier +func NewModuleQuerier() Querier { return Querier{ Queriers: make(map[string]WasmQuerierInterface), } diff --git a/x/wasm/test_utils.go b/x/wasm/test_utils.go index 157179ef4..1a18b8d7a 100644 --- a/x/wasm/test_utils.go +++ b/x/wasm/test_utils.go @@ -20,6 +20,7 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/terra-project/core/x/auth" + "github.com/terra-project/core/x/wasm/internal/keeper" ) var ( @@ -49,7 +50,7 @@ func setupTest(t *testing.T) (testData, func()) { require.NoError(t, err) viper.Set(flags.FlagHome, tempDir) - input := CreateTestInput(t) + input := keeper.CreateTestInput(t) data := testData{ module: NewAppModule(input.WasmKeeper, input.AccKeeper), ctx: input.Ctx,