Skip to content

Commit 7fb1ea8

Browse files
Fix gas limit exceeded
1 parent 0567911 commit 7fb1ea8

File tree

1 file changed

+46
-48
lines changed

1 file changed

+46
-48
lines changed

rpc/v8/estimate_fee_test.go

+46-48
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ func TestEstimateFee(t *testing.T) {
6464
NumSteps: uint64(123),
6565
}, nil)
6666

67-
_, httpHeader, err := handler.EstimateFee([]rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag}, rpc.BlockID{Latest: true})
67+
_, httpHeader, err := handler.EstimateFee(
68+
[]rpc.BroadcastedTransaction{},
69+
[]rpc.SimulationFlag{rpc.SkipValidateFlag},
70+
rpc.BlockID{Latest: true},
71+
)
6872
require.Nil(t, err)
6973
assert.Equal(t, httpHeader.Get(rpc.ExecutionStepsHeader), "123")
7074
})
@@ -76,7 +80,11 @@ func TestEstimateFee(t *testing.T) {
7680
Cause: json.RawMessage("oops"),
7781
})
7882

79-
_, httpHeader, err := handler.EstimateFee([]rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag}, rpc.BlockID{Latest: true})
83+
_, httpHeader, err := handler.EstimateFee(
84+
[]rpc.BroadcastedTransaction{},
85+
[]rpc.SimulationFlag{rpc.SkipValidateFlag},
86+
rpc.BlockID{Latest: true},
87+
)
8088
require.Equal(t, rpccore.ErrTransactionExecutionError.CloneWithData(rpc.TransactionExecutionErrorData{
8189
TransactionIndex: 44,
8290
ExecutionError: json.RawMessage("oops"),
@@ -150,10 +158,9 @@ func TestEstimateFeeWithVMDeclare(t *testing.T) {
150158
},
151159
expected: []rpc.FeeEstimate{
152160
createFeeEstimate(t,
153-
"0x0", "0x2",
154-
"0x4176980", "0x1",
155-
"0xc0", "0x2",
156-
"0x4176b00", rpc.FRI,
161+
"0x4802740",
162+
"0xc0",
163+
"0x4176b00",
157164
),
158165
},
159166
},
@@ -191,10 +198,9 @@ func TestEstimateFeeWithVMDeploy(t *testing.T) {
191198
},
192199
expected: []rpc.FeeEstimate{
193200
createFeeEstimate(t,
194-
"0x0", "0x2",
195-
"0xfdb0d", "0x1",
196-
"0xe0", "0x2",
197-
"0xe6bcc", rpc.FRI,
201+
"0xfdb0d",
202+
"0xe0",
203+
"0xe6bcc",
198204
),
199205
},
200206
},
@@ -267,10 +273,9 @@ func TestEstimateFeeWithVMInvoke(t *testing.T) {
267273
},
268274
expected: []rpc.FeeEstimate{
269275
createFeeEstimate(t,
270-
"0x0", "0x2",
271-
"0xbde1b", "0x1",
272-
"0x80", "0x2",
273-
"0xacaea", rpc.FRI,
276+
"0xbde1b",
277+
"0x80",
278+
"0xacaea",
274279
),
275280
},
276281
},
@@ -322,29 +327,20 @@ func TestEstimateFeeWithVMInvoke(t *testing.T) {
322327
),
323328
},
324329
{
325-
name: "gas limit exceeded",
330+
name: "gas limit exceeded, ok",
326331
broadcastedTransactions: []rpc.BroadcastedTransaction{
327332
createInvokeTransaction(t,
328333
accountAddr, validEntryPoint, &felt.Zero,
329334
addr, utils.HexToFelt(t, "0x64"), // 100
330335
),
331336
},
332-
jsonErr: rpccore.ErrTransactionExecutionError.CloneWithData(
333-
rpc.TransactionExecutionErrorData{
334-
TransactionIndex: 0,
335-
ExecutionError: mustMarshal(t, executionError{
336-
ClassHash: accountClassHash.String(),
337-
ContractAddress: accountAddr.String(),
338-
Error: executionError{
339-
ClassHash: accountClassHash.String(),
340-
ContractAddress: accountAddr.String(),
341-
Error: "0x4f7574206f6620676173 ('Out of gas')",
342-
Selector: executeEntryPointSelector,
343-
},
344-
Selector: executeEntryPointSelector,
345-
}),
346-
},
347-
),
337+
expected: []rpc.FeeEstimate{
338+
createFeeEstimate(t,
339+
"0x5f71ed",
340+
"0x80",
341+
"0x1372ee",
342+
),
343+
},
348344
},
349345
}
350346

