mirror of
https://github.com/FlipsideCrypto/web3.py.git
synced 2026-02-06 10:56:47 +00:00
start cleaning up test imports
This commit is contained in:
parent
d5daaf4ab9
commit
820e6b8847
@ -2,7 +2,7 @@ import pytest
|
||||
import json
|
||||
import textwrap
|
||||
|
||||
from web3.utils.abi import (
|
||||
from eth_utils import (
|
||||
event_signature_to_log_topic,
|
||||
)
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from web3.utils.string import (
|
||||
from eth_utils import (
|
||||
force_bytes,
|
||||
)
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from web3.utils.abi import (
|
||||
from eth_utils import (
|
||||
function_abi_to_4byte_selector,
|
||||
)
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from web3.utils.string import force_bytes
|
||||
from eth_utils import (
|
||||
force_bytes,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from web3.utils.string import force_bytes
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def wait_for_first_block(web3, wait_for_block):
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from web3.utils.string import force_bytes
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def wait_for_first_block(web3, wait_for_block):
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from web3.utils.string import force_bytes
|
||||
from eth_utils import force_bytes
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
||||
@ -6,23 +6,15 @@ from bitcoin import encode_pubkey
|
||||
|
||||
from ethereum.utils import privtoaddr
|
||||
|
||||
from web3.utils.crypto import (
|
||||
sha3 as _sha3,
|
||||
)
|
||||
from web3.utils.string import (
|
||||
from eth_utils import (
|
||||
force_bytes,
|
||||
force_text,
|
||||
coerce_return_to_bytes,
|
||||
coerce_return_to_text,
|
||||
coerce_args_to_bytes,
|
||||
)
|
||||
from web3.utils.types import (
|
||||
keccak,
|
||||
is_string,
|
||||
)
|
||||
from web3.utils.formatting import (
|
||||
add_0x_prefix,
|
||||
)
|
||||
from web3.utils.encoding import (
|
||||
encode_hex,
|
||||
decode_hex,
|
||||
)
|
||||
@ -30,7 +22,7 @@ from web3.utils.encoding import (
|
||||
|
||||
@coerce_return_to_bytes
|
||||
def sha3(s):
|
||||
return add_0x_prefix(_sha3(s))
|
||||
return encode_hex(keccak(s))
|
||||
|
||||
|
||||
assert sha3(b'') == b'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
|
||||
|
||||
@ -2,7 +2,7 @@ import pytest
|
||||
import json
|
||||
import textwrap
|
||||
|
||||
from web3.utils.abi import (
|
||||
from eth_utils import (
|
||||
event_signature_to_log_topic,
|
||||
)
|
||||
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from eth_utils import (
|
||||
denoms,
|
||||
to_normalized_address,
|
||||
decode_hex,
|
||||
)
|
||||
|
||||
from web3.providers.manager import (
|
||||
PrivateKeySigningManager,
|
||||
)
|
||||
from web3.utils.address import to_address
|
||||
from web3.utils.currency import denoms
|
||||
from web3.utils.encoding import decode_hex
|
||||
|
||||
from testrpc.client.utils import (
|
||||
mk_random_privkey,
|
||||
@ -21,7 +24,7 @@ def account_private_key():
|
||||
@pytest.fixture()
|
||||
def account_public_key(account_private_key):
|
||||
from ethereum.utils import privtoaddr
|
||||
return to_address(encode_address(privtoaddr(account_private_key)))
|
||||
return to_normalized_address(encode_address(privtoaddr(account_private_key)))
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
||||
@ -2,7 +2,10 @@ import random
|
||||
|
||||
from flaky import flaky
|
||||
|
||||
from web3.utils.encoding import decode_hex
|
||||
from eth_utils import (
|
||||
decode_hex,
|
||||
)
|
||||
|
||||
from web3.utils.compat import (
|
||||
Timeout,
|
||||
)
|
||||
|
||||
@ -4,12 +4,10 @@ from testrpc.client.utils import (
|
||||
mk_random_privkey,
|
||||
)
|
||||
|
||||
from web3.utils.string import (
|
||||
from eth_utils import (
|
||||
force_bytes,
|
||||
)
|
||||
from web3.utils.address import (
|
||||
to_address,
|
||||
is_same_address,
|
||||
to_normalized_address,
|
||||
)
|
||||
|
||||
|
||||
@ -26,7 +24,7 @@ def account_private_key():
|
||||
@pytest.fixture()
|
||||
def account_public_key(account_private_key):
|
||||
from ethereum.utils import privtoaddr
|
||||
return to_address(privtoaddr(account_private_key))
|
||||
return to_normalized_address(privtoaddr(account_private_key))
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
from testrpc.client.utils import (
|
||||
encode_32bytes,
|
||||
from eth_utils import (
|
||||
is_same_address,
|
||||
remove_0x_prefix,
|
||||
)
|
||||
|
||||
from web3.utils.address import (
|
||||
is_same_address,
|
||||
)
|
||||
from web3.utils.formatting import (
|
||||
remove_0x_prefix,
|
||||
from testrpc.client.utils import (
|
||||
encode_32bytes,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from web3.utils.abi import (
|
||||
from eth_utils import (
|
||||
event_abi_to_log_topic,
|
||||
)
|
||||
|
||||
from web3.utils.filters import (
|
||||
construct_event_filter_params,
|
||||
)
|
||||
|
||||
@ -2,13 +2,12 @@ import pytest
|
||||
|
||||
import rlp
|
||||
|
||||
from web3.utils.address import (
|
||||
to_address,
|
||||
)
|
||||
from web3.utils.encoding import (
|
||||
from eth_utils import (
|
||||
encode_hex,
|
||||
decode_hex,
|
||||
is_same_address,
|
||||
)
|
||||
|
||||
from web3.utils.transactions import (
|
||||
Transaction,
|
||||
UnsignedTransaction,
|
||||
@ -35,7 +34,7 @@ def test_transaction_serialization():
|
||||
serialized_txn = serialize_transaction(transaction)
|
||||
unserialized_txn = rlp.decode(serialized_txn, UnsignedTransaction)
|
||||
|
||||
assert to_address(unserialized_txn.to) == transaction['to']
|
||||
assert is_same_address(unserialized_txn.to, transaction['to'])
|
||||
assert unserialized_txn.startgas == int(transaction['gas'], 16)
|
||||
assert unserialized_txn.gasprice == int(transaction['gasPrice'], 16)
|
||||
assert unserialized_txn.nonce == int(transaction['nonce'], 16)
|
||||
@ -65,7 +64,7 @@ def test_adding_signature_to_transaction(wait_for_first_block,
|
||||
decode_hex(signature_hex),
|
||||
)
|
||||
|
||||
assert to_address(signed_transaction.to) == transaction['to']
|
||||
assert is_same_address(signed_transaction.to, transaction['to'])
|
||||
assert signed_transaction.startgas == int(transaction['gas'], 16)
|
||||
assert signed_transaction.gasprice == int(transaction['gasPrice'], 16)
|
||||
assert signed_transaction.nonce == int(transaction['nonce'], 16)
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import pytest
|
||||
|
||||
from web3.utils.formatting import (
|
||||
pad_left,
|
||||
pad_right,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
(["test", 3, ""], "test"),
|
||||
(["test", 5, ""], "test"),
|
||||
(["test", 8, ""], "test"),
|
||||
(["test", 8, "0"], "0000test"),
|
||||
]
|
||||
)
|
||||
def test_padLeft(value, expected):
|
||||
assert pad_left(*value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
(["test", 3, ""], "test"),
|
||||
(["test", 5, ""], "test"),
|
||||
(["test", 8, ""], "test"),
|
||||
(["test", 8, "0"], "test0000"),
|
||||
]
|
||||
)
|
||||
def test_padRight(value, expected):
|
||||
assert pad_right(*value) == expected
|
||||
@ -4,17 +4,18 @@ import collections
|
||||
|
||||
import rlp
|
||||
|
||||
from web3.utils.crypto import sha3
|
||||
from web3.utils.string import force_text
|
||||
from web3.utils.address import to_address
|
||||
from web3.utils.types import (
|
||||
from eth_utils import (
|
||||
force_text,
|
||||
to_normalized_address,
|
||||
is_string,
|
||||
is_object,
|
||||
)
|
||||
from web3.utils.encoding import (
|
||||
to_decimal,
|
||||
is_dict,
|
||||
encode_hex,
|
||||
decode_hex,
|
||||
keccak,
|
||||
)
|
||||
|
||||
from web3.utils.encoding import (
|
||||
to_decimal,
|
||||
)
|
||||
from web3.utils.transactions import (
|
||||
is_bitcoin_available,
|
||||
@ -43,7 +44,7 @@ class RequestManager(object):
|
||||
|
||||
if is_string(response_raw):
|
||||
response = json.loads(force_text(response_raw))
|
||||
elif is_object(response_raw):
|
||||
elif is_dict(response_raw):
|
||||
response = response_raw
|
||||
|
||||
if "error" in response:
|
||||
@ -208,13 +209,13 @@ class BaseSendRawTransactionMixin(ManagerWrapper):
|
||||
if method in self.TXN_SENDING_METHODS:
|
||||
if method == 'eth_sendRawTransaction':
|
||||
txn = rlp.decode(decode_hex(params[0]), Transaction)
|
||||
self._known_transactions[to_address(txn.sender)].add(result)
|
||||
self._known_nonces[to_address(txn.sender)].add(txn.nonce)
|
||||
self._known_transactions[to_normalized_address(txn.sender)].add(result)
|
||||
self._known_nonces[to_normalized_address(txn.sender)].add(txn.nonce)
|
||||
else:
|
||||
txn = params[0]
|
||||
self._known_transactions[to_address(txn['from'])].add(result)
|
||||
self._known_transactions[to_normalized_address(txn['from'])].add(result)
|
||||
if 'nonce' in txn:
|
||||
self._known_nonces[to_address(txn['from'])].add(
|
||||
self._known_nonces[to_normalized_address(txn['from'])].add(
|
||||
to_decimal(txn['nonce'])
|
||||
)
|
||||
return result
|
||||
@ -264,11 +265,11 @@ class PrivateKeySigningManager(BaseSendRawTransactionMixin):
|
||||
|
||||
def register_private_key(self, key):
|
||||
from bitcoin import privtopub
|
||||
address = to_address(sha3(privtopub(key)[1:])[-40:])
|
||||
address = to_normalized_address(keccak(privtopub(key)[1:])[-20:])
|
||||
self.keys[address] = key
|
||||
|
||||
def sign_and_serialize_transaction(self, transaction):
|
||||
txn_from = to_address(transaction['from'])
|
||||
txn_from = to_normalized_address(transaction['from'])
|
||||
if txn_from not in self.keys:
|
||||
raise KeyError("No signing key registered for from address: {0}".format(txn_from))
|
||||
transaction = Transaction(
|
||||
@ -280,5 +281,5 @@ class PrivateKeySigningManager(BaseSendRawTransactionMixin):
|
||||
data=decode_hex(transaction['data']),
|
||||
)
|
||||
transaction.sign(self.keys[txn_from])
|
||||
assert to_address(transaction.sender) == txn_from
|
||||
assert to_normalized_address(transaction.sender) == txn_from
|
||||
return rlp.encode(transaction, Transaction)
|
||||
|
||||
@ -2,6 +2,10 @@ import logging
|
||||
|
||||
from .base import JSONBaseProvider # noqa: E402
|
||||
|
||||
from eth_utils import (
|
||||
to_dict,
|
||||
)
|
||||
|
||||
from web3.utils.six import (
|
||||
urlunparse,
|
||||
)
|
||||
@ -9,7 +13,6 @@ from web3.utils.compat import (
|
||||
make_post_request,
|
||||
)
|
||||
from web3.utils.http import construct_user_agent
|
||||
from web3.utils.functional import cast_return_to_dict
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -28,7 +31,7 @@ class HTTPProvider(JSONBaseProvider):
|
||||
def __str__(self):
|
||||
return "RPC connection {0}".format(self.endpoint_uri)
|
||||
|
||||
@cast_return_to_dict
|
||||
@to_dict
|
||||
def get_request_kwargs(self):
|
||||
if 'headers' not in self._request_kwargs:
|
||||
yield 'headers', self.get_request_headers()
|
||||
|
||||
@ -14,7 +14,7 @@ from eth_utils import (
|
||||
is_address,
|
||||
)
|
||||
|
||||
from eth_abi.utils.parsing import (
|
||||
from eth_abi.abi import (
|
||||
process_type,
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user