Simplify ReservedTestAccountManager and make it adhere to its superclass API, while adding functionality for our own needs.

pull/3491/head
derekpierre 2024-04-27 10:15:43 -04:00
parent c977db21e9
commit 556029def5
No known key found for this signature in database
8 changed files with 40 additions and 52 deletions

View File

@ -153,7 +153,7 @@ def test_dkg_initiation(
ritual_token.approve(
coordinator_agent.contract_address,
amount,
sender=accounts.get_ape_account(initiator.transacting_power.account),
sender=accounts[initiator.transacting_power.account],
)
receipt = coordinator_agent.initiate_ritual(
@ -314,7 +314,7 @@ def test_authorized_decryption(
global_allow_list.authorize(
ritual_id,
[signer.accounts[0]],
sender=accounts.get_ape_account(initiator.transacting_power.account),
sender=accounts[initiator.transacting_power.account],
)
# ritual_id, ciphertext, conditions are obtained from the side channel

View File

@ -73,7 +73,7 @@ def initiate_dkg(
ritual_token.approve(
coordinator_agent.contract_address,
amount,
sender=accounts.get_ape_account(initiator.transacting_power.account),
sender=accounts[initiator.transacting_power.account],
)
receipt = coordinator_agent.initiate_ritual(
providers=cohort_addresses,

View File

@ -78,7 +78,7 @@ def test_initiate_ritual(
ritual_token.approve(
agent.contract_address,
amount,
sender=accounts.get_ape_account(initiator.transacting_power.account),
sender=accounts[initiator.transacting_power.account],
)
authority = get_random_checksum_address()

View File

@ -91,7 +91,7 @@ def test_transacting_power_sign_message(testerchain, accounts):
# Test invalid address/pubkey pair
is_verified = verify_eip_191(
address=accounts.accounts[1],
address=accounts.accounts_addresses[1],
message=data_to_sign,
signature=signature,
)

View File

@ -67,7 +67,7 @@ def erc20_evm_condition_balanceof(testerchain, test_registry):
@pytest.fixture
def erc721_contract(accounts, project):
account = accounts.ape_accounts[0]
account = accounts[0]
# deploy contract
deployed_contract = project.ConditionNFT.deploy(sender=account)

View File

@ -81,7 +81,7 @@ def accounts():
@pytest.fixture(scope="module")
def deployer_account(accounts):
return accounts.ape_accounts[0]
return accounts[0]
@pytest.fixture(scope="module")
@ -343,7 +343,7 @@ def staking_providers(
taco_application.bondOperator(
provider_address,
operator_address,
sender=accounts.get_ape_account(provider_address),
sender=accounts[provider_address],
)
# track

View File

@ -24,10 +24,10 @@ def test_select_client_account(
):
"""Fine-grained assertions about the return value of interactive client account selection"""
signer = mocker.Mock()
signer.accounts = accounts.accounts
signer.accounts = accounts.accounts_addresses
mock_stdin.line(str(selection))
expected_account = accounts.accounts[selection]
expected_account = accounts.accounts_addresses[selection]
selected_account = select_client_account(
emitter=test_emitter,
signer=signer,
@ -101,7 +101,7 @@ def test_select_client_account_valid_sources(
mock_stdin.line(str(selection))
signer = mocker.Mock()
signer.accounts = accounts.accounts
signer.accounts = accounts.accounts_addresses
mock_signer = mocker.patch.object(
KeystoreSigner, "from_signer_uri", return_value=signer
@ -111,7 +111,7 @@ def test_select_client_account_valid_sources(
emitter=test_emitter,
signer_uri=MOCK_SIGNER_URI,
)
expected_account = accounts.accounts[selection]
expected_account = accounts.accounts_addresses[selection]
assert selected_account == expected_account
mock_signer.assert_called_once_with(uri=MOCK_SIGNER_URI, testnet=True)
assert mock_stdin.empty()
@ -123,7 +123,7 @@ def test_select_client_account_valid_sources(
# From Wallet
mock_stdin.line(str(selection))
expected_account = accounts.accounts[selection]
expected_account = accounts.accounts_addresses[selection]
selected_account = select_client_account(
domain=TEMPORARY_DOMAIN_NAME,
emitter=test_emitter,
@ -142,7 +142,7 @@ def test_select_client_account_valid_sources(
Web3Signer, "from_signer_uri", return_value=signer
)
mock_stdin.line(str(selection))
expected_account = accounts.accounts[selection]
expected_account = accounts.accounts_addresses[selection]
selected_account = select_client_account(
domain=TEMPORARY_DOMAIN_NAME,
emitter=test_emitter,

View File

@ -1,9 +1,11 @@
from functools import cached_property
from typing import List, Union
import maya
from ape.api import AccountAPI
from ape.managers.accounts import TestAccountManager
from eth_tester.exceptions import TransactionFailed
from eth_typing import ChecksumAddress
from hexbytes import HexBytes
from nucypher.blockchain.eth.interfaces import (
@ -29,25 +31,23 @@ class ReservedTestAccountManager(TestAccountManager):
_ETHERBASE = 0
_ALICE = 1
_BOB = 2
_FIRST_STAKING_PROVIDER = 5
_FIRST_STAKING_PROVIDER = 3
_FIRST_URSULA = _FIRST_STAKING_PROVIDER + NUMBER_OF_STAKING_PROVIDERS_IN_TESTS
# Unassigned
_FIRST_UNASSIGNED = _FIRST_URSULA + NUMBER_OF_URSULAS_IN_TESTS
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__accounts = None
self.__ape_accounts = None
@property
def accounts(self) -> List[str]:
if self.__accounts:
return self.__accounts
test_accounts = [account.address for account in self.ape_accounts]
self.__accounts = test_accounts
@cached_property
def accounts_addresses(self) -> List[str]:
test_accounts = [account.address for account in self.accounts]
return test_accounts
@property
def ape_accounts(self) -> List[AccountAPI]:
def accounts(self) -> List[AccountAPI]:
if self.__ape_accounts:
return self.__ape_accounts
@ -67,62 +67,50 @@ class ReservedTestAccountManager(TestAccountManager):
return test_accounts
@property
def etherbase_account(self):
return self[self._ETHERBASE]
def etherbase_account(self) -> ChecksumAddress:
return self[self._ETHERBASE].address
@property
def alice_account(self):
return self[self._ALICE]
def alice_account(self) -> ChecksumAddress:
return self[self._ALICE].address
@property
def bob_account(self):
return self[self._BOB]
def bob_account(self) -> ChecksumAddress:
return self[self._BOB].address
def ursula_account(self, index):
if index not in self.__OPERATORS_RANGE:
raise ValueError(
f"Ursula index must be lower than {self.NUMBER_OF_URSULAS_IN_TESTS}"
)
return self[index + self._FIRST_URSULA]
return self[index + self._FIRST_URSULA].address
@property
def ursulas_accounts(self):
def ursulas_accounts(self) -> List[ChecksumAddress]:
return list(self.ursula_account(i) for i in self.__OPERATORS_RANGE)
def stake_provider_account(self, index):
def stake_provider_account(self, index) -> ChecksumAddress:
if index not in self.__STAKING_PROVIDERS_RANGE:
raise ValueError(
f"Stake provider index must be lower than {self.NUMBER_OF_URSULAS_IN_TESTS}"
)
return self[index + self._FIRST_STAKING_PROVIDER]
return self[index + self._FIRST_STAKING_PROVIDER].address
@property
def stake_providers_accounts(self):
def stake_providers_accounts(self) -> List[ChecksumAddress]:
return list(
self.stake_provider_account(i) for i in self.__STAKING_PROVIDERS_RANGE
)
@property
def unassigned_accounts(self):
special_accounts = [
self.etherbase_account,
self.alice_account,
self.bob_account,
def unassigned_accounts(self) -> List[ChecksumAddress]:
unassigned = [
account.address for account in self.accounts[self._FIRST_UNASSIGNED :]
]
assigned_accounts = set(
self.stake_providers_accounts + self.ursulas_accounts + special_accounts
)
accounts = set(self.accounts)
return list(accounts.difference(assigned_accounts))
def get_ape_account(self, account_address: str) -> AccountAPI:
account_index = self.accounts.index(account_address)
ape_account = self.ape_accounts[account_index]
return ape_account
return unassigned
def get_account_signer(self, account_address: str) -> Signer:
ape_account = self.get_ape_account(account_address)
return InMemorySigner(private_key=ape_account.private_key)
return InMemorySigner(private_key=self[account_address].private_key)
def free_gas_price_strategy(w3, transaction_params=None):