Skip to content

Commit

Permalink
Rename features to availableCapabilities as in wasmvm
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Sep 9, 2022
1 parent 0e41c8c commit 0f2b184
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 93 deletions.
2 changes: 1 addition & 1 deletion INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,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],
Expand All @@ -524,7 +524,7 @@ func NewWasmApp(
app.GRPCQueryRouter(),
wasmDir,
wasmConfig,
supportedFeatures,
availableCapabilities,
wasmOpts...,
)

Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -196,16 +196,16 @@ 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)

evt := sdk.NewEvent(
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.AttributeKeyCapability, strings.TrimSpace(f)))
}
ctx.EventManager().EmitEvent(evt)

Expand Down
Loading

0 comments on commit 0f2b184

Please sign in to comment.