2020
2121WITHDRAWALS_FORK = "shanghai"
2222
23+ ONE_GWEI = 10 ** 9
24+
2325# Common contracts across withdrawals tests
2426SET_STORAGE = Yul (
2527 """
@@ -67,7 +69,7 @@ def test_withdrawals_use_value_in_tx(_):
6769 tx = Transaction (
6870 # Transaction sent from the `TestAddress`, which has 0 balance at start
6971 nonce = 0 ,
70- gas_price = 10 ,
72+ gas_price = ONE_GWEI ,
7173 gas_limit = 21000 ,
7274 to = to_address (0x100 ),
7375 data = "0x" ,
@@ -77,7 +79,7 @@ def test_withdrawals_use_value_in_tx(_):
7779 index = 0 ,
7880 validator = 0 ,
7981 address = TestAddress ,
80- amount = tx .gas_price * tx . gas_limit + 1 ,
82+ amount = tx .gas_limit + 1 ,
8183 )
8284
8385 blocks = [
@@ -100,7 +102,7 @@ def test_withdrawals_use_value_in_tx(_):
100102 ),
101103 ]
102104 post = {
103- TestAddress : Account (balance = 1 ),
105+ TestAddress : Account (balance = ONE_GWEI ),
104106 }
105107
106108 yield BlockchainTest (pre = pre , post = post , blocks = blocks )
@@ -111,17 +113,17 @@ def test_withdrawals_use_value_in_contract(_):
111113 """
112114 Test sending value from contract that has not received a withdrawal
113115 """
114- SEND_ONE_WEI = Yul (
116+ SEND_ONE_GWEI = Yul (
115117 """
116118 {
117- let ret := call(gas(), 0x200, 1 , 0, 0, 0, 0)
119+ let ret := call(gas(), 0x200, 1000000000 , 0, 0, 0, 0)
118120 sstore(number(), ret)
119121 }
120122 """
121123 )
122124 pre = {
123125 TestAddress : Account (balance = 1000000000000000000000 , nonce = 0 ),
124- to_address (0x100 ): Account (balance = 0 , code = SEND_ONE_WEI ),
126+ to_address (0x100 ): Account (balance = 0 , code = SEND_ONE_GWEI ),
125127 to_address (0x200 ): Account (balance = 0 ),
126128 }
127129 tx = Transaction (
@@ -157,7 +159,7 @@ def test_withdrawals_use_value_in_contract(_):
157159 }
158160 ),
159161 to_address (0x200 ): Account (
160- balance = 1 ,
162+ balance = ONE_GWEI ,
161163 ),
162164 }
163165
@@ -184,7 +186,7 @@ def test_withdrawals_balance_within_block(_):
184186 code = SAVE_BALANCE_ON_BLOCK_NUMBER ,
185187 ),
186188 to_address (0x200 ): Account (
187- balance = 1 ,
189+ balance = ONE_GWEI ,
188190 ),
189191 }
190192 blocks = [
@@ -202,7 +204,7 @@ def test_withdrawals_balance_within_block(_):
202204 index = 0 ,
203205 validator = 0 ,
204206 address = to_address (0x200 ),
205- amount = 10 ** 9 ,
207+ amount = 1 ,
206208 )
207209 ],
208210 ),
@@ -221,8 +223,8 @@ def test_withdrawals_balance_within_block(_):
221223 post = {
222224 to_address (0x100 ): Account (
223225 storage = {
224- 1 : 1 ,
225- 2 : 10 ** 9 + 1 ,
226+ 1 : ONE_GWEI ,
227+ 2 : 2 * ONE_GWEI ,
226228 }
227229 )
228230 }
@@ -267,7 +269,7 @@ def test_withdrawals_multiple_withdrawals_same_address(_):
267269 index = i ,
268270 validator = 0 ,
269271 address = ADDRESSES [i % len (ADDRESSES )],
270- amount = 10 ** 9 ,
272+ amount = 1 ,
271273 )
272274 for i in range (len (ADDRESSES ) * 16 )
273275 ],
@@ -278,7 +280,7 @@ def test_withdrawals_multiple_withdrawals_same_address(_):
278280
279281 for addr in ADDRESSES :
280282 post [addr ] = Account (
281- balance = 16 * 10 ** 9 ,
283+ balance = 16 * ONE_GWEI ,
282284 storage = {},
283285 )
284286
@@ -294,7 +296,7 @@ def test_withdrawals_multiple_withdrawals_same_address(_):
294296 index = i * 16 + j ,
295297 validator = i ,
296298 address = ADDRESSES [i ],
297- amount = 10 ** 9 ,
299+ amount = 1 ,
298300 )
299301 for j in range (16 )
300302 ],
@@ -319,7 +321,7 @@ def test_withdrawals_many_withdrawals(_):
319321 post = {}
320322 for i in range (N ):
321323 addr = to_address (0x100 * i )
322- amount = i * 10 ** 9
324+ amount = i * 1
323325 pre [addr ] = Account (
324326 code = SET_STORAGE ,
325327 )
@@ -333,7 +335,7 @@ def test_withdrawals_many_withdrawals(_):
333335 )
334336 post [addr ] = Account (
335337 code = SET_STORAGE ,
336- balance = amount ,
338+ balance = amount * ONE_GWEI ,
337339 storage = {},
338340 )
339341
@@ -357,7 +359,7 @@ def test_withdrawals_self_destructing_account(_):
357359 TestAddress : Account (balance = 1000000000000000000000 , nonce = 0 ),
358360 to_address (0x100 ): Account (
359361 code = SELFDESTRUCT ,
360- balance = 100 ,
362+ balance = ( 100 * ONE_GWEI ) ,
361363 ),
362364 to_address (0x200 ): Account (
363365 balance = 0 ,
@@ -378,7 +380,7 @@ def test_withdrawals_self_destructing_account(_):
378380 index = 0 ,
379381 validator = 0 ,
380382 address = to_address (0x100 ),
381- amount = 99 ,
383+ amount = ( 99 ) ,
382384 )
383385
384386 block = Block (
@@ -389,11 +391,11 @@ def test_withdrawals_self_destructing_account(_):
389391 post = {
390392 to_address (0x100 ): Account (
391393 code = None ,
392- balance = 99 ,
394+ balance = ( 99 * ONE_GWEI ) ,
393395 ),
394396 to_address (0x200 ): Account (
395397 code = None ,
396- balance = 100 ,
398+ balance = ( 100 * ONE_GWEI ) ,
397399 ),
398400 }
399401
@@ -444,16 +446,16 @@ def test_withdrawals_newly_created_contract(_):
444446 post = {
445447 created_contract : Account (
446448 code = "0x00" ,
447- balance = 1 ,
449+ balance = ONE_GWEI ,
448450 ),
449451 }
450452
451453 yield BlockchainTest (pre = pre , post = post , blocks = [block ])
452454
453455 # Same test but include value in the contract creating transaction
454456
455- tx .value = 1
456- post [created_contract ].balance = 2
457+ tx .value = ONE_GWEI
458+ post [created_contract ].balance = 2 * ONE_GWEI
457459
458460 yield BlockchainTest (pre = pre , post = post , blocks = [block ])
459461
@@ -497,13 +499,13 @@ def test_withdrawals_no_evm_execution(_):
497499 index = 0 ,
498500 validator = 0 ,
499501 address = to_address (0x100 ),
500- amount = 10 ** 9 ,
502+ amount = 1 ,
501503 ),
502504 Withdrawal (
503505 index = 1 ,
504506 validator = 1 ,
505507 address = to_address (0x200 ),
506- amount = 10 ** 9 ,
508+ amount = 1 ,
507509 ),
508510 ],
509511 ),
@@ -525,13 +527,13 @@ def test_withdrawals_no_evm_execution(_):
525527 index = 0 ,
526528 validator = 0 ,
527529 address = to_address (0x300 ),
528- amount = 10 ** 9 ,
530+ amount = 1 ,
529531 ),
530532 Withdrawal (
531533 index = 1 ,
532534 validator = 1 ,
533535 address = to_address (0x400 ),
534- amount = 10 ** 9 ,
536+ amount = 1 ,
535537 ),
536538 ],
537539 ),
@@ -562,6 +564,10 @@ def test_withdrawals_zero_amount(_):
562564 code = "0x00" ,
563565 balance = 0 ,
564566 ),
567+ to_address (0x300 ): Account (
568+ code = "0x00" ,
569+ balance = 0 ,
570+ ),
565571 }
566572
567573 withdrawal_1 = Withdrawal (
@@ -584,6 +590,10 @@ def test_withdrawals_zero_amount(_):
584590 code = "0x00" ,
585591 balance = 0 ,
586592 ),
593+ to_address (0x300 ): Account (
594+ code = "0x00" ,
595+ balance = 0 ,
596+ ),
587597 }
588598
589599 yield BlockchainTest (pre = pre , post = post , blocks = [block ])
@@ -597,7 +607,19 @@ def test_withdrawals_zero_amount(_):
597607 amount = 1 ,
598608 )
599609 block .withdrawals .append (withdrawal_2 )
600- post [to_address (0x200 )].balance = 1
610+ post [to_address (0x200 )].balance = ONE_GWEI
611+ yield BlockchainTest (pre = pre , post = post , blocks = [block ])
612+
613+ # Same test but add another withdrawal with max amount in same
614+ # block.
615+ withdrawal_3 = Withdrawal (
616+ index = 2 ,
617+ validator = 0 ,
618+ address = to_address (0x300 ),
619+ amount = 2 ** 64 - 1 ,
620+ )
621+ block .withdrawals .append (withdrawal_3 )
622+ post [to_address (0x300 )].balance = (2 ** 64 - 1 ) * ONE_GWEI
601623 yield BlockchainTest (pre = pre , post = post , blocks = [block ])
602624
603625 # Same test but reverse order of withdrawals.
0 commit comments