Skip to content

Commit

Permalink
Add custom message handler option (#402)
Browse files Browse the repository at this point in the history
* Add custom message handler option

* Update changelog
  • Loading branch information
alpe authored Feb 1, 2021
1 parent 0f46dee commit 4141cc3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
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)
})
}

}

0 comments on commit 4141cc3

Please sign in to comment.