mirror of
https://github.com/FlipsideCrypto/web3.py.git
synced 2026-02-06 10:56:47 +00:00
python2
This commit is contained in:
parent
ce23481cd6
commit
daa2982f71
@ -1,5 +1,6 @@
|
||||
import pytest
|
||||
import warnings
|
||||
import sys
|
||||
|
||||
from web3.contract import (
|
||||
Contract,
|
||||
@ -60,8 +61,12 @@ def test_process_legacy_constructor_signature(args, kwargs, expected):
|
||||
assert getattr(actual, key) == value
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info.major == 2, reason="Python2 fails weirdly on this test")
|
||||
def test_deprecated_properties():
|
||||
instance = ContactClassForTest(ABI, ADDRESS, '0x1', '0x2', '0x3')
|
||||
instance = ContactClassForTest(ABI, ADDRESS, '0x1', '0x2', source='0x3')
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
instance.source
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
instance.code
|
||||
@ -69,10 +74,8 @@ def test_deprecated_properties():
|
||||
with pytest.warns(DeprecationWarning):
|
||||
instance.code_runtime
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
instance.source
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info.major == 2, reason="Python2 fails weirdly on this test")
|
||||
def test_deprecated_instantiation():
|
||||
with pytest.warns(Warning) as record:
|
||||
ContactClassForTest(ADDRESS)
|
||||
|
||||
@ -121,15 +121,17 @@ class Contract(object):
|
||||
|
||||
def __init__(self,
|
||||
*args,
|
||||
code=empty,
|
||||
code_runtime=empty,
|
||||
source=empty,
|
||||
abi=empty,
|
||||
address=empty):
|
||||
**kwargs):
|
||||
"""Create a new smart contract proxy object.
|
||||
|
||||
:param address: Contract address as 0x hex string
|
||||
"""
|
||||
code = kwargs.pop('code', empty)
|
||||
code_runtime = kwargs.pop('code_runtime', empty)
|
||||
source = kwargs.pop('source', empty)
|
||||
abi = kwargs.pop('abi', empty)
|
||||
address = kwargs.pop('address', empty)
|
||||
|
||||
if self.web3 is None:
|
||||
raise AttributeError(
|
||||
'The `Contract` class has not been initialized. Please use the '
|
||||
@ -155,17 +157,17 @@ class Contract(object):
|
||||
raise TypeError("The 'address' argument was found twice")
|
||||
address = arg_1
|
||||
|
||||
if arg_2:
|
||||
if arg_2 is not empty:
|
||||
if code:
|
||||
raise TypeError("The 'code' argument was found twice")
|
||||
code = arg_2
|
||||
|
||||
if arg_3:
|
||||
if arg_3 is not empty:
|
||||
if code_runtime:
|
||||
raise TypeError("The 'code_runtime' argument was found twice")
|
||||
code_runtime = arg_3
|
||||
|
||||
if arg_4:
|
||||
if arg_4 is not empty:
|
||||
if source:
|
||||
raise TypeError("The 'source' argument was found twice")
|
||||
source = arg_4
|
||||
|
||||
@ -341,9 +341,10 @@ class Eth(object):
|
||||
|
||||
def contract(self,
|
||||
*args,
|
||||
contract_name=None,
|
||||
ContractFactoryClass=Contract,
|
||||
**kwargs):
|
||||
ContractFactoryClass = kwargs.pop('ContractFactoryClass', Contract)
|
||||
contract_name = kwargs.pop('contract_name', None)
|
||||
|
||||
has_address = any((
|
||||
'address' in kwargs,
|
||||
len(args) >= 1 and is_address(args[0]),
|
||||
@ -359,13 +360,13 @@ class Eth(object):
|
||||
address = args[1]
|
||||
kwargs['abi'] = args[0]
|
||||
|
||||
return Contract.factory(self.web3, contract_name, **kwargs)(address)
|
||||
return ContractFactoryClass.factory(self.web3, contract_name, **kwargs)(address)
|
||||
else:
|
||||
try:
|
||||
kwargs['abi'] = args[0]
|
||||
except IndexError:
|
||||
pass
|
||||
return Contract.factory(self.web3, contract_name, **kwargs)
|
||||
return ContractFactoryClass.factory(self.web3, contract_name, **kwargs)
|
||||
|
||||
def getCompilers(self):
|
||||
return self.web3._requestManager.request_blocking("eth_getCompilers", [])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user