def generate_go_happyuc_fixture(destination_dir):
    with contextlib.ExitStack() as stack:
        datadir = stack.enter_context(tempdir())

        keystore_dir = os.path.join(datadir, 'keystore')
        ensure_path_exists(keystore_dir)
        keyfile_path = os.path.join(keystore_dir, KEYFILE_FILENAME)
        with open(keyfile_path, 'w') as keyfile:
            keyfile.write(KEYFILE_DATA)
        genesis_file_path = os.path.join(datadir, 'genesis.json')
        with open(genesis_file_path, 'w') as genesis_file:
            genesis_file.write(json.dumps(GENESIS_DATA))

        ghuc_ipc_path_dir = stack.enter_context(tempdir())
        ghuc_ipc_path = os.path.join(ghuc_ipc_path_dir, 'ghuc.ipc')

        ghuc_port = get_open_port()
        ghuc_binary = get_ghuc_binary()

        with get_ghuc_process(ghuc_binary=ghuc_binary,
                              datadir=datadir,
                              genesis_file_path=genesis_file_path,
                              ghuc_ipc_path=ghuc_ipc_path,
                              ghuc_port=ghuc_port):

            wait_for_socket(ghuc_ipc_path)
            webu = Webu(Webu.IPCProvider(ghuc_ipc_path))
            chain_data = setup_chain_state(webu)
            # close ghuc by exiting context
            # must be closed before copying data dir
            verify_chain_state(webu, chain_data)

        # verify that chain state is still valid after closing
        # and re-opening ghuc
        with get_ghuc_process(ghuc_binary=ghuc_binary,
                              datadir=datadir,
                              genesis_file_path=genesis_file_path,
                              ghuc_ipc_path=ghuc_ipc_path,
                              ghuc_port=ghuc_port):

            wait_for_socket(ghuc_ipc_path)
            webu = Webu(Webu.IPCProvider(ghuc_ipc_path))
            verify_chain_state(webu, chain_data)

        static_data = {
            'raw_txn_account': RAW_TXN_ACCOUNT,
            'keyfile_pw': KEYFILE_PW,
        }
        config = merge(chain_data, static_data)
        pprint.pprint(config)
        write_config_json(config, datadir)

        shutil.copytree(datadir, destination_dir)
Beispiel #2
0
def generate_go_happyuc_fixture(destination_dir):
    with contextlib.ExitStack() as stack:
        datadir = stack.enter_context(common.tempdir())

        keystore_dir = os.path.join(datadir, 'keystore')
        common.ensure_path_exists(keystore_dir)
        keyfile_path = os.path.join(keystore_dir, common.KEYFILE_FILENAME)
        with open(keyfile_path, 'w') as keyfile:
            keyfile.write(common.KEYFILE_DATA)
        genesis_file_path = os.path.join(datadir, 'genesis.json')
        with open(genesis_file_path, 'w') as genesis_file:
            genesis_file.write(json.dumps(common.GENESIS_DATA))

        ghuc_ipc_path_dir = stack.enter_context(common.tempdir())
        ghuc_ipc_path = os.path.join(ghuc_ipc_path_dir, 'ghuc.ipc')

        ghuc_port = common.get_open_port()
        ghuc_binary = common.get_ghuc_binary()

        ghuc_proc = stack.enter_context(
            common.get_ghuc_process(  # noqa: F841
                ghuc_binary=ghuc_binary,
                datadir=datadir,
                genesis_file_path=genesis_file_path,
                ipc_path=ghuc_ipc_path,
                port=ghuc_port,
                networkid=str(common.GENESIS_DATA['config']['chainId'])))

        common.wait_for_socket(ghuc_ipc_path)
        webu = Webu(Webu.IPCProvider(ghuc_ipc_path))
        chain_data = setup_chain_state(webu)
        static_data = {
            'raw_txn_account': common.RAW_TXN_ACCOUNT,
            'keyfile_pw': common.KEYFILE_PW,
        }
        pprint.pprint(merge(chain_data, static_data))

        shutil.copytree(datadir, destination_dir)
Beispiel #3
0
def generate_parity_fixture(destination_dir):
    """
    The parity fixture generation strategy is to start a ghuc client with
    existing fixtures copied into a temp datadir.  Then a parity client
    is started is peered with the ghuc client.
    """
    with contextlib.ExitStack() as stack:

        ghuc_datadir = stack.enter_context(common.tempdir())

        ghuc_port = common.get_open_port()

        ghuc_ipc_path_dir = stack.enter_context(common.tempdir())
        ghuc_ipc_path = os.path.join(ghuc_ipc_path_dir, 'ghuc.ipc')

        ghuc_keystore_dir = os.path.join(ghuc_datadir, 'keystore')
        common.ensure_path_exists(ghuc_keystore_dir)
        ghuc_keyfile_path = os.path.join(ghuc_keystore_dir,
                                         common.KEYFILE_FILENAME)
        with open(ghuc_keyfile_path, 'w') as keyfile:
            keyfile.write(common.KEYFILE_DATA)

        genesis_file_path = os.path.join(ghuc_datadir, 'genesis.json')
        with open(genesis_file_path, 'w') as genesis_file:
            genesis_file.write(json.dumps(common.GENESIS_DATA))

        stack.enter_context(
            common.get_ghuc_process(common.get_ghuc_binary(), ghuc_datadir,
                                    genesis_file_path, ghuc_ipc_path,
                                    ghuc_port,
                                    str(CHAIN_CONFIG['params']['networkID'])))
        # set up fixtures
        common.wait_for_socket(ghuc_ipc_path)
        webu_ghuc = Webu(Webu.IPCProvider(ghuc_ipc_path))
        chain_data = go_happyuc.setup_chain_state(webu_ghuc)
        fixture_block_count = webu_ghuc.eth.blockNumber

        datadir = stack.enter_context(common.tempdir())

        keystore_dir = os.path.join(datadir, 'keys')
        os.makedirs(keystore_dir, exist_ok=True)
        parity_keyfile_path = os.path.join(keystore_dir,
                                           common.KEYFILE_FILENAME)
        with open(parity_keyfile_path, 'w') as keyfile:
            keyfile.write(common.KEYFILE_DATA)

        chain_config_file_path = os.path.join(datadir, 'chain_config.json')
        with open(chain_config_file_path, 'w') as chain_file:
            chain_file.write(json.dumps(CHAIN_CONFIG))

        parity_ipc_path_dir = stack.enter_context(common.tempdir())
        parity_ipc_path = os.path.join(parity_ipc_path_dir, 'jsonrpc.ipc')

        parity_port = common.get_open_port()
        parity_binary = get_parity_binary()

        parity_proc = stack.enter_context(
            get_parity_process(  # noqa: F841
                parity_binary=parity_binary,
                datadir=datadir,
                ipc_path=parity_ipc_path,
                keys_path=keystore_dir,
                chain_config_file_path=chain_config_file_path,
                parity_port=parity_port,
            ))

        common.wait_for_socket(parity_ipc_path)
        webu = Webu(Webu.IPCProvider(parity_ipc_path))

        time.sleep(10)
        connect_nodes(webu, webu_ghuc)
        wait_for_chain_sync(webu, fixture_block_count)

        static_data = {
            'raw_txn_account': common.RAW_TXN_ACCOUNT,
            'keyfile_pw': common.KEYFILE_PW,
        }
        pprint.pprint(merge(chain_data, static_data))

        shutil.copytree(datadir, destination_dir)

        parity_proc = stack.enter_context(
            parity_export_blocks_process(  # noqa: F841
                parity_binary=parity_binary,
                datadir=destination_dir,
                chain_config_file_path=os.path.join(destination_dir,
                                                    'chain_config.json'),
                parity_port=parity_port,
            ))
Beispiel #4
0
def webu(ghuc_process, ghuc_ipc_path):
    wait_for_socket(ghuc_ipc_path)
    _webu = Webu(Webu.IPCProvider(ghuc_ipc_path))
    return _webu
Beispiel #5
0
def webu(parity_process, ipc_path):
    wait_for_socket(ipc_path)
    _webu = Webu(Webu.IPCProvider(ipc_path))
    return _webu