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

Commit

Permalink
A few fixes for test compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
vub authored and vub committed Jan 2, 2016
1 parent 6bfc645 commit 7828427
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
3 changes: 2 additions & 1 deletion ethereum/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
# Difficulty adjustment algo
def calc_difficulty(parent, timestamp):
config = parent.config
print 'cutoff', config['HOMESTEAD_FORK_BLKNUM']
offset = parent.difficulty // config['BLOCK_DIFF_FACTOR']
if parent.number >= (config['HOMESTEAD_FORK_BLKNUM'] - 1):
sign = max(1 - 2 * ((timestamp - parent.timestamp) // config['HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF']), -99)
sign = max(1 - ((timestamp - parent.timestamp) // config['HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF']), -99)
else:
sign = 1 if timestamp - parent.timestamp < config['DIFF_ADJUSTMENT_CUTOFF'] else -1
# If we enter a special mode where the genesis difficulty starts off below
Expand Down
4 changes: 2 additions & 2 deletions ethereum/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
# Blank account initial nonce
ACCOUNT_INITIAL_NONCE=0,
# Homestead fork (500k on livenet?)
HOMESTEAD_FORK_BLKNUM=2**100,
HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF=16,
HOMESTEAD_FORK_BLKNUM=900000,
HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF=10,
)
assert default_config['NEPHEW_REWARD'] == \
default_config['BLOCK_REWARD'] // 32
Expand Down
11 changes: 8 additions & 3 deletions ethereum/ethash_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from Crypto.Hash import keccak
sha3_256 = lambda x: keccak.new(digest_bits=256, data=x)
sha3_512 = lambda x: keccak.new(digest_bits=512, data=x)
try:
from Crypto.Hash import keccak
sha3_256 = lambda x: keccak.new(digest_bits=256, data=x).digest()
sha3_512 = lambda x: keccak.new(digest_bits=512, data=x)
except:
import sha3 as _sha3
sha3_256 = lambda x: _sha3.sha3_256(x).digest()
sha3_512 = lambda x: _sha3.sha3_512(x).digest()
from rlp.utils import decode_hex, encode_hex
import sys

Expand Down
15 changes: 10 additions & 5 deletions ethereum/tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import sys
import ethereum.testutils as testutils
import copy

from ethereum.slogging import get_logger
logger = get_logger()
Expand Down Expand Up @@ -41,7 +42,7 @@ def valueconv(k, v):
return v


def run_block_test(params):
def run_block_test(params, config_overrides = {}):
b = blocks.genesis(env, start_alloc=params["pre"])
gbh = params["genesisBlockHeader"]
b.bloom = utils.scanners['int256b'](gbh["bloom"])
Expand All @@ -65,9 +66,12 @@ def run_block_test(params):
raise Exception("state root mismatch")
if b.hash != utils.scanners['bin'](gbh["hash"]):
raise Exception("header hash mismatch")
assert b.header.check_pow()
# assert b.header.check_pow()
blockmap = {b.hash: b}
env.db.put(b.hash, rlp.encode(b))
old_config = copy.deepcopy(env.config)
for k, v in config_overrides.items():
env.config[k] = v
for blk in params["blocks"]:
if 'blockHeader' not in blk:
try:
Expand Down Expand Up @@ -96,11 +100,12 @@ def run_block_test(params):
# assert blk["uncleHeader"] == \
# [translate_keys(u, translator_list, lambda x: x, [])
# for u in blkdict["uncles"]]
env.config = old_config


def do_test_block(filename, testname=None, testdata=None, limit=99999999):
print('\nrunning test:%r in %r' % (testname, filename))
run_block_test(testdata)
run_block_test(testdata, {'HOMESTEAD_FORK_BLKNUM':0} if 'Homestead' in filename else {})

excludes = [('bcWalletTest.json', u'walletReorganizeOwners'),
('bl10251623GO.json', u'randomBlockTest'),
Expand All @@ -116,13 +121,13 @@ def do_test_block(filename, testname=None, testdata=None, limit=99999999):
for testname, testdata in list(tests.items()):
if testname == sys.argv[2]:
print("Testing: %s %s" % (filename, testname))
run_block_test(testdata)
run_block_test(testdata, {'HOMESTEAD_FORK_BLKNUM':0} if 'Homestead' in filename else {})
else:
for filename, tests in list(fixtures.items()):
for testname, testdata in list(tests.items()):
if (filename.split('/')[-1], testname) not in excludes:
print("Testing: %s %s" % (filename, testname))
run_block_test(testdata)
run_block_test(testdata, {'HOMESTEAD_FORK_BLKNUM':0} if 'Homestead' in filename else {})
else:
fixtures = testutils.get_tests_from_file_or_dir(
os.path.join(testutils.fixture_path, 'BlockchainTests'))
Expand Down
1 change: 1 addition & 0 deletions ethereum/tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def gen_func(filename, testname, testdata):
def do_test_state(filename, testname=None, testdata=None, limit=99999999):
set_level(None, 'info')
logger.debug('running test:%r in %r' % (testname, filename))
print 'running test:%r in %r' % (testname, filename)
testutils.check_state_test(testutils.fixture_to_bytes(testdata))


Expand Down
8 changes: 6 additions & 2 deletions ethereum/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from Crypto.Hash import keccak
sha3_256 = lambda x: keccak.new(digest_bits=256, data=x).digest()
try:
from Crypto.Hash import keccak
sha3_256 = lambda x: keccak.new(digest_bits=256, data=x).digest()
except:
import sha3 as _sha3
sha3_256 = lambda x: _sha3.sha3_256(x).digest()
from bitcoin import privtopub
import sys
import rlp
Expand Down
2 changes: 1 addition & 1 deletion fixtures
Submodule fixtures updated 63 files
+963 −0 BasicTests/difficultyCustomHomestead.json
+7,203 −0 BasicTests/difficultyFrontier.json
+7,203 −0 BasicTests/difficultyHomestead.json
+7,203 −0 BasicTests/difficultyMorden.json
+7,203 −0 BasicTests/difficultyOlimpic.json
+318 −0 BlockchainTests/Homestead/bcBlockGasLimitTest.json
+11,573 −0 BlockchainTests/Homestead/bcForkStressTest.json
+1,117 −0 BlockchainTests/Homestead/bcGasPricerTest.json
+1,241 −0 BlockchainTests/Homestead/bcInvalidHeaderTest.json
+3,501 −0 BlockchainTests/Homestead/bcMultiChainTest.json
+980 −0 BlockchainTests/Homestead/bcRPC_API_Test.json
+1,145 −0 BlockchainTests/Homestead/bcStateTest.json
+5,424 −0 BlockchainTests/Homestead/bcTotalDifficultyTest.json
+2,116 −0 BlockchainTests/Homestead/bcUncleHeaderValiditiy.json
+4,514 −0 BlockchainTests/Homestead/bcUncleTest.json
+1,902 −0 BlockchainTests/Homestead/bcValidBlockTest.json
+10,900 −0 BlockchainTests/Homestead/bcWalletTest.json
+34 −34 BlockchainTests/bcBlockGasLimitTest.json
+2,901 −2,901 BlockchainTests/bcForkStressTest.json
+249 −249 BlockchainTests/bcGasPricerTest.json
+21 −21 BlockchainTests/bcInvalidHeaderTest.json
+790 −844 BlockchainTests/bcMultiChainTest.json
+215 −215 BlockchainTests/bcRPC_API_Test.json
+34 −789 BlockchainTests/bcStateTest.json
+1,279 −1,379 BlockchainTests/bcTotalDifficultyTest.json
+318 −449 BlockchainTests/bcUncleHeaderValiditiy.json
+864 −864 BlockchainTests/bcUncleTest.json
+271 −271 BlockchainTests/bcValidBlockTest.json
+2,265 −2,264 BlockchainTests/bcWalletTest.json
+6,900 −0 StateTests/Homestead/stCallCodes.json
+2,746 −0 StateTests/Homestead/stCallCreateCallCodeTest.json
+58 −58 StateTests/Homestead/stCallDelegateCodes.json
+58 −58 StateTests/Homestead/stCallDelegateCodesCallCode.json
+327 −0 StateTests/Homestead/stHomeSteadSpecific.json
+1,101 −0 StateTests/Homestead/stInitCodeTest.json
+3,833 −0 StateTests/Homestead/stLogTests.json
+382 −0 StateTests/Homestead/stMemoryStressTest.json
+4,091 −0 StateTests/Homestead/stMemoryTest.json
+5,928 −0 StateTests/Homestead/stPreCompiledContracts.json
+8,064 −0 StateTests/Homestead/stQuadraticComplexityTest.json
+8,403 −0 StateTests/Homestead/stRecursiveCreate.json
+1,197 −0 StateTests/Homestead/stRefundTest.json
+980 −0 StateTests/Homestead/stSpecialTest.json
+18,866 −0 StateTests/Homestead/stSystemOperationsTest.json
+2,411 −0 StateTests/Homestead/stTransactionTest.json
+527 −0 StateTests/Homestead/stTransitionTest.json
+3,319 −0 StateTests/Homestead/stWalletTest.json
+174 −72 StateTests/stCallCodes.json
+36 −13 StateTests/stCallCreateCallCodeTest.json
+75 −108 StateTests/stDelegatecallTest.json
+16 −9 StateTests/stInitCodeTest.json
+2 −2 StateTests/stMemoryStressTest.json
+3 −3 StateTests/stSpecialTest.json
+9 −9 StateTests/stTransactionTest.json
+30 −36 StateTests/stTransitionTest.json
+89 −24 StateTests/stWalletTest.json
+18 −0 TransactionTests/Homestead/tt10mbDataField.json
+507 −0 TransactionTests/Homestead/ttTransactionTest.json
+0 −0 TransactionTests/Homestead/ttWrongRLPTransaction.json
+4 −3 TransactionTests/tt10mbDataField.json
+133 −52 TransactionTests/ttTransactionTest.json
+69 −0 TransactionTests/ttWrongRLPTransaction.json
+23 −29 VMTests/vmPerformanceTest.json

0 comments on commit 7828427

Please sign in to comment.