Example #1
0
def password_account(web3_empty,
                     account_password,
                     account_private_key,
                     account_public_key,
                     wait_for_transaction):
    from eth_tester_client.utils import normalize_address

    web3 = web3_empty

    address = web3.personal.importRawKey(account_private_key, account_password)

    # sanity check
    assert normalize_address(address) == normalize_address(account_public_key)

    initial_balance = 1000000000000000000000  # 1,000 ether

    funding_txn_hash = web3.personal.signAndSendTransaction({
        'from': web3.eth.coinbase,
        'to': address,
        'value': initial_balance,
    }, 'this-is-not-a-secure-password')
    wait_for_transaction(web3, funding_txn_hash)

    assert web3.eth.getBalance(address) == initial_balance
    return address
def test_personal_importRawKey_as_bytes(web3, account_private_key, account_password,
                               account_public_key):
    address = web3.personal.importRawKey(account_private_key, account_password)

    # sanity check
    assert normalize_address(address) == normalize_address(account_public_key)

    assert web3.personal.unlockAccount(address, account_password) is True
def test_personal_importRawKey_as_hex_without_0x(web3, account_private_key, account_password,
                               account_public_key):
    address = web3.personal.importRawKey(strip_0x(encode_32bytes(account_private_key)), account_password)

    # sanity check
    assert normalize_address(address) == normalize_address(account_public_key)

    assert web3.personal.unlockAccount(address, account_password) is True
Example #4
0
def test_personal_importRawKey_as_bytes(web3_empty, account_private_key,
                                        account_password, account_public_key):
    web3 = web3_empty

    address = web3.personal.importRawKey(account_private_key, account_password)

    # sanity check
    assert normalize_address(address) == normalize_address(account_public_key)

    assert web3.personal.unlockAccount(address, account_password) is True
def test_personal_importRawKey(accounts, rpc_client):
    initial_accounts = rpc_client('personal_listAccounts')

    private_key = mk_random_privkey()

    new_account = rpc_client('personal_importRawKey', [private_key, 'a-password'])
    n_new_account = normalize_address(new_account)

    assert n_new_account in {normalize_address(acct) for acct in rpc_client('personal_listAccounts')}
    assert rpc_client('personal_unlockAccount', [new_account, 'a-password']) is True
Example #6
0
def password_account(rpc_client, accounts, account_password,
                     account_private_key, account_public_key):
    from eth_tester_client.utils import normalize_address
    address = rpc_client(
        'personal_importRawKey',
        [account_private_key, account_password],
    )
    assert normalize_address(address) == normalize_address(account_public_key)

    initial_balance = 1000000000000000000000  # 1,000 ether

    rpc_client('eth_sendTransaction', [{
        'from': accounts[0],
        'to': address,
        'value': initial_balance,
    }])

    assert rpc_client('eth_getBalance', [address]) == initial_balance
    return address
Example #7
0
def password_account(web3_empty, account_password, account_private_key,
                     account_public_key, wait_for_transaction):
    from eth_tester_client.utils import normalize_address

    web3 = web3_empty

    address = web3.personal.importRawKey(account_private_key, account_password)

    # sanity check
    assert normalize_address(address) == normalize_address(account_public_key)

    initial_balance = 1000000000000000000000  # 1,000 ether

    funding_txn_hash = web3.personal.signAndSendTransaction(
        {
            'from': web3.eth.coinbase,
            'to': address,
            'value': initial_balance,
        }, 'this-is-not-a-secure-password')
    wait_for_transaction(web3, funding_txn_hash)

    assert web3.eth.getBalance(address) == initial_balance
    return address
def test_personal_listAccounts(accounts, rpc_client):
    actual = rpc_client('personal_listAccounts')
    n_actual = {normalize_address(acct) for acct in actual}
    n_expected = {normalize_address(acct) for acct in accounts}

    assert n_actual == n_expected
Example #9
0
def test_eth_coinbase(accounts, rpc_client):
    result = rpc_client('eth_coinbase')
    assert normalize_address(result) == normalize_address(accounts[0])
Example #10
0
def accounts():
    from ethereum import tester
    from eth_tester_client.utils import normalize_address
    return [normalize_address(acct) for acct in tester.accounts]