Skip to content

Commit

Permalink
Add test for wasm limits
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Sep 27, 2024
1 parent aaad097 commit 5c9bb81
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions x/wasm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ func TestCreateNilCreatorAddress(t *testing.T) {
require.Error(t, err, "nil creator is not allowed")
}

func TestWasmLimits(t *testing.T) {
cfg := types.DefaultWasmConfig()
cfg.WasmLimits = wasmvmtypes.WasmLimits{
MaxImports: ptr(uint32(1)), // very low limit that every contract will fail
}
ctx, keepers := createTestInput(t, false, AvailableCapabilities, cfg, dbm.NewMemDB())
keeper := keepers.ContractKeeper

deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 1))
creator := keepers.Faucet.NewFundedRandomAccount(ctx, deposit...)

_, _, err := keeper.Create(ctx, creator, hackatomWasm, nil)
assert.Error(t, err)
assert.ErrorContains(t, err, "Import")
}

func TestCreateNilWasmCode(t *testing.T) {
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities)
deposit := sdk.NewCoins(sdk.NewInt64Coin("denom", 100000))
Expand Down
4 changes: 0 additions & 4 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,6 @@ func TestQueryContractInfo(t *testing.T) {
}
}

func ptr[T any](v T) *T {
return &v
}

func TestQueryWasmLimitsConfig(t *testing.T) {
cfg := types.DefaultWasmConfig()

Expand Down
5 changes: 5 additions & 0 deletions x/wasm/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,8 @@ func keyPubAddr() (crypto.PrivKey, sdk.AccAddress) {
addr := sdk.AccAddress(pub.Address())
return key, addr
}

// ptr returns a pointer to the value passed in
func ptr[T any](v T) *T {
return &v
}

0 comments on commit 5c9bb81

Please sign in to comment.