예제 #1
0
def test_incorrect_checksum():
    with pytest.raises(ValidationError,
                       match=".* not a valid BIP39 mnemonic phrase!"):
        # Moved 12th word of valid phrase to be 1st
        Account.from_mnemonic(
            "student into trim cross then helmet popular suit hammer cart shrug oval"
        )
def test_signature_verification(message_encodings):
    account = Account.create()
    structured_msg = encode_structured_data(**message_encodings)
    signed = Account.sign_message(structured_msg, account.key)
    new_addr = Account.recover_message(structured_msg,
                                       signature=signed.signature)
    assert new_addr == account.address
예제 #3
0
def test_invalid_transaction_fields(txn_dict, bad_fields):
    if not bad_fields:
        Account.sign_transaction(txn_dict, TEST_PRIVATE_KEY)
    else:
        with pytest.raises((TypeError, ABITypeError)) as excinfo:
            Account.sign_transaction(txn_dict, TEST_PRIVATE_KEY)
        for field in bad_fields:
            assert field in str(excinfo.value)
예제 #4
0
def acct(request):
    if request.param == 'instance':
        return Account()
    elif request.param == 'class':
        return Account
    else:
        raise Exception(f"account invocation {request.param} is not supported")
def test_signature_variables(message_encodings):
    # Check that the signature of typed message is the same as that
    # mentioned in the EIP. The link is as follows
    # https://github.com/ethereum/EIPs/blob/master/assets/eip-712/Example.js
    structured_msg = encode_structured_data(**message_encodings)
    privateKey = keccak(text="cow")
    acc = Account.from_key(privateKey)
    assert HexBytes(
        acc.address) == HexBytes("0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826")
    sig = Account.sign_message(structured_msg, privateKey)
    assert sig.v == 27
    assert hex(
        sig.r
    ) == "0x58635e9afd7a2a5338cf2af3d711b50235a1955c43f8bca1657c9d0834fcdb5a"
    assert hex(
        sig.s
    ) == "0x44a7c0169616cfdfc16815714c9bc1c94139e17a0761a17530cf3dd1746bc10b"
예제 #6
0
def test_compatibility(seed, language, account_path):
    mnemonic = Mnemonic(language).to_mnemonic(seed)
    acct = Account.from_mnemonic(mnemonic, account_path=account_path)
    # NOTE Must do `cd tests/integration/ethers-cli && npm install -g .
    ethers_cli = subprocess.run(
        ['ethers-cli', '-m', mnemonic, '-l', language, '-p', account_path],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    if ethers_cli.stderr:
        raise IOError(ethers_cli.stderr.decode("utf-8"))
    ethers_address = ethers_cli.stdout.decode("utf-8").strip()
    assert acct.address == ethers_address
예제 #7
0
def test_unknown_language():
    with pytest.raises(ValidationError, match="Invalid language choice.*"):
        Account.create_with_mnemonic(language="pig latin")
예제 #8
0
def test_bad_account_path2():
    with pytest.raises(ValidationError, match="Path.*is not valid.*"):
        Account.create_with_mnemonic(account_path='m/not/an/account/path')
예제 #9
0
def test_bad_account_path1():
    with pytest.raises(ValidationError, match="Path is not valid.*"):
        Account.from_mnemonic(
            "finish oppose decorate face calm tragic certain desk hour urge dinosaur mango",
            account_path='not an account path')
예제 #10
0
def test_incorrect_num_words():
    with pytest.raises(ValidationError,
                       match="Invalid choice for number of words.*"):
        Account.create_with_mnemonic(num_words=11)
예제 #11
0
def test_incorrect_size():
    with pytest.raises(ValidationError, match="Language not detected .*"):
        Account.from_mnemonic("this is not a seed phrase")
예제 #12
0
def test_bad_passphrase():
    a1, mnemonic = Account.create_with_mnemonic(passphrase="My passphrase")
    a2 = Account.from_mnemonic(mnemonic, passphrase="Not my passphrase")
    assert a1.address != a2.address
예제 #13
0
def test_account_restore():
    a1, mnemonic = Account.create_with_mnemonic(num_words=24,
                                                passphrase="TESTING")
    a2 = Account.from_mnemonic(mnemonic, passphrase="TESTING")
    assert a1.address == a2.address
예제 #14
0
def test_account_derivation(mnemonic, account_path, expected_address):
    a = Account.from_mnemonic(mnemonic, account_path=account_path)
    assert a.address == expected_address
예제 #15
0
import pytest

from eth_utils import (
    ValidationError, )

from wan_account import (
    Account, )
from wan_account.hdaccount import (
    ETHEREUM_DEFAULT_PATH, )

Account.enable_unaudited_hdwallet_features()


@pytest.mark.parametrize(
    "mnemonic,account_path,expected_address",
    [
        # Ganache
        # https://github.com/trufflesuite/ganache-core/blob/d1cb5318cb3c694743f86f29d74/test/accounts.js
        (
            "into trim cross then helmet popular suit hammer cart shrug oval student",
            ETHEREUM_DEFAULT_PATH,
            "0x604a95C9165Bc95aE016a5299dd7d400dDDBEa9A",
        ),
        # Metamask
        # https://github.com/MetaMask/eth-hd-keyring/blob/79d088e4a73624537e924b3943830526/test/index.js
        (
            "finish oppose decorate face calm tragic certain desk hour urge dinosaur mango",
            ETHEREUM_DEFAULT_PATH,
            "0x1c96099350f13D558464eC79B9bE4445AA0eF579",
        ),
        (
예제 #16
0
def keyed_acct():
    return Account.from_key(PRIVATE_KEY_AS_BYTES)
예제 #17
0
def test_malformed_seed():
    with pytest.raises(ValidationError,
                       match=".* not a valid BIP39 mnemonic phrase!"):
        # Missing 12th word
        Account.from_mnemonic(
            "into trim cross then helmet popular suit hammer cart shrug oval")