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

Commit 6a5cedd

Browse files
committed
added tests and warning for solc_wrapper
1 parent 94efcbd commit 6a5cedd

File tree

6 files changed

+242
-115
lines changed

6 files changed

+242
-115
lines changed

ethereum/_solidity.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf8 -*-
2+
import os
23
import re
34
import subprocess
4-
import os
5+
import warnings
56

67
import yaml
78

@@ -236,10 +237,9 @@ def compile_file(filepath, libraries=None, combined='bin,abi', optimize=True):
236237
237238
Args:
238239
filepath (str): The path to the contract source code.
239-
libraries (dict): A dictionary mapping library name to address.
240-
combined (str: The flags passed to the solidity compiler to defined
241-
what output should be used.
242-
optimize (bool): Flag to set up compiler optimization.
240+
libraries (dict): A dictionary mapping library name to it's address.
241+
combined (str): The argument for solc's --combined-json.
242+
optimize (bool): Enable/disables compiler optimization.
243243
244244
Returns:
245245
dict: A mapping from the contract name to it's binary.
@@ -306,6 +306,8 @@ class Solc(object):
306306

307307
@staticmethod
308308
def _code_or_path(sourcecode, path, contract_name, libraries, combined):
309+
warnings.warn('solc_wrapper is deprecated, please use the functions compile_file or compile_code')
310+
309311
if sourcecode and path:
310312
raise ValueError('sourcecode and path are mutually exclusive.')
311313

@@ -346,18 +348,21 @@ def combined(cls, code, path=None):
346348
@param path: absolute path to solidity-file. Note: code & path are exclusive!
347349
"""
348350

349-
contracts = cls._code_or_path(
350-
sourcecode=code,
351-
path=path,
352-
contract_name=None,
353-
libraries=None,
354-
combined='abi,bin,devdoc,userdoc',
355-
)
351+
if code and path:
352+
raise ValueError('sourcecode and path are mutually exclusive.')
356353

357354
if path:
355+
contracts = compile_file(path)
356+
358357
with open(path) as handler:
359358
code = handler.read()
360359

360+
elif code:
361+
contracts = compile_code(code)
362+
363+
else:
364+
raise ValueError('either code or path needs to be supplied.')
365+
361366
sorted_contracts = []
362367
for name in solidity_names(code):
363368
sorted_contracts.append((name[1], contracts[name[1]]))
@@ -369,7 +374,7 @@ def compile_rich(cls, code, path=None):
369374

370375
return {
371376
contract_name: {
372-
'code': '0x' + contract.get('bin'),
377+
'code': '0x' + contract.get('bin_hex'),
373378
'info': {
374379
'abiDefinition': contract.get('abi'),
375380
'compilerVersion': cls.compiler_version(),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
contract AContract {}
2+
library ALibrary {}
3+
4+
/* contract InComment */
5+
6+
contract WithSpace {}
7+
8+
contract
9+
WithLineBreak
10+
{
11+
}
12+
13+
/* library InComment */
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "seven_library.sol";
2+
3+
contract SevenContract {
4+
function test() returns (int256 seven) {
5+
seven = SevenLibrary.seven();
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
library SevenLibrary {
2+
function seven() returns (int256 y);
3+
}
4+
5+
contract SevenContract {
6+
function test() returns (int256 seven) {
7+
seven = SevenLibrary.seven();
8+
}
9+
}
10+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library SevenLibrary {
2+
function seven() returns (int256 y) {
3+
y = 7;
4+
}
5+
}

0 commit comments

Comments
 (0)