@@ -362,24 +358,27 @@ func runTests(t *testing.T, tests []test, handler *rpc.Handler) {
362358

363359
if test.jsonErr != nil {
364360
require.Equal(t, test.jsonErr, jsonErr,
365-
fmt.Sprintf("expected: %v\n, got: %v\n",
366-
handleJSONError(t, test.jsonErr),
367-
handleJSONError(t, jsonErr),
368-
),
361+
msg(t, test.expected, feeEstimate, test.jsonErr, jsonErr),
369362
)
370363
return
371364
}
372365

373366
require.Equal(t, test.expected, feeEstimate,
374-
fmt.Sprintf("expected: %s\n, got: %s\n",
375-
mustMarshal(t, test.expected),
376-
mustMarshal(t, feeEstimate),
377-
),
367+
msg(t, test.expected, feeEstimate, test.jsonErr, jsonErr),
378368
)
379369
})
380370
}
381371
}
382372

373+
func msg(t *testing.T, expectedResult, result []rpc.FeeEstimate, expectedError, err *jsonrpc.Error) string {
374+
return fmt.Sprintf("expected: %s\n, got: %s\nexpected error: %s\n, got: %s\n",
375+
mustMarshal(t, expectedResult),
376+
mustMarshal(t, result),
377+
handleJSONError(t, expectedError),
378+
handleJSONError(t, err),
379+
)
380+
}
381+
383382
func mustMarshal(t *testing.T, v any) json.RawMessage {
384383
t.Helper()
385384
data, err := json.Marshal(v)
@@ -524,20 +523,19 @@ func createResourceBounds(t *testing.T,
524523
}
525524

526525
func createFeeEstimate(t *testing.T,
527-
l1GasConsumed, l1GasPrice,
528-
l2GasConsumed, l2GasPrice,
529-
l1DataGasConsumed, l1DataGasPrice,
530-
overallFee string, unit rpc.FeeUnit,
526+
l2GasConsumed,
527+
l1DataGasConsumed,
528+
overallFee string,
531529
) rpc.FeeEstimate {
532530
return rpc.FeeEstimate{
533-
L1GasConsumed: utils.HexToFelt(t, l1GasConsumed),
534-
L1GasPrice: utils.HexToFelt(t, l1GasPrice),
531+
L1GasConsumed: &felt.Zero,
532+
L1GasPrice: utils.HexToFelt(t, "0x2"),
535533
L2GasConsumed: utils.HexToFelt(t, l2GasConsumed),
536-
L2GasPrice: utils.HexToFelt(t, l2GasPrice),
534+
L2GasPrice: utils.HexToFelt(t, "0x1"),
537535
L1DataGasConsumed: utils.HexToFelt(t, l1DataGasConsumed),
538-
L1DataGasPrice: utils.HexToFelt(t, l1DataGasPrice),
536+
L1DataGasPrice: utils.HexToFelt(t, "0x2"),
539537
OverallFee: utils.HexToFelt(t, overallFee),
540-
Unit: utils.HeapPtr(unit),
538+
Unit: utils.HeapPtr(rpc.FRI),
541539
}
542540
}
543541

0 commit comments

Comments
 (0)