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

[Feature] Append Custom Wasm Interface #347

Merged
merged 1 commit into from
Jun 15, 2020
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
13 changes: 9 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions app/app_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -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())

Expand Down
113 changes: 62 additions & 51 deletions x/wasm/alias.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand All @@ -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
Expand All @@ -112,6 +125,4 @@ type (
WasmQuerierInterface = types.WasmQuerierInterface
Querier = types.Querier
WasmCustomQuery = types.WasmCustomQuery
Keeper = keeper.Keeper
InitMsg = keeper.InitMsg
)
4 changes: 2 additions & 2 deletions x/wasm/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions x/wasm/internal/types/msg_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions x/wasm/internal/types/query_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
3 changes: 2 additions & 1 deletion x/wasm/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down