Files
wasmd/x/wasm/keeper/options_test.go
Alexander Peters c05df881fb Charge gas for custom event attributes and messages (#539)
* Charge gas for custom event attributes

* Introduce gas register for gas costs

* Review feedback

* Tests and minor updates

* Godoc
2021-06-25 10:00:46 +02:00

71 lines
2.3 KiB
Go

package keeper
import (
"github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
"github.com/CosmWasm/wasmd/x/wasm/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(*testing.T, Keeper)
}{
"wasm engine": {
srcOpt: WithWasmEngine(&wasmtesting.MockWasmer{}),
verify: func(t *testing.T, k Keeper) {
assert.IsType(t, k.wasmVM, &wasmtesting.MockWasmer{})
},
},
"message handler": {
srcOpt: WithMessageHandler(&wasmtesting.MockMessageHandler{}),
verify: func(t *testing.T, k Keeper) {
assert.IsType(t, k.messenger, &wasmtesting.MockMessageHandler{})
},
},
"query plugins": {
srcOpt: WithQueryHandler(&wasmtesting.MockQueryHandler{}),
verify: func(t *testing.T, k Keeper) {
assert.IsType(t, k.wasmVMQueryHandler, &wasmtesting.MockQueryHandler{})
},
},
"coin transferrer": {
srcOpt: WithCoinTransferrer(&wasmtesting.MockCoinTransferrer{}),
verify: func(t *testing.T, k Keeper) {
assert.IsType(t, k.bank, &wasmtesting.MockCoinTransferrer{})
},
},
"costs": {
srcOpt: WithGasRegister(&wasmtesting.MockGasRegister{}),
verify: func(t *testing.T, k Keeper) {
assert.IsType(t, k.gasRegister, &wasmtesting.MockGasRegister{})
},
},
"api costs": {
srcOpt: WithApiCosts(1, 2),
verify: func(t *testing.T, k Keeper) {
t.Cleanup(setApiDefaults)
assert.Equal(t, uint64(1), costHumanize)
assert.Equal(t, uint64(2), costCanonical)
},
},
}
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, nil, nil, "tempDir", types.DefaultWasmConfig(), SupportedFeatures, spec.srcOpt)
spec.verify(t, k)
})
}
}
func setApiDefaults() {
costHumanize = DefaultGasCostHumanAddress * DefaultGasMultiplier
costCanonical = DefaultGasCostCanonicalAddress * DefaultGasMultiplier
}