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

Commit 9281d4e

Browse files
authored
Merge pull request #357 from pipermerriam/piper/python3-support
Piper/python3 support thanks @pipermerriam, this is a big step!
2 parents 79e78c3 + 818a91d commit 9281d4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+217
-191
lines changed

.coveragerc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ omit =
99
*/ethereum/fastvm.py
1010
*/ethereum/spv.py
1111

12-
[report]
1312
exclude_lines =
1413
pragma: no cover
1514
def __repr__

.travis.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: python
2-
python: 2.7
2+
python: 3.5
33
sudo: required
44
dist: trusty
55
before_install:
@@ -9,17 +9,26 @@ before_install:
99
env:
1010
matrix:
1111
- TOX_ENV=py27
12+
- TOX_ENV=py34
13+
- TOX_ENV=py35
1214
global:
13-
secure: cKbIgpTJ1yjKLBxpCEiT6IH7NShDWZUE+BvnrAfc+ujCsR6LyLJcKxFQmKnWryJCqg7fp82Ep2bF2oDKzanAROar2xDY1SFGbai42seYMaFCw53YPGJ6u3VNCcfT0rN9BWgE7el/m4fjcD6CRsZYKArNNJbMX8csRt3uXXCFLso=
15+
- COVERAGE_APPEND="--append"
16+
- secure: cKbIgpTJ1yjKLBxpCEiT6IH7NShDWZUE+BvnrAfc+ujCsR6LyLJcKxFQmKnWryJCqg7fp82Ep2bF2oDKzanAROar2xDY1SFGbai42seYMaFCw53YPGJ6u3VNCcfT0rN9BWgE7el/m4fjcD6CRsZYKArNNJbMX8csRt3uXXCFLso=
1417
install:
15-
- pip install -Ur requirements.txt
16-
- pip install -Ur dev_requirements.txt
18+
- travis_retry pip install setuptools --upgrade
19+
- travis_retry pip install tox
20+
- travis_retry pip install coverage
1721
script:
18-
- coverage run --source ethereum -m py.test --ignore ethereum/tests/test_vm.py --ignore ethereum/tests/test_state.py
19-
- coverage run --append --source ethereum -m py.test ethereum/tests/test_vm.py
20-
- coverage run --append --source ethereum -m py.test ethereum/tests/test_state.py
22+
- if [ -d .tox/$TOX_ENV/ ]; then cd .tox/$TOX_ENV && coverage erase; fi;
23+
- tox -e $TOX_ENV -- --ignore ethereum/tests/test_vm.py --ignore ethereum/tests/test_state.py
24+
- tox -e $TOX_ENV -- ethereum/tests/test_vm.py
25+
- tox -e $TOX_ENV -- ethereum/tests/test_state.py
26+
- cd .tox/$TOX_ENV && coverage report --show-missing
2127
after_success:
22-
- coveralls
28+
- travis_retry pip install coveralls
29+
- cd .tox/$TOX_ENV && coveralls
30+
after_script:
31+
- cat .tox/$TOX_ENV/log/*.log
2332
notifications:
2433
slack:
2534
secure: W/UAhQ/GgYwMWrl3aiVAVOWr4WGdWrxUOX/rTB3ZgwDwGqDYLzQO5UqbsQlo1JXPZ6JOWfIPMURhHu7DSfue9dBW6xQ+NL+bFHe9lSXG4nqFK3IjezYyTBzNRJRDbGUvSSqgj6D5cwhJ8BjfUIRPbJz3CxL64KmsNXezEaMY60w=

ethereum/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess
66
import re
77
# Import slogging to patch logging as soon as possible
8-
import slogging # noqa
8+
from . import slogging # noqa
99

1010

1111
GIT_DESCRIBE_RE = re.compile('^(?P<version>v\d+\.\d+\.\d+)-(?P<git>\d+-g[a-fA-F0-9]+(?:-dirty)?)$')

ethereum/_solidity.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import yaml
88

9+
from rlp.utils import decode_hex
10+
from . import utils
11+
912
BINARY = 'solc'
1013

1114

@@ -49,7 +52,7 @@ def solc_arguments(libraries=None, combined='bin,abi', optimize=True):
4952

5053
if libraries is not None and len(libraries):
5154
addresses = [
52-
'{name}:{address}'.format(name=name, address=address)
55+
'{name}:{address}'.format(name=name, address=address.decode('utf8'))
5356
for name, address in libraries.items()
5457
]
5558
args.extend([
@@ -64,21 +67,21 @@ def solc_parse_output(compiler_output):
6467
""" Parses the compiler output. """
6568
result = yaml.safe_load(compiler_output)['contracts']
6669

67-
if 'bin' in result.values()[0]:
70+
if 'bin' in tuple(result.values())[0]:
6871
for value in result.values():
6972
value['bin_hex'] = value['bin']
7073

7174
# decoding can fail if the compiled contract has unresolved symbols
7275
try:
73-
value['bin'] = value['bin_hex'].decode('hex')
76+
value['bin'] = decode_hex(value['bin_hex'])
7477
except TypeError:
7578
pass
7679

7780
for json_data in ('abi', 'devdoc', 'userdoc'):
7881
# the values in the output can be configured through the
7982
# --combined-json flag, check that it's present in the first value and
8083
# assume all values are consistent
81-
if json_data not in result.values()[0]:
84+
if json_data not in tuple(result.values())[0]:
8285
continue
8386

8487
for value in result.values():
@@ -182,7 +185,7 @@ def solidity_resolve_address(hex_code, library_symbol, library_address):
182185
raise ValueError('Address should not contain the 0x prefix')
183186

184187
try:
185-
_ = library_address.decode('hex')
188+
_ = decode_hex(library_address)
186189
except TypeError:
187190
raise ValueError('library_address contains invalid characters, it must be hex encoded.')
188191

@@ -291,8 +294,11 @@ def compile_code(sourcecode, libraries=None, combined='bin,abi', optimize=True):
291294
args = solc_arguments(libraries=libraries, combined=combined, optimize=optimize)
292295
args.insert(0, get_compiler_path())
293296

294-
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
295-
stdoutdata, _ = process.communicate(input=sourcecode)
297+
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
298+
stdoutdata, stderrdata = process.communicate(input=utils.to_string(sourcecode))
299+
300+
if process.returncode != 0:
301+
raise CompileError(stderrdata)
296302

297303
return solc_parse_output(stdoutdata)
298304

ethereum/abi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def listen(self, log, noprint=True):
222222
if indexed[i]]
223223
unindexed_types = [types[i] for i in range(len(types))
224224
if not indexed[i]]
225-
# print('listen', log.data.encode('hex'), log.topics)
225+
# print('listen', encode_hex(log.data), log.topics)
226226
deserialized_args = decode_abi(unindexed_types, log.data)
227227
o = {}
228228
c1, c2 = 0, 0
@@ -494,14 +494,14 @@ def decode_single(typ, data):
494494
return (o - 2**int(sub)) if o >= 2**(int(sub) - 1) else o
495495
elif base == 'ureal':
496496
high, low = [int(x) for x in sub.split('x')]
497-
return big_endian_to_int(data) * 1.0 / 2**low
497+
return big_endian_to_int(data) * 1.0 // 2**low
498498
elif base == 'real':
499499
high, low = [int(x) for x in sub.split('x')]
500500
o = big_endian_to_int(data)
501501
i = (o - 2**(high+low)) if o >= 2**(high+low-1) else o
502-
return (i * 1.0 / 2**low)
502+
return (i * 1.0 // 2**low)
503503
elif base == 'bool':
504-
return bool(int(data.encode('hex'), 16))
504+
return bool(int(encode_hex(data), 16))
505505

506506

507507
# Decodes multiple arguments using the head/tail mechanism

ethereum/blocks.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def calc_difficulty(parent, timestamp):
7474
period_count = (parent.number + 1) // config['EXPDIFF_PERIOD']
7575
if period_count >= config['EXPDIFF_FREE_PERIODS']:
7676
o = max(o + 2**(period_count - config['EXPDIFF_FREE_PERIODS']), config['MIN_DIFF'])
77-
# print 'Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o)
77+
# print('Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o))
7878
return o
7979

8080

@@ -676,8 +676,8 @@ def validate_uncles(self):
676676
return False
677677
if uncle.prevhash not in eligible_ancestor_hashes:
678678
log.error("Uncle does not have a valid ancestor", block=self,
679-
eligible=[x.encode('hex') for x in eligible_ancestor_hashes],
680-
uncle_prevhash=uncle.prevhash.encode('hex'))
679+
eligible=[encode_hex(x) for x in eligible_ancestor_hashes],
680+
uncle_prevhash=encode_hex(uncle.prevhash))
681681
return False
682682
if uncle in ineligible:
683683
log.error("Duplicate uncle", block=self,
@@ -1035,7 +1035,7 @@ def commit_state(self):
10351035
# except:
10361036
# pass
10371037
# sys.stderr.write("pre: %r\n" % self.account_to_dict(addr)['storage'])
1038-
# sys.stderr.write("pre: %r\n" % self.get_storage(addr).root_hash.encode('hex'))
1038+
# sys.stderr.write("pre: %r\n" % encode_hex(self.get_storage(addr).root_hash))
10391039
# sys.stderr.write("changed: %s %s %s\n" % (encode_hex(addr), encode_hex(enckey), encode_hex(val)))
10401040
if v:
10411041
t.update(enckey, val)
@@ -1168,11 +1168,12 @@ def finalize(self):
11681168
self.delta_balance(self.coinbase, delta)
11691169
self.ether_delta += delta
11701170

1171+
br = self.config['BLOCK_REWARD']
1172+
udpf = self.config['UNCLE_DEPTH_PENALTY_FACTOR']
1173+
11711174
for uncle in self.uncles:
1172-
r = self.config['BLOCK_REWARD'] * \
1173-
(self.config['UNCLE_DEPTH_PENALTY_FACTOR'] + uncle.number - self.number) \
1174-
/ self.config['UNCLE_DEPTH_PENALTY_FACTOR']
1175-
r = int(r)
1175+
r = int(br * (udpf + uncle.number - self.number) // udpf)
1176+
11761177
self.delta_balance(uncle.coinbase, r)
11771178
self.ether_delta += r
11781179
self.commit_state()
@@ -1307,7 +1308,7 @@ def calc_gaslimit(parent):
13071308

13081309
def check_gaslimit(parent, gas_limit):
13091310
config = parent.config
1310-
# block.gasLimit - parent.gasLimit <= parent.gasLimit / GasLimitBoundDivisor
1311+
# block.gasLimit - parent.gasLimit <= parent.gasLimit // GasLimitBoundDivisor
13111312
gl = parent.gas_limit // config['GASLIMIT_ADJMAX_FACTOR']
13121313
a = bool(abs(gas_limit - parent.gas_limit) <= gl)
13131314
b = bool(gas_limit >= config['MIN_GAS_LIMIT'])

ethereum/bloom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def bloom(val):
2727

2828
def bloom_insert(bloom, val):
2929
h = utils.sha3(val)
30-
# print 'bloom_insert', bloom_bits(val), repr(val)
30+
# print('bloom_insert', bloom_bits(val), repr(val))
3131
for i in range(0, BUCKETS_PER_VAL * 2, 2):
3232
bloom |= 1 << ((safe_ord(h[i + 1]) + (safe_ord(h[i]) << 8)) & 2047)
3333
return bloom

ethereum/chain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class Chain(object):
110110
"""
111111
head_candidate = None
112112

113-
def __init__(self, env, genesis=None, new_head_cb=None, coinbase='\x00' * 20):
113+
def __init__(self, env, genesis=None, new_head_cb=None, coinbase=b'\x00' * 20):
114114
assert isinstance(env, Env)
115115
self.env = env
116116
self.db = self.blockchain = env.db
@@ -121,7 +121,7 @@ def __init__(self, env, genesis=None, new_head_cb=None, coinbase='\x00' * 20):
121121
self._initialize_blockchain(genesis)
122122
log.debug('chain @', head_hash=self.head)
123123
self.genesis = self.get(self.index.get_block_by_number(0))
124-
log.debug('got genesis', nonce=self.genesis.nonce.encode('hex'),
124+
log.debug('got genesis', nonce=encode_hex(self.genesis.nonce),
125125
difficulty=self.genesis.difficulty)
126126
self._update_head_candidate()
127127

ethereum/ethash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from functools import lru_cache
1010

1111

12-
cache_seeds = ['\x00' * 32]
12+
cache_seeds = [b'\x00' * 32]
1313

1414

1515
def mkcache(block_number):

ethereum/ethash_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def deserialize_cache(ds):
9494
class ListWrapper(list):
9595
def __init__(self, data):
9696
self.data = data
97-
self.len = len(data) / HASH_BYTES
97+
self.len = len(data) // HASH_BYTES
9898

9999
def __len__(self):
100100
return self.len
@@ -122,14 +122,14 @@ def isprime(x):
122122
def get_cache_size(block_number):
123123
sz = CACHE_BYTES_INIT + CACHE_BYTES_GROWTH * (block_number // EPOCH_LENGTH)
124124
sz -= HASH_BYTES
125-
while not isprime(sz / HASH_BYTES):
125+
while not isprime(sz // HASH_BYTES):
126126
sz -= 2 * HASH_BYTES
127127
return sz
128128

129129

130130
def get_full_size(block_number):
131131
sz = DATASET_BYTES_INIT + DATASET_BYTES_GROWTH * (block_number // EPOCH_LENGTH)
132132
sz -= MIX_BYTES
133-
while not isprime(sz / MIX_BYTES):
133+
while not isprime(sz // MIX_BYTES):
134134
sz -= 2 * MIX_BYTES
135135
return sz

0 commit comments

Comments
 (0)