Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 9cd646f

Browse files
authored
Merge pull request #371 from hackaugusto/issue_370
Fix for the issue #370
2 parents 436bedc + 584f15e commit 9cd646f

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

ethereum/tester.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,16 @@ class ContractCreationFailed(Exception):
9898

9999
class ABIContract(object): # pylint: disable=too-few-public-methods
100100

101-
def __init__(self, test_state, abi_translator, address, listen=True, log_listener=None, default_key=None): # pylint: disable=too-many-arguments
101+
def __init__(self, _state, _abi, address, listen=True, # pylint: disable=too-many-arguments
102+
log_listener=None, default_key=None):
102103
self.address = address
103104
self.default_key = default_key or DEFAULT_KEY
105+
106+
if isinstance(_abi, ContractTranslator):
107+
abi_translator = _abi
108+
else:
109+
abi_translator = ContractTranslator(_abi)
110+
104111
self.translator = abi_translator
105112

106113
def listener(log):
@@ -110,10 +117,10 @@ def listener(log):
110117
log_listener(result)
111118

112119
if listen:
113-
test_state.block.log_listeners.append(listener)
120+
_state.block.log_listeners.append(listener)
114121

115122
for function_name in self.translator.function_data:
116-
function = self.method_factory(test_state, function_name)
123+
function = self.method_factory(_state, function_name)
117124
method = types.MethodType(function, self)
118125
setattr(self, function_name, method)
119126

@@ -377,10 +384,13 @@ def trace(self, sender, to, value, data=None):
377384
return recorder.pop_records()
378385

379386
def mine(self, number_of_blocks=1, coinbase=DEFAULT_ACCOUNT, **kwargs):
380-
if 'n' in kwargs: # compatibility
387+
if 'n' in kwargs: # compatibility
381388
number_of_blocks = kwargs['n']
382-
warnings.warn('The argument \'n\' is deprecated and its support will be removed '\
383-
'in the future versions. Please use the name \'number_of_blocks\'.')
389+
warnings.warn(
390+
"The argument 'n' is deprecated and its support will be removed "
391+
"in the future versions. Please use the name 'number_of_blocks'."
392+
)
393+
384394
for _ in range(number_of_blocks):
385395
self.block.finalize()
386396
self.block.commit_state()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
contract Simple {
2+
function test() returns (int256) {
3+
return 1;
4+
}
5+
}

ethereum/tests/test_tester.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf8 -*-
2+
import json
3+
from os import path
4+
5+
import pytest
6+
7+
from ethereum.tester import state, ABIContract
8+
from ethereum._solidity import get_solidity, compile_file
9+
10+
SOLIDITY_AVAILABLE = get_solidity() is not None
11+
CONTRACTS_DIR = path.join(path.dirname(__file__), 'contracts')
12+
13+
14+
@pytest.mark.skipif(not SOLIDITY_AVAILABLE, reason='solc compiler not available')
15+
def test_abicontract_interface():
16+
""" Test for issue #370. """
17+
tester_state = state()
18+
19+
contract_path = path.join(CONTRACTS_DIR, 'simple_contract.sol')
20+
simple_compiled = compile_file(contract_path)
21+
simple_address = tester_state.evm(simple_compiled['Simple']['bin'])
22+
23+
# ABIContract class must accept json_abi
24+
abi_json = json.dumps(simple_compiled['Simple']['abi'])
25+
26+
abi = ABIContract(
27+
_state=tester_state,
28+
_abi=abi_json,
29+
address=simple_address,
30+
listen=False,
31+
log_listener=None,
32+
default_key=None,
33+
)
34+
35+
assert abi.test() == 1 # pylint: disable=no-member

0 commit comments

Comments
 (0)