Skip to content

Commit

Permalink
pass proto codec for wasm simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed May 17, 2021
1 parent 7f3d484 commit a73a08a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func NewTerraApp(
market.NewAppModule(appCodec, app.MarketKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
wasm.NewAppModule(appCodec, app.WasmKeeper, app.AccountKeeper, app.BankKeeper),
wasm.NewAppModule(appCodec, app.WasmKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand Down Expand Up @@ -535,7 +535,7 @@ func NewTerraApp(
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
market.NewAppModule(appCodec, app.MarketKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper),
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
wasm.NewAppModule(appCodec, app.WasmKeeper, app.AccountKeeper, app.BankKeeper),
wasm.NewAppModule(appCodec, app.WasmKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
)

app.sm.RegisterStoreDecoders()
Expand Down
3 changes: 3 additions & 0 deletions x/wasm/keeper/connector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keeper

import (
"fmt"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
"github.com/terra-project/core/custom/auth/ante"
"github.com/terra-project/core/x/wasm/types"
Expand Down Expand Up @@ -148,6 +150,7 @@ func (k Keeper) dispatchMessage(ctx sdk.Context, contractAddr sdk.AccAddress, ms
}
}

fmt.Println("SIBONG", msg, sdkMsg)
res, err := k.handleSdkMessage(ctx, contractAddr, sdkMsg)
if err != nil {
return nil, nil, err
Expand Down
8 changes: 6 additions & 2 deletions x/wasm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,22 @@ type AppModule struct {
keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
registry codectypes.InterfaceRegistry
}

// NewAppModule creates a new AppModule object
func NewAppModule(
cdc codec.Codec,
keeper keeper.Keeper,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper) AppModule {
bankKeeper types.BankKeeper,
registry codectypes.InterfaceRegistry) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{cdc},
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
registry: registry,
}
}

Expand Down Expand Up @@ -194,8 +197,9 @@ func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {

// WeightedOperations returns the all the wasm module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
protoCdc := codec.NewProtoCodec(am.registry)
return simulation.WeightedOperations(
simState.AppParams, simState.Cdc,
am.accountKeeper, am.bankKeeper, am.keeper,
am.accountKeeper, am.bankKeeper, am.keeper, protoCdc,
)
}
28 changes: 19 additions & 9 deletions x/wasm/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func WeightedOperations(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
protoCdc *codec.ProtoCodec,
) simulation.WeightedOperations {
var weightMsgStoreCode int
var weightMsgInstantiateContract int
Expand Down Expand Up @@ -90,15 +91,15 @@ func WeightedOperations(
),
simulation.NewWeightedOperation(
weightMsgInstantiateContract,
SimulateMsgInstantiateContract(ak, bk, k),
SimulateMsgInstantiateContract(ak, bk, k, protoCdc),
),
simulation.NewWeightedOperation(
weightMsgExecuteContract,
SimulateMsgExecuteContract(ak, bk, k),
SimulateMsgExecuteContract(ak, bk, k, protoCdc),
),
simulation.NewWeightedOperation(
weightMsgMigrateContract,
SimulateMsgMigrateContract(ak, bk, k),
SimulateMsgMigrateContract(ak, bk, k, protoCdc),
),
simulation.NewWeightedOperation(
weightMsgUpdateContractAdmin,
Expand Down Expand Up @@ -185,7 +186,11 @@ func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
}

// nolint: funlen
func SimulateMsgInstantiateContract(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
func SimulateMsgInstantiateContract(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
protoCdc *codec.ProtoCodec) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
Expand Down Expand Up @@ -236,12 +241,16 @@ func SimulateMsgInstantiateContract(ak types.AccountKeeper, bk types.BankKeeper,
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
}

return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil
return simtypes.NewOperationMsg(msg, true, "", protoCdc), nil, nil
}
}

// nolint: funlen
func SimulateMsgExecuteContract(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
func SimulateMsgExecuteContract(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper,
protoCdc *codec.ProtoCodec) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
Expand Down Expand Up @@ -295,15 +304,16 @@ func SimulateMsgExecuteContract(ak types.AccountKeeper, bk types.BankKeeper, k k
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
}

return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil
return simtypes.NewOperationMsg(msg, true, "", protoCdc), nil, nil
}
}

// nolint: funlen
func SimulateMsgMigrateContract(
ak types.AccountKeeper,
bk types.BankKeeper,
k keeper.Keeper) simtypes.Operation {
k keeper.Keeper,
protoCdc *codec.ProtoCodec) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
Expand Down Expand Up @@ -365,7 +375,7 @@ func SimulateMsgMigrateContract(
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
}

return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil
return simtypes.NewOperationMsg(msg, true, "", protoCdc), nil, nil
}
}

Expand Down

0 comments on commit a73a08a

Please sign in to comment.