mirror of
https://github.com/FlipsideCrypto/web3.py.git
synced 2026-02-06 10:56:47 +00:00
trim tests
This commit is contained in:
parent
57cf653507
commit
d5daaf4ab9
@ -1,186 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from web3.utils.address import (
|
||||
is_address,
|
||||
is_strict_address,
|
||||
is_checksum_address,
|
||||
to_checksum_address,
|
||||
to_address,
|
||||
is_same_address,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
(lambda : None, False),
|
||||
("function", False),
|
||||
({}, False),
|
||||
("0xc6d9d2cd449a754c494264e1809c50e34d64562b", True),
|
||||
("c6d9d2cd449a754c494264e1809c50e34d64562b", True),
|
||||
# malformed
|
||||
("c6d9d2cd449a754c494264e1809c50e34d64562", False), # too short
|
||||
("0xc6d9d2cd449a754c494264e1809c50e34d64562", False),
|
||||
("c6d9d2cd449a754c494264e1809c50e34d64562bb", False), # too long
|
||||
("0xc6d9d2cd449a754c494264e1809c50e34d64562bb", False),
|
||||
("c6d9d2cd449a754c494264e1809c50e34d64562x", False), # non-hex-character
|
||||
("0xc6d9d2cd449a754c494264e1809c50e34d6456x", False),
|
||||
]
|
||||
)
|
||||
def test_is_address(value, expected):
|
||||
assert is_address(value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
('0x52908400098527886E0F7030069857D2E4169EE7', True),
|
||||
('0x8617E340B3D01FA5F11F306F4090FD50E238070D', True),
|
||||
('0xde709f2102306220921060314715629080e2fb77', True),
|
||||
('0x27b1fdb04752bbc536007a920d24acb045561c26', True),
|
||||
('0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed', True),
|
||||
('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359', True),
|
||||
('0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB', True),
|
||||
('0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', True),
|
||||
('0XD1220A0CF47C7B9BE7A2E6BA89F429762E7B9ADB', False),
|
||||
('0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb', False)
|
||||
]
|
||||
)
|
||||
def test_is_checksum_address(value, expected):
|
||||
assert is_checksum_address(value) == expected, (value, to_checksum_address(value))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
(lambda: None, False),
|
||||
("function", False),
|
||||
({}, False),
|
||||
('0xc6d9d2cd449a754c494264e1809c50e34d64562b', True),
|
||||
('c6d9d2cd449a754c494264e1809c50e34d64562b', False)
|
||||
]
|
||||
)
|
||||
def test_is_strict_address(value, expected):
|
||||
assert is_strict_address(value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
(
|
||||
(
|
||||
b'\xd3\xcd\xa9\x13\xde\xb6\xf6yg\xb9\x9dg\xac\xdf\xa1q,)6\x01',
|
||||
'0xd3cda913deb6f67967b99d67acdfa1712c293601',
|
||||
),
|
||||
(
|
||||
b'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
),
|
||||
(
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
),
|
||||
(
|
||||
b'0XC6D9D2CD449A754C494264E1809C50E34D64562B',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
),
|
||||
(
|
||||
'0XC6D9D2CD449A754C494264E1809C50E34D64562B',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
),
|
||||
(
|
||||
'c6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
),
|
||||
(
|
||||
'C6D9D2CD449A754C494264E1809C50E34D64562B',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
),
|
||||
(
|
||||
'0x000000000000000000000000c305c901078781c232a2a521c2af7980f8385ee9',
|
||||
'0xc305c901078781c232a2a521c2af7980f8385ee9',
|
||||
),
|
||||
(
|
||||
b'0x000000000000000000000000c305c901078781c232a2a521c2af7980f8385ee9',
|
||||
'0xc305c901078781c232a2a521c2af7980f8385ee9',
|
||||
),
|
||||
(
|
||||
'000000000000000000000000c305c901078781c232a2a521c2af7980f8385ee9',
|
||||
'0xc305c901078781c232a2a521c2af7980f8385ee9',
|
||||
),
|
||||
)
|
||||
)
|
||||
def test_to_address(value, expected):
|
||||
assert to_address(value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
(
|
||||
(
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cD449A754c494264e1809c50e34D64562b',
|
||||
),
|
||||
(
|
||||
'c6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cD449A754c494264e1809c50e34D64562b',
|
||||
),
|
||||
)
|
||||
)
|
||||
def test_to_checksum_address(value, expected):
|
||||
assert to_checksum_address(value) == expected, (to_checksum_address(value), expected)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"address1,address2,expected",
|
||||
(
|
||||
(
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cD449A754c494264e1809c50e34D64562b',
|
||||
True,
|
||||
),
|
||||
(
|
||||
'c6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cD449A754c494264e1809c50e34D64562b',
|
||||
True,
|
||||
),
|
||||
(
|
||||
b'\xd3\xcd\xa9\x13\xde\xb6\xf6yg\xb9\x9dg\xac\xdf\xa1q,)6\x01',
|
||||
'0xd3cda913deb6f67967b99d67acdfa1712c293601',
|
||||
True,
|
||||
),
|
||||
(
|
||||
b'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
True,
|
||||
),
|
||||
(
|
||||
b'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc305c901078781c232a2a521c2af7980f8385ee9',
|
||||
False,
|
||||
),
|
||||
(
|
||||
'c6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
True,
|
||||
),
|
||||
(
|
||||
'C6D9D2CD449A754C494264E1809C50E34D64562B',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
True,
|
||||
),
|
||||
(
|
||||
'0x000000000000000000000000c305c901078781c232a2a521c2af7980f8385ee9',
|
||||
'0xc305c901078781c232a2a521c2af7980f8385ee9',
|
||||
True,
|
||||
),
|
||||
(
|
||||
b'0x000000000000000000000000c305c901078781c232a2a521c2af7980f8385ee9',
|
||||
'0xc6d9d2cd449a754c494264e1809c50e34d64562b',
|
||||
False,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
def test_is_same_address(address1, address2, expected):
|
||||
assert is_same_address(address1, address2) == expected
|
||||
@ -1,89 +0,0 @@
|
||||
import decimal
|
||||
|
||||
import pytest
|
||||
from hypothesis import (
|
||||
given,
|
||||
strategies as st,
|
||||
)
|
||||
|
||||
from web3.utils.currency import (
|
||||
units,
|
||||
to_wei,
|
||||
from_wei,
|
||||
MIN_WEI,
|
||||
MAX_WEI,
|
||||
)
|
||||
|
||||
|
||||
@given(
|
||||
amount_in_wei=st.integers(min_value=MIN_WEI, max_value=MAX_WEI),
|
||||
intermediate_unit=st.sampled_from(tuple(units.keys())),
|
||||
)
|
||||
def test_conversion_rount_trip(amount_in_wei, intermediate_unit):
|
||||
intermediate_amount = from_wei(amount_in_wei, intermediate_unit)
|
||||
result_amount = to_wei(intermediate_amount, intermediate_unit)
|
||||
assert result_amount == amount_in_wei
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
([1000000000000000000, 'wei'], '1000000000000000000'),
|
||||
([1000000000000000000, 'kwei'], '1000000000000000'),
|
||||
([1000000000000000000, 'mwei'], '1000000000000'),
|
||||
([1000000000000000000, 'gwei'], '1000000000'),
|
||||
([1000000000000000000, 'szabo'], '1000000'),
|
||||
([1000000000000000000, 'finney'], '1000'),
|
||||
([1000000000000000000, 'ether'], '1'),
|
||||
([1000000000000000000, 'kether'], '0.001'),
|
||||
([1000000000000000000, 'grand'], '0.001'),
|
||||
([1000000000000000000, 'mether'], '0.000001'),
|
||||
([1000000000000000000, 'gether'], '0.000000001'),
|
||||
([1000000000000000000, 'tether'], '0.000000000001'),
|
||||
]
|
||||
)
|
||||
def test_from_wei(value, expected):
|
||||
assert from_wei(*value) == decimal.Decimal(expected)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
([1, 'wei'], '1'),
|
||||
([1, 'kwei'], '1000'),
|
||||
([1, 'Kwei'], '1000'),
|
||||
([1, 'babbage'], '1000'),
|
||||
([1, 'mwei'], '1000000'),
|
||||
([1, 'Mwei'], '1000000'),
|
||||
([1, 'lovelace'], '1000000'),
|
||||
([1, 'gwei'], '1000000000'),
|
||||
([1, 'Gwei'], '1000000000'),
|
||||
([1, 'shannon'], '1000000000'),
|
||||
([1, 'szabo'], '1000000000000'),
|
||||
([1, 'finney'], '1000000000000000'),
|
||||
([1, 'ether'], '1000000000000000000'),
|
||||
([1, 'kether'], '1000000000000000000000'),
|
||||
([1, 'grand'], '1000000000000000000000'),
|
||||
([1, 'mether'], '1000000000000000000000000'),
|
||||
([1, 'gether'], '1000000000000000000000000000'),
|
||||
([1, 'tether'], '1000000000000000000000000000000')
|
||||
]
|
||||
)
|
||||
def test_to_wei(value, expected):
|
||||
assert to_wei(*value) == decimal.Decimal(expected)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'value,unit',
|
||||
(
|
||||
(1, 'wei1'),
|
||||
(1, 'not-a-unit'),
|
||||
(-1, 'ether'),
|
||||
)
|
||||
)
|
||||
def test_invalid_to_wei_values(value, unit):
|
||||
with pytest.raises(ValueError):
|
||||
to_wei(value, unit)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
from_wei(value, unit)
|
||||
@ -6,35 +6,11 @@ from hypothesis import (
|
||||
)
|
||||
|
||||
from web3.utils.encoding import (
|
||||
encode_hex,
|
||||
decode_hex,
|
||||
from_decimal,
|
||||
to_decimal,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
('myString', '0x6d79537472696e67'),
|
||||
('myString\x00', '0x6d79537472696e6700'),
|
||||
(
|
||||
b'\xd9e\x11\xbe\xdbj\x81Q\xea\xb5\x9et\xd6l\r\xa7\xdfc\x14c\xb8b\x1ap\x8e@\x93\xe6\xec\xd7P\x8a',
|
||||
'0xd96511bedb6a8151eab59e74d66c0da7df631463b8621a708e4093e6ecd7508a',
|
||||
)
|
||||
]
|
||||
)
|
||||
def test_encode_hex(value, expected):
|
||||
assert encode_hex(value) == expected
|
||||
|
||||
|
||||
@given(value=st.binary(min_size=0, average_size=32, max_size=256))
|
||||
def test_hex_encode_decode_round_trip(value):
|
||||
intermediate_value = encode_hex(value)
|
||||
result_value = decode_hex(intermediate_value)
|
||||
assert result_value == value, "Expected: {0!r}, Result: {1!r}, Intermediate: {2!r}".format(value, result_value, intermediate_value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
from web3.utils.functional import compose
|
||||
|
||||
|
||||
def test_composition_no_functions():
|
||||
fn = compose()
|
||||
assert fn(5) == 5
|
||||
|
||||
|
||||
def test_composition_single_function():
|
||||
def fn(x):
|
||||
return x * 2
|
||||
|
||||
assert compose(fn)(5) == 10
|
||||
|
||||
|
||||
def test_composition_multiple_function():
|
||||
def fn(x):
|
||||
return x + 1
|
||||
|
||||
assert compose(fn, fn, fn)(5) == 8
|
||||
@ -1,43 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'value,expected,encoding',
|
||||
(
|
||||
(
|
||||
'',
|
||||
'0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',
|
||||
None,
|
||||
),
|
||||
(
|
||||
'test123',
|
||||
'0xf81b517a242b218999ec8eec0ea6e2ddbef2a367a14e93f4a32a39e260f686ad',
|
||||
None,
|
||||
),
|
||||
(
|
||||
'test(int)',
|
||||
'0xf4d03772bec1e62fbe8c5691e1a9101e520e8f8b5ca612123694632bf3cb51b1',
|
||||
None,
|
||||
),
|
||||
(
|
||||
'0x80',
|
||||
'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
|
||||
'hex',
|
||||
),
|
||||
(
|
||||
'0x80',
|
||||
'0x6b03a5eef7706e3fb52a61c19ab1122fad7237726601ac665bd4def888f0e4a0',
|
||||
None,
|
||||
),
|
||||
(
|
||||
'0x3c9229289a6125f7fdf1885a77bb12c37a8d3b4962d936f7e3084dece32a3ca1',
|
||||
'0x82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28',
|
||||
'hex',
|
||||
)
|
||||
)
|
||||
)
|
||||
def test_sha3(web3, value, expected, encoding):
|
||||
actual = web3.sha3(value, encoding=encoding)
|
||||
assert expected == actual
|
||||
@ -1,89 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from web3.utils.types import (
|
||||
is_integer,
|
||||
is_boolean,
|
||||
is_string,
|
||||
is_array,
|
||||
is_object,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
(3, True),
|
||||
(None, False),
|
||||
("3", False),
|
||||
("0x3", False),
|
||||
(True, False),
|
||||
(False, False),
|
||||
]
|
||||
)
|
||||
def test_is_integer(value, expected):
|
||||
assert is_integer(value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
("3", True),
|
||||
(None, False),
|
||||
(3, False),
|
||||
({}, False),
|
||||
]
|
||||
)
|
||||
def test_is_string(value, expected):
|
||||
assert is_string(value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
(lambda : None, False),
|
||||
(3, False),
|
||||
(None, False),
|
||||
("3", False),
|
||||
("0x3", False),
|
||||
({}, True),
|
||||
({"test": 3}, True),
|
||||
]
|
||||
)
|
||||
def test_is_object(value, expected):
|
||||
assert is_object(value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
(lambda : None, False),
|
||||
(3, False),
|
||||
(None, False),
|
||||
("3", False),
|
||||
("0x3", False),
|
||||
(True, True),
|
||||
(False, True),
|
||||
]
|
||||
)
|
||||
def test_is_boolean(value, expected):
|
||||
assert is_boolean(value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,expected",
|
||||
[
|
||||
(lambda : None, False),
|
||||
(3, False),
|
||||
(None, False),
|
||||
("3", False),
|
||||
("0x3", False),
|
||||
([], True),
|
||||
([3], True),
|
||||
([3, 3], True),
|
||||
([None], True),
|
||||
([tuple()], True),
|
||||
([(1, 2)], True),
|
||||
]
|
||||
)
|
||||
def test_is_array(value, expected):
|
||||
assert is_array(value) == expected
|
||||
Loading…
Reference in New Issue
Block a user