Skip to content

Commit a4add36

Browse files
committed
refactor(Tests): use more streamlined approach for adding accys in tests
1 parent dd93604 commit a4add36

5 files changed

Lines changed: 25 additions & 29 deletions

File tree

tests/conftest.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,29 @@ def sponsor(project, owner):
4141
@pytest.fixture(scope="session")
4242
def encode_accessory_data():
4343
def encode_accessory_data(
44-
accessory: ContractInstance, *methods: str | ContractMethodHandler
44+
*methods: str | ContractMethodHandler,
45+
accessory: ContractInstance | None = None,
4546
) -> list[dict]:
46-
selectors = []
47-
48-
for method in methods:
49-
if isinstance(method, ContractMethodHandler):
50-
selectors.extend(abi.selector for abi in method.abis)
51-
else:
52-
selectors.append(method)
53-
54-
return [
55-
dict(
56-
accessory=accessory,
57-
method=accessory.contract_type.method_identifiers.get(method_id),
58-
)
59-
for method_id in selectors
60-
]
47+
if accessory:
48+
return [
49+
dict(
50+
accessory=accessory,
51+
method=method,
52+
)
53+
for method in methods
54+
]
55+
56+
else:
57+
return [
58+
dict(
59+
accessory=method.contract,
60+
method=method.contract.contract_type.method_identifiers.get(
61+
abi.selector
62+
),
63+
)
64+
for method in methods
65+
if not isinstance(method, str)
66+
for abi in method.abis
67+
]
6168

6269
return encode_accessory_data

tests/test_create.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ def purse(singleton, owner, create2_deployer, encode_accessory_data):
99
# NOTE: Add multicall as an accessory at the same time
1010
data=singleton.update_accessories.encode_input(
1111
encode_accessory_data(
12-
# Accessory
13-
create2_deployer,
14-
# Methods
1512
create2_deployer.create,
1613
)
1714
),

tests/test_multicall.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ def purse(singleton, owner, multicall, encode_accessory_data):
88
singleton,
99
# NOTE: Add multicall as an accessory at the same time
1010
data=singleton.update_accessories.encode_input(
11-
encode_accessory_data(
12-
# Accessory
13-
multicall,
14-
# Methods
15-
multicall.execute,
16-
)
11+
encode_accessory_data(multicall.execute)
1712
),
1813
) as purse:
1914
yield purse

tests/test_sponsor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ def purse(singleton, owner, sponsor, encode_accessory_data):
99
# NOTE: Add multicall as an accessory at the same time
1010
data=singleton.update_accessories.encode_input(
1111
encode_accessory_data(
12-
# Accessory
13-
sponsor,
14-
# Methods
1512
sponsor.sponsor_nonce,
1613
sponsor.sponsor,
1714
)

tests/test_wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_can_transfer(purse, accounts):
1717

1818
def test_add_rm_accessory(owner, purse, multicall, encode_accessory_data):
1919
# TODO: Add `.method_id(args_str)` to `ContractMethodHandler`
20-
accessory_data = encode_accessory_data(multicall, multicall.execute)
20+
accessory_data = encode_accessory_data(multicall.execute)
2121
method_id = accessory_data[0]["method"]
2222
assert purse.accessoryByMethodId(method_id) == ZERO_ADDRESS
2323

0 commit comments

Comments
 (0)