1
- import os
2
- import time
3
-
4
1
import flexitest
5
2
from web3 import Web3
6
3
from web3 ._utils .events import get_event_data
7
4
8
- from envs import testenv
5
+ from envs import net_settings , testenv
6
+ from mixins .bridge_out_precompile_contract_mixin import BridgePrecompileMixin
7
+ from utils import *
9
8
from utils .constants import PRECOMPILE_BRIDGEOUT_ADDRESS
10
9
11
10
withdrawal_intent_event_abi = {
12
11
"anonymous" : False ,
13
12
"inputs" : [
14
13
{"indexed" : False , "internalType" : "uint64" , "name" : "amount" , "type" : "uint64" },
15
- {"indexed" : False , "internalType" : "bytes" , "name" : "dest_pk " , "type" : "bytes32 " },
14
+ {"indexed" : False , "internalType" : "bytes" , "name" : "destination " , "type" : "bytes " },
16
15
],
17
16
"name" : "WithdrawalIntentEvent" ,
18
17
"type" : "event" ,
19
18
}
20
- event_signature_text = "WithdrawalIntentEvent(uint64,bytes32 )"
19
+ event_signature_text = "WithdrawalIntentEvent(uint64,bytes )"
21
20
22
21
23
22
@flexitest .register
24
- class ElBridgePrecompileTest (testenv . StrataTestBase ):
23
+ class ElBridgePrecompileTest (BridgePrecompileMixin ):
25
24
def __init__ (self , ctx : flexitest .InitContext ):
26
- ctx .set_env ("basic" )
25
+ ctx .set_env (
26
+ testenv .BasicEnvConfig (
27
+ 101 ,
28
+ prover_client_settings = ProverClientSettings .new_with_proving (),
29
+ rollup_settings = net_settings .get_fast_batch_settings (),
30
+ auto_generate_blocks = True ,
31
+ )
32
+ )
27
33
28
34
def main (self , ctx : flexitest .RunContext ):
29
- self .warning ("SKIPPING TEST fn_el_bridge_precompile" )
30
- return True
31
-
32
- reth = ctx .get_service ("reth" )
33
- web3 : Web3 = reth .create_web3 ()
35
+ web3 : Web3 = self .reth .create_web3 ()
34
36
35
37
source = web3 .address
36
38
dest = web3 .to_checksum_address (PRECOMPILE_BRIDGEOUT_ADDRESS )
37
- # 64 bytes
38
- dest_pk = os . urandom ( 32 ). hex ( )
39
- self .debug ( dest_pk )
39
+
40
+ priv_keys = get_priv_keys ( ctx )
41
+ self .deposit ( ctx , self . deployed_contract_receipt . contractAddress , priv_keys )
40
42
41
43
assert web3 .is_connected (), "cannot connect to reth"
42
44
@@ -46,24 +48,36 @@ def main(self, ctx: flexitest.RunContext):
46
48
47
49
assert original_bridge_balance == 0
48
50
49
- # 10 rollup btc as wei
50
- to_transfer_wei = 10_000_000_000_000_000_000
51
+ cfg = ctx .env .rollup_cfg ()
52
+ deposit_amount = cfg .deposit_amount
53
+ to_transfer_sats = deposit_amount * 10_000_000_000
54
+ to_transfer_wei = to_transfer_sats # Same value in wei
55
+ dest_pk = "0x04db4c79cc3ffca26f51e21241b9332d646b0772dd7e98de9c1de6b10990cab80b"
51
56
52
57
txid = web3 .eth .send_transaction (
53
58
{
54
59
"to" : dest ,
55
- "value" : hex (to_transfer_wei ),
56
- "gas" : hex (100000 ),
60
+ "value" : hex (to_transfer_sats ),
57
61
"from" : source ,
62
+ "gas" : hex (200000 ),
58
63
"data" : dest_pk ,
59
64
}
60
65
)
61
- self .debug (txid .to_0x_hex ())
62
66
63
- # build block
64
- time .sleep (2 )
65
-
66
- receipt = web3 .eth .get_transaction_receipt (txid )
67
+ def check_transaction_and_blocks ():
68
+ try :
69
+ receipt = web3 .eth .get_transaction_receipt (txid )
70
+ return receipt
71
+ except Exception as e :
72
+ return e
73
+
74
+ receipt = wait_until_with_value (
75
+ check_transaction_and_blocks ,
76
+ lambda result : not isinstance (result , Exception ),
77
+ error_with = "Transaction receipt for txid not available" ,
78
+ timeout = 60 ,
79
+ step = 2 ,
80
+ )
67
81
68
82
assert receipt .status == 1 , "precompile transaction failed"
69
83
assert len (receipt .logs ) == 1 , "no logs or invalid logs"
@@ -74,11 +88,8 @@ def main(self, ctx: flexitest.RunContext):
74
88
assert log .topics [0 ].hex () == event_signature_hash
75
89
event_data = get_event_data (web3 .codec , withdrawal_intent_event_abi , log )
76
90
77
- # 1 rollup btc = 10**18 wei
78
- to_transfer_sats = to_transfer_wei // 10_000_000_000
79
-
80
- assert event_data .args .amount == to_transfer_sats
81
- assert event_data .args .dest_pk .hex () == dest_pk
91
+ assert event_data .args .amount == deposit_amount
92
+ assert event_data .args .destination .hex () == dest_pk [2 :] # Remove 0x prefix for comparison
82
93
83
94
final_block_no = web3 .eth .block_number
84
95
final_bridge_balance = web3 .eth .get_balance (dest )
0 commit comments