def test_app_smoke(monkeypatch: MonkeyPatch, keyfiles: None, client_app: App, passwords: List[str]): i = 0 input_sequence = (value for value in [str(i), passwords[i]]) mock_prompt(monkeypatch, input_sequence) client_app.start()
def test_app_insufficient_funds_abort(monkeypatch: MonkeyPatch, client_app: App, passwords: List[str]): i = 2 input_sequence = (value for value in [passwords[i], False]) mock_prompt(monkeypatch, input_sequence) client_app.start()
def test_account_manager_cli_select_wrong_password(monkeypatch: MonkeyPatch, keystore_path: str, keyfiles: None, passwords: List[str]): input_sequence = ( value for value in ['2', passwords[3], passwords[4], passwords[5]]) mock_prompt(monkeypatch, input_sequence) manager = AccountManagerCLI(keystore_path) account = manager.select_account() with pytest.raises(ValueError): manager.unlock_account(account)
def initialized_client_app( client_app: App, monkeypatch: MonkeyPatch, keyfiles: None, private_keys: List[PrivateKeyHex], addresses: List[Address], passwords: List[str], faucet_private_key: PrivateKeyHex, faucet_address: Address, web3: Web3, wait_for_transaction, token_contract: Contract, use_tester: bool ): i = 0 fund_account( addresses[i], WEI_ALLOWANCE, REI_ALLOWANCE, token_contract, web3, wait_for_transaction, faucet_private_key ) if use_tester: ethereum.tester.accounts.append(decode_hex(addresses[i])) ethereum.tester.keys.append(decode_hex(private_keys[i])) input_sequence = (value for value in [str(i), passwords[i]]) mock_prompt(monkeypatch, input_sequence) client_app.start() assert client_app.account.unlocked assert client_app.session is not None request_original = uSession._request_resource def request_patched(self: uSession, method: str, url: str, **kwargs): if use_tester: self.client.context.web3.testing.mine(1) return request_original(self, method, url, **kwargs) monkeypatch.setattr(microraiden.client.session.Session, '_request_resource', request_patched) if use_tester: client_app.session.retry_interval = 0.1 yield client_app client_app.drain(faucet_address, rdn_and_eth=True)
def test_app_insufficient_funds_retry( monkeypatch: MonkeyPatch, keyfiles: None, client_app: App, passwords: List[str], private_keys: List[PrivateKeyHex], addresses: List[Address], token_contract: Contract, web3: Web3, wait_for_transaction, faucet_private_key: PrivateKeyHex, faucet_address: Address, use_tester: bool): i = 3 j = 4 fund_account(addresses[j], WEI_ALLOWANCE, REI_ALLOWANCE, token_contract, web3, wait_for_transaction, faucet_private_key) if use_tester: ethereum.tester.accounts.append(decode_hex(addresses[j])) ethereum.tester.keys.append(decode_hex(private_keys[j])) input_sequence = (value for value in [i, True, j, passwords[j]]) mock_prompt(monkeypatch, input_sequence) client_app.start() sweep_account(private_keys[j], faucet_address, token_contract, web3, wait_for_transaction)
def test_account_manager_cli_autoselect(monkeypatch: MonkeyPatch, keystore_path: str, passwords: List[str]): i = 2 input_sequence = (value for value in [passwords[i]]) mock_prompt(monkeypatch, input_sequence) Account(keystore_path=keystore_path, password=passwords[i]) manager = AccountManagerCLI(keystore_path) account = manager.select_account() assert account.locked manager.unlock_account(account) assert account.unlocked account.lock() with pytest.raises(ValueError): # Wrong password. account.unlock(passwords[1]) account.unlock(passwords[i])
def test_account_manager_cli_generate(monkeypatch: MonkeyPatch, keystore_path: str, passwords: List[str]): i = 0 input_sequence = (value for value in [passwords[i]]) mock_prompt(monkeypatch, input_sequence) manager = AccountManagerCLI(keystore_path) account = manager.select_account() assert account.locked assert len(manager.accounts) == 1 assert len(glob.glob(os.path.join(keystore_path, '*'))) == 1 with pytest.raises(ValueError): # Wrong password. account.unlock(passwords[1]) account.unlock(passwords[i]) # Wrong password but ignored. try: account.unlock(passwords[1]) except ValueError: assert False, "Already unlocked account is supposed to ignore wrong password."
def test_account_manager_cli_select(addresses: List[Address], monkeypatch: MonkeyPatch, keystore_path: str, keyfiles: None, passwords: List[str], web3: Web3, token_address: Address): i = 2 input_sequence = (value for value in ['2', passwords[i]]) mock_prompt(monkeypatch, input_sequence) manager = AccountManagerCLI(keystore_path, web3=web3, token_address=token_address) account = manager.select_account() assert account.locked assert account.address == addresses[i] manager.unlock_account(account) assert account.unlocked account.lock() with pytest.raises(ValueError): # Wrong password. account.unlock(passwords[1]) account.unlock(passwords[i])
def test_app_drain(monkeypatch: MonkeyPatch, keyfiles: None, client_app: App, passwords: List[str], private_keys: List[PrivateKeyHex], addresses: List[Address], web3: Web3, token_contract: Contract, faucet_address: Address, use_tester: bool, wait_for_transaction, faucet_private_key: PrivateKeyHex): i = 6 j = 3 fund_account(addresses[i], WEI_ALLOWANCE, REI_ALLOWANCE, token_contract, web3, wait_for_transaction, faucet_private_key) fund_account(addresses[j], WEI_ALLOWANCE, REI_ALLOWANCE, token_contract, web3, wait_for_transaction, faucet_private_key) if use_tester: ethereum.tester.accounts.append(decode_hex(addresses[i])) ethereum.tester.keys.append(decode_hex(private_keys[i])) ethereum.tester.accounts.append(decode_hex(addresses[j])) ethereum.tester.keys.append(decode_hex(private_keys[j])) input_sequence = ( value for value in [str(i), passwords[i], False, True, str(j), passwords[j], True]) mock_prompt(monkeypatch, input_sequence) client_app.start() account_rei = token_contract.call().balanceOf(addresses[i]) account_wei = web3.eth.getBalance(addresses[i]) faucet_rei = token_contract.call().balanceOf(faucet_address) faucet_wei = web3.eth.getBalance(faucet_address) assert account_rei > 0 assert account_wei > 0 # Should drain nothing. client_app.drain(faucet_address) assert token_contract.call().balanceOf(addresses[i]) == account_rei assert web3.eth.getBalance(addresses[i]) == account_wei with pytest.raises(AssertionError): # Address not checksummed. client_app.drain(to_normalized_address(faucet_address), rdn=True) # Not confirmed. client_app.drain(faucet_address, rdn=True) assert token_contract.call().balanceOf(addresses[i]) == account_rei assert web3.eth.getBalance(addresses[i]) == account_wei # Confirmed. client_app.drain(faucet_address, rdn=True) assert token_contract.call().balanceOf(addresses[i]) == 0 assert 0 < web3.eth.getBalance(addresses[i]) < account_wei assert token_contract.call().balanceOf( faucet_address) == faucet_rei + account_rei assert web3.eth.getBalance(faucet_address) == faucet_wei # Second round, different account. client_app.start() account_rei = token_contract.call().balanceOf(addresses[j]) account_wei = web3.eth.getBalance(addresses[j]) faucet_rei = token_contract.call().balanceOf(faucet_address) faucet_wei = web3.eth.getBalance(faucet_address) assert account_rei > 0 assert account_wei > 0 # Drain both ETH and RDN. client_app.drain(faucet_address, rdn_and_eth=True) assert token_contract.call().balanceOf(addresses[j]) == 0 assert web3.eth.getBalance(addresses[j]) == 0 assert token_contract.call().balanceOf( faucet_address) == faucet_rei + account_rei assert web3.eth.getBalance(faucet_address) > faucet_wei