mirror of
https://github.com/FlipsideCrypto/web3.py.git
synced 2026-02-06 19:06:52 +00:00
fix eth_sign test
This commit is contained in:
parent
0a48bc156c
commit
c2fcbf4a76
@ -7,14 +7,13 @@ from bitcoin import encode_pubkey
|
||||
|
||||
from ethereum.utils import privtoaddr
|
||||
|
||||
from eth_tester_client.utils import (
|
||||
coerce_return_to_bytes,
|
||||
coerce_args_to_bytes,
|
||||
)
|
||||
|
||||
from web3.providers.rpc import TestRPCProvider
|
||||
from web3.utils.string import (
|
||||
force_bytes,
|
||||
force_text,
|
||||
coerce_return_to_bytes,
|
||||
coerce_return_to_text,
|
||||
coerce_args_to_bytes,
|
||||
)
|
||||
from web3.utils.types import (
|
||||
is_string,
|
||||
@ -37,6 +36,7 @@ assert sha3(b'') == b'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad804
|
||||
|
||||
|
||||
@coerce_args_to_bytes
|
||||
@coerce_return_to_text
|
||||
def extract_ecdsa_signer(msg_hash, signature):
|
||||
msg_hash_bytes = decode_hex(msg_hash) if msg_hash.startswith(b'0x') else msg_hash
|
||||
signature_bytes = decode_hex(signature) if signature.startswith(b'0x') else signature
|
||||
@ -61,17 +61,17 @@ def test_eth_sign(web3):
|
||||
if isinstance(web3.currentProvider, TestRPCProvider):
|
||||
pytest.skip("testrpc doesn't implement `getBlockTransactionCount`")
|
||||
|
||||
private_key_hex = b'0x5e95384d8050109aab08c1922d3c230739bc16976553c317e5d0b87b59371f2a'
|
||||
private_key_hex = '0x5e95384d8050109aab08c1922d3c230739bc16976553c317e5d0b87b59371f2a'
|
||||
private_key = decode_hex(private_key_hex)
|
||||
|
||||
# This imports the private key into the running geth instance and unlocks
|
||||
# the account so that it can sign things.
|
||||
# `0xa5df35f30ba0ce878b1061ae086289adff3ba1e0`
|
||||
address = force_bytes(web3.personal.importRawKey(private_key, "password"))
|
||||
address = web3.personal.importRawKey(private_key, "password")
|
||||
web3.personal.unlockAccount(address, "password")
|
||||
|
||||
assert add_0x_prefix(encode_hex(privtoaddr(private_key))) == add_0x_prefix(address)
|
||||
assert address == b'0xa5df35f30ba0ce878b1061ae086289adff3ba1e0'
|
||||
assert address == '0xa5df35f30ba0ce878b1061ae086289adff3ba1e0'
|
||||
|
||||
# the data to be signed
|
||||
data = b'1234567890abcdefghijklmnopqrstuvwxyz'
|
||||
@ -88,7 +88,7 @@ def test_eth_sign(web3):
|
||||
vector_sig = priv_key.ecdsa_sign_recoverable(data_hash_bytes, raw=True, digest=sha3_256)
|
||||
vector_sig_bytes, rec_id = priv_key.ecdsa_recoverable_serialize(vector_sig)
|
||||
vector_sig_bytes_full = vector_sig_bytes + force_bytes(chr(rec_id))
|
||||
vector_address = extract_ecdsa_signer(data_hash_bytes, vector_sig_bytes_full)
|
||||
vector_address = force_text(extract_ecdsa_signer(data_hash_bytes, vector_sig_bytes_full))
|
||||
|
||||
assert vector_address == address
|
||||
|
||||
@ -118,8 +118,9 @@ def test_eth_sign(web3):
|
||||
raw_sig=signature,
|
||||
digest=sha3_256,
|
||||
)
|
||||
with pytest.raises(AssertionError):
|
||||
# TODO: figure out why this happens and fix it.
|
||||
# For some unknown reason, the extracted account from the signature
|
||||
# returned from geth is not present in the account list.
|
||||
assert is_valid is True
|
||||
|
||||
assert is_valid is False
|
||||
# TODO: figure out why this happens and fix it.
|
||||
# For some unknown reason, the extracted account from the signature
|
||||
# returned from geth is not present in the account list.
|
||||
pytest.skip("This is not behaving as expected")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user