Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed Oct 19, 2021
1 parent d2e72d4 commit 27e18ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
17 changes: 17 additions & 0 deletions x/wasm/keeper/recursive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,20 @@ func TestLimitRecursiveQueryGas(t *testing.T) {
})
}
}

func TestLimitRecursiveQueryDepth(t *testing.T) {

contractAddr, _, ctx, keeper, _ := initRecurseContract(t)
msg := buildQuery(t, Recurse{
Depth: types.ContractMaxQueryDepth - 1, // need to exclude first query
})

_, err := keeper.queryToContract(ctx, contractAddr, msg)
require.NoError(t, err)

msg = buildQuery(t, Recurse{
Depth: types.ContractMaxQueryDepth,
})
_, err = keeper.queryToContract(ctx, contractAddr, msg)
require.Error(t, err)
}
5 changes: 3 additions & 2 deletions x/wasm/types/wasmer_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
)

const maxQueryDepth = 20
// ContractMaxQueryDepth maximum recursive query depth allowed
const ContractMaxQueryDepth = 20

var _ WasmerEngine = &WasmerEngineWithQueryDepth{}

Expand All @@ -25,7 +26,7 @@ func NewWasmerEngineWithQueryDepth(wasmVM *wasmvm.VM) *WasmerEngineWithQueryDept
// IncreaseQueryDepth increase execution depth by 1 and check whether
// the depth exceeds max one or not
func (wasmer *WasmerEngineWithQueryDepth) IncreaseQueryDepth() error {
if wasmer.QueryDepth >= maxQueryDepth {
if wasmer.QueryDepth >= ContractMaxQueryDepth {
return ErrExceedMaxQueryDepth
}

Expand Down

0 comments on commit 27e18ac

Please sign in to comment.