Skip to content

Commit

Permalink
test(logic): check out of gas in predicate execution
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Jul 4, 2024
1 parent e6f0fbe commit 009ce4c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions x/logic/keeper/grpc_query_ask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package keeper_test
import (
gocontext "context"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"io/fs"
"testing"

Expand All @@ -19,6 +20,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/axone-protocol/axoned/v8/x/logic"
Expand Down Expand Up @@ -137,6 +139,14 @@ func TestGRPCAsk(t *testing.T) {
maxGas: 1000,
expectedError: "out of gas: logic <ReadPerByte> (1018/1000): limit exceeded",
},
{
query: "bank_balances(X, Y).",
maxGas: 3000,
expectedAnswer: &types.Answer{
Variables: []string{"X", "Y"},
Results: []types.Result{{Error: "error(resource_error(gas(panic: {ValuePerByte},4204,3000)),root)"}},
},
},
{
query: "block_height(X).",
maxGas: 3000,
Expand Down Expand Up @@ -325,6 +335,11 @@ foo(a4).
bankKeeper := logictestutil.NewMockBankKeeper(ctrl)
fsProvider := logictestutil.NewMockFS(ctrl)

bankKeeper.EXPECT().GetAccountsBalances(gomock.Any()).Do(func(ctx gocontext.Context) []bankypes.Balance {
sdk.UnwrapSDKContext(ctx).GasMeter().ConsumeGas(2000, "ValuePerByte")
return nil
}).AnyTimes()

logicKeeper := keeper.NewKeeper(
encCfg.Codec,
key,
Expand Down

0 comments on commit 009ce4c

Please sign in to comment.