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

Commit 28f1b58

Browse files
committed
added test and rename encode
1 parent 06b76e5 commit 28f1b58

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

ethereum/abi.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf8 -*-
22
import ast
33
import re
4+
import warnings
45

56
import yaml # use yaml instead of json to get non unicode (works with ascii only data)
67
from rlp.utils import decode_hex, encode_hex
@@ -171,7 +172,7 @@ def __init__(self, contract_interface):
171172
else:
172173
raise ValueError('Unknown type {}'.format(description['type']))
173174

174-
def encode(self, function_name, args):
175+
def encode_function_call(self, function_name, args):
175176
""" Return the encoded function call.
176177
177178
Args:
@@ -195,6 +196,10 @@ def encode(self, function_name, args):
195196

196197
return function_selector + arguments
197198

199+
def encode(self, function_name, args):
200+
warnings.warn('encode is deprecated, please use encode_function_call', DeprecationWarning)
201+
return self.encode_function_call(function_name, args)
202+
198203
def encode_constructor_arguments(self, args):
199204
""" Return the encoded constructor call. """
200205
if self.constructor_data is None:

ethereum/tester.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def abi_contract(self, sourcecode, sender=DEFAULT_KEY, endowment=0, # pylint: d
201201
language='serpent', log_listener=None, listen=True,
202202
libraries=None, path=None, constructor_parameters=None,
203203
**kwargs):
204+
# pylint: disable=too-many-locals
204205

205206
compiler = languages[language]
206207
contract_interface = compiler.mk_full_signature(sourcecode, path=path, **kwargs)

ethereum/tests/test_solidity.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,31 @@ def test_interop():
7676
assert c2.main(c1.address) == 10
7777

7878

79+
CONSTRUCTOR_CONTRACT = '''
80+
contract testme {
81+
uint value;
82+
function testme(uint a) {
83+
value = a;
84+
}
85+
function getValue() returns (uint) {
86+
return value;
87+
}
88+
}
89+
'''
90+
91+
92+
@pytest.mark.skipif(get_solidity() is None, reason="'solc' compiler not available")
93+
def test_constructor():
94+
state = tester.state()
95+
96+
contract = state.abi_contract(
97+
CONSTRUCTOR_CONTRACT,
98+
language='solidity',
99+
constructor_parameters=(2, ),
100+
)
101+
assert contract.getValue() == 2 # pylint: disable=no-member
102+
103+
79104
compile_rich_contract = """
80105
contract contract_add {
81106
function add7(uint a) returns(uint d) { return a + 7; }

0 commit comments

Comments
 (0)