Skip to content

Commit

Permalink
Add wasm limits query test
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Sep 27, 2024
1 parent a50e8d7 commit aaad097
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"

dbm "github.com/cosmos/cosmos-db"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
Expand Down Expand Up @@ -686,6 +687,54 @@ func TestQueryContractInfo(t *testing.T) {
}
}

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

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

specs := map[string]struct {
limits wasmvmtypes.WasmLimits
expJSON []byte
}{
"all 15": {
limits: wasmvmtypes.WasmLimits{
InitialMemoryLimit: ptr(uint32(15)),
TableSizeLimit: ptr(uint32(15)),
MaxImports: ptr(uint32(15)),
MaxFunctions: ptr(uint32(15)),
MaxFunctionParams: ptr(uint32(15)),
MaxTotalFunctionParams: ptr(uint32(15)),
MaxFunctionResults: ptr(uint32(15)),
},
expJSON: []byte(`{"initial_memory_limit":15,"table_size_limit":15,"max_imports":15,"max_functions":15,"max_function_params":15,"max_total_function_params":15,"max_function_results":15}`),
},
"empty": {
limits: wasmvmtypes.WasmLimits{},
expJSON: []byte("{}"),
},
}

for name, spec := range specs {
t.Run(name, func(t *testing.T) {
cfg.WasmLimits = spec.limits

ctx, keepers := createTestInput(t, false, AvailableCapabilities, cfg, dbm.NewMemDB())
keeper := keepers.WasmKeeper

q := Querier(keeper)

response, err := q.WasmLimitsConfig(ctx, &types.QueryWasmLimitsConfigRequest{})
require.NoError(t, err)
require.NotNil(t, response)

assert.Equal(t, string(spec.expJSON), response.Config)
// assert.Equal(t, spec.expJSON, []byte(response.Config))
})
}
}

func TestQueryPinnedCodes(t *testing.T) {
ctx, keepers := CreateTestInput(t, false, AvailableCapabilities)
keeper := keepers.WasmKeeper
Expand Down

0 comments on commit aaad097

Please sign in to comment.