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

Add custom message handler option #402

Merged
merged 2 commits into from
Feb 1, 2021
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.15.0...HEAD)

- Implement IBC contract support [\#394](https://github.com/CosmWasm/wasmd/pull/394)
- Support custom MessageHandler [\#327](https://github.com/CosmWasm/wasmd/issues/327)
- 🎉 Implement IBC contract support [\#394](https://github.com/CosmWasm/wasmd/pull/394)

## [v0.15.0](https://github.com/CosmWasm/wasmd/tree/v0.15.0) (2021-01-27)

Expand Down
9 changes: 9 additions & 0 deletions x/wasm/internal/keeper/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ func (f optsFn) apply(keeper *Keeper) {
f(keeper)
}

// WithMessageHandler is an optional constructor parameter to replace the default wasm vm engine with the
// given one.
func WithWasmEngine(x types.WasmerEngine) Option {
return optsFn(func(k *Keeper) {
k.wasmer = x
})
}

// WithMessageHandler is an optional constructor parameter to set a custom message handler.
func WithMessageHandler(n messenger) Option {
return optsFn(func(k *Keeper) {
k.messenger = n
})
}
57 changes: 57 additions & 0 deletions x/wasm/internal/keeper/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package keeper

import (
"github.com/CosmWasm/wasmd/x/wasm/internal/keeper/wasmtesting"
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/stretchr/testify/assert"
"testing"
)

func TestConstructorOptions(t *testing.T) {
specs := map[string]struct {
srcOpt Option
verify func(Keeper)
}{
"wasm engine": {
srcOpt: WithWasmEngine(&wasmtesting.MockWasmer{}),
verify: func(k Keeper) {
assert.IsType(t, k.wasmer, &wasmtesting.MockWasmer{})
},
},
"message handler": {
srcOpt: WithMessageHandler(&wasmtesting.MockMessageHandler{}),
verify: func(k Keeper) {
assert.IsType(t, k.messenger, &wasmtesting.MockMessageHandler{})
},
},
}
for name, spec := range specs {
t.Run(name, func(t *testing.T) {
k := NewKeeper(
nil,
nil,
paramtypes.NewSubspace(nil, nil, nil, nil, ""),
authkeeper.AccountKeeper{},
nil,
stakingkeeper.Keeper{},
distributionkeeper.Keeper{},
nil,
nil,
nil,
nil,
"tempDir",
types.DefaultWasmConfig(),
"",
nil,
nil,
spec.srcOpt,
)
spec.verify(k)
})
}

}