@@ -4,7 +4,9 @@ use test_utils::runner::Contract;
4
4
use test_utils:: running_tests:: run_test_case;
5
5
use test_utils:: { assert_gas, assert_passed, test_case} ;
6
6
7
- // gas values comes from https://book.starknet.io/ch03-01-02-fee-mechanism.html#computation
7
+ // all calculations are based on formula from
8
+ // https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/fee-mechanism/#overall_fee
9
+
8
10
#[ test]
9
11
fn declare_cost_is_omitted ( ) {
10
12
let test = test_case ! (
@@ -32,7 +34,6 @@ fn declare_cost_is_omitted() {
32
34
assert_gas ! ( result, "declare_cost_is_omitted" , 1 ) ;
33
35
}
34
36
35
- // FIXME(#1596): Code (steps) was added but the cost did not change
36
37
#[ test]
37
38
fn deploy_syscall_cost ( ) {
38
39
let test = test_case ! (
@@ -59,10 +60,39 @@ fn deploy_syscall_cost() {
59
60
let result = run_test_case ( & test) ;
60
61
61
62
assert_passed ! ( result) ;
62
- // 1224 = 2 * cost per 32-byte word (contract_address and contract modification info)
63
- // 612 = updated class_hash (through deploy)
64
63
// 6 = gas cost from steps
65
- assert_gas ! ( result, "deploy_syscall_cost" , 1224 + 612 + 6 ) ;
64
+ // 1101 = gas cost of onchain data (deploy cost)
65
+ assert_gas ! ( result, "deploy_syscall_cost" , 6 + 1101 ) ;
66
+ }
67
+
68
+ #[ test]
69
+ fn snforge_std_deploy_cost ( ) {
70
+ let test = test_case ! (
71
+ indoc!(
72
+ r"
73
+ use snforge_std::{ declare, ContractClassTrait };
74
+
75
+ #[test]
76
+ fn deploy_cost() {
77
+ let contract = declare('GasChecker');
78
+ let address = contract.deploy(@array![]).unwrap();
79
+ assert(address != 0.try_into().unwrap(), 'wrong deployed addr');
80
+ }
81
+ "
82
+ ) ,
83
+ Contract :: from_code_path(
84
+ "GasChecker" . to_string( ) ,
85
+ Path :: new( "tests/data/contracts/gas_checker.cairo" ) ,
86
+ )
87
+ . unwrap( )
88
+ ) ;
89
+
90
+ let result = run_test_case ( & test) ;
91
+
92
+ assert_passed ! ( result) ;
93
+ // 2 = gas cost from steps
94
+ // 1101 = gas cost of onchain data (deploy cost)
95
+ assert_gas ! ( result, "deploy_cost" , 2 + 1101 ) ;
66
96
}
67
97
68
98
#[ test]
@@ -114,9 +144,9 @@ fn contract_keccak_cost() {
114
144
let result = run_test_case ( & test) ;
115
145
116
146
assert_passed ! ( result) ;
117
- // 1836 = 3 * cost per 32-byte word (deploy )
147
+ // 1101 = cost of deploy (see snforge_std_deploy_cost test )
118
148
// 11 = cost of single keccak builtin
119
- assert_gas ! ( result, "contract_keccak_cost" , 1836 + 11 ) ;
149
+ assert_gas ! ( result, "contract_keccak_cost" , 1101 + 11 ) ;
120
150
}
121
151
122
152
#[ test]
@@ -172,9 +202,9 @@ fn contract_range_check_cost() {
172
202
let result = run_test_case ( & test) ;
173
203
174
204
assert_passed ! ( result) ;
175
- // 1836 = 3 * cost per 32-byte word (deploy )
205
+ // 1101 = cost of deploy (see snforge_std_deploy_cost test )
176
206
// 2 = cost of 22 range check builtins
177
- assert_gas ! ( result, "contract_range_check_cost" , 1836 + 2 ) ;
207
+ assert_gas ! ( result, "contract_range_check_cost" , 1101 + 2 ) ;
178
208
}
179
209
180
210
#[ test]
@@ -228,9 +258,9 @@ fn contract_bitwise_cost() {
228
258
let result = run_test_case ( & test) ;
229
259
230
260
assert_passed ! ( result) ;
231
- // 1836 = 3 * cost per 32-byte word (deploy )
261
+ // 1101 = cost of deploy (see snforge_std_deploy_cost test )
232
262
// 2 = cost of 6 bitwise builtins
233
- assert_gas ! ( result, "contract_bitwise_cost" , 1836 + 2 ) ;
263
+ assert_gas ! ( result, "contract_bitwise_cost" , 1101 + 2 ) ;
234
264
}
235
265
236
266
#[ test]
@@ -284,9 +314,9 @@ fn contract_pedersen_cost() {
284
314
let result = run_test_case ( & test) ;
285
315
286
316
assert_passed ! ( result) ;
287
- // 1836 = 3 * cost per 32-byte word (deploy )
317
+ // 1101 = cost of deploy (see snforge_std_deploy_cost test )
288
318
// 2 = cost of 12 pedersen builtins
289
- assert_gas ! ( result, "contract_pedersen_cost" , 1836 + 2 ) ;
319
+ assert_gas ! ( result, "contract_pedersen_cost" , 1101 + 2 ) ;
290
320
}
291
321
292
322
#[ test]
@@ -340,9 +370,9 @@ fn contract_poseidon_cost() {
340
370
let result = run_test_case ( & test) ;
341
371
342
372
assert_passed ! ( result) ;
343
- // 1836 = 3 * cost per 32-byte word (deploy )
373
+ // 1101 = cost of deploy (see snforge_std_deploy_cost test )
344
374
// 2 = cost of 12 poseidon builtins
345
- assert_gas ! ( result, "contract_poseidon_cost" , 1836 + 2 ) ;
375
+ assert_gas ! ( result, "contract_poseidon_cost" , 1101 + 2 ) ;
346
376
}
347
377
348
378
#[ test]
@@ -397,9 +427,9 @@ fn contract_ec_op_cost() {
397
427
let result = run_test_case ( & test) ;
398
428
399
429
assert_passed ! ( result) ;
400
- // 1836 = 3 * cost per 32-byte word (deploy )
430
+ // 1101 = cost of deploy (see snforge_std_deploy_cost test )
401
431
// 6 = cost of single ec_op builtin
402
- assert_gas ! ( result, "contract_ec_op_cost" , 1836 + 6 ) ;
432
+ assert_gas ! ( result, "contract_ec_op_cost" , 1101 + 6 ) ;
403
433
}
404
434
405
435
#[ test]
@@ -434,10 +464,9 @@ fn storage_write_cost() {
434
464
let result = run_test_case ( & test) ;
435
465
436
466
assert_passed ! ( result) ;
437
- // 1836 = 3 * cost per 32-byte word (deploy)
438
- // 1224 = 2 * cost per 32-byte word (storage write)
439
467
// 3 = gas cost of steps
440
- assert_gas ! ( result, "storage_write_cost" , 1836 + 1224 + 3 ) ;
468
+ // 2203 = gas cost of onchain data
469
+ assert_gas ! ( result, "storage_write_cost" , 3 + 2203 ) ;
441
470
}
442
471
443
472
#[ test]
@@ -465,10 +494,9 @@ fn storage_write_from_test_cost() {
465
494
let result = run_test_case ( & test) ;
466
495
467
496
assert_passed ! ( result) ;
468
- // 1224 = 2 * cost per 32-byte word (modified contract)
469
- // 1224 = 2 * cost per 32-byte word (storage write)
470
497
// 1 = gas cost of steps
471
- assert_gas ! ( result, "storage_write_from_test_cost" , 1224 + 1224 + 1 ) ;
498
+ // 1652 = gas cost of onchain data
499
+ assert_gas ! ( result, "storage_write_from_test_cost" , 1 + 1652 ) ;
472
500
}
473
501
474
502
#[ test]
@@ -504,10 +532,9 @@ fn multiple_storage_writes_cost() {
504
532
let result = run_test_case ( & test) ;
505
533
506
534
assert_passed ! ( result) ;
507
- // 1836 = 3 * cost per 32-byte word (deploy)
508
- // 1224 = 2 * cost per 32-byte word (storage write)
509
535
// 3 = gas cost of steps
510
- assert_gas ! ( result, "multiple_storage_writes_cost" , 1836 + 1224 + 3 ) ;
536
+ // 2203 = gas cost of onchain data
537
+ assert_gas ! ( result, "multiple_storage_writes_cost" , 3 + 2203 ) ;
511
538
}
512
539
513
540
#[ test]
@@ -542,10 +569,9 @@ fn l1_message_cost() {
542
569
let result = run_test_case ( & test) ;
543
570
544
571
assert_passed ! ( result) ;
545
- // 1836 = 3 * cost per 32-byte word (deploy)
546
- // 2448 = 4 * cost per 32-byte word (l2_l1_message, header is of length 3 and payload size is 1)
547
572
// 3 = gas cost of steps
548
- assert_gas ! ( result, "l1_message_cost" , 1836 + 2448 + 3 ) ;
573
+ // 27865 = gas cost of onchain data
574
+ assert_gas ! ( result, "l1_message_cost" , 3 + 27865 ) ;
549
575
}
550
576
551
577
#[ test]
@@ -562,9 +588,9 @@ fn l1_message_from_test_cost() {
562
588
let result = run_test_case ( & test) ;
563
589
564
590
assert_passed ! ( result) ;
565
- // 2448 = 4 * cost per 32-byte word (l2_l1_message, header is of length 3 and payload size is 1)
566
591
// 1 = gas cost of steps
567
- assert_gas ! ( result, "l1_message_from_test_cost" , 2448 + 1 ) ;
592
+ // 26764 = gas cost of onchain data
593
+ assert_gas ! ( result, "l1_message_from_test_cost" , 1 + 26764 ) ;
568
594
}
569
595
570
596
#[ test]
@@ -611,9 +637,7 @@ fn l1_message_cost_for_proxy() {
611
637
let result = run_test_case ( & test) ;
612
638
613
639
assert_passed ! ( result) ;
614
- // 1836 = 3 * cost per 32-byte word (deploy)
615
- // 1836 = 3 * cost per 32-byte word (deploy)
616
- // 2448 = 4 * cost per 32-byte word (l2_l1_message, header is of length 3 and payload size is 1)
617
640
// 8 = gas cost of steps
618
- assert_gas ! ( result, "l1_message_cost_for_proxy" , 1836 + 1836 + 2448 + 8 ) ;
641
+ // 29206 = gas cost of onchain data
642
+ assert_gas ! ( result, "l1_message_cost_for_proxy" , 8 + 29206 ) ;
619
643
}
0 commit comments