Example #1
0
def test_chain_config_nodekey_loading(nodekey_bytes, nodekey_path):
    chain_config = ChainConfig(
        network_id=1,
        nodekey_path=nodekey_path,
    )

    assert chain_config.nodekey.to_bytes() == nodekey_bytes
def database_server_ipc_path():
    core_db = MemoryDB()
    core_db[b'key-a'] = b'value-a'

    chaindb = ChainDB(core_db)
    # TODO: use a custom chain class only for testing.
    chaindb.persist_header(ROPSTEN_GENESIS_HEADER)

    with tempfile.TemporaryDirectory() as temp_dir:
        chain_config = ChainConfig(network_id=ROPSTEN_NETWORK_ID,
                                   data_dir=temp_dir)

        manager = get_chaindb_manager(chain_config, core_db)
        chaindb_server_process = multiprocessing.Process(
            target=serve_chaindb,
            args=(manager, ),
        )
        chaindb_server_process.start()

        wait_for_ipc(chain_config.database_ipc_path)

        try:
            yield chain_config.database_ipc_path
        finally:
            kill_process_gracefully(chaindb_server_process,
                                    logging.getLogger())
Example #3
0
def test_chain_config_explictely_provided_nodekey(nodekey_bytes, as_bytes):
    chain_config = ChainConfig(
        network_id=1,
        nodekey=nodekey_bytes if as_bytes else keys.PrivateKey(nodekey_bytes),
    )

    assert chain_config.nodekey.to_bytes() == nodekey_bytes
Example #4
0
def test_chain_config_explicit_properties():
    chain_config = ChainConfig(network_id=1,
                               data_dir='./data-dir',
                               nodekey_path='./nodekey')

    assert chain_config.data_dir == Path('./data-dir').resolve()
    assert chain_config.nodekey_path == Path('./nodekey').resolve()
Example #5
0
def test_chain_config_explicit_properties():
    chain_config = ChainConfig(network_id=1,
                               data_dir='./data-dir',
                               nodekey_path='./nodekey')

    assert is_same_path(chain_config.data_dir, './data-dir')
    assert is_same_path(chain_config.nodekey_path, './nodekey')
Example #6
0
def test_chain_config_computed_properties(xdg_trinity_root):
    data_dir = get_local_data_dir('muffin', xdg_trinity_root)
    chain_config = ChainConfig(network_id=1234, data_dir=data_dir)

    assert chain_config.network_id == 1234
    assert chain_config.data_dir == data_dir
    assert chain_config.database_dir == data_dir / DATABASE_DIR_NAME / "full"
    assert chain_config.nodekey_path == get_nodekey_path(data_dir)
Example #7
0
def test_chain_config_computed_properties_custom_xdg(tmpdir, xdg_trinity_root):
    alt_xdg_root = tmpdir.mkdir('trinity-custom')
    assert not is_under_path(alt_xdg_root, xdg_trinity_root)

    data_dir = get_data_dir_for_network_id(1, alt_xdg_root)
    chain_config = ChainConfig(trinity_root_dir=alt_xdg_root, network_id=1)

    assert chain_config.network_id == 1
    assert chain_config.data_dir == data_dir
    assert chain_config.database_dir == data_dir / DATABASE_DIR_NAME / "full"
    assert chain_config.nodekey_path == get_nodekey_path(data_dir)
def test_full_initialized_data_dir_with_custom_nodekey():
    chain_config = ChainConfig(network_id=1, max_peers=1, nodekey=NODEKEY)

    os.makedirs(chain_config.data_dir, exist_ok=True)
    os.makedirs(chain_config.database_dir, exist_ok=True)
    os.makedirs(chain_config.logfile_path, exist_ok=True)
    chain_config.logfile_path.touch()

    assert chain_config.nodekey_path is None
    assert chain_config.nodekey is not None

    assert is_data_dir_initialized(chain_config)
Example #9
0
def chain_config():
    _chain_config = ChainConfig(network_id=1, max_peers=1)
    initialize_data_dir(_chain_config)
    return _chain_config
def chain_config():
    return ChainConfig(network_id=1, max_peers=1)
Example #11
0
import argparse

from eth_utils import encode_hex

from eth.chains.mainnet import MAINNET_NETWORK_ID
from eth.chains.ropsten import ROPSTEN_NETWORK_ID
from eth.db.chain import ChainDB
from eth.db.backends.level import LevelDB

from trinity.config import ChainConfig
from trinity.constants import SYNC_FULL, SYNC_LIGHT

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-ropsten', action='store_true')
    parser.add_argument('-light', action='store_true')
    args = parser.parse_args()

    network_id = MAINNET_NETWORK_ID
    if args.ropsten:
        network_id = ROPSTEN_NETWORK_ID
    sync_mode = SYNC_FULL
    if args.light:
        sync_mode = SYNC_LIGHT

    cfg = ChainConfig(network_id, sync_mode=sync_mode)
    chaindb = ChainDB(LevelDB(cfg.database_dir))
    head = chaindb.get_canonical_head()
    print("Head #%d; hash: %s, state_root: %s" %
          (head.block_number, head.hex_hash, encode_hex(head.state_root)))
def chain_config():
    return ChainConfig(network_id=1)