* Use ICS4Wrapper to send raw IBC packets & fix Fee in wasm stack (cherry picked from commit 6dfa5cb41c52180d30c2d0e1aed3fa2685a68c33) # Conflicts: # app/app.go # x/wasm/keeper/handler_plugin.go # x/wasm/keeper/keeper_cgo.go # x/wasm/keeper/keeper_test.go # x/wasm/keeper/options_test.go # x/wasm/keeper/test_common.go * Fix merge conflicts * Inline ibc packet sender interface and minor chore * Rename IBCPacketSender --------- Co-authored-by: Assaf Morami <assaf.morami@gmail.com> Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
126 lines
4.1 KiB
Go
126 lines
4.1 KiB
Go
package keeper
|
|
|
|
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"
|
|
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
|
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting"
|
|
"github.com/CosmWasm/wasmd/x/wasm/types"
|
|
)
|
|
|
|
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, &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) {
|
|
assert.IsType(t, &wasmtesting.MockMessageHandler{}, k.messenger)
|
|
},
|
|
},
|
|
"query plugins": {
|
|
srcOpt: WithQueryHandler(&wasmtesting.MockQueryHandler{}),
|
|
verify: func(t *testing.T, k Keeper) {
|
|
assert.IsType(t, &wasmtesting.MockQueryHandler{}, k.wasmVMQueryHandler)
|
|
},
|
|
},
|
|
"message handler decorator": {
|
|
srcOpt: WithMessageHandlerDecorator(func(old Messenger) Messenger {
|
|
require.IsType(t, &MessageHandlerChain{}, old)
|
|
return &wasmtesting.MockMessageHandler{}
|
|
}),
|
|
verify: func(t *testing.T, k Keeper) {
|
|
assert.IsType(t, &wasmtesting.MockMessageHandler{}, k.messenger)
|
|
},
|
|
},
|
|
"query plugins decorator": {
|
|
srcOpt: WithQueryHandlerDecorator(func(old WasmVMQueryHandler) WasmVMQueryHandler {
|
|
require.IsType(t, QueryPlugins{}, old)
|
|
return &wasmtesting.MockQueryHandler{}
|
|
}),
|
|
verify: func(t *testing.T, k Keeper) {
|
|
assert.IsType(t, &wasmtesting.MockQueryHandler{}, k.wasmVMQueryHandler)
|
|
},
|
|
},
|
|
"coin transferrer": {
|
|
srcOpt: WithCoinTransferrer(&wasmtesting.MockCoinTransferrer{}),
|
|
verify: func(t *testing.T, k Keeper) {
|
|
assert.IsType(t, &wasmtesting.MockCoinTransferrer{}, k.bank)
|
|
},
|
|
},
|
|
"costs": {
|
|
srcOpt: WithGasRegister(&wasmtesting.MockGasRegister{}),
|
|
verify: func(t *testing.T, k Keeper) {
|
|
assert.IsType(t, &wasmtesting.MockGasRegister{}, k.gasRegister)
|
|
},
|
|
},
|
|
"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)
|
|
},
|
|
},
|
|
"max recursion query limit": {
|
|
srcOpt: WithMaxQueryStackSize(1),
|
|
verify: func(t *testing.T, k Keeper) {
|
|
assert.IsType(t, uint32(1), k.maxQueryStackSize)
|
|
},
|
|
},
|
|
"accepted account types": {
|
|
srcOpt: WithAcceptedAccountTypesOnContractInstantiation(&authtypes.BaseAccount{}, &vestingtypes.ContinuousVestingAccount{}),
|
|
verify: func(t *testing.T, k Keeper) {
|
|
exp := map[reflect.Type]struct{}{
|
|
reflect.TypeOf(&authtypes.BaseAccount{}): {},
|
|
reflect.TypeOf(&vestingtypes.ContinuousVestingAccount{}): {},
|
|
}
|
|
assert.Equal(t, exp, k.acceptedAccountTypes)
|
|
},
|
|
},
|
|
"account pruner": {
|
|
srcOpt: WithAccountPruner(VestingCoinBurner{}),
|
|
verify: func(t *testing.T, k Keeper) {
|
|
assert.Equal(t, VestingCoinBurner{}, k.accountPruner)
|
|
},
|
|
},
|
|
}
|
|
for name, spec := range specs {
|
|
t.Run(name, func(t *testing.T) {
|
|
k := NewKeeper(nil, nil, authkeeper.AccountKeeper{}, &bankkeeper.BaseKeeper{}, stakingkeeper.Keeper{}, nil, nil, nil, nil, nil, nil, nil, nil, "tempDir", types.DefaultWasmConfig(), AvailableCapabilities, "", spec.srcOpt)
|
|
spec.verify(t, k)
|
|
})
|
|
}
|
|
}
|
|
|
|
func setAPIDefaults() {
|
|
costHumanize = DefaultGasCostHumanAddress * DefaultGasMultiplier
|
|
costCanonical = DefaultGasCostCanonicalAddress * DefaultGasMultiplier
|
|
}
|