Update tests to use account management class instead of testerchain.

Use actual signer instead of relying on the underlying blockchain to manage accounts and perform fake signing.
pull/3491/head
derekpierre 2024-04-26 16:29:32 -04:00
parent 4122e2ffc1
commit c7480e4bf5
No known key found for this signature in database
24 changed files with 152 additions and 117 deletions

3
ape-config.yaml Normal file
View File

@ -0,0 +1,3 @@
test:
mnemonic: test test test test test test test test test test test junk
number_of_accounts: 30

View File

@ -153,7 +153,7 @@ def test_dkg_initiation(
ritual_token.approve(
coordinator_agent.contract_address,
amount,
sender=accounts[initiator.transacting_power.account],
sender=accounts.get_ape_account(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[initiator.transacting_power.account],
sender=accounts.get_ape_account(initiator.transacting_power.account),
)
# ritual_id, ciphertext, conditions are obtained from the side channel

View File

@ -19,9 +19,10 @@ def test_ursula_operator_confirmation(
taco_application_agent,
taco_child_application_agent,
deployer_account,
accounts,
):
staking_provider = testerchain.stake_provider_account(0)
operator_address = testerchain.ursula_account(0)
staking_provider = accounts.stake_provider_account(0)
operator_address = accounts.ursula_account(0)
min_authorization = taco_application_agent.get_min_authorization()
# make an staking_providers and some stakes

View File

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

View File

@ -9,7 +9,6 @@ from twisted.internet.task import deferLater
from nucypher.blockchain.eth.agents import CoordinatorAgent
from nucypher.blockchain.eth.models import Coordinator
from nucypher.blockchain.eth.signers.software import Web3Signer
from nucypher.crypto.powers import TransactingPower
@ -44,9 +43,9 @@ def cohort_ursulas(cohort, taco_application_agent):
@pytest.fixture(scope='module')
def transacting_powers(testerchain, cohort_ursulas):
def transacting_powers(accounts, cohort_ursulas):
return [
TransactingPower(account=ursula, signer=Web3Signer(testerchain.client))
TransactingPower(account=ursula, signer=accounts.get_account_signer(ursula))
for ursula in cohort_ursulas
]
@ -79,7 +78,7 @@ def test_initiate_ritual(
ritual_token.approve(
agent.contract_address,
amount,
sender=accounts[initiator.transacting_power.account],
sender=accounts.get_ape_account(initiator.transacting_power.account),
)
authority = get_random_checksum_address()

View File

@ -19,9 +19,10 @@ def test_sampling_distribution(
threshold_staking,
coordinator_agent,
deployer_account,
accounts,
):
# setup
stake_provider_accounts = testerchain.stake_providers_accounts
stake_provider_accounts = accounts.stake_providers_accounts
amount = taco_application_agent.get_min_authorization()
all_locked_tokens = len(stake_provider_accounts) * amount

View File

@ -29,13 +29,14 @@ def test_authorized_tokens(
def test_staking_providers_and_operators_relationships(
testerchain,
accounts,
taco_application_agent,
threshold_staking,
taco_application,
deployer_account,
get_random_checksum_address,
):
staking_provider_account, operator_account, *other = testerchain.unassigned_accounts
staking_provider_account, operator_account, *other = accounts.unassigned_accounts
threshold_staking.setRoles(staking_provider_account, sender=deployer_account)
threshold_staking.authorizationIncreased(
staking_provider_account,

View File

@ -5,11 +5,13 @@ from twisted.logger import LogLevel, globalLogPublisher
from nucypher.acumen.perception import FleetSensor
from nucypher.blockchain.eth.constants import NULL_ADDRESS
from nucypher.blockchain.eth.signers.software import Web3Signer
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
from nucypher.crypto.powers import TransactingPower
from tests.constants import TEST_ETH_PROVIDER_URI
from tests.utils.ursula import make_ursulas, start_pytest_ursula_services
from tests.utils.ursula import (
make_ursulas,
start_pytest_ursula_services,
)
def test_ursula_stamp_verification_tolerance(ursulas, mocker):
@ -79,6 +81,7 @@ def test_ursula_stamp_verification_tolerance(ursulas, mocker):
def test_invalid_operators_tolerance(
testerchain,
accounts,
test_registry,
ursulas,
threshold_staking,
@ -90,15 +93,12 @@ def test_invalid_operators_tolerance(
#
# Setup
#
(
creator,
_staking_provider,
operator_address,
*everyone_else,
) = testerchain.client.accounts
existing_ursula, other_ursula, *the_others = list(ursulas)
_staking_provider, operator_address = (
accounts.unassigned_accounts[0],
accounts.unassigned_accounts[1],
)
# We start with an ursula with no tokens staked
owner, _, _ = threshold_staking.rolesOf(_staking_provider, sender=deployer_account)
assert owner == NULL_ADDRESS
@ -112,7 +112,7 @@ def test_invalid_operators_tolerance(
# now lets bond this worker
tpower = TransactingPower(
account=_staking_provider, signer=Web3Signer(testerchain.client)
account=_staking_provider, signer=accounts.get_account_signer(_staking_provider)
)
taco_application_agent.bond_operator(
staking_provider=_staking_provider,
@ -121,7 +121,11 @@ def test_invalid_operators_tolerance(
)
# Make the Operator
ursulas = make_ursulas(ursula_test_config, [_staking_provider], [operator_address])
ursulas = make_ursulas(
ursula_test_config,
[_staking_provider],
[accounts.get_account_signer(operator_address)],
)
ursula = ursulas[0]
ursula.run(
preflight=False,

View File

@ -15,9 +15,9 @@ from tests.constants import INSECURE_DEVELOPMENT_PASSWORD, TEST_ETH_PROVIDER_URI
TransactingPower.lock_account = LOCK_FUNCTION
def test_character_transacting_power_signing(testerchain, test_registry):
def test_character_transacting_power_signing(testerchain, test_registry, accounts):
# Pretend to be a character.
eth_address = testerchain.etherbase_account
eth_address = accounts.etherbase_account
signer = Character(
is_me=True,
domain=TEMPORARY_DOMAIN_NAME,
@ -54,7 +54,7 @@ def test_character_transacting_power_signing(testerchain, test_registry):
"gasPrice": testerchain.client.w3.eth.gas_price,
"gas": 100000,
"from": eth_address,
"to": testerchain.unassigned_accounts[1],
"to": accounts.unassigned_accounts[1],
"value": 1,
"data": b"",
}
@ -67,9 +67,9 @@ def test_character_transacting_power_signing(testerchain, test_registry):
assert to_checksum_address(restored_dict["to"]) == transaction_dict["to"]
def test_transacting_power_sign_message(testerchain):
def test_transacting_power_sign_message(testerchain, accounts):
# Manually create a TransactingPower
eth_address = testerchain.etherbase_account
eth_address = accounts.etherbase_account
power = TransactingPower(
password=INSECURE_DEVELOPMENT_PASSWORD,
signer=Web3Signer(testerchain.client),
@ -91,15 +91,15 @@ def test_transacting_power_sign_message(testerchain):
# Test invalid address/pubkey pair
is_verified = verify_eip_191(
address=testerchain.client.accounts[1],
address=accounts.accounts[1],
message=data_to_sign,
signature=signature,
)
assert is_verified is False
def test_transacting_power_sign_transaction(testerchain):
eth_address = testerchain.unassigned_accounts[2]
def test_transacting_power_sign_transaction(testerchain, accounts):
eth_address = accounts.unassigned_accounts[2]
power = TransactingPower(
password=INSECURE_DEVELOPMENT_PASSWORD,
signer=Web3Signer(testerchain.client),
@ -111,7 +111,7 @@ def test_transacting_power_sign_transaction(testerchain):
"gasPrice": testerchain.client.w3.eth.gas_price,
"gas": 100000,
"from": eth_address,
"to": testerchain.unassigned_accounts[1],
"to": accounts.unassigned_accounts[1],
"value": 1,
"data": b"",
}
@ -134,7 +134,9 @@ def test_transacting_power_sign_transaction(testerchain):
power.sign_transaction(transaction_dict=transaction_dict)
def test_transacting_power_sign_agent_transaction(testerchain, coordinator_agent):
def test_transacting_power_sign_agent_transaction(
testerchain, coordinator_agent, accounts
):
public_key = Keypair.random().public_key()
g2_point = Ferveo.G2Point.from_public_key(public_key)
contract_function = coordinator_agent.contract.functions.setProviderPublicKey(
@ -144,9 +146,9 @@ def test_transacting_power_sign_agent_transaction(testerchain, coordinator_agent
payload = {
"chainId": int(testerchain.client.chain_id),
"nonce": testerchain.client.w3.eth.get_transaction_count(
testerchain.etherbase_account
accounts.etherbase_account
),
"from": testerchain.etherbase_account,
"from": accounts.etherbase_account,
"gasPrice": testerchain.client.gas_price,
"gas": 500_000,
}
@ -157,7 +159,7 @@ def test_transacting_power_sign_agent_transaction(testerchain, coordinator_agent
transacting_power = TransactingPower(
password=INSECURE_DEVELOPMENT_PASSWORD,
signer=Web3Signer(testerchain.client),
account=testerchain.etherbase_account,
account=accounts.etherbase_account,
)
signed_raw_transaction = transacting_power.sign_transaction(unsigned_transaction)

View File

@ -34,6 +34,7 @@ def mock_funded_account_password_keystore(
taco_application_agent,
test_registry,
deployer_account,
accounts,
):
"""
Generate a random keypair & password and create a local keystore. Then prepare a staking provider
@ -49,14 +50,14 @@ def mock_funded_account_password_keystore(
testerchain.client.w3.eth.send_transaction(
{
"to": account.address,
"from": testerchain.etherbase_account,
"from": accounts.etherbase_account,
"value": Web3.to_wei("100", "ether"),
}
)
)
# initialize threshold stake
provider_address = testerchain.unassigned_accounts[0]
provider_address = accounts.unassigned_accounts[0]
threshold_staking.setRoles(provider_address, sender=deployer_account)
threshold_staking.setStakes(
provider_address,
@ -92,6 +93,7 @@ def test_ursula_and_local_keystore_signer_integration(
mocker,
mock_funded_account_password_keystore,
testerchain,
accounts,
):
config_root_path = tmp_path
ursula_config_path = config_root_path / UrsulaConfiguration.generate_filename()
@ -101,7 +103,7 @@ def test_ursula_and_local_keystore_signer_integration(
testerchain.client.w3.eth.send_transaction(
{
"to": worker_account,
"from": testerchain.etherbase_account,
"from": accounts.etherbase_account,
"value": Web3.to_wei("100", "ether"),
}
)

View File

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

View File

@ -79,7 +79,9 @@ def test_user_address_context_invalid_eip712_typed_data(valid_user_address_conte
get_context_value(USER_ADDRESS_CONTEXT, **context)
def test_user_address_context_variable_verification(testerchain, valid_user_address_context):
def test_user_address_context_variable_verification(
valid_user_address_context, accounts
):
# valid user address context - signature matches address
address = get_context_value(USER_ADDRESS_CONTEXT, **valid_user_address_context)
assert address == valid_user_address_context[USER_ADDRESS_CONTEXT]["address"]
@ -89,7 +91,7 @@ def test_user_address_context_variable_verification(testerchain, valid_user_addr
mismatch_with_address_context = copy.deepcopy(valid_user_address_context)
mismatch_with_address_context[USER_ADDRESS_CONTEXT][
"address"
] = testerchain.etherbase_account
] = accounts.etherbase_account
with pytest.raises(ContextVariableVerificationFailed):
get_context_value(USER_ADDRESS_CONTEXT, **mismatch_with_address_context)
@ -119,9 +121,9 @@ def test_user_address_context_variable_verification(testerchain, valid_user_addr
side_effect=_dont_validate_user_address,
)
def test_rpc_condition_evaluation_no_providers(
get_context_value_mock, testerchain, rpc_condition
get_context_value_mock, testerchain, accounts, rpc_condition
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.unassigned_accounts[0]}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.unassigned_accounts[0]}}
with pytest.raises(NoConnectionToChain):
_ = rpc_condition.verify(providers={}, **context)
@ -136,9 +138,9 @@ def test_rpc_condition_evaluation_no_providers(
side_effect=_dont_validate_user_address,
)
def test_rpc_condition_evaluation_invalid_provider_for_chain(
get_context_value_mock, testerchain, rpc_condition
get_context_value_mock, testerchain, accounts, rpc_condition
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.unassigned_accounts[0]}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.unassigned_accounts[0]}}
new_chain = 23
rpc_condition.chain = new_chain
condition_providers = {new_chain: {testerchain.provider}}
@ -152,8 +154,10 @@ def test_rpc_condition_evaluation_invalid_provider_for_chain(
GET_CONTEXT_VALUE_IMPORT_PATH,
side_effect=_dont_validate_user_address,
)
def test_rpc_condition_evaluation(get_context_value_mock, testerchain, rpc_condition, condition_providers):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.unassigned_accounts[0]}}
def test_rpc_condition_evaluation(
get_context_value_mock, accounts, rpc_condition, condition_providers
):
context = {USER_ADDRESS_CONTEXT: {"address": accounts.unassigned_accounts[0]}}
condition_result, call_result = rpc_condition.verify(
providers=condition_providers, **context
)
@ -168,9 +172,9 @@ def test_rpc_condition_evaluation(get_context_value_mock, testerchain, rpc_condi
side_effect=_dont_validate_user_address,
)
def test_rpc_condition_evaluation_multiple_chain_providers(
get_context_value_mock, testerchain, rpc_condition
get_context_value_mock, testerchain, accounts, rpc_condition
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.unassigned_accounts[0]}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.unassigned_accounts[0]}}
condition_providers = {
"1": {"fake1a", "fake1b"},
@ -194,9 +198,9 @@ def test_rpc_condition_evaluation_multiple_chain_providers(
side_effect=_dont_validate_user_address,
)
def test_rpc_condition_evaluation_multiple_providers_no_valid_fallback(
get_context_value_mock, mocker, testerchain, rpc_condition
get_context_value_mock, mocker, accounts, rpc_condition
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.unassigned_accounts[0]}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.unassigned_accounts[0]}}
def my_configure_w3(provider: BaseProvider):
return Web3(provider)
@ -223,9 +227,9 @@ def test_rpc_condition_evaluation_multiple_providers_no_valid_fallback(
side_effect=_dont_validate_user_address,
)
def test_rpc_condition_evaluation_multiple_providers_valid_fallback(
get_context_value_mock, mocker, testerchain, rpc_condition
get_context_value_mock, mocker, testerchain, accounts, rpc_condition
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.unassigned_accounts[0]}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.unassigned_accounts[0]}}
def my_configure_w3(provider: BaseProvider):
return Web3(provider)
@ -260,9 +264,9 @@ def test_rpc_condition_evaluation_multiple_providers_valid_fallback(
side_effect=_dont_validate_user_address,
)
def test_rpc_condition_evaluation_no_connection_to_chain(
get_context_value_mock, testerchain, rpc_condition
get_context_value_mock, testerchain, accounts, rpc_condition
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.unassigned_accounts[0]}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.unassigned_accounts[0]}}
# condition providers for other unrelated chains
providers = {
@ -318,15 +322,15 @@ def test_rpc_condition_evaluation_with_context_var_in_return_value_test(
side_effect=_dont_validate_user_address,
)
def test_erc20_evm_condition_evaluation(
get_context_value_mock, testerchain, erc20_evm_condition_balanceof, condition_providers
get_context_value_mock, erc20_evm_condition_balanceof, condition_providers, accounts
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.unassigned_accounts[0]}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.unassigned_accounts[0]}}
condition_result, call_result = erc20_evm_condition_balanceof.verify(
providers=condition_providers, **context
)
assert condition_result is True
context[USER_ADDRESS_CONTEXT]["address"] = testerchain.etherbase_account
context[USER_ADDRESS_CONTEXT]["address"] = accounts.etherbase_account
condition_result, call_result = erc20_evm_condition_balanceof.verify(
providers=condition_providers, **context
)
@ -334,15 +338,15 @@ def test_erc20_evm_condition_evaluation(
def test_erc20_evm_condition_evaluation_with_custom_context_variable(
testerchain, custom_context_variable_erc20_condition, condition_providers
custom_context_variable_erc20_condition, condition_providers, accounts
):
context = {":addressToUse": testerchain.unassigned_accounts[0]}
context = {":addressToUse": accounts.unassigned_accounts[0]}
condition_result, call_result = custom_context_variable_erc20_condition.verify(
providers=condition_providers, **context
)
assert condition_result is True
context[":addressToUse"] = testerchain.etherbase_account
context[":addressToUse"] = accounts.etherbase_account
condition_result, call_result = custom_context_variable_erc20_condition.verify(
providers=condition_providers, **context
)
@ -723,11 +727,11 @@ def test_not_of_simple_compound_conditions_lingo_evaluation(
)
def test_onchain_conditions_lingo_evaluation(
get_context_value_mock,
testerchain,
compound_lingo,
condition_providers,
accounts,
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.etherbase_account}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.etherbase_account}}
result = compound_lingo.eval(providers=condition_providers, **context)
assert result is True
@ -738,11 +742,11 @@ def test_onchain_conditions_lingo_evaluation(
)
def test_not_of_onchain_conditions_lingo_evaluation(
get_context_value_mock,
testerchain,
compound_lingo,
condition_providers,
accounts,
):
context = {USER_ADDRESS_CONTEXT: {"address": testerchain.etherbase_account}}
context = {USER_ADDRESS_CONTEXT: {"address": accounts.etherbase_account}}
result = compound_lingo.eval(providers=condition_providers, **context)
assert result is True

View File

@ -8,8 +8,8 @@ from nucypher.crypto.powers import TransactingPower
@pytest.mark.skip(
"This test need to be refactored to use some other transaction than deployment"
)
def test_block_confirmations(testerchain, test_registry, mocker):
origin = testerchain.etherbase_account
def test_block_confirmations(testerchain, test_registry, mocker, accounts):
origin = accounts.etherbase_account
transacting_power = TransactingPower(
account=origin, signer=Web3Signer(testerchain.client)
)

View File

@ -8,10 +8,7 @@ from twisted.internet.task import Clock
from nucypher.characters.lawful import Bob, Enrico
from nucypher.config.constants import TEMPORARY_DOMAIN_NAME
from tests.constants import (
MOCK_ETH_PROVIDER_URI,
NUMBER_OF_URSULAS_IN_DEVELOPMENT_DOMAIN,
)
from tests.constants import MOCK_ETH_PROVIDER_URI
from tests.utils.middleware import MockRestMiddleware
@ -38,7 +35,7 @@ def test_bob_full_retrieve_flow(
assert b"Welcome to flippering number 0." == delivered_cleartexts[0]
def test_bob_retrieves(alice, ursulas):
def test_bob_retrieves(accounts, alice, ursulas):
"""A test to show that Bob can retrieve data from Ursula"""
# Let's partition Ursulas in two parts
@ -60,7 +57,7 @@ def test_bob_retrieves(alice, ursulas):
# Alice creates a policy granting access to Bob
# Just for fun, let's assume she distributes KFrags among Ursulas unknown to Bob
shares = NUMBER_OF_URSULAS_IN_DEVELOPMENT_DOMAIN - 2
shares = accounts.NUMBER_OF_URSULAS_IN_TESTS - 2
label = b'label://' + os.urandom(32)
contract_end_datetime = maya.now() + datetime.timedelta(days=5)
policy = alice.grant(

View File

@ -5,7 +5,6 @@ import pytest
from eth_utils import is_checksum_address
from web3 import Web3
from nucypher.blockchain.eth.clients import EthereumClient
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.signers import KeystoreSigner
from nucypher.blockchain.eth.signers.software import Web3Signer
@ -21,14 +20,17 @@ from tests.constants import (
@pytest.mark.parametrize("selection", range(NUMBER_OF_ETH_TEST_ACCOUNTS))
def test_select_client_account(
mock_stdin, test_emitter, testerchain, selection, capsys
mock_stdin, test_emitter, testerchain, accounts, selection, capsys, mocker
):
"""Fine-grained assertions about the return value of interactive client account selection"""
signer = mocker.Mock()
signer.accounts = accounts.accounts
mock_stdin.line(str(selection))
expected_account = testerchain.client.accounts[selection]
expected_account = accounts.accounts[selection]
selected_account = select_client_account(
emitter=test_emitter,
signer=Web3Signer(testerchain.client),
signer=signer,
polygon_endpoint=MOCK_ETH_PROVIDER_URI,
domain=TEMPORARY_DOMAIN_NAME,
)
@ -50,11 +52,13 @@ def test_select_client_account_with_no_accounts(
testerchain,
capsys,
):
mocker.patch.object(EthereumClient, "accounts", return_value=[])
signer = mocker.Mock()
signer.accounts = []
with pytest.raises(click.Abort):
select_client_account(
emitter=test_emitter,
signer=Web3Signer(testerchain.client),
signer=signer,
polygon_endpoint=MOCK_ETH_PROVIDER_URI,
domain=TEMPORARY_DOMAIN_NAME,
)
@ -81,11 +85,13 @@ def test_select_client_account_ambiguous_source(
@pytest.mark.parametrize("selection", range(NUMBER_OF_ETH_TEST_ACCOUNTS))
@pytest.mark.usefixtures("mock_registry_sources")
def test_select_client_account_valid_sources(
mocker,
mock_stdin,
test_emitter,
testerchain,
accounts,
patch_keystore,
mock_accounts,
selection,
@ -93,15 +99,19 @@ def test_select_client_account_valid_sources(
):
# From External Signer
mock_stdin.line(str(selection))
signer = mocker.Mock()
signer.accounts = accounts.accounts
mock_signer = mocker.patch.object(
KeystoreSigner, "from_signer_uri", return_value=Web3Signer(testerchain.client)
KeystoreSigner, "from_signer_uri", return_value=signer
)
selected_account = select_client_account(
domain=TEMPORARY_DOMAIN_NAME,
emitter=test_emitter,
signer_uri=MOCK_SIGNER_URI,
)
expected_account = testerchain.client.accounts[selection]
expected_account = accounts.accounts[selection]
assert selected_account == expected_account
mock_signer.assert_called_once_with(uri=MOCK_SIGNER_URI, testnet=True)
assert mock_stdin.empty()
@ -113,11 +123,11 @@ def test_select_client_account_valid_sources(
# From Wallet
mock_stdin.line(str(selection))
expected_account = testerchain.client.accounts[selection]
expected_account = accounts.accounts[selection]
selected_account = select_client_account(
domain=TEMPORARY_DOMAIN_NAME,
emitter=test_emitter,
signer=Web3Signer(testerchain.client),
signer=signer,
)
assert selected_account == expected_account
assert mock_stdin.empty()
@ -128,8 +138,11 @@ def test_select_client_account_valid_sources(
)
# From pre-initialized Provider
mock_signer = mocker.patch.object(
Web3Signer, "from_signer_uri", return_value=signer
)
mock_stdin.line(str(selection))
expected_account = testerchain.client.accounts[selection]
expected_account = accounts.accounts[selection]
selected_account = select_client_account(
domain=TEMPORARY_DOMAIN_NAME,
emitter=test_emitter,
@ -183,6 +196,7 @@ def test_select_client_account_with_balance_display(
mock_stdin,
test_emitter,
testerchain,
accounts,
capsys,
selection,
show_matic,
@ -199,7 +213,7 @@ def test_select_client_account_with_balance_display(
)
# check for accurate selection consistency with client index
assert selected_account == testerchain.client.accounts[selection]
assert selected_account == accounts[selection]
assert mock_stdin.empty()
# Display account info
@ -212,7 +226,7 @@ def test_select_client_account_with_balance_display(
for column_name in headers:
assert column_name in captured.out, f'"{column_name}" column was not displayed'
for account in testerchain.client.accounts:
for account in accounts:
assert account in captured.out
if show_matic:

View File

@ -42,7 +42,7 @@ def test_destroy_with_no_configurations(click_runner, custom_filepath):
def test_corrupted_configuration(
click_runner, custom_filepath, testerchain, test_registry, mocker
click_runner, custom_filepath, accounts, test_registry, mocker
):
#
# Setup
@ -53,7 +53,13 @@ def test_corrupted_configuration(
shutil.rmtree(custom_filepath, ignore_errors=True)
assert not custom_filepath.exists()
alice, ursula, another_ursula, staking_provider, *all_yall = testerchain.unassigned_accounts
(
alice,
ursula,
another_ursula,
staking_provider,
*all_yall,
) = accounts.unassigned_accounts
#
# Chaos

View File

@ -87,7 +87,6 @@ def test_ursula_startup_ip_checkup(click_runner, mocker):
def test_ursula_run_ip_checkup(
testerchain,
custom_filepath,
click_runner,
mocker,
ursulas,
@ -110,10 +109,10 @@ def test_ursula_run_ip_checkup(
mocker.patch.object(Ursula, 'from_teacher_uri', return_value=teacher)
# Mock worker qualification
staking_provider = ursulas[1]
worker = ursulas[1]
def set_staking_provider_address(operator, *args, **kwargs):
operator.checksum_address = staking_provider.checksum_address
operator.checksum_address = worker.checksum_address
return True
monkeypatch.setattr(Operator, "block_until_ready", set_staking_provider_address)
@ -121,6 +120,7 @@ def test_ursula_run_ip_checkup(
mocker.patch("nucypher.cli.commands.ursula.migrate", return_value=None)
ursula_test_config.rest_host = MOCK_IP_ADDRESS
ursula_test_config.operator_address = worker.operator_address
mocker.patch.object(
UrsulaConfiguration, "from_configuration_file", return_value=ursula_test_config
)

View File

@ -12,10 +12,10 @@ def mock_ursula_run(mocker, ursulas, monkeypatch, ursula_test_config, mock_prome
ursula_test_config.rest_host = MOCK_IP_ADDRESS
# Mock worker qualification
staking_provider = ursulas[1]
worker = ursulas[1]
def set_staking_provider_address(operator):
operator.checksum_address = staking_provider.checksum_address
operator.checksum_address = worker.checksum_address
return True
monkeypatch.setattr(Operator, "block_until_ready", set_staking_provider_address)
@ -23,6 +23,8 @@ def mock_ursula_run(mocker, ursulas, monkeypatch, ursula_test_config, mock_prome
# Mock migration
mocker.patch("nucypher.cli.commands.ursula.migrate", return_value=None)
ursula_test_config.operator_address = worker.operator_address
# Mock Ursula configuration
mocker.patch.object(
UrsulaConfiguration, "from_configuration_file", return_value=ursula_test_config

View File

@ -11,7 +11,7 @@ from tests.constants import FAKE_PASSWORD_CONFIRMED, MOCK_IP_ADDRESS
@pytest.fixture
def v4_config_file(tempfile_path, ursula_test_config):
def v4_config_file(tempfile_path, ursula_test_config, accounts):
config_dictionary = {
"federated_only": None,
"checksum_address": None,
@ -29,7 +29,7 @@ def v4_config_file(tempfile_path, ursula_test_config):
"signer_uri": ursula_test_config.signer_uri,
"gas_strategy": "fast",
"max_gas_price": None,
"operator_address": ursula_test_config.operator_address,
"operator_address": accounts.ursulas_accounts[0],
"rest_host": MOCK_IP_ADDRESS,
"rest_port": ursula_test_config.rest_port,
"db_filepath": "/root/.local/share/nucypher/ursula.db",
@ -69,10 +69,10 @@ def test_ursula_run_specified_config_file(
mocker.patch("nucypher.cli.utils.unlock_nucypher_keystore", return_value=True)
# Mock worker qualification
staking_provider = ursulas[1]
worker = ursulas[1]
def set_staking_provider_address(operator, *args, **kwargs):
operator.checksum_address = staking_provider.checksum_address
operator.checksum_address = worker.checksum_address
return True
monkeypatch.setattr(Operator, "block_until_ready", set_staking_provider_address)

View File

@ -84,7 +84,7 @@ def test_interactive_initialize_ursula(click_runner, mocker, tmpdir):
def test_initialize_custom_configuration_root(
click_runner, custom_filepath: Path, testerchain
click_runner, custom_filepath: Path, accounts
):
deploy_port = select_test_port()
# Use a custom local filepath for configuration
@ -104,7 +104,7 @@ def test_initialize_custom_configuration_root(
"--polygon-endpoint",
MOCK_ETH_PROVIDER_URI,
"--operator-address",
testerchain.ursulas_accounts[0],
accounts.ursulas_accounts[0],
)
result = click_runner.invoke(
nucypher_cli, init_args, input=FAKE_PASSWORD_CONFIRMED, catch_exceptions=False

View File

@ -41,18 +41,18 @@ all_configurations = tuple(
)
@pytest.mark.parametrize("character,configuration", characters_and_configurations)
def test_development_character_configurations(
character, configuration, mocker, testerchain
character, configuration, mocker, accounts
):
params = dict(
dev_mode=True,
lonely=True,
domain=TEMPORARY_DOMAIN_NAME,
checksum_address=testerchain.unassigned_accounts[0],
checksum_address=accounts.unassigned_accounts[0],
eth_endpoint=MOCK_ETH_PROVIDER_URI,
polygon_endpoint=MOCK_ETH_PROVIDER_URI,
)
if character is Ursula:
params.update(dict(operator_address=testerchain.unassigned_accounts[0]))
params.update(dict(operator_address=accounts.unassigned_accounts[0]))
config = configuration(**params)
assert config.is_me is True
@ -160,11 +160,11 @@ def test_default_character_configuration_preservation(
expected_filepath.unlink()
def test_ursula_development_configuration(testerchain):
def test_ursula_development_configuration(accounts):
config = UrsulaConfiguration(
dev_mode=True,
checksum_address=testerchain.unassigned_accounts[0],
operator_address=testerchain.unassigned_accounts[1],
checksum_address=accounts.unassigned_accounts[0],
operator_address=accounts.unassigned_accounts[1],
domain=TEMPORARY_DOMAIN_NAME,
eth_endpoint=MOCK_ETH_PROVIDER_URI,
polygon_endpoint=MOCK_ETH_PROVIDER_URI,

View File

@ -10,7 +10,7 @@ from tests.constants import INSECURE_DEVELOPMENT_PASSWORD, MOCK_ETH_PROVIDER_URI
from tests.utils.middleware import MockRestMiddleware
def test_alices_powers_are_persistent(ursulas, temp_dir_path, testerchain):
def test_alices_powers_are_persistent(ursulas, temp_dir_path, accounts):
# Create a non-learning AliceConfiguration
config_root = temp_dir_path / 'nucypher-custom-alice-config'
alice_config = AliceConfiguration(
@ -18,7 +18,7 @@ def test_alices_powers_are_persistent(ursulas, temp_dir_path, testerchain):
config_root=config_root,
network_middleware=MockRestMiddleware(eth_endpoint=MOCK_ETH_PROVIDER_URI),
domain=TEMPORARY_DOMAIN_NAME,
checksum_address=testerchain.alice_account,
checksum_address=accounts.alice_account,
start_learning_now=False,
save_metadata=False,
reload_metadata=False,

View File

@ -66,7 +66,7 @@ def test_generate_alice_keystore(temp_dir_path):
@pytest.mark.usefixtures("mock_registry_sources")
def test_characters_use_keystore(temp_dir_path, testerchain):
def test_characters_use_keystore(temp_dir_path, testerchain, accounts):
keystore = Keystore.generate(
password=INSECURE_DEVELOPMENT_PASSWORD,
keystore_dir=temp_dir_path
@ -83,7 +83,7 @@ def test_characters_use_keystore(temp_dir_path, testerchain):
domain=TEMPORARY_DOMAIN_NAME,
eth_endpoint=MOCK_ETH_PROVIDER_URI,
polygon_endpoint=MOCK_ETH_PROVIDER_URI,
checksum_address=testerchain.alice_account,
checksum_address=accounts.alice_account,
pre_payment_method=pre_payment_method,
)
Bob(
@ -101,7 +101,7 @@ def test_characters_use_keystore(temp_dir_path, testerchain):
rest_port=12345,
domain=TEMPORARY_DOMAIN_NAME,
pre_payment_method=pre_payment_method,
operator_address=testerchain.ursulas_accounts[0],
operator_address=accounts.ursulas_accounts[0],
signer=Web3Signer(testerchain.client),
condition_blockchain_endpoints={TESTERCHAIN_CHAIN_ID: MOCK_ETH_PROVIDER_URI},
)
@ -154,7 +154,7 @@ def test_tls_hosting_certificate_remains_the_same(temp_dir_path, mocker):
@pytest.mark.usefixtures("mock_sign_message")
def test_ritualist(temp_dir_path, testerchain, dkg_public_key):
def test_ritualist(temp_dir_path, testerchain, accounts, dkg_public_key):
keystore = Keystore.generate(
password=INSECURE_DEVELOPMENT_PASSWORD, keystore_dir=temp_dir_path
)
@ -171,7 +171,7 @@ def test_ritualist(temp_dir_path, testerchain, dkg_public_key):
rest_port=12345,
domain=TEMPORARY_DOMAIN_NAME,
pre_payment_method=pre_payment_method,
operator_address=testerchain.ursulas_accounts[0],
operator_address=accounts.ursulas_accounts[0],
signer=Web3Signer(testerchain.client),
eth_endpoint=MOCK_ETH_PROVIDER_URI,
polygon_endpoint=MOCK_ETH_PROVIDER_URI,

View File

@ -7,19 +7,18 @@ import requests
from cryptography.hazmat.primitives import serialization
from twisted.internet import threads
from tests.utils.ursula import make_ursulas
from tests.utils.ursula import make_reserved_ursulas
@pytest_twisted.inlineCallbacks
def test_ursula_serves_statics(ursula_test_config, testerchain):
def test_ursula_serves_statics(ursula_test_config, accounts):
with tempfile.TemporaryDirectory() as STATICS_DIR:
os.environ['NUCYPHER_STATIC_FILES_ROOT'] = str(STATICS_DIR)
node = make_ursulas(
node = make_reserved_ursulas(
accounts=accounts,
ursula_config=ursula_test_config,
quantity=1,
staking_provider_addresses=testerchain.stake_providers_accounts,
operator_addresses=testerchain.ursulas_accounts,
).pop()
node_deployer = node.get_deployer()