@@ -64,7 +64,11 @@ func TestEstimateFee(t *testing.T) {
64
64
NumSteps : uint64 (123 ),
65
65
}, nil )
66
66
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
+ )
68
72
require .Nil (t , err )
69
73
assert .Equal (t , httpHeader .Get (rpc .ExecutionStepsHeader ), "123" )
70
74
})
@@ -76,7 +80,11 @@ func TestEstimateFee(t *testing.T) {
76
80
Cause : json .RawMessage ("oops" ),
77
81
})
78
82
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
+ )
80
88
require .Equal (t , rpccore .ErrTransactionExecutionError .CloneWithData (rpc.TransactionExecutionErrorData {
81
89
TransactionIndex : 44 ,
82
90
ExecutionError : json .RawMessage ("oops" ),
@@ -150,10 +158,9 @@ func TestEstimateFeeWithVMDeclare(t *testing.T) {
150
158
},
151
159
expected : []rpc.FeeEstimate {
152
160
createFeeEstimate (t ,
153
- "0x0" , "0x2" ,
154
- "0x4176980" , "0x1" ,
155
- "0xc0" , "0x2" ,
156
- "0x4176b00" , rpc .FRI ,
161
+ "0x4802740" ,
162
+ "0xc0" ,
163
+ "0x4176b00" ,
157
164
),
158
165
},
159
166
},
@@ -191,10 +198,9 @@ func TestEstimateFeeWithVMDeploy(t *testing.T) {
191
198
},
192
199
expected : []rpc.FeeEstimate {
193
200
createFeeEstimate (t ,
194
- "0x0" , "0x2" ,
195
- "0xfdb0d" , "0x1" ,
196
- "0xe0" , "0x2" ,
197
- "0xe6bcc" , rpc .FRI ,
201
+ "0xfdb0d" ,
202
+ "0xe0" ,
203
+ "0xe6bcc" ,
198
204
),
199
205
},
200
206
},
@@ -267,10 +273,9 @@ func TestEstimateFeeWithVMInvoke(t *testing.T) {
267
273
},
268
274
expected : []rpc.FeeEstimate {
269
275
createFeeEstimate (t ,
270
- "0x0" , "0x2" ,
271
- "0xbde1b" , "0x1" ,
272
- "0x80" , "0x2" ,
273
- "0xacaea" , rpc .FRI ,
276
+ "0xbde1b" ,
277
+ "0x80" ,
278
+ "0xacaea" ,
274
279
),
275
280
},
276
281
},
@@ -322,29 +327,20 @@ func TestEstimateFeeWithVMInvoke(t *testing.T) {
322
327
),
323
328
},
324
329
{
325
- name : "gas limit exceeded" ,
330
+ name : "gas limit exceeded, ok " ,
326
331
broadcastedTransactions : []rpc.BroadcastedTransaction {
327
332
createInvokeTransaction (t ,
328
333
accountAddr , validEntryPoint , & felt .Zero ,
329
334
addr , utils .HexToFelt (t , "0x64" ), // 100
330
335
),
331
336
},
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
+ },
348
344
},
349
345
}
350
346
@@ -362,24 +358,27 @@ func runTests(t *testing.T, tests []test, handler *rpc.Handler) {
362
358
363
359
if test .jsonErr != nil {
364
360
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 ),
369
362
)
370
363
return
371
364
}
372
365
373
366
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 ),
378
368
)
379
369
})
380
370
}
381
371
}
382
372
373
+ func msg (t * testing.T , expectedResult , result []rpc.FeeEstimate , expectedError , err * jsonrpc.Error ) string {
374
+ return fmt .Sprintf ("expected: %s\n , got: %s\n expected 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
+
383
382
func mustMarshal (t * testing.T , v any ) json.RawMessage {
384
383
t .Helper ()
385
384
data , err := json .Marshal (v )
@@ -524,20 +523,19 @@ func createResourceBounds(t *testing.T,
524
523
}
525
524
526
525
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 ,
531
529
) rpc.FeeEstimate {
532
530
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" ),
535
533
L2GasConsumed : utils .HexToFelt (t , l2GasConsumed ),
536
- L2GasPrice : utils .HexToFelt (t , l2GasPrice ),
534
+ L2GasPrice : utils .HexToFelt (t , "0x1" ),
537
535
L1DataGasConsumed : utils .HexToFelt (t , l1DataGasConsumed ),
538
- L1DataGasPrice : utils .HexToFelt (t , l1DataGasPrice ),
536
+ L1DataGasPrice : utils .HexToFelt (t , "0x2" ),
539
537
OverallFee : utils .HexToFelt (t , overallFee ),
540
- Unit : utils .HeapPtr (unit ),
538
+ Unit : utils .HeapPtr (rpc . FRI ),
541
539
}
542
540
}
543
541
0 commit comments