|
6 | 6 |
|
7 | 7 | from ..base_types import Address, Hash, Wei |
8 | 8 | from ..base_types_json import to_json |
9 | | -from ..composite_types import AccessList |
| 9 | +from ..composite_types import AccessList, Account |
10 | 10 |
|
11 | 11 |
|
12 | 12 | @pytest.mark.parametrize( |
@@ -290,3 +290,57 @@ def test_json_deserialization( |
290 | 290 | ) |
291 | 291 | model_type = type(model_instance) |
292 | 292 | assert model_type(**json) == model_instance |
| 293 | + |
| 294 | + |
| 295 | +@pytest.mark.parametrize( |
| 296 | + "account_1, account_2, equal", |
| 297 | + [ |
| 298 | + (Account(), Account(), True), |
| 299 | + (Account(nonce=1), Account(nonce=2), False), |
| 300 | + (Account(nonce=1), Account(nonce=1), True), |
| 301 | + (Account(nonce=1), Account(nonce=1, code="0x1234"), False), |
| 302 | + (Account(nonce=1, code="0x1234"), Account(nonce=1), False), |
| 303 | + ( |
| 304 | + Account(nonce=1, code="0x1234"), |
| 305 | + Account(nonce=1, code="0x1234"), |
| 306 | + True, |
| 307 | + ), |
| 308 | + ( |
| 309 | + Account(nonce=1, code="0x1234"), |
| 310 | + Account(nonce=1, code="0x5678"), |
| 311 | + False, |
| 312 | + ), |
| 313 | + ( |
| 314 | + Account(nonce=1, code="0x1234"), |
| 315 | + Account(nonce=2, code="0x5678"), |
| 316 | + False, |
| 317 | + ), |
| 318 | + ( |
| 319 | + Account(nonce=1, code="0x1234"), |
| 320 | + Account(nonce=2, code="0x1234"), |
| 321 | + False, |
| 322 | + ), |
| 323 | + ( |
| 324 | + Account(nonce=1, code="0x1234"), |
| 325 | + Account(nonce=1, code="0x1234", storage={0: 0, 1: 1}), |
| 326 | + False, |
| 327 | + ), |
| 328 | + ( |
| 329 | + Account(nonce=1, code="0x1234", storage={1: 1, 0: 0}), |
| 330 | + Account(nonce=1, code="0x1234", storage={0: 0, 1: 1}), |
| 331 | + True, |
| 332 | + ), |
| 333 | + ], |
| 334 | +) |
| 335 | +def test_account_hash( |
| 336 | + account_1: Account, account_2: Account, equal: bool |
| 337 | +) -> None: |
| 338 | + """Test two different accounts to return the same hash.""" |
| 339 | + if equal: |
| 340 | + assert account_1.hash() == account_2.hash(), ( |
| 341 | + f"Account 1: {account_1.hash()}, Account 2: {account_2.hash()}" |
| 342 | + ) |
| 343 | + else: |
| 344 | + assert account_1.hash() != account_2.hash(), ( |
| 345 | + f"Account 1: {account_1.hash()}, Account 2: {account_2.hash()}" |
| 346 | + ) |
0 commit comments