From 8aab70c45f6891e5c1558738affd77ff8e922423 Mon Sep 17 00:00:00 2001 From: Alexander Peters Date: Fri, 9 Sep 2022 09:22:31 +0200 Subject: [PATCH] Rename features to availableCapabilities (#993) * Rename features to availableCapabilities as in wasmvm * Review feedback --- INTEGRATION.md | 2 +- app/app.go | 4 +- x/wasm/keeper/bench_test.go | 4 +- x/wasm/keeper/genesis_test.go | 2 +- x/wasm/keeper/ibc_test.go | 4 +- x/wasm/keeper/keeper.go | 10 +-- x/wasm/keeper/keeper_test.go | 92 +++++++++++++--------------- x/wasm/keeper/legacy_querier_test.go | 8 +-- x/wasm/keeper/options_test.go | 2 +- x/wasm/keeper/querier_test.go | 24 ++++---- x/wasm/keeper/recurse_test.go | 2 +- x/wasm/keeper/relay_test.go | 12 ++-- x/wasm/keeper/staking_test.go | 4 +- x/wasm/keeper/test_common.go | 8 +-- x/wasm/types/errors.go | 2 +- x/wasm/types/events.go | 8 +-- 16 files changed, 92 insertions(+), 96 deletions(-) diff --git a/INTEGRATION.md b/INTEGRATION.md index 2d7f50891..07000f1d5 100644 --- a/INTEGRATION.md +++ b/INTEGRATION.md @@ -202,5 +202,5 @@ the SDK is implemented properly. Once you have tested this and are happy with the results, you can wire it up in `app.go`. Just edit [the default `NewKeeper` constructor](https://github.com/CosmWasm/wasmd/blob/v0.8.0-rc1/app/app.go#L257-L258) -to have the proper `supportedFeatures` and pass in the `CustomEncoder` and `CustomQuerier` as the last two arguments to `NewKeeper`. +to have the proper `availableCapabilities` and pass in the `CustomEncoder` and `CustomQuerier` as the last two arguments to `NewKeeper`. Now you can compile your chain and upload your custom contracts on it. \ No newline at end of file diff --git a/app/app.go b/app/app.go index 0be2e10c5..8ba79d996 100644 --- a/app/app.go +++ b/app/app.go @@ -508,7 +508,7 @@ func NewWasmApp( // The last arguments can contain custom message handlers, and custom query handlers, // if we want to allow any custom callbacks - supportedFeatures := "iterator,staking,stargate,cosmwasm_1_1" + availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1" app.WasmKeeper = wasm.NewKeeper( appCodec, keys[wasm.StoreKey], @@ -525,7 +525,7 @@ func NewWasmApp( app.GRPCQueryRouter(), wasmDir, wasmConfig, - supportedFeatures, + availableCapabilities, wasmOpts..., ) diff --git a/x/wasm/keeper/bench_test.go b/x/wasm/keeper/bench_test.go index 1ad1693bb..f32b39a0c 100644 --- a/x/wasm/keeper/bench_test.go +++ b/x/wasm/keeper/bench_test.go @@ -51,7 +51,7 @@ func BenchmarkInstantiationOverhead(b *testing.B) { for name, spec := range specs { b.Run(name, func(b *testing.B) { wasmConfig := types.WasmConfig{MemoryCacheSize: 0} - ctx, keepers := createTestInput(b, false, SupportedFeatures, wasmConfig, spec.db()) + ctx, keepers := createTestInput(b, false, AvailableCapabilities, wasmConfig, spec.db()) example := InstantiateHackatomExampleContract(b, ctx, keepers) if spec.pinned { require.NoError(b, keepers.ContractKeeper.PinCode(ctx, example.CodeID)) @@ -86,7 +86,7 @@ func BenchmarkCompilation(b *testing.B) { b.Run(name, func(b *testing.B) { wasmConfig := types.WasmConfig{MemoryCacheSize: 0} db := dbm.NewMemDB() - ctx, keepers := createTestInput(b, false, SupportedFeatures, wasmConfig, db) + ctx, keepers := createTestInput(b, false, AvailableCapabilities, wasmConfig, db) // print out code size for comparisons code, err := os.ReadFile(spec.wasmFile) diff --git a/x/wasm/keeper/genesis_test.go b/x/wasm/keeper/genesis_test.go index f4e5b476a..e5410aabb 100644 --- a/x/wasm/keeper/genesis_test.go +++ b/x/wasm/keeper/genesis_test.go @@ -668,7 +668,7 @@ func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []sdk.StoreKey) { wasmConfig := wasmTypes.DefaultWasmConfig() pk := paramskeeper.NewKeeper(encodingConfig.Marshaler, encodingConfig.Amino, keyParams, tkeyParams) - srcKeeper := NewKeeper(encodingConfig.Marshaler, keyWasm, pk.Subspace(wasmTypes.ModuleName), authkeeper.AccountKeeper{}, nil, stakingkeeper.Keeper{}, distributionkeeper.Keeper{}, nil, nil, nil, nil, nil, nil, tempDir, wasmConfig, SupportedFeatures) + srcKeeper := NewKeeper(encodingConfig.Marshaler, keyWasm, pk.Subspace(wasmTypes.ModuleName), authkeeper.AccountKeeper{}, nil, stakingkeeper.Keeper{}, distributionkeeper.Keeper{}, nil, nil, nil, nil, nil, nil, tempDir, wasmConfig, AvailableCapabilities) return &srcKeeper, ctx, []sdk.StoreKey{keyWasm, keyParams} } diff --git a/x/wasm/keeper/ibc_test.go b/x/wasm/keeper/ibc_test.go index 704e2f6c2..ef04b583c 100644 --- a/x/wasm/keeper/ibc_test.go +++ b/x/wasm/keeper/ibc_test.go @@ -11,14 +11,14 @@ import ( ) func TestDontBindPortNonIBCContract(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) example := InstantiateHackatomExampleContract(t, ctx, keepers) // ensure we bound the port _, _, err := keepers.IBCKeeper.PortKeeper.LookupModuleByPort(ctx, keepers.WasmKeeper.GetContractInfo(ctx, example.Contract).IBCPortID) require.Error(t, err) } func TestBindingPortForIBCContractOnInstantiate(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) example := InstantiateIBCReflectContract(t, ctx, keepers) // ensure we bound the port owner, _, err := keepers.IBCKeeper.PortKeeper.LookupModuleByPort(ctx, keepers.WasmKeeper.GetContractInfo(ctx, example.Contract).IBCPortID) require.NoError(t, err) diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index deb78d9db..6e250e9f6 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -103,10 +103,10 @@ func NewKeeper( queryRouter GRPCQueryRouter, homeDir string, wasmConfig types.WasmConfig, - supportedFeatures string, + availableCapabilities string, opts ...Option, ) Keeper { - wasmer, err := wasmvm.NewVM(filepath.Join(homeDir, "wasm"), supportedFeatures, contractMemoryLimit, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize) + wasmer, err := wasmvm.NewVM(filepath.Join(homeDir, "wasm"), availableCapabilities, contractMemoryLimit, wasmConfig.ContractDebugMode, wasmConfig.MemoryCacheSize) if err != nil { panic(err) } @@ -196,7 +196,7 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, return 0, sdkerrors.Wrap(types.ErrCreateFailed, err.Error()) } codeID = k.autoIncrementID(ctx, types.KeyLastCodeID) - k.Logger(ctx).Debug("storing new contract", "features", report.RequiredFeatures, "code_id", codeID) + k.Logger(ctx).Debug("storing new contract", "capabilities", report.RequiredCapabilities, "code_id", codeID) codeInfo := types.NewCodeInfo(checksum, creator, *instantiateAccess) k.storeCodeInfo(ctx, codeID, codeInfo) @@ -204,8 +204,8 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, types.EventTypeStoreCode, sdk.NewAttribute(types.AttributeKeyCodeID, strconv.FormatUint(codeID, 10)), ) - for _, f := range strings.Split(report.RequiredFeatures, ",") { - evt.AppendAttributes(sdk.NewAttribute(types.AttributeKeyFeature, strings.TrimSpace(f))) + for _, f := range strings.Split(report.RequiredCapabilities, ",") { + evt.AppendAttributes(sdk.NewAttribute(types.AttributeKeyRequiredCapability, strings.TrimSpace(f))) } ctx.EventManager().EmitEvent(evt) diff --git a/x/wasm/keeper/keeper_test.go b/x/wasm/keeper/keeper_test.go index 5b3fc3807..0cde32592 100644 --- a/x/wasm/keeper/keeper_test.go +++ b/x/wasm/keeper/keeper_test.go @@ -4,27 +4,23 @@ import ( "bytes" "encoding/json" "errors" - fuzz "github.com/google/gofuzz" - "github.com/tendermint/tendermint/libs/rand" "math" "os" "testing" "time" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - stypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + fuzz "github.com/google/gofuzz" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - + "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" @@ -42,15 +38,15 @@ func init() { var hackatomWasm []byte -const SupportedFeatures = "iterator,staking,stargate,cosmwasm_1_1" +const AvailableCapabilities = "iterator,staking,stargate,cosmwasm_1_1" func TestNewKeeper(t *testing.T) { - _, keepers := CreateTestInput(t, false, SupportedFeatures) + _, keepers := CreateTestInput(t, false, AvailableCapabilities) require.NotNil(t, keepers.ContractKeeper) } func TestCreateSuccess(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -70,14 +66,14 @@ func TestCreateSuccess(t *testing.T) { } func TestCreateNilCreatorAddress(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) _, err := keepers.ContractKeeper.Create(ctx, nil, hackatomWasm, nil) require.Error(t, err, "nil creator is not allowed") } func TestCreateNilWasmCode(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) creator := keepers.Faucet.NewFundedAccount(ctx, deposit...) @@ -86,7 +82,7 @@ func TestCreateNilWasmCode(t *testing.T) { } func TestCreateInvalidWasmCode(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) creator := keepers.Faucet.NewFundedAccount(ctx, deposit...) @@ -123,7 +119,7 @@ func TestCreateStoresInstantiatePermission(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.ContractKeeper, keepers.BankKeeper keepers.WasmKeeper.SetParams(ctx, types.Params{ CodeUploadAccess: types.AllowEverybody, @@ -142,7 +138,7 @@ func TestCreateStoresInstantiatePermission(t *testing.T) { } func TestCreateWithParamPermissions(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -188,7 +184,7 @@ func TestCreateWithParamPermissions(t *testing.T) { // ensure that the user cannot set the code instantiate permission to something more permissive // than the default func TestEnforceValidPermissionsOnCreate(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper contractKeeper := keepers.ContractKeeper @@ -264,7 +260,7 @@ func TestEnforceValidPermissionsOnCreate(t *testing.T) { } func TestCreateDuplicate(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -290,7 +286,7 @@ func TestCreateDuplicate(t *testing.T) { } func TestCreateWithSimulation(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) ctx = ctx.WithBlockHeader(tmproto.Header{Height: 1}). WithGasMeter(stypes.NewInfiniteGasMeter()) @@ -304,7 +300,7 @@ func TestCreateWithSimulation(t *testing.T) { require.Equal(t, uint64(1), contractID) // then try to create it in non-simulation mode (should not fail) - ctx, keepers = CreateTestInput(t, false, SupportedFeatures) + ctx, keepers = CreateTestInput(t, false, AvailableCapabilities) ctx = ctx.WithGasMeter(sdk.NewGasMeter(10_000_000)) creator = keepers.Faucet.NewFundedAccount(ctx, deposit...) contractID, err = keepers.ContractKeeper.Create(ctx, creator, hackatomWasm, nil) @@ -344,7 +340,7 @@ func TestIsSimulationMode(t *testing.T) { } func TestCreateWithGzippedPayload(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -363,7 +359,7 @@ func TestCreateWithGzippedPayload(t *testing.T) { } func TestCreateWithBrokenGzippedPayload(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -380,7 +376,7 @@ func TestCreateWithBrokenGzippedPayload(t *testing.T) { } func TestInstantiate(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -470,7 +466,7 @@ func TestInstantiateWithDeposit(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) accKeeper, bankKeeper, keeper := keepers.AccountKeeper, keepers.BankKeeper, keepers.ContractKeeper if spec.fundAddr { @@ -537,7 +533,7 @@ func TestInstantiateWithPermissions(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) accKeeper, bankKeeper, keeper := keepers.AccountKeeper, keepers.BankKeeper, keepers.ContractKeeper fundAccounts(t, ctx, accKeeper, bankKeeper, spec.srcActor, deposit) @@ -551,7 +547,7 @@ func TestInstantiateWithPermissions(t *testing.T) { } func TestInstantiateWithNonExistingCodeID(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) creator := keepers.Faucet.NewFundedAccount(ctx, deposit...) @@ -567,7 +563,7 @@ func TestInstantiateWithNonExistingCodeID(t *testing.T) { } func TestInstantiateWithContractDataResponse(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) wasmerMock := &wasmtesting.MockWasmer{ InstantiateFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { @@ -584,7 +580,7 @@ func TestInstantiateWithContractDataResponse(t *testing.T) { } func TestExecute(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.ContractKeeper, keepers.BankKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -721,7 +717,7 @@ func TestExecuteWithDeposit(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) accKeeper, bankKeeper, keeper := keepers.AccountKeeper, keepers.BankKeeper, keepers.ContractKeeper if spec.newBankParams != nil { bankKeeper.SetParams(ctx, *spec.newBankParams) @@ -755,7 +751,7 @@ func TestExecuteWithDeposit(t *testing.T) { } func TestExecuteWithNonExistingAddress(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -768,7 +764,7 @@ func TestExecuteWithNonExistingAddress(t *testing.T) { } func TestExecuteWithPanic(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -799,7 +795,7 @@ func TestExecuteWithPanic(t *testing.T) { } func TestExecuteWithCpuLoop(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -840,7 +836,7 @@ func TestExecuteWithCpuLoop(t *testing.T) { } func TestExecuteWithStorageLoop(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -881,7 +877,7 @@ func TestExecuteWithStorageLoop(t *testing.T) { } func TestMigrate(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -1075,7 +1071,7 @@ func TestMigrate(t *testing.T) { } func TestMigrateReplacesTheSecondIndex(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) example := InstantiateHackatomExampleContract(t, ctx, keepers) // then assert a second index exists @@ -1109,7 +1105,7 @@ func TestMigrateReplacesTheSecondIndex(t *testing.T) { } func TestMigrateWithDispatchedMessage(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -1194,7 +1190,7 @@ func TestMigrateWithDispatchedMessage(t *testing.T) { } func TestIterateContractsByCode(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) k, c := keepers.WasmKeeper, keepers.ContractKeeper example1 := InstantiateHackatomExampleContract(t, ctx, keepers) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) @@ -1240,7 +1236,7 @@ func TestIterateContractsByCodeWithMigration(t *testing.T) { return &wasmvmtypes.Response{}, 1, nil }} wasmtesting.MakeInstantiable(&mockWasmVM) - ctx, keepers := CreateTestInput(t, false, SupportedFeatures, WithWasmEngine(&mockWasmVM)) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithWasmEngine(&mockWasmVM)) k, c := keepers.WasmKeeper, keepers.ContractKeeper example1 := InstantiateHackatomExampleContract(t, ctx, keepers) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) @@ -1279,7 +1275,7 @@ type stealFundsMsg struct { } func TestSudo(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.ContractKeeper, keepers.BankKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -1362,7 +1358,7 @@ func mustMarshal(t *testing.T, r interface{}) []byte { } func TestUpdateContractAdmin(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -1430,7 +1426,7 @@ func TestUpdateContractAdmin(t *testing.T) { } func TestClearContractAdmin(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.ContractKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -1493,7 +1489,7 @@ func TestClearContractAdmin(t *testing.T) { } func TestPinCode(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) k := keepers.WasmKeeper var capturedChecksums []wasmvm.Checksum @@ -1520,7 +1516,7 @@ func TestPinCode(t *testing.T) { } func TestUnpinCode(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) k := keepers.WasmKeeper var capturedChecksums []wasmvm.Checksum @@ -1554,7 +1550,7 @@ func TestUnpinCode(t *testing.T) { } func TestInitializePinnedCodes(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) k := keepers.WasmKeeper var capturedChecksums []wasmvm.Checksum @@ -1594,7 +1590,7 @@ func TestPinnedContractLoops(t *testing.T) { // a pinned contract that calls itself via submessages should terminate with an // error at some point - ctx, keepers := CreateTestInput(t, false, SupportedFeatures, WithWasmEngine(&mock)) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithWasmEngine(&mock)) k := keepers.WasmKeeper example := SeedNewContractInstance(t, ctx, keepers, &mock) @@ -1710,7 +1706,7 @@ func TestNewDefaultWasmVMContractResponseHandler(t *testing.T) { } func TestReply(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) k := keepers.WasmKeeper var mock wasmtesting.MockWasmer wasmtesting.MakeInstantiable(&mock) @@ -1779,7 +1775,7 @@ func TestReply(t *testing.T) { } func TestQueryIsolation(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) k := keepers.WasmKeeper var mock wasmtesting.MockWasmer wasmtesting.MakeInstantiable(&mock) @@ -1857,7 +1853,7 @@ func TestBuildContractAddress(t *testing.T) { } func TestSetAccessConfig(t *testing.T) { - parentCtx, keepers := CreateTestInput(t, false, SupportedFeatures) + parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities) k := keepers.WasmKeeper creatorAddr := RandomAccountAddress(t) nonCreatorAddr := RandomAccountAddress(t) @@ -1940,7 +1936,7 @@ func TestSetAccessConfig(t *testing.T) { } func TestAppendToContractHistory(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) var contractAddr sdk.AccAddress = rand.Bytes(types.ContractAddrLen) var orderedEntries []types.ContractCodeHistoryEntry diff --git a/x/wasm/keeper/legacy_querier_test.go b/x/wasm/keeper/legacy_querier_test.go index dac7eaa78..1f22a5082 100644 --- a/x/wasm/keeper/legacy_querier_test.go +++ b/x/wasm/keeper/legacy_querier_test.go @@ -17,7 +17,7 @@ import ( ) func TestLegacyQueryContractState(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000)) @@ -154,7 +154,7 @@ func TestLegacyQueryContractState(t *testing.T) { } func TestLegacyQueryContractListByCodeOrdering(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 1000000)) @@ -218,7 +218,7 @@ func TestLegacyQueryContractListByCodeOrdering(t *testing.T) { } func TestLegacyQueryContractHistory(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper var otherAddr sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen) @@ -329,7 +329,7 @@ func TestLegacyQueryCodeList(t *testing.T) { for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper for _, codeID := range spec.codeIDs { diff --git a/x/wasm/keeper/options_test.go b/x/wasm/keeper/options_test.go index 6e50c7ba9..07195e046 100644 --- a/x/wasm/keeper/options_test.go +++ b/x/wasm/keeper/options_test.go @@ -84,7 +84,7 @@ func TestConstructorOptions(t *testing.T) { } 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) + 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(), AvailableCapabilities, spec.srcOpt) spec.verify(t, k) }) } diff --git a/x/wasm/keeper/querier_test.go b/x/wasm/keeper/querier_test.go index 88ee6d3aa..21df7f94f 100644 --- a/x/wasm/keeper/querier_test.go +++ b/x/wasm/keeper/querier_test.go @@ -27,7 +27,7 @@ import ( ) func TestQueryAllContractState(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) @@ -114,7 +114,7 @@ func TestQueryAllContractState(t *testing.T) { } func TestQuerySmartContractState(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) @@ -157,7 +157,7 @@ func TestQuerySmartContractState(t *testing.T) { } func TestQuerySmartContractPanics(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) contractAddr := BuildContractAddress(1, 1) keepers.WasmKeeper.storeCodeInfo(ctx, 1, types.CodeInfo{}) keepers.WasmKeeper.storeContractInfo(ctx, contractAddr, &types.ContractInfo{ @@ -202,7 +202,7 @@ func TestQuerySmartContractPanics(t *testing.T) { } func TestQueryRawContractState(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) @@ -257,7 +257,7 @@ func TestQueryRawContractState(t *testing.T) { } func TestQueryContractListByCodeOrdering(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 1000000)) @@ -313,7 +313,7 @@ func TestQueryContractListByCodeOrdering(t *testing.T) { } func TestQueryContractHistory(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper var ( @@ -457,7 +457,7 @@ func TestQueryCodeList(t *testing.T) { wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper specs := map[string]struct { @@ -533,7 +533,7 @@ func TestQueryContractInfo(t *testing.T) { contractAddr = RandomAccountAddress(t) anyDate = time.Now().UTC() ) - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) // register an example extension. must be protobuf keepers.EncodingConfig.InterfaceRegistry.RegisterImplementations( (*types.ContractInfoExtension)(nil), @@ -599,7 +599,7 @@ func TestQueryContractInfo(t *testing.T) { } func TestQueryPinnedCodes(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper exampleContract1 := InstantiateHackatomExampleContract(t, ctx, keepers) @@ -656,7 +656,7 @@ func TestQueryPinnedCodes(t *testing.T) { } func TestQueryParams(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper q := Querier(keeper) @@ -687,7 +687,7 @@ func TestQueryCodeInfo(t *testing.T) { wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper anyAddress, err := sdk.AccAddressFromBech32("cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz") @@ -742,7 +742,7 @@ func TestQueryCodeInfoList(t *testing.T) { wasmCode, err := os.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) - ctx, keepers := CreateTestInput(t, false, SupportedFeatures) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities) keeper := keepers.WasmKeeper anyAddress, err := sdk.AccAddressFromBech32("cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz") diff --git a/x/wasm/keeper/recurse_test.go b/x/wasm/keeper/recurse_test.go index 18778a52d..5a16da787 100644 --- a/x/wasm/keeper/recurse_test.go +++ b/x/wasm/keeper/recurse_test.go @@ -45,7 +45,7 @@ func initRecurseContract(t *testing.T) (contract sdk.AccAddress, creator sdk.Acc return realWasmQuerier.HandleQuery(ctx, caller, request) }) } - ctx, keepers := CreateTestInput(t, false, SupportedFeatures, WithQueryHandlerDecorator(countingQuerierDec)) + ctx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithQueryHandlerDecorator(countingQuerierDec)) keeper = keepers.WasmKeeper exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) return exampleContract.Contract, exampleContract.CreatorAddr, ctx, keeper diff --git a/x/wasm/keeper/relay_test.go b/x/wasm/keeper/relay_test.go index dd9c3da23..a1d2819e5 100644 --- a/x/wasm/keeper/relay_test.go +++ b/x/wasm/keeper/relay_test.go @@ -20,7 +20,7 @@ func TestOnOpenChannel(t *testing.T) { var m wasmtesting.MockWasmer wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} - parentCtx, keepers := CreateTestInput(t, false, SupportedFeatures, WithMessageHandler(messenger)) + parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) example := SeedNewContractInstance(t, parentCtx, keepers, &m) const myContractGas = 40 @@ -90,7 +90,7 @@ func TestOnConnectChannel(t *testing.T) { var m wasmtesting.MockWasmer wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} - parentCtx, keepers := CreateTestInput(t, false, SupportedFeatures, WithMessageHandler(messenger)) + parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) example := SeedNewContractInstance(t, parentCtx, keepers, &m) const myContractGas = 40 @@ -201,7 +201,7 @@ func TestOnCloseChannel(t *testing.T) { var m wasmtesting.MockWasmer wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} - parentCtx, keepers := CreateTestInput(t, false, SupportedFeatures, WithMessageHandler(messenger)) + parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) example := SeedNewContractInstance(t, parentCtx, keepers, &m) const myContractGas = 40 @@ -311,7 +311,7 @@ func TestOnRecvPacket(t *testing.T) { var m wasmtesting.MockWasmer wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} - parentCtx, keepers := CreateTestInput(t, false, SupportedFeatures, WithMessageHandler(messenger)) + parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) example := SeedNewContractInstance(t, parentCtx, keepers, &m) const myContractGas = 40 const storageCosts = sdk.Gas(2903) @@ -473,7 +473,7 @@ func TestOnAckPacket(t *testing.T) { var m wasmtesting.MockWasmer wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} - parentCtx, keepers := CreateTestInput(t, false, SupportedFeatures, WithMessageHandler(messenger)) + parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) example := SeedNewContractInstance(t, parentCtx, keepers, &m) const myContractGas = 40 @@ -578,7 +578,7 @@ func TestOnTimeoutPacket(t *testing.T) { var m wasmtesting.MockWasmer wasmtesting.MakeIBCInstantiable(&m) messenger := &wasmtesting.MockMessageHandler{} - parentCtx, keepers := CreateTestInput(t, false, SupportedFeatures, WithMessageHandler(messenger)) + parentCtx, keepers := CreateTestInput(t, false, AvailableCapabilities, WithMessageHandler(messenger)) example := SeedNewContractInstance(t, parentCtx, keepers, &m) const myContractGas = 40 diff --git a/x/wasm/keeper/staking_test.go b/x/wasm/keeper/staking_test.go index 633cbcf1f..15f0e0ac7 100644 --- a/x/wasm/keeper/staking_test.go +++ b/x/wasm/keeper/staking_test.go @@ -93,7 +93,7 @@ type InvestmentResponse struct { } func TestInitializeStaking(t *testing.T) { - ctx, k := CreateTestInput(t, false, SupportedFeatures) + ctx, k := CreateTestInput(t, false, AvailableCapabilities) accKeeper, stakingKeeper, keeper, bankKeeper := k.AccountKeeper, k.StakingKeeper, k.ContractKeeper, k.BankKeeper valAddr := addValidator(t, ctx, stakingKeeper, k.Faucet, sdk.NewInt64Coin("stake", 1234567)) @@ -168,7 +168,7 @@ type initInfo struct { } func initializeStaking(t *testing.T) initInfo { - ctx, k := CreateTestInput(t, false, SupportedFeatures) + ctx, k := CreateTestInput(t, false, AvailableCapabilities) accKeeper, stakingKeeper, keeper, bankKeeper := k.AccountKeeper, k.StakingKeeper, k.WasmKeeper, k.BankKeeper valAddr := addValidator(t, ctx, stakingKeeper, k.Faucet, sdk.NewInt64Coin("stake", 1000000)) diff --git a/x/wasm/keeper/test_common.go b/x/wasm/keeper/test_common.go index c0b293701..2cce8aad7 100644 --- a/x/wasm/keeper/test_common.go +++ b/x/wasm/keeper/test_common.go @@ -189,16 +189,16 @@ func CreateDefaultTestInput(t testing.TB) (sdk.Context, TestKeepers) { } // CreateTestInput encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default) -func CreateTestInput(t testing.TB, isCheckTx bool, supportedFeatures string, opts ...Option) (sdk.Context, TestKeepers) { +func CreateTestInput(t testing.TB, isCheckTx bool, availableCapabilities string, opts ...Option) (sdk.Context, TestKeepers) { // Load default wasm config - return createTestInput(t, isCheckTx, supportedFeatures, types.DefaultWasmConfig(), dbm.NewMemDB(), opts...) + return createTestInput(t, isCheckTx, availableCapabilities, types.DefaultWasmConfig(), dbm.NewMemDB(), opts...) } // encoders can be nil to accept the defaults, or set it to override some of the message handlers (like default) func createTestInput( t testing.TB, isCheckTx bool, - supportedFeatures string, + availableCapabilities string, wasmConfig types.WasmConfig, db dbm.DB, opts ...Option, @@ -387,7 +387,7 @@ func createTestInput( querier, tempDir, wasmConfig, - supportedFeatures, + availableCapabilities, opts..., ) keeper.SetParams(ctx, types.DefaultParams()) diff --git a/x/wasm/types/errors.go b/x/wasm/types/errors.go index 50814f813..7accd72bc 100644 --- a/x/wasm/types/errors.go +++ b/x/wasm/types/errors.go @@ -55,7 +55,7 @@ var ( // ErrMaxIBCChannels error for maximum number of ibc channels reached ErrMaxIBCChannels = sdkErrors.Register(DefaultCodespace, 16, "max transfer channels") - // ErrUnsupportedForContract error when a feature is used that is not supported for/ by this contract + // ErrUnsupportedForContract error when a capability is used that is not supported for/ by this contract ErrUnsupportedForContract = sdkErrors.Register(DefaultCodespace, 17, "unsupported for this contract") // ErrPinContractFailed error for pinning contract failures diff --git a/x/wasm/types/events.go b/x/wasm/types/events.go index 0c32476f5..251b95f04 100644 --- a/x/wasm/types/events.go +++ b/x/wasm/types/events.go @@ -21,8 +21,8 @@ const ( const ( AttributeReservedPrefix = "_" - AttributeKeyContractAddr = "_contract_address" - AttributeKeyCodeID = "code_id" - AttributeKeyResultDataHex = "result" - AttributeKeyFeature = "feature" + AttributeKeyContractAddr = "_contract_address" + AttributeKeyCodeID = "code_id" + AttributeKeyResultDataHex = "result" + AttributeKeyRequiredCapability = "required_capability" )