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

Commit ff0f149

Browse files
authored
Merge pull request #435 from konradkonrad/fix_solidity_combinedjson
Fix solidity combinedjson -- thanks @LefterisJP!
2 parents 9bd9e9a + 6c2f87b commit ff0f149

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
- COVERAGE_APPEND="--append"
1212
- secure: cKbIgpTJ1yjKLBxpCEiT6IH7NShDWZUE+BvnrAfc+ujCsR6LyLJcKxFQmKnWryJCqg7fp82Ep2bF2oDKzanAROar2xDY1SFGbai42seYMaFCw53YPGJ6u3VNCcfT0rN9BWgE7el/m4fjcD6CRsZYKArNNJbMX8csRt3uXXCFLso=
1313
- secure: "QyFPrxQHd2LlNQ6zNeTFYhgPmZaOHoWuywcgn8qaSOh6PklyFxHbexkwg0bl23JvtgNEZ1mCD8j0x1/ydSdtxgCFwK9SEL0h7aYuAq+OAIa/G18OPeTJMf7ASsb2QZdfkt9reFpUnjbadzHkuv+rqqb4bFnTJBKwB2LWzHPLhWg="
14-
- SOLC_VERSION=0.4.8
14+
- SOLC_VERSION=0.4.9
1515
cache:
1616
directories:
1717
- $HOME/.bin

ethereum/_solidity.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,34 @@ def compile_file(filepath, libraries=None, combined='bin,abi', optimize=True, ex
261261
return solc_parse_output(output)
262262

263263

264+
def solidity_get_contract_data(all_contracts, filepath, contract_name):
265+
""" A backwards compatible method of getting the contract data out
266+
of a solc --combined-json output"""
267+
try:
268+
contract_data = all_contracts[contract_name]
269+
except:
270+
if filepath is None:
271+
filename = '<stdin>'
272+
else:
273+
_, filename = os.path.split(filepath)
274+
contract_data = all_contracts[filename + ":" + contract_name]
275+
return contract_data
276+
277+
278+
def solidity_get_contract_key(all_contracts, filepath, contract_name):
279+
""" A backwards compatible method of getting the key to the all_contracts
280+
dictionary for a particular contract"""
281+
if contract_name in all_contracts:
282+
return contract_name
283+
else:
284+
if filepath is None:
285+
filename = '<stdin>'
286+
else:
287+
_, filename = os.path.split(filepath)
288+
contract_key = filename + ":" + contract_name
289+
return contract_key if contract_key in all_contracts else None
290+
291+
264292
def compile_contract(filepath, contract_name, libraries=None, combined='bin,abi', optimize=True, extra_args=None):
265293
all_contracts = compile_file(
266294
filepath,
@@ -269,8 +297,7 @@ def compile_contract(filepath, contract_name, libraries=None, combined='bin,abi'
269297
optimize=optimize,
270298
extra_args=extra_args
271299
)
272-
273-
return all_contracts[contract_name]
300+
return solidity_get_contract_data(all_contracts, filepath, contract_name)
274301

275302

276303
def compile_last_contract(filepath, libraries=None, combined='bin,abi', optimize=True, extra_args=None):
@@ -335,7 +362,7 @@ def _code_or_path(sourcecode, path, contract_name, libraries, combined, extra_ar
335362
last_contract = all_contract_names[-1]
336363

337364
result = compile_code(sourcecode, libraries=libraries, combined=combined, extra_args=extra_args)
338-
return result[last_contract]
365+
return solidity_get_contract_data(result, path, last_contract)
339366

340367
@classmethod
341368
def compile(cls, code, path=None, libraries=None, contract_name='', extra_args=None):
@@ -378,7 +405,12 @@ def combined(cls, code, path=None, extra_args=None):
378405

379406
sorted_contracts = []
380407
for name in solidity_names(code):
381-
sorted_contracts.append((name[1], contracts[name[1]]))
408+
sorted_contracts.append(
409+
(
410+
name[1],
411+
solidity_get_contract_data(contracts, path, name[1])
412+
)
413+
)
382414
return sorted_contracts
383415

384416
@classmethod

ethereum/tests/test_solidity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
def bytecode_is_generated(cinfo, cname):
1818
return 'code' in cinfo[cname] and len(cinfo[cname]['code']) > 10
1919

20+
2021
@pytest.mark.skipif(not SOLIDITY_AVAILABLE, reason='solc compiler not available')
2122
def test_library_from_file():
2223
state = tester.state()
@@ -249,6 +250,7 @@ def test_abi_contract():
249250
assert contract.mul2(2) == 4
250251
assert contract.mul2(-2) == -4
251252

253+
252254
@pytest.mark.skipif(not SOLIDITY_AVAILABLE, reason='solc compiler not available')
253255
def test_extra_args():
254256
src = """

ethereum/tests/test_tester.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
import pytest
66

77
from ethereum.tester import state, ABIContract
8-
from ethereum._solidity import get_solidity, compile_file
8+
from ethereum._solidity import (
9+
get_solidity,
10+
compile_file,
11+
solidity_get_contract_data,
12+
)
913

1014
SOLIDITY_AVAILABLE = get_solidity() is not None
1115
CONTRACTS_DIR = path.join(path.dirname(__file__), 'contracts')
@@ -17,11 +21,17 @@ def test_abicontract_interface():
1721
tester_state = state()
1822

1923
contract_path = path.join(CONTRACTS_DIR, 'simple_contract.sol')
24+
contract_name = 'Simple'
2025
simple_compiled = compile_file(contract_path)
21-
simple_address = tester_state.evm(simple_compiled['Simple']['bin'])
26+
simple_data = solidity_get_contract_data(
27+
simple_compiled,
28+
contract_path,
29+
contract_name,
30+
)
31+
simple_address = tester_state.evm(simple_data['bin'])
2232

2333
# ABIContract class must accept json_abi
24-
abi_json = json.dumps(simple_compiled['Simple']['abi']).encode('utf-8')
34+
abi_json = json.dumps(simple_data['abi']).encode('utf-8')
2535

2636
abi = ABIContract(
2737
_state=tester_state,

0 commit comments

Comments
 (0)