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 18, 2024
1 parent 0927eb8 commit c13d9c4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions x/logic/keeper/grpc_query_ask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -137,16 +139,18 @@ func TestGRPCAsk(t *testing.T) {
maxGas: 1000,
expectedError: "out of gas: logic <ReadPerByte> (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').",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c13d9c4

Please sign in to comment.