Skip to content

Commit

Permalink
added tests for permitting binary addresses in web3
Browse files Browse the repository at this point in the history
fixed ethtester tests
  • Loading branch information
voith committed Jun 11, 2018
1 parent 72e456d commit 0aad54c
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 54 deletions.
17 changes: 15 additions & 2 deletions tests/core/contracts/test_contract_init.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest

from eth_utils import (
to_bytes,
)

from web3.exceptions import (
BadFunctionCallOutput,
NameNotFound,
Expand All @@ -11,12 +15,21 @@


@pytest.fixture
def math_addr(MathContract):
def math_deploy_receipt(MathContract):
web3 = MathContract.web3
deploy_txn = MathContract.constructor().transact({'from': web3.eth.coinbase})
deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn)
assert deploy_receipt is not None
return deploy_receipt['contractAddress']
return deploy_receipt


@pytest.fixture(params=['hex', 'bytes'])
def math_addr(request, math_deploy_receipt):
addr = math_deploy_receipt['contractAddress']
if request.param == 'bytes':
return to_bytes(hexstr=addr)
else:
return addr


def test_contract_with_unset_address(MathContract):
Expand Down
6 changes: 6 additions & 0 deletions tests/core/eth-module/test_eth_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
Mock,
)

from eth_utils import (
to_bytes,
)

ABI = [{}]
ADDRESS = '0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
BYTES_ADDRESS = to_bytes(hexstr=ADDRESS)
NON_CHECKSUM_ADDRESS = '0xd3cda913deb6f67967b99d67acdfa1712c293601'
INVALID_CHECKSUM_ADDRESS = '0xd3CDA913deB6f67967B99D67aCDFa1712C293601'

Expand All @@ -13,6 +18,7 @@
'args,kwargs,expected',
(
((ADDRESS,), {}, None),
((BYTES_ADDRESS,), {}, None),
((INVALID_CHECKSUM_ADDRESS,), {}, ValueError),
((NON_CHECKSUM_ADDRESS,), {}, ValueError),
((), {'address': ADDRESS}, None),
Expand Down
10 changes: 10 additions & 0 deletions tests/core/utilities/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest

from eth_utils import (
to_bytes,
)

from web3.exceptions import (
InvalidAddress,
)
Expand Down Expand Up @@ -64,9 +68,12 @@
]

ADDRESS = '0xd3CdA913deB6f67967B99D67aCDFa1712C293601'
BYTES_ADDRESS = to_bytes(hexstr=ADDRESS)
PADDED_ADDRESS = '0x000000000000000000000000d3cda913deb6f67967b99d67acdfa1712c293601'
INVALID_CHECKSUM_ADDRESS = '0xd3CDA913deB6f67967B99D67aCDFa1712C293601'
NON_CHECKSUM_ADDRESS = '0xd3cda913deb6f67967b99d67acdfa1712c293601'
BYTES_ADDRESS_LEN_LT_20 = bytes(1) * 19
BYTES_ADDRESS_LEN_GT_20 = bytes(1) * 21


