def test_new_stakeholder(click_runner, custom_filepath, agency_local_registry, testerchain): init_args = ('stake', 'init-stakeholder', '--config-root', custom_filepath, '--provider', TEST_PROVIDER_URI, '--network', TEMPORARY_DOMAIN, '--registry-filepath', agency_local_registry.filepath) result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False) assert result.exit_code == 0 # Files and Directories assert os.path.isdir(custom_filepath), 'Configuration file does not exist' custom_config_filepath = os.path.join( custom_filepath, StakeHolderConfiguration.generate_filename()) assert os.path.isfile( custom_config_filepath), 'Configuration file does not exist' with open(custom_config_filepath, 'r') as config_file: raw_config_data = config_file.read() config_data = json.loads(raw_config_data) assert config_data['provider_uri'] == TEST_PROVIDER_URI
def stakeholder_configuration_file_location(custom_filepath): _configuration_file_location = os.path.join( MOCK_CUSTOM_INSTALLATION_PATH, StakeHolderConfiguration.generate_filename()) return _configuration_file_location
def stakeholder_configuration_file_location(custom_filepath) -> Path: _configuration_file_location = MOCK_CUSTOM_INSTALLATION_PATH / StakeHolderConfiguration.generate_filename( ) return _configuration_file_location
def test_ursula_and_local_keystore_signer_integration( click_runner, tmp_path, manual_staker, stake_value, token_economics, mocker, mock_funded_account_password_keystore, testerchain): config_root_path = tmp_path ursula_config_path = config_root_path / UrsulaConfiguration.generate_filename( ) stakeholder_config_path = config_root_path / StakeHolderConfiguration.generate_filename( ) worker_account, password, mock_keystore_path = mock_funded_account_password_keystore # # Stakeholder Steps # init_args = ('stake', 'init-stakeholder', '--config-root', config_root_path, '--provider', TEST_PROVIDER_URI, '--network', TEMPORARY_DOMAIN) click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False) stake_args = ('stake', 'create', '--config-file', stakeholder_config_path, '--staking-address', manual_staker, '--value', stake_value.to_tokens(), '--lock-periods', token_economics.minimum_locked_periods, '--force') # TODO: Is This test is writing to the default system directory and ignoring updates to the passed filepath? user_input = f'0\n{password}\nY\n' click_runner.invoke(nucypher_cli, stake_args, input=user_input, catch_exceptions=False) init_args = ('stake', 'bond-worker', '--config-file', stakeholder_config_path, '--staking-address', manual_staker, '--worker-address', worker_account.address, '--force') user_input = password click_runner.invoke(nucypher_cli, init_args, input=user_input, catch_exceptions=False) # # Worker Steps # # Good signer... mock_signer_uri = f'keystore:{mock_keystore_path}' pre_config_signer = KeystoreSigner.from_signer_uri(uri=mock_signer_uri, testnet=True) assert worker_account.address in pre_config_signer.accounts deploy_port = select_test_port() init_args = ( 'ursula', 'init', '--network', TEMPORARY_DOMAIN, '--worker-address', worker_account.address, '--config-root', config_root_path, '--provider', TEST_PROVIDER_URI, '--rest-host', MOCK_IP_ADDRESS, '--rest-port', deploy_port, # The bit we are testing for here '--signer', mock_signer_uri) cli_env = { NUCYPHER_ENVVAR_KEYRING_PASSWORD: password, NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD: password, } result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False, env=cli_env) assert result.exit_code == 0, result.stdout # Inspect the configuration file for the signer URI with open(ursula_config_path, 'r') as config_file: raw_config_data = config_file.read() config_data = json.loads(raw_config_data) assert config_data['signer_uri'] == mock_signer_uri,\ "Keystore URI was not correctly included in configuration file" # Recreate a configuration with the signer URI preserved ursula_config = UrsulaConfiguration.from_configuration_file( ursula_config_path) assert ursula_config.signer_uri == mock_signer_uri # Mock decryption of web3 client keyring mocker.patch.object(Account, 'decrypt', return_value=worker_account.privateKey) ursula_config.attach_keyring(checksum_address=worker_account.address) ursula_config.keyring.unlock(password=password) # Produce an Ursula with a Keystore signer correctly derived from the signer URI, and don't do anything else! mocker.patch.object(StakeList, 'refresh', autospec=True) ursula = ursula_config.produce(client_password=password, commit_now=False, block_until_ready=False) try: # Verify the keystore path is still preserved assert isinstance(ursula.signer, KeystoreSigner) assert isinstance(ursula.signer.path, str), "Use str" assert ursula.signer.path == str(mock_keystore_path) # Show that we can produce the exact same signer as pre-config... assert pre_config_signer.path == ursula.signer.path # ...and that transactions are signed by the keystore signer txhash = ursula.commit_to_next_period() receipt = testerchain.wait_for_receipt(txhash) transaction_data = testerchain.client.w3.eth.getTransaction( receipt['transactionHash']) assert transaction_data['from'] == worker_account.address finally: ursula.stop()