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

Python3 CI Test PR (DO NOT MERGE) #363

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ omit =
*/ethereum/fastvm.py
*/ethereum/spv.py

[report]
exclude_lines =
pragma: no cover
def __repr__
Expand Down
25 changes: 17 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python
python: 2.7
python: 3.5
sudo: required
dist: trusty
before_install:
Expand All @@ -9,17 +9,26 @@ before_install:
env:
matrix:
- TOX_ENV=py27
- TOX_ENV=py34
- TOX_ENV=py35
global:
secure: cKbIgpTJ1yjKLBxpCEiT6IH7NShDWZUE+BvnrAfc+ujCsR6LyLJcKxFQmKnWryJCqg7fp82Ep2bF2oDKzanAROar2xDY1SFGbai42seYMaFCw53YPGJ6u3VNCcfT0rN9BWgE7el/m4fjcD6CRsZYKArNNJbMX8csRt3uXXCFLso=
- COVERAGE_APPEND="--append"
- secure: cKbIgpTJ1yjKLBxpCEiT6IH7NShDWZUE+BvnrAfc+ujCsR6LyLJcKxFQmKnWryJCqg7fp82Ep2bF2oDKzanAROar2xDY1SFGbai42seYMaFCw53YPGJ6u3VNCcfT0rN9BWgE7el/m4fjcD6CRsZYKArNNJbMX8csRt3uXXCFLso=
install:
- pip install -Ur requirements.txt
- pip install -Ur dev_requirements.txt
- travis_retry pip install setuptools --upgrade
- travis_retry pip install tox
- travis_retry pip install coverage
script:
- coverage run --source ethereum -m py.test --ignore ethereum/tests/test_vm.py --ignore ethereum/tests/test_state.py
- coverage run --append --source ethereum -m py.test ethereum/tests/test_vm.py
- coverage run --append --source ethereum -m py.test ethereum/tests/test_state.py
- if [ -d .tox/$TOX_ENV/ ]; then cd .tox/$TOX_ENV && coverage erase; fi;
- tox -e $TOX_ENV -- --ignore ethereum/tests/test_vm.py --ignore ethereum/tests/test_state.py
- tox -e $TOX_ENV -- ethereum/tests/test_vm.py
- tox -e $TOX_ENV -- ethereum/tests/test_state.py
- cd .tox/$TOX_ENV && coverage report --show-missing
after_success:
- coveralls
- travis_retry pip install coveralls
- cd .tox/$TOX_ENV && coveralls
after_script:
- cat .tox/$TOX_ENV/log/*.log
notifications:
slack:
secure: W/UAhQ/GgYwMWrl3aiVAVOWr4WGdWrxUOX/rTB3ZgwDwGqDYLzQO5UqbsQlo1JXPZ6JOWfIPMURhHu7DSfue9dBW6xQ+NL+bFHe9lSXG4nqFK3IjezYyTBzNRJRDbGUvSSqgj6D5cwhJ8BjfUIRPbJz3CxL64KmsNXezEaMY60w=
Expand Down
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ coveralls
pytest>=2.9.0
pytest-catchlog==1.2.2
pytest-timeout==1.0.0
https://github.com/ethereum/serpent/tarball/develop
https://github.com/pipermerriam/serpent/tarball/piper/python3-support-with-pyethereum3
2 changes: 1 addition & 1 deletion ethereum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import re
# Import slogging to patch logging as soon as possible
import slogging # noqa
from . import slogging # noqa


GIT_DESCRIBE_RE = re.compile('^(?P<version>v\d+\.\d+\.\d+)-(?P<git>\d+-g[a-fA-F0-9]+(?:-dirty)?)$')
Expand Down
20 changes: 13 additions & 7 deletions ethereum/_solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import yaml

from rlp.utils import decode_hex
from . import utils

BINARY = 'solc'


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

if libraries is not None and len(libraries):
addresses = [
'{name}:{address}'.format(name=name, address=address)
'{name}:{address}'.format(name=name, address=address.decode('utf8'))
for name, address in libraries.items()
]
args.extend([
Expand All @@ -64,21 +67,21 @@ def solc_parse_output(compiler_output):
""" Parses the compiler output. """
result = yaml.safe_load(compiler_output)['contracts']

if 'bin' in result.values()[0]:
if 'bin' in tuple(result.values())[0]:
for value in result.values():
value['bin_hex'] = value['bin']

# decoding can fail if the compiled contract has unresolved symbols
try:
value['bin'] = value['bin_hex'].decode('hex')
value['bin'] = decode_hex(value['bin_hex'])
except TypeError:
pass

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

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

try:
_ = library_address.decode('hex')
_ = decode_hex(library_address)
except TypeError:
raise ValueError('library_address contains invalid characters, it must be hex encoded.')

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

process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
stdoutdata, _ = process.communicate(input=sourcecode)
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdoutdata, stderrdata = process.communicate(input=utils.to_string(sourcecode))

if process.returncode != 0:
raise CompileError(stderrdata)

return solc_parse_output(stdoutdata)

Expand Down
8 changes: 4 additions & 4 deletions ethereum/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def listen(self, log, noprint=True):
if indexed[i]]
unindexed_types = [types[i] for i in range(len(types))
if not indexed[i]]
# print('listen', log.data.encode('hex'), log.topics)
# print('listen', encode_hex(log.data), log.topics)
deserialized_args = decode_abi(unindexed_types, log.data)
o = {}
c1, c2 = 0, 0
Expand Down Expand Up @@ -494,14 +494,14 @@ def decode_single(typ, data):
return (o - 2**int(sub)) if o >= 2**(int(sub) - 1) else o
elif base == 'ureal':
high, low = [int(x) for x in sub.split('x')]
return big_endian_to_int(data) * 1.0 / 2**low
return big_endian_to_int(data) * 1.0 // 2**low
elif base == 'real':
high, low = [int(x) for x in sub.split('x')]
o = big_endian_to_int(data)
i = (o - 2**(high+low)) if o >= 2**(high+low-1) else o
return (i * 1.0 / 2**low)
return (i * 1.0 // 2**low)
elif base == 'bool':
return bool(int(data.encode('hex'), 16))
return bool(int(encode_hex(data), 16))


# Decodes multiple arguments using the head/tail mechanism
Expand Down
19 changes: 10 additions & 9 deletions ethereum/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def calc_difficulty(parent, timestamp):
period_count = (parent.number + 1) // config['EXPDIFF_PERIOD']
if period_count >= config['EXPDIFF_FREE_PERIODS']:
o = max(o + 2**(period_count - config['EXPDIFF_FREE_PERIODS']), config['MIN_DIFF'])
# print 'Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o)
# print('Calculating difficulty of block %d, timestamp difference %d, parent diff %d, child diff %d' % (parent.number + 1, timestamp - parent.timestamp, parent.difficulty, o))
return o


Expand Down Expand Up @@ -676,8 +676,8 @@ def validate_uncles(self):
return False
if uncle.prevhash not in eligible_ancestor_hashes:
log.error("Uncle does not have a valid ancestor", block=self,
eligible=[x.encode('hex') for x in eligible_ancestor_hashes],
uncle_prevhash=uncle.prevhash.encode('hex'))
eligible=[encode_hex(x) for x in eligible_ancestor_hashes],
uncle_prevhash=encode_hex(uncle.prevhash))
return False
if uncle in ineligible:
log.error("Duplicate uncle", block=self,
Expand Down Expand Up @@ -1035,7 +1035,7 @@ def commit_state(self):
# except:
# pass
# sys.stderr.write("pre: %r\n" % self.account_to_dict(addr)['storage'])
# sys.stderr.write("pre: %r\n" % self.get_storage(addr).root_hash.encode('hex'))
# sys.stderr.write("pre: %r\n" % encode_hex(self.get_storage(addr).root_hash))
# sys.stderr.write("changed: %s %s %s\n" % (encode_hex(addr), encode_hex(enckey), encode_hex(val)))
if v:
t.update(enckey, val)
Expand Down Expand Up @@ -1168,11 +1168,12 @@ def finalize(self):
self.delta_balance(self.coinbase, delta)
self.ether_delta += delta

br = self.config['BLOCK_REWARD']
udpf = self.config['UNCLE_DEPTH_PENALTY_FACTOR']

for uncle in self.uncles:
r = self.config['BLOCK_REWARD'] * \
(self.config['UNCLE_DEPTH_PENALTY_FACTOR'] + uncle.number - self.number) \
/ self.config['UNCLE_DEPTH_PENALTY_FACTOR']
r = int(r)
r = int(br * (udpf + uncle.number - self.number) // udpf)

self.delta_balance(uncle.coinbase, r)
self.ether_delta += r
self.commit_state()
Expand Down Expand Up @@ -1307,7 +1308,7 @@ def calc_gaslimit(parent):

def check_gaslimit(parent, gas_limit):
config = parent.config
# block.gasLimit - parent.gasLimit <= parent.gasLimit / GasLimitBoundDivisor
# block.gasLimit - parent.gasLimit <= parent.gasLimit // GasLimitBoundDivisor
gl = parent.gas_limit // config['GASLIMIT_ADJMAX_FACTOR']
a = bool(abs(gas_limit - parent.gas_limit) <= gl)
b = bool(gas_limit >= config['MIN_GAS_LIMIT'])
Expand Down
2 changes: 1 addition & 1 deletion ethereum/bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def bloom(val):

def bloom_insert(bloom, val):
h = utils.sha3(val)
# print 'bloom_insert', bloom_bits(val), repr(val)
# print('bloom_insert', bloom_bits(val), repr(val))
for i in range(0, BUCKETS_PER_VAL * 2, 2):
bloom |= 1 << ((safe_ord(h[i + 1]) + (safe_ord(h[i]) << 8)) & 2047)
return bloom
Expand Down
4 changes: 2 additions & 2 deletions ethereum/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Chain(object):
"""
head_candidate = None

def __init__(self, env, genesis=None, new_head_cb=None, coinbase='\x00' * 20):
def __init__(self, env, genesis=None, new_head_cb=None, coinbase=b'\x00' * 20):
assert isinstance(env, Env)
self.env = env
self.db = self.blockchain = env.db
Expand All @@ -121,7 +121,7 @@ def __init__(self, env, genesis=None, new_head_cb=None, coinbase='\x00' * 20):
self._initialize_blockchain(genesis)
log.debug('chain @', head_hash=self.head)
self.genesis = self.get(self.index.get_block_by_number(0))
log.debug('got genesis', nonce=self.genesis.nonce.encode('hex'),
log.debug('got genesis', nonce=encode_hex(self.genesis.nonce),
difficulty=self.genesis.difficulty)
self._update_head_candidate()

Expand Down
2 changes: 1 addition & 1 deletion ethereum/ethash.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import lru_cache


cache_seeds = ['\x00' * 32]
cache_seeds = [b'\x00' * 32]


def mkcache(block_number):
Expand Down
6 changes: 3 additions & 3 deletions ethereum/ethash_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def deserialize_cache(ds):
class ListWrapper(list):
def __init__(self, data):
self.data = data
self.len = len(data) / HASH_BYTES
self.len = len(data) // HASH_BYTES

def __len__(self):
return self.len
Expand Down Expand Up @@ -122,14 +122,14 @@ def isprime(x):
def get_cache_size(block_number):
sz = CACHE_BYTES_INIT + CACHE_BYTES_GROWTH * (block_number // EPOCH_LENGTH)
sz -= HASH_BYTES
while not isprime(sz / HASH_BYTES):
while not isprime(sz // HASH_BYTES):
sz -= 2 * HASH_BYTES
return sz


def get_full_size(block_number):
sz = DATASET_BYTES_INIT + DATASET_BYTES_GROWTH * (block_number // EPOCH_LENGTH)
sz -= MIX_BYTES
while not isprime(sz / MIX_BYTES):
while not isprime(sz // MIX_BYTES):
sz -= 2 * MIX_BYTES
return sz
10 changes: 5 additions & 5 deletions ethereum/ethpow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def check_pow(block_number, header_hash, mixhash, nonce, difficulty):
# Grab current cache
cache = get_cache(block_number)
mining_output = hashimoto_light(block_number, cache, header_hash, nonce)
if mining_output['mix digest'] != mixhash:
if mining_output[b'mix digest'] != mixhash:
return False
return utils.big_endian_to_int(mining_output['result']) <= 2**256 / (difficulty or 1)
return utils.big_endian_to_int(mining_output[b'result']) <= 2**256 // (difficulty or 1)


class Miner():
Expand Down Expand Up @@ -114,9 +114,9 @@ def mine(block_number, difficulty, mining_hash, start_nonce=0, rounds=1000):
for i in range(1, rounds + 1):
bin_nonce = utils.zpad(utils.int_to_big_endian((nonce + i) & TT64M1), 8)
o = hashimoto_light(block_number, cache, mining_hash, bin_nonce)
if o["result"] <= target:
if o[b"result"] <= target:
log.debug("nonce found")
assert len(bin_nonce) == 8
assert len(o["mix digest"]) == 32
return bin_nonce, o["mix digest"]
assert len(o[b"mix digest"]) == 32
return bin_nonce, o[b"mix digest"]
return None, None
16 changes: 9 additions & 7 deletions ethereum/fast_rlp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import rlp
from utils import int_to_big_endian, big_endian_to_int, safe_ord
import db
from .utils import int_to_big_endian, big_endian_to_int, safe_ord
from . import db


def _encode_optimized(item):
Expand Down Expand Up @@ -73,7 +73,9 @@ def consume_length_prefix(rlp, start):
decode_optimized = _decode_optimized
else:
encode_optimized = rlp.codec.encode_raw
decode_optimized = rlp.codec.decode_raw
# rlp does not implement a decode_raw function.
# decode_optimized = rlp.codec.decode_raw
decode_optimized = _decode_optimized


def main():
Expand All @@ -85,20 +87,20 @@ def run():
x = trie.Trie(db.EphemDB())
for i in range(10000):
x.update(str(i), str(i**3))
print 'elapsed', time.time() - st
print('elapsed', time.time() - st)
return x.root_hash

trie.rlp_encode = _encode_optimized
print 'trie.rlp_encode = encode_optimized'
print('trie.rlp_encode = encode_optimized')
r3 = run()

trie.rlp_encode = rlp.codec.encode_raw
print 'trie.rlp_encode = rlp.codec.encode_raw'
print('trie.rlp_encode = rlp.codec.encode_raw')
r2 = run()
assert r2 == r3

trie.rlp_encode = rlp.encode
print 'trie.rlp_encode = rlp.encode'
print('trie.rlp_encode = rlp.encode')
r = run()
assert r == r2

Expand Down
2 changes: 1 addition & 1 deletion ethereum/fastvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def vm_execute(ext, msg, code):
_prevop = None # for trace only

while 1:
# print 'op: ', op, time.time() - s
# print('op: ', op, time.time() - s)
# s = time.time()
# stack size limit error
if compustate.pc not in processed_code:
Expand Down
Loading