@pytest.mark.parametrize(
Expand All @@ -78,9 +85,12 @@
(MALFORMED_SELECTOR_COLLISION_ABI, validate_abi, ValueError),
(MALFORMED_SIGNATURE_COLLISION_ABI, validate_abi, ValueError),
(ADDRESS, validate_address, None),
(BYTES_ADDRESS, validate_address, None),
(PADDED_ADDRESS, validate_address, InvalidAddress),
(INVALID_CHECKSUM_ADDRESS, validate_address, InvalidAddress),
(NON_CHECKSUM_ADDRESS, validate_address, InvalidAddress),
(BYTES_ADDRESS_LEN_LT_20, validate_address, InvalidAddress),
(BYTES_ADDRESS_LEN_GT_20, validate_address, InvalidAddress),
("NotAddress", validate_address, InvalidAddress),
(b'not string', validate_address, InvalidAddress),
('bool', validate_abi_type, None),
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/go_ethereum/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from eth_utils import (
is_checksum_address,
is_dict,
to_bytes,
to_text,
)

Expand Down Expand Up @@ -172,6 +173,14 @@ def emitter_contract(web3, emitter_contract_factory, geth_fixture_data):
return emitter_contract_factory(address=geth_fixture_data['emitter_address'])


@pytest.fixture(scope="module", params=['bytes', 'hex'])
def emitter_contract_address(emitter_contract, request):
if request.param == 'bytes':
return to_bytes(hexstr=emitter_contract.address)
else:
return emitter_contract.address


@pytest.fixture
def unlocked_account(web3, unlockable_account, unlockable_account_pw):
web3.personal.unlockAccount(unlockable_account, unlockable_account_pw)
Expand All @@ -189,6 +198,21 @@ def unlockable_account(web3, coinbase):
yield coinbase


@pytest.fixture(params=['bytes', 'hex'])
def unlockable_account_dual_type(unlockable_account, request):
if request.param == 'bytes':
return to_bytes(hexstr=unlockable_account)
else:
return unlockable_account


@pytest.yield_fixture
def unlocked_account_dual_type(web3, unlockable_account_dual_type, unlockable_account_pw):
web3.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
yield unlockable_account_dual_type
web3.personal.lockAccount(unlockable_account_dual_type)


@pytest.fixture(scope="module")
def funded_account_for_raw_txn(geth_fixture_data):
account = geth_fixture_data['raw_txn_account']
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/parity/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def test_trace_block(self, web3, block_with_txn):
def test_trace_transaction(self, web3, parity_fixture_data):
super().test_trace_transaction(web3, parity_fixture_data)

def test_trace_call(self, web3, math_contract):
super().test_trace_call(web3, math_contract)
def test_trace_call(self, web3, math_contract, math_contract_address):
super().test_trace_call(web3, math_contract, math_contract_address)

def test_eth_call_with_0_result(self, web3, math_contract):
super().test_eth_call_with_0_result(web3, math_contract)
def test_eth_call_with_0_result(self, web3, math_contract, math_contract_address):
super().test_eth_call_with_0_result(web3, math_contract, math_contract_address)
30 changes: 30 additions & 0 deletions tests/integration/parity/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from eth_utils import (
is_checksum_address,
is_dict,
to_bytes,
)

from .install_parity import (
Expand Down Expand Up @@ -138,11 +139,27 @@ def math_contract(web3, math_contract_factory, parity_fixture_data):
return math_contract_factory(address=parity_fixture_data['math_address'])


@pytest.fixture(scope="module", params=['bytes', 'hex'])
def math_contract_address(math_contract, request):
if request.param == 'bytes':
return math_contract.address
else:
return math_contract.address


@pytest.fixture(scope="module")
def emitter_contract(web3, emitter_contract_factory, parity_fixture_data):
return emitter_contract_factory(address=parity_fixture_data['emitter_address'])


@pytest.fixture(scope="module", params=['bytes', 'hex'])
def emitter_contract_address(emitter_contract, request):
if request.param == 'bytes':
return to_bytes(hexstr=emitter_contract.address)
else:
return emitter_contract.address


@pytest.fixture(scope="module")
def unlocked_account(web3, unlockable_account, unlockable_account_pw):
yield unlockable_account
Expand All @@ -158,6 +175,19 @@ def unlockable_account(web3, coinbase):
yield coinbase


@pytest.fixture(params=['bytes', 'hex'])
def unlockable_account_dual_type(unlockable_account, request):
if request.param == 'bytes':
return to_bytes(hexstr=unlockable_account)
else:
return unlockable_account


@pytest.fixture
def unlocked_account_dual_type(unlockable_account_dual_type):
return unlockable_account_dual_type


@pytest.fixture(scope="module")
def funded_account_for_raw_txn(parity_fixture_data):
account = parity_fixture_data['raw_txn_account']
Expand Down
32 changes: 32 additions & 0 deletions tests/integration/test_ethereum_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from eth_utils import (
is_checksum_address,
is_dict,
to_bytes,
)

from web3 import Web3
Expand Down Expand Up @@ -63,6 +64,14 @@ def math_contract(web3, math_contract_factory, math_contract_deploy_txn_hash):
return math_contract_factory(contract_address)


@pytest.fixture(scope="module", params=['bytes', 'hex'])
def math_contract_address(math_contract, request):
if request.param == 'bytes':
return math_contract.address
else:
return math_contract.address


#
# Emitter Contract Setup
#
Expand All @@ -81,6 +90,14 @@ def emitter_contract(web3, emitter_contract_factory, emitter_contract_deploy_txn
return emitter_contract_factory(contract_address)


@pytest.fixture(scope="module", params=['bytes', 'hex'])
def emitter_contract_address(emitter_contract, request):
if request.param == 'bytes':
return to_bytes(hexstr=emitter_contract.address)
else:
return emitter_contract.address


@pytest.fixture(scope="module")
def empty_block(web3):
web3.testing.mine()
Expand Down Expand Up @@ -151,6 +168,21 @@ def unlocked_account(web3, unlockable_account, unlockable_account_pw):
web3.personal.lockAccount(unlockable_account)


@pytest.fixture(params=['bytes', 'hex'])
def unlockable_account_dual_type(unlockable_account, request):
if request.param == 'bytes':
return to_bytes(hexstr=unlockable_account)
else:
return unlockable_account


@pytest.fixture
def unlocked_account_dual_type(web3, unlockable_account_dual_type, unlockable_account_pw):
web3.personal.unlockAccount(unlockable_account_dual_type, unlockable_account_pw)
yield unlockable_account_dual_type
web3.personal.lockAccount(unlockable_account_dual_type)


@pytest.fixture(scope="module")
def funded_account_for_raw_txn(web3):
account = '0x39EEed73fb1D3855E90Cbd42f348b3D7b340aAA6'
Expand Down
Loading

0 comments on commit 0aad54c

Please sign in to comment.