Skip to content

Commit b3d8ae5

Browse files
✨ Relaxed testing equality of Account and Address
1 parent fd3530d commit b3d8ae5

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

wake/testing/core.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@
2525
from ..development.transactions import TransactionAbc, TransactionStatusEnum
2626

2727

28+
_ORIG_ADDRESS_EQ = Address.__eq__
29+
_ORIG_ACCOUNT_EQ = Account.__eq__
30+
31+
def enable_relaxed_equality_address_account():
32+
def _address_eq(self: Address, other: Account | Address) -> bool:
33+
if isinstance(other, Account):
34+
return _ORIG_ADDRESS_EQ(self, other.address)
35+
return _ORIG_ADDRESS_EQ(self, other)
36+
37+
def _account_eq(self: Account, other: Account | Address) -> bool:
38+
if isinstance(other, Address):
39+
return _ORIG_ADDRESS_EQ(self.address, other)
40+
return _ORIG_ACCOUNT_EQ(self, other)
41+
42+
Address.__eq__ = _address_eq
43+
Account.__eq__ = _account_eq
44+
45+
def disable_relaxed_equality_address_account():
46+
Address.__eq__ = _ORIG_ADDRESS_EQ
47+
Account.__eq__ = _ORIG_ACCOUNT_EQ
48+
49+
2850
class Chain(wake.development.core.Chain):
2951
_block_gas_limit: int
3052
_gas_price: Wei
@@ -58,6 +80,11 @@ def _connect_setup(
5880
) -> None:
5981
connected_chains.append(self)
6082

83+
if len(connected_chains) == 1: # enable on first chain
84+
enable_relaxed_equality_address_account()
85+
elif len(connected_chains) == 2: # disable on second chain
86+
disable_relaxed_equality_address_account()
87+
6188
self._require_signed_txs = False
6289
self._gas_price = Wei(0)
6390
self._max_priority_fee_per_gas = Wei(0)

0 commit comments

Comments
 (0)