def run_scenario(scenario, config_file): """ Run a test scenario: * set up the virtualchain to use our mock UTXO provider and mock bitcoin blockchain * seed it with the initial values in the wallet * set the initial consensus hash * run the scenario method * run the check method """ # use mock bitcoind virtualchain.setup_virtualchain( blockstore_state_engine, bitcoind_connection_factory=mock_bitcoind.connect_mock_bitcoind) # set up blockstore # NOTE: utxo_opts encodes the mock-bitcoind options blockstore_opts, bitcoin_opts, utxo_opts, dht_opts = blockstore.lib.configure( config_file=config_file, interactive=False) # override multiprocessing options to ensure single-process behavior utxo_opts['multiprocessing_num_procs'] = 1 utxo_opts['multiprocessing_num_blocks'] = 64 blockstored.set_bitcoin_opts(bitcoin_opts) blockstored.set_utxo_opts(utxo_opts) db = blockstored.get_state_engine() bitcoind = mock_bitcoind.connect_mock_bitcoind(utxo_opts) sync_virtualchain_upcall = lambda: virtualchain.sync_virtualchain( utxo_opts, bitcoind.getblockcount(), db) mock_utxo = blockstore.lib.connect_utxo_provider(utxo_opts) working_dir = virtualchain.get_working_dir() # set up test environment testlib.set_utxo_client(mock_utxo) testlib.set_bitcoind(bitcoind) testlib.set_state_engine(db) test_env = { "sync_virtualchain_upcall": sync_virtualchain_upcall, "working_dir": working_dir } # sync initial utxos testlib.next_block(**test_env) # load the scenario into the mock blockchain and mock utxo provider try: scenario.scenario(scenario.wallets, **test_env) except Exception, e: log.exception(e) traceback.print_exc() log.error("Failed to run scenario '%s'" % scenario.__name__) return False
def run_scenario( scenario, config_file ): """ Run a test scenario: * set up the virtualchain to use our mock UTXO provider and mock bitcoin blockchain * seed it with the initial values in the wallet * set the initial consensus hash * run the scenario method * run the check method """ # use mock bitcoind virtualchain.setup_virtualchain( blockstore_state_engine, bitcoind_connection_factory=mock_bitcoind.connect_mock_bitcoind ) # set up blockstore # NOTE: utxo_opts encodes the mock-bitcoind options blockstore_opts, bitcoin_opts, utxo_opts, dht_opts = blockstore.lib.configure( config_file=config_file, interactive=False ) # override multiprocessing options to ensure single-process behavior utxo_opts['multiprocessing_num_procs'] = 1 utxo_opts['multiprocessing_num_blocks'] = 64 blockstored.set_bitcoin_opts( bitcoin_opts ) blockstored.set_utxo_opts( utxo_opts ) db = blockstored.get_state_engine() bitcoind = mock_bitcoind.connect_mock_bitcoind( utxo_opts ) sync_virtualchain_upcall = lambda: virtualchain.sync_virtualchain( utxo_opts, bitcoind.getblockcount(), db ) mock_utxo = blockstore.lib.connect_utxo_provider( utxo_opts ) working_dir = virtualchain.get_working_dir() # set up test environment testlib.set_utxo_client( mock_utxo ) testlib.set_bitcoind( bitcoind ) testlib.set_state_engine( db ) test_env = { "sync_virtualchain_upcall": sync_virtualchain_upcall, "working_dir": working_dir } # sync initial utxos testlib.next_block( **test_env ) # load the scenario into the mock blockchain and mock utxo provider try: scenario.scenario( scenario.wallets, **test_env ) except Exception, e: log.exception(e) traceback.print_exc() log.error("Failed to run scenario '%s'" % scenario.__name__) return False
def run_scenario( scenario, config_file ): """ Run a test scenario: * set up the virtualchain to use our mock UTXO provider and mock bitcoin blockchain * seed it with the initial values in the wallet * set the initial consensus hash * run the scenario method * run the check method """ # use mock bitcoind virtualchain.setup_virtualchain( blockstore_state_engine, bitcoind_connection_factory=mock_bitcoind.connect_mock_bitcoind ) # set up blockstore # NOTE: utxo_opts encodes the mock-bitcoind options blockstore_opts, bitcoin_opts, utxo_opts, dht_opts = blockstore.lib.configure( config_file=config_file, interactive=False ) # override multiprocessing options to ensure single-process behavior utxo_opts['multiprocessing_num_procs'] = 1 utxo_opts['multiprocessing_num_blocks'] = 64 blockstored.set_bitcoin_opts( bitcoin_opts ) blockstored.set_utxo_opts( utxo_opts ) db = blockstored.get_state_engine() bitcoind = mock_bitcoind.connect_mock_bitcoind( utxo_opts ) # count blocks as given (needs to be by ref) block_counter = {'count': virtualchain.get_first_block_id() } # load the scenario into the mock blockchain and mock utxo provider try: scenario.scenario( scenario.wallets, bitcoind=bitcoind, block_counter=block_counter ) except Exception, e: log.exception(e) log.error("Failed to run scenario '%s'" % scenario.__name__) return False
def run_scenario(scenario, config_file): """ Run a test scenario: * set up the virtualchain to use our mock UTXO provider and mock bitcoin blockchain * seed it with the initial values in the wallet * set the initial consensus hash * run the scenario method * run the check method """ mock_bitcoind_save_path = "/tmp/mock_bitcoind.dat" if os.path.exists(mock_bitcoind_save_path): try: os.unlink(mock_bitcoind_save_path) except: pass # use mock bitcoind worker_env = { # use mock_bitcoind to connect to bitcoind (but it has to import it in order to use it) "VIRTUALCHAIN_MOD_CONNECT_BLOCKCHAIN": mock_bitcoind.__file__, "MOCK_BITCOIND_SAVE_PATH": mock_bitcoind_save_path, "BLOCKSTORE_TEST": "1" } if os.environ.get("PYTHONPATH", None) is not None: worker_env["PYTHONPATH"] = os.environ["PYTHONPATH"] virtualchain.setup_virtualchain( blockstore_state_engine, bitcoind_connection_factory=mock_bitcoind.connect_mock_bitcoind, index_worker_env=worker_env) # set up blockstore # NOTE: utxo_opts encodes the mock-bitcoind options blockstore_opts, bitcoin_opts, utxo_opts, dht_opts = blockstore.lib.configure( config_file=config_file, interactive=False) # override multiprocessing options to ensure single-process behavior utxo_opts['multiprocessing_num_procs'] = 1 utxo_opts['multiprocessing_num_blocks'] = 10 # pass along extra arguments utxo_opts['save_file'] = mock_bitcoind_save_path # save headers as well utxo_opts['spv_headers_path'] = mock_bitcoind_save_path + ".spvheaders" with open(utxo_opts['spv_headers_path'], "w") as f: # write out "initial" headers, up to the first block empty_header = ("00" * 81).decode('hex') for i in xrange(0, blockstore.FIRST_BLOCK_MAINNET): f.write(empty_header) blockstored.set_bitcoin_opts(bitcoin_opts) blockstored.set_utxo_opts(utxo_opts) db = blockstored.get_state_engine() bitcoind = mock_bitcoind.connect_mock_bitcoind(utxo_opts) sync_virtualchain_upcall = lambda: virtualchain.sync_virtualchain( utxo_opts, bitcoind.getblockcount(), db) mock_utxo = blockstore.lib.connect_utxo_provider(utxo_opts) working_dir = virtualchain.get_working_dir() # set up test environment testlib.set_utxo_opts(utxo_opts) testlib.set_utxo_client(mock_utxo) testlib.set_bitcoind(bitcoind) testlib.set_state_engine(db) test_env = { "sync_virtualchain_upcall": sync_virtualchain_upcall, "working_dir": working_dir, "bitcoind": bitcoind, "bitcoind_save_path": mock_bitcoind_save_path } # sync initial utxos testlib.next_block(**test_env) try: os.unlink(mock_bitcoind_save_path) except: pass # load the scenario into the mock blockchain and mock utxo provider try: scenario.scenario(scenario.wallets, **test_env) except Exception, e: log.exception(e) traceback.print_exc() log.error("Failed to run scenario '%s'" % scenario.__name__) return False
def run_scenario(scenario, config_file): """ Run a test scenario: * set up the virtualchain to use our mock UTXO provider and mock bitcoin blockchain * seed it with the initial values in the wallet * set the initial consensus hash * run the scenario method * run the check method """ mock_bitcoind_save_path = "/tmp/mock_bitcoind.dat" if os.path.exists(mock_bitcoind_save_path): try: os.unlink(mock_bitcoind_save_path) except: pass # use mock bitcoind worker_env = { # use mock_bitcoind to connect to bitcoind (but it has to import it in order to use it) "VIRTUALCHAIN_MOD_CONNECT_BLOCKCHAIN": mock_bitcoind.__file__, "MOCK_BITCOIND_SAVE_PATH": mock_bitcoind_save_path, "BLOCKSTORE_TEST": "1", } if os.environ.get("PYTHONPATH", None) is not None: worker_env["PYTHONPATH"] = os.environ["PYTHONPATH"] virtualchain.setup_virtualchain( blockstore_state_engine, bitcoind_connection_factory=mock_bitcoind.connect_mock_bitcoind, index_worker_env=worker_env, ) # set up blockstore # NOTE: utxo_opts encodes the mock-bitcoind options blockstore_opts, bitcoin_opts, utxo_opts, dht_opts = blockstore.lib.configure( config_file=config_file, interactive=False ) # override multiprocessing options to ensure single-process behavior utxo_opts["multiprocessing_num_procs"] = 1 utxo_opts["multiprocessing_num_blocks"] = 10 # pass along extra arguments utxo_opts["save_file"] = mock_bitcoind_save_path # save headers as well utxo_opts["spv_headers_path"] = mock_bitcoind_save_path + ".spvheaders" with open(utxo_opts["spv_headers_path"], "w") as f: # write out "initial" headers, up to the first block empty_header = ("00" * 81).decode("hex") for i in xrange(0, blockstore.FIRST_BLOCK_MAINNET): f.write(empty_header) blockstored.set_bitcoin_opts(bitcoin_opts) blockstored.set_utxo_opts(utxo_opts) db = blockstored.get_state_engine() bitcoind = mock_bitcoind.connect_mock_bitcoind(utxo_opts) sync_virtualchain_upcall = lambda: virtualchain.sync_virtualchain(utxo_opts, bitcoind.getblockcount(), db) mock_utxo = blockstore.lib.connect_utxo_provider(utxo_opts) working_dir = virtualchain.get_working_dir() # set up test environment testlib.set_utxo_opts(utxo_opts) testlib.set_utxo_client(mock_utxo) testlib.set_bitcoind(bitcoind) testlib.set_state_engine(db) test_env = { "sync_virtualchain_upcall": sync_virtualchain_upcall, "working_dir": working_dir, "bitcoind": bitcoind, "bitcoind_save_path": mock_bitcoind_save_path, } # sync initial utxos testlib.next_block(**test_env) try: os.unlink(mock_bitcoind_save_path) except: pass # load the scenario into the mock blockchain and mock utxo provider try: scenario.scenario(scenario.wallets, **test_env) except Exception, e: log.exception(e) traceback.print_exc() log.error("Failed to run scenario '%s'" % scenario.__name__) return False