def set_logging_level(lvl=0): trace_lvl_map = [ ':info', 'eth.vm.log:trace', ':info,eth.vm.log:trace,eth.vm.exit:trace', ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace', ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,' + 'eth.vm.storage:trace,eth.vm.memory:trace' ] configure_logging(config_string=trace_lvl_map[lvl]) if lvl == 0: set_level(None, 'info') print('Set logging level: %d' % lvl)
def set_logging_level(lvl=0): trace_lvl_map = [ ":info", "eth.vm.log:trace", ":info,eth.vm.log:trace,eth.vm.exit:trace", ":info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace", ":info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace," + "eth.vm.storage:trace,eth.vm.memory:trace", ] configure_logging(config_string=trace_lvl_map[lvl]) if lvl == 0: set_level(None, "info") print("Set logging level: %d" % lvl)
import re import os import io from contextlib import redirect_stderr, redirect_stdout from ethereum.utils import decode_hex, parse_int_or_hex, sha3, to_string, \ remove_0x_head, encode_hex, big_endian_to_int import ethereum.transactions as transactions from ethereum.exceptions import InvalidTransaction from ethereum.messages import apply_transaction from ethereum.config import default_config, config_homestead, config_tangerine, config_spurious, config_metropolis, Env import ethereum.tools.new_statetest_utils as new_statetest_utils from ethereum.slogging import configure_logging configure_logging(':trace', log_json=True) init_state = new_statetest_utils.init_state def compute_state_test_unit(state, txdata, konfig): state.env.config = konfig s = state.snapshot() try: # Create the transaction tx = transactions.Transaction( nonce=parse_int_or_hex(txdata['nonce'] or b"0"), gasprice=parse_int_or_hex(txdata['gasPrice'] or b"0"), startgas=parse_int_or_hex(txdata['gasLimit'] or b"0"), to=decode_hex(remove_0x_head(txdata['to'])), value=parse_int_or_hex(txdata['value'] or b"0"),
get_skips_and_block_making_time, sign_block, get_contract_code, \ casper_config, get_casper_ct, get_casper_code, get_rlp_decoder_code, \ get_hash_without_ed_code, make_casper_genesis, get_timestamp, \ make_withdrawal_signature from ethereum.block_creation import make_head_candidate from ethereum.transaction_queue import TransactionQueue from ethereum.slogging import LogRecorder, configure_logging, set_level import serpent from ethereum.config import default_config, Env import copy import time import rlp # config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug' config_string = ':info,eth.vm.log:trace' configure_logging(config_string=config_string) NUM_PARTICIPANTS = 10 BLOCK_MAKING_PPB = 10 print('Initializing privkeys, addresses and randaos for validators') privkeys = [utils.sha3(str(i)) for i in range(NUM_PARTICIPANTS)] addrs = [utils.privtoaddr(k) for k in privkeys] randaos = [RandaoManager(utils.sha3(str(i))) for i in range(NUM_PARTICIPANTS)] deposit_sizes = [i * 500 + 500 for i in range(NUM_PARTICIPANTS)] vcodes = [generate_validation_code(a) for a in addrs] vchashes = [utils.sha3(c) for c in vcodes] assert len(privkeys) == len(addrs) == len(randaos) == len(deposit_sizes) == len(vcodes) == len(vchashes) == NUM_PARTICIPANTS # Creating casper contract translator ct = get_casper_ct()
import json import sys import ethereum.tools.new_statetest_utils as new_statetest_utils import ethereum.tools.testutils as testutils from ethereum.slogging import get_logger, configure_logging logger = get_logger() # customize VM log output to your needs # hint: use 'py.test' with the '-s' option to dump logs to the console if '--trace' in sys.argv: # not default configure_logging(':trace') sys.argv.remove('--trace') checker = new_statetest_utils.verify_state_test place_to_check = 'GeneralStateTests' def test_state(filename, testname, testdata): logger.debug('running test:%r in %r' % (testname, filename)) try: checker(testdata) except new_statetest_utils.EnvNotFoundException: pass def pytest_generate_tests(metafunc): testutils.generate_test_params( place_to_check, metafunc, exclude_func=lambda filename, _, __: ( 'stQuadraticComplexityTest' in filename or # Takes too long
import networksim from casper import Validator import casper from ethereum.parse_genesis_declaration import mk_basic_state from ethereum.config import Env from ethereum.casper_utils import casper_config, get_casper_code, get_rlp_decoder_code, \ get_casper_ct, RandaoManager, generate_validation_code, get_hash_without_ed_code, \ call_casper from ethereum.utils import sha3, privtoaddr from ethereum.transactions import Transaction from ethereum.state_transition import apply_transaction from ethereum.slogging import LogRecorder, configure_logging, set_level # config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug' config_string = ':info' # ,eth.vm.log:trace' configure_logging(config_string=config_string) n = networksim.NetworkSimulator(latency=125) n.time = 2 print 'Generating keys' keys = [sha3(str(i)) for i in range(20)] print 'Initializing randaos' randaos = [RandaoManager(sha3(k)) for k in keys] deposit_sizes = [128] * 15 + [256] * 5 print 'Creating genesis state' s = mk_basic_state({}, None, env=Env(config=casper_config)) s.gas_limit = 10**9 s.prev_headers[0].timestamp = 2 s.timestamp = 2 s.prev_headers[0].difficulty = 1
import json import os import sys import ethereum.testutils as testutils from ethereum.slogging import get_logger, configure_logging logger = get_logger() # customize VM log output to your needs # hint: use 'py.test' with the '-s' option to dump logs to the console if '--trace' in sys.argv: # not default configure_logging(':trace') sys.argv.remove('trace') def do_test_vm(filename, testname=None, testdata=None, limit=99999999): logger.debug('running test:%r in %r' % (testname, filename)) testutils.check_vm_test(testutils.fixture_to_bytes(testdata)) if __name__ == '__main__': if len(sys.argv) == 1: # read fixture from stdin fixtures = {'stdin': json.load(sys.stdin)} else: # load fixtures from specified file or dir try: fixtures = testutils.get_tests_from_file_or_dir(sys.argv[1]) except: fixtures = {'stdin': json.loads(sys.argv[1])} for filename, tests in list(fixtures.items()): for testname, testdata in list(tests.items()): if len(sys.argv) < 3 or testname == sys.argv[2]:
import json import sys import ethereum.testutils as testutils from ethereum.slogging import get_logger, configure_logging logger = get_logger() # customize VM log output to your needs # hint: use 'py.test' with the '-s' option to dump logs to the console if "--trace" in sys.argv: # not default configure_logging(":trace") sys.argv.remove("--trace") def test_state(filename, testname, testdata): logger.debug("running test:%r in %r" % (testname, filename)) testutils.check_state_test(testutils.fixture_to_bytes(testdata)) def pytest_generate_tests(metafunc): testutils.generate_test_params( "StateTests", metafunc, lambda filename, _, __: ( "stQuadraticComplexityTest.json" in filename or "stMemoryStressTest.json" in filename or "stPreCompiledContractsTransaction.json" in filename ), )