Example #1
0
def empty_account(web3, wait_for_transaction):
    from eth_tester_client.utils import normalize_address
    from eth_tester_client.utils import mk_random_privkey, force_bytes
    address = web3.personal.importRawKey(mk_random_privkey(), "a-password")

    assert web3.eth.getBalance(address) == 0
    return address
Example #2
0
def empty_account(web3_empty):
    web3 = web3_empty

    from eth_tester_client.utils import mk_random_privkey
    address = web3.personal.importRawKey(mk_random_privkey(), "a-password")

    assert web3.eth.getBalance(address) == 0
    return address
Example #3
0
def empty_account(web3_empty):
    web3 = web3_empty

    from eth_tester_client.utils import mk_random_privkey
    address = web3.personal.importRawKey(mk_random_privkey(), "a-password")

    assert web3.eth.getBalance(address) == 0
    return address
def test_import_raw_key(client):
    pk = mk_random_privkey()

    initial_accounts = client.get_accounts()

    address = client.import_raw_key(pk, 'some-password')

    assert address not in initial_accounts
    assert address in client.get_accounts()
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
def test_eth_sendRawTransaction(web3, wait_for_transaction, extra_accounts):
    private_key = mk_random_privkey()
    address = encode_address(privtoaddr(private_key))

    funding_txn_hash = web3.eth.sendTransaction({
        "from": web3.eth.coinbase,
        "to": address,
        "value": 10000000000000000,
    })
    wait_for_transaction(web3, funding_txn_hash)

    if isinstance(web3.currentProvider, TestRPCProvider):
        # ethereum-tester-client doesn't quite implement the
        # `sendRawTransaction` correctly because of how the underlying tester
        # evm works.  It needs to know about the address for this to work.
        web3.personal.importRawKey(private_key, "password")
        web3.personal.unlockAccount(address, "password")

    initial_balance = web3.eth.getBalance(extra_accounts[1])

    tx = Transaction(
        web3.eth.getTransactionCount(address),
        web3.eth.gasPrice,
        100000,
        extra_accounts[1],
        1234,
        '',
    )
    tx.sign(private_key)

    raw_tx = rlp.encode(tx)
    raw_tx_hex = encode_data(raw_tx)

    txn_hash = web3.eth.sendRawTransaction(raw_tx_hex)
    wait_for_transaction(web3, txn_hash)
    txn_receipt = web3.eth.getTransactionReceipt(txn_hash)

    after_balance = web3.eth.getBalance(extra_accounts[1])

    assert after_balance - initial_balance == 1234
def account_private_key():
    from eth_tester_client.utils import mk_random_privkey
    return mk_random_privkey()
def test_priv_key_generation():
    for i in range(100):
        pk = mk_random_privkey()
        assert len(pk) == 32
Example #9
0
def account_private_key():
    from eth_tester_client.utils import mk_random_privkey, force_bytes
    return mk_random_privkey()