示例#1
0
def test_cli_select_chain_helper(project_dir, write_project_file, stdin,
                                 expected):
    project = Project()
    project.config['chains.local_a.chain.class'] = 'populus.chain.TesterChain'
    project.config[
        'chains.local_a.web3.provider.class'] = 'web3.providers.ipc.IPCProvider'
    project.config['chains.local_a.web3.provider.settings.ipc_path'] = (
        get_geth_ipc_path(
            get_local_chain_datadir(project.project_dir, 'local_a')))
    project.config['chains.local_b.chain.class'] = 'populus.chain.TesterChain'
    project.config[
        'chains.local_b.web3.provider.class'] = 'web3.providers.ipc.IPCProvider'
    project.config['chains.local_b.web3.provider.settings.ipc_path'] = (
        get_geth_ipc_path(
            get_local_chain_datadir(project.project_dir, 'local_b')))
    project.config['chains.local_c.chain.class'] = 'populus.chain.TesterChain'
    project.config[
        'chains.local_c.web3.provider.class'] = 'web3.providers.ipc.IPCProvider'
    project.config['chains.local_c.web3.provider.settings.ipc_path'] = (
        get_geth_ipc_path(
            get_local_chain_datadir(project.project_dir, 'local_c')))
    project.write_config()

    @click.command()
    def wrapper():
        chain_name = select_chain(project)
        print("~~{0}~~".format(chain_name))

    runner = CliRunner()
    result = runner.invoke(wrapper, [], input=stdin)

    assert result.exit_code == 0
    assert expected in result.output
示例#2
0
def test_project_directory_properties(project_dir):
    project = Project()

    contracts_dir = get_contracts_dir(project_dir)
    assert is_same_path(project.contracts_dir, contracts_dir)

    build_dir = get_build_dir(project_dir)
    assert is_same_path(project.build_dir, build_dir)

    compiled_contracts_file_path = get_compiled_contracts_file_path(
        project_dir)
    assert is_same_path(project.compiled_contracts_file_path,
                        compiled_contracts_file_path)

    blockchains_dir = get_blockchains_dir(project_dir)
    assert is_same_path(project.blockchains_dir, blockchains_dir)

    data_dir = get_data_dir(project_dir, 'some-test-chain-name')
    assert is_same_path(
        project.get_blockchain_data_dir('some-test-chain-name'), data_dir)

    chaindata_dir = get_chaindata_dir(data_dir)
    assert is_same_path(
        project.get_blockchain_chaindata_dir('some-test-chain-name'),
        chaindata_dir)

    geth_ipc_path = get_geth_ipc_path(data_dir)
    assert is_same_path(
        project.get_blockchain_ipc_path('some-test-chain-name'), geth_ipc_path)
示例#3
0
def test_geth_chain_has_registrar(project_dir, write_project_file):
    project = Project()
    project.config['chains.local.chain.class'] = 'populus.chain.LocalGethChain'
    project.config['chains.local.registrar'] = 'faking-it'
    project.config['chains.local.web3.provider.class'] = 'web3.providers.ipc.IPCProvider'
    project.config['chains.local.web3.provider.settings.ipc_path'] = (
        get_geth_ipc_path(get_local_chain_datadir(project.project_dir, 'local'))
    )

    with project.get_chain('local') as chain:
        assert chain.has_registrar is True
示例#4
0
def reset_chain(data_dir):
    chaindata_dir = get_chaindata_dir(data_dir)
    remove_dir_if_exists(chaindata_dir)

    dapp_dir = get_dapp_dir(data_dir)
    remove_dir_if_exists(dapp_dir)

    nodekey_path = get_nodekey_path(data_dir)
    remove_file_if_exists(nodekey_path)

    geth_ipc_path = get_geth_ipc_path(data_dir)
    remove_file_if_exists(geth_ipc_path)
示例#5
0
def local_chain(project_dir):
    project = Project()
    project.config['chains.local.chain.class'] = 'populus.chain.LocalGethChain'
    project.config[
        'chains.local.web3.provider.class'] = 'web3.providers.ipc.IPCProvider'
    project.config['chains.local.web3.provider.settings.ipc_path'] = (
        get_geth_ipc_path(get_local_chain_datadir(project.project_dir,
                                                  'local')))
    project.write_config()

    chain = project.get_chain('local')

    return chain
def test_project_directory_properties(project_dir):
    project = Project()

    contracts_dir = get_contracts_dir(project_dir)
    assert is_same_path(project.contracts_dir, contracts_dir)

    build_dir = get_build_dir(project_dir)
    assert is_same_path(project.build_dir, build_dir)

    compiled_contracts_file_path = get_compiled_contracts_file_path(project_dir)
    assert is_same_path(project.compiled_contracts_file_path, compiled_contracts_file_path)

    blockchains_dir = get_blockchains_dir(project_dir)
    assert is_same_path(project.blockchains_dir, blockchains_dir)

    data_dir = get_data_dir(project_dir, "some-test-chain-name")
    assert is_same_path(project.get_blockchain_data_dir("some-test-chain-name"), data_dir)

    chaindata_dir = get_chaindata_dir(data_dir)
    assert is_same_path(project.get_blockchain_chaindata_dir("some-test-chain-name"), chaindata_dir)

    geth_ipc_path = get_geth_ipc_path(data_dir)
    assert is_same_path(project.get_blockchain_ipc_path("some-test-chain-name"), geth_ipc_path)
示例#7
0
def test_project_local_chain_ipc(project_dir):
    project = Project()

    ipc_path = get_geth_ipc_path(
        get_local_chain_datadir(project.project_dir, 'local'))

    project.config['chains.local.chain.class'] = 'populus.chain.LocalGethChain'
    project.config[
        'chains.local.web3.provider.class'] = 'web3.providers.ipc.IPCProvider'
    project.config['chains.local.web3.provider.settings.ipc_path'] = ipc_path
    project.write_config()

    chain = project.get_chain('local')

    with chain as running_local_chain:
        web3 = running_local_chain.web3
        assert web3.version.node.startswith('Geth')

        running_local_chain.wait.for_block(block_number=1, timeout=180)

        block_1 = web3.eth.getBlock(1)
        assert block_1['hash'] != MAINNET_BLOCK_1_HASH
        assert block_1['hash'] != TESTNET_BLOCK_1_HASH
        assert block_1['miner'] == web3.eth.coinbase
示例#8
0
 def get_blockchain_ipc_path(self, chain_name):
     return get_geth_ipc_path(self.get_blockchain_data_dir(chain_name))