From e5df7cb8189853a352d2064fc9aae36b0969a141 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 19 Apr 2023 13:03:23 +0200 Subject: [PATCH] Add wasmvm decorator option --- x/wasm/keeper/options.go | 7 +++++++ x/wasm/keeper/options_test.go | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/x/wasm/keeper/options.go b/x/wasm/keeper/options.go index 223a771f63..4537c7969e 100644 --- a/x/wasm/keeper/options.go +++ b/x/wasm/keeper/options.go @@ -24,6 +24,13 @@ func WithWasmEngine(x types.WasmerEngine) Option { }) } +// WithWasmEngineDecorator is an optional constructor parameter to decorate the default wasmVM engine. +func WithWasmEngineDecorator(d func(old types.WasmerEngine) types.WasmerEngine) Option { + return optsFn(func(k *Keeper) { + k.wasmVM = d(k.wasmVM) + }) +} + // WithMessageHandler is an optional constructor parameter to set a custom handler for wasmVM messages. // This option should not be combined with Option `WithMessageEncoders` or `WithMessageHandlerDecorator` func WithMessageHandler(x Messenger) Option { diff --git a/x/wasm/keeper/options_test.go b/x/wasm/keeper/options_test.go index d64e4a3f35..29557c3cd2 100644 --- a/x/wasm/keeper/options_test.go +++ b/x/wasm/keeper/options_test.go @@ -4,6 +4,8 @@ import ( "reflect" "testing" + wasmvm "github.com/CosmWasm/wasmvm" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -27,6 +29,15 @@ func TestConstructorOptions(t *testing.T) { assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM) }, }, + "decorate wasmvm": { + srcOpt: WithWasmEngineDecorator(func(old types.WasmerEngine) types.WasmerEngine { + require.IsType(t, &wasmvm.VM{}, old) + return &wasmtesting.MockWasmer{} + }), + verify: func(t *testing.T, k Keeper) { + assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM) + }, + }, "message handler": { srcOpt: WithMessageHandler(&wasmtesting.MockMessageHandler{}), verify: func(t *testing.T, k Keeper) {