From c13d9c43df8ae86e637b6eea422354c567ed70e9 Mon Sep 17 00:00:00 2001 From: Benjamin DENEUX Date: Thu, 4 Jul 2024 16:53:36 +0200 Subject: [PATCH] test(logic): check out of gas in predicate execution --- x/logic/keeper/grpc_query_ask_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/x/logic/keeper/grpc_query_ask_test.go b/x/logic/keeper/grpc_query_ask_test.go index f42692c1..62a5d500 100644 --- a/x/logic/keeper/grpc_query_ask_test.go +++ b/x/logic/keeper/grpc_query_ask_test.go @@ -17,8 +17,10 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" 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" @@ -137,16 +139,18 @@ func TestGRPCAsk(t *testing.T) { maxGas: 1000, expectedError: "out of gas: logic (1018/1000): limit exceeded", }, + { + query: "bank_balances(X, Y).", + maxGas: 3000, + expectedError: "error executing query: out of gas in location: panic: {ValuePerByte}: out of gas: invalid argument", + }, { query: "block_height(X).", maxGas: 3000, predicateCosts: map[string]uint64{ "block_height/1": 10000, }, - expectedAnswer: &types.Answer{ - Variables: []string{"X"}, - Results: []types.Result{{Error: "error(resource_error(gas(block_height/1,12353,3000)),block_height/1)"}}, - }, + expectedError: "error executing query: out of gas in location: block_height/1: out of gas: invalid argument", }, { program: "father(bob, 'élodie').", @@ -325,6 +329,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,