|
7 | 7 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) |
8 | 8 |
|
9 | 9 | from l1_events import L1Events |
| 10 | +from test_utils import TestUtils |
10 | 11 |
|
11 | 12 |
|
12 | 13 | class TestL1Events(unittest.TestCase): |
13 | | - RAW_JSON_LOG = { |
14 | | - "address": "0xc662c410c0ecf747543f5ba90660f6abebd9c8c4", |
15 | | - "topics": [ |
16 | | - "0xdb80dd488acf86d17c747445b0eabb5d57c541d3bd7b6b87af987858e5066b2b", # event_signature |
17 | | - "0x000000000000000000000000f5b6ee2caeb6769659f6c091d209dfdcaf3f69eb", # from_address |
18 | | - "0x0616757a151c21f9be8775098d591c2807316d992bbc3bb1a5c1821630589256", # to_address |
19 | | - "0x01b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb19", # selector |
20 | | - ], |
21 | | - "data": "0x0000000000000000000000000000000000000000000000000000000000000060" |
22 | | - "000000000000000000000000000000000000000000000000000000000019b255" |
23 | | - "00000000000000000000000000000000000000000000000000001308aba4ade2" |
24 | | - "0000000000000000000000000000000000000000000000000000000000000005" |
25 | | - "00000000000000000000000004c46e830bb56ce22735d5d8fc9cb90309317d0f" |
26 | | - "000000000000000000000000c50a951c4426760ba75c5253985a16196b342168" |
27 | | - "011bf9dbebdd770c31ff13808c96a1cb2de15a240274dc527e7d809bb2bf38df" |
28 | | - "0000000000000000000000000000000000000000000000956dfdeac59085edc3" |
29 | | - "0000000000000000000000000000000000000000000000000000000000000000", |
30 | | - "blockHash": "0xb33512d13e1a2ff4f3aa6e799a4a2455249be5198760a3f41300a8362d802bf8", |
31 | | - "blockNumber": "0x16cda82", |
32 | | - "blockTimestamp": "0x692c23df", |
33 | | - "transactionHash": "0x726df509fdd23a944f923a6fc18e80cbe7300a54aa34f8e6bd77e9961ca6ce52", |
34 | | - "transactionIndex": "0x4f", |
35 | | - "logIndex": "0x7b", |
36 | | - "removed": False, |
37 | | - } |
38 | | - |
39 | | - L1_EVENT = L1Events.L1Event( |
40 | | - contract_address="0x616757a151c21f9be8775098d591c2807316d992bbc3bb1a5c1821630589256", |
41 | | - entry_point_selector=0x1B64B1B3B690B43B9B514FB81377518F4039CD3E4F4914D8A6BDF01D679FB19, |
42 | | - calldata=[ |
43 | | - 0xF5B6EE2CAEB6769659F6C091D209DFDCAF3F69EB, |
44 | | - 0x04C46E830BB56CE22735D5D8FC9CB90309317D0F, |
45 | | - 0xC50A951C4426760BA75C5253985A16196B342168, |
46 | | - 0x11BF9DBEBDD770C31FF13808C96A1CB2DE15A240274DC527E7D809BB2BF38DF, |
47 | | - 0x956DFDEAC59085EDC3, |
48 | | - 0x0, |
49 | | - ], |
50 | | - nonce=0x19B255, |
51 | | - fee=0x1308ABA4ADE2, |
52 | | - l1_tx_hash="0x726df509fdd23a944f923a6fc18e80cbe7300a54aa34f8e6bd77e9961ca6ce52", |
53 | | - block_timestamp=1764500447, |
54 | | - block_number=23911042, |
55 | | - ) |
56 | | - |
57 | | - # L1_HANDLER tx from feeder gateway, expected to match the L1Event decoded from L1 logs. |
58 | | - FEEDER_TX = { |
59 | | - "transaction_hash": "0x83c298ad90f4d1b35c0a324fa162a3ab3d3d3a4dcc046f0965bd045083a472", |
60 | | - "version": "0x0", |
61 | | - "contract_address": "0x616757a151c21f9be8775098d591c2807316d992bbc3bb1a5c1821630589256", |
62 | | - "entry_point_selector": "0x1b64b1b3b690b43b9b514fb81377518f4039cd3e4f4914d8a6bdf01d679fb19", |
63 | | - "nonce": "0x19b255", |
64 | | - "calldata": [ |
65 | | - "0xf5b6ee2caeb6769659f6c091d209dfdcaf3f69eb", |
66 | | - "0x4c46e830bb56ce22735d5d8fc9cb90309317d0f", |
67 | | - "0xc50a951c4426760ba75c5253985a16196b342168", |
68 | | - "0x11bf9dbebdd770c31ff13808c96a1cb2de15a240274dc527e7d809bb2bf38df", |
69 | | - "0x956dfdeac59085edc3", |
70 | | - "0x0", |
71 | | - ], |
72 | | - "type": "L1_HANDLER", |
73 | | - } |
74 | | - |
75 | 14 | def test_decode_log_success(self): |
76 | | - result = L1Events.decode_log(self.RAW_JSON_LOG) |
| 15 | + result = L1Events.decode_log(TestUtils.RAW_JSON_LOG) |
77 | 16 |
|
78 | 17 | self.assertIsInstance(result, L1Events.L1Event) |
79 | | - self.assertEqual(result, self.L1_EVENT) |
| 18 | + self.assertEqual(result, TestUtils.L1_EVENT) |
80 | 19 |
|
81 | 20 | def test_decode_log_invalid_topics_raises_error(self): |
82 | 21 | with self.assertRaisesRegex( |
83 | 22 | ValueError, "Log has insufficient topics for LogMessageToL2 event" |
84 | 23 | ): |
85 | | - log = copy.deepcopy(self.RAW_JSON_LOG) |
| 24 | + log = copy.deepcopy(TestUtils.RAW_JSON_LOG) |
86 | 25 | log["topics"] = ["0x1", "0x2"] |
87 | 26 | L1Events.decode_log(log) |
88 | 27 |
|
89 | 28 | def test_decode_log_wrong_signature_raises_error(self): |
90 | | - log = copy.deepcopy(self.RAW_JSON_LOG) |
| 29 | + log = copy.deepcopy(TestUtils.RAW_JSON_LOG) |
91 | 30 | log["topics"][0] = "0x0000000000000000000000000000000000000000000000000000000000000001" |
92 | 31 | with self.assertRaisesRegex(ValueError, "Unhandled event signature"): |
93 | 32 | L1Events.decode_log(log) |
94 | 33 |
|
95 | 34 | def test_matches_l1_handler_tx_success(self): |
96 | | - l1_event = self.L1_EVENT |
| 35 | + l1_event = TestUtils.L1_EVENT |
97 | 36 |
|
98 | | - feeder_tx = self.FEEDER_TX |
| 37 | + feeder_tx = TestUtils.FEEDER_TX |
99 | 38 |
|
100 | 39 | self.assertTrue(L1Events.l1_event_matches_feeder_tx(l1_event, feeder_tx)) |
101 | 40 |
|
102 | 41 | def test_matches_l1_handler_tx_mismatches(self): |
103 | | - l1_event = self.L1_EVENT |
| 42 | + l1_event = TestUtils.L1_EVENT |
104 | 43 |
|
105 | | - base_feeder_tx = self.FEEDER_TX |
| 44 | + base_feeder_tx = TestUtils.FEEDER_TX |
106 | 45 |
|
107 | 46 | mismatch_cases = [ |
108 | 47 | ("type", {"type": "INVOKE"}), |
|
0 commit comments