Beispiel #1
0
def deploy_client(request, populus_config):
    client_type = populus_config.get_value(request, 'deploy_client_type')

    if client_type == 'ethtester':
        from populus.ethtester_client import EthTesterClient
        client = EthTesterClient()
    elif client_type == 'rpc':
        from eth_rpc_client import Client
        rpc_host = populus_config.get_value(request, 'deploy_client_rpc_host')
        rpc_port = populus_config.get_value(request, 'deploy_client_rpc_port')
        client = Client(rpc_host, rpc_port)
    elif client_type == 'ipc':
        from eth_ipc_client import Client
        ipc_path = populus_config.get_value(request, 'ipc_path')
        if ipc_path is None:
            from populus.geth import get_geth_data_dir
            geth_project_dir = populus_config.get_value(request, 'geth_project_dir')
            geth_chain_name = populus_config.get_value(request, 'geth_chain_name')
            geth_data_dir = get_geth_data_dir(geth_project_dir, geth_chain_name)
            ipc_path = os.path.join(geth_data_dir, 'geth.ipc')
        client = Client(ipc_path)
    else:
        raise ValueError(
            "Unsupported client type '{0}'.  Supported values are 'tester', "
            "'rpc', and 'ipc'"
        )

    return client
Beispiel #2
0
def get_client(name):
    if len(clients) == 0:
        clients.update({
            name: Client(host=node['host'], port=node['port'])
            for name, node in get_nodes().iteritems()
        })
    return clients[name]
Beispiel #3
0
def test_new_filter(rpc_server, eth_coinbase):
    """
    """
    client = Client(CLIENT_HOST, CLIENT_PORT)

    filt_id = client.new_filter(from_block="latest", to_block="pending")
    
    assert is_valid_filter_id(filt_id)
Beispiel #4
0
def test_running_node_without_mining(project_test04, open_port):
    data_dir = get_geth_data_dir(project_test04, 'default')

    command, proc = run_geth_node(data_dir, rpc_port=open_port, mine=False)
    wait_for_popen(proc)
    rpc_client = Client('127.0.0.1', port=open_port)
    coinbase = rpc_client.get_coinbase()
    proc.send_signal(signal.SIGINT)
    wait_for_popen(proc)
    assert coinbase == get_geth_accounts(data_dir)[0]
Beispiel #5
0
def ipc_client(request, populus_config):
    from eth_ipc_client import Client
    ipc_path = populus_config.get_value(request, 'ipc_path')
    if ipc_path is None:
        from populus.geth import get_geth_data_dir
        geth_project_dir = populus_config.get_value(request, 'geth_project_dir')
        geth_chain_name = populus_config.get_value(request, 'geth_chain_name')
        geth_data_dir = get_geth_data_dir(geth_project_dir, geth_chain_name)
        ipc_path = os.path.join(geth_data_dir, 'geth.ipc')
    client = Client(ipc_path)
    return client
Beispiel #6
0
def test_get_filter_changes(rpc_server, eth_coinbase):
    """
    """

    client = Client(CLIENT_HOST, CLIENT_PORT)

    filt_id = client.new_filter()     
    assert is_valid_filter_id(filt_id)
    
    resp = client.get_filter_logs(filt_id)
    assert resp == []
Beispiel #7
0
def test_uninstall_filter(rpc_server, eth_coinbase): 
    """
    """
    client = Client(CLIENT_HOST, CLIENT_PORT)

    filt_id = client.new_filter() 
    
    assert is_valid_filter_id(filt_id)
    
    resp = client.uninstall_filter(filt_id) 
    
    assert resp == True
def test_send_a_transaction_uses_coinbase_as_from(rpc_server, eth_coinbase):
    client = Client('127.0.0.1', '8545')

    to_addr = tester.encode_hex(tester.accounts[1])

    txn_hash = client.send_transaction(
        to=to_addr,
        value=12345,
    )

    after_balance = client.get_balance(eth_coinbase)

    assert after_balance == 1000004999999999999987655L
Beispiel #9
0
def test_running_node_and_mining(project_test04, open_port):
    data_dir = get_geth_data_dir(project_test04, 'default')

    command, proc = run_geth_node(data_dir, rpc_port=open_port, mine=True)
    wait_for_popen(proc)
    rpc_client = Client('127.0.0.1', port=open_port)
    block_num = rpc_client.get_block_number()
    start = time.time()

    rpc_client.wait_for_block(block_num + 1, 60)

    assert block_num < rpc_client.get_block_number()
    proc.send_signal(signal.SIGINT)
    wait_for_popen(proc)
Beispiel #10
0
def test_running_node_and_mining(project_test04, open_port):
    data_dir = get_geth_data_dir(project_test04, 'default')

    command, proc = run_geth_node(data_dir, rpc_port=open_port, mine=True)
    time.sleep(2)
    rpc_client = Client('127.0.0.1', port=open_port)
    block_num = rpc_client.get_block_number()
    start = time.time()
    while time.time() < start + 10:
        time.sleep(0.2)
        if rpc_client.get_block_number() > block_num:
            break
    assert block_num < rpc_client.get_block_number()
    proc.send_signal(signal.SIGINT)
    wait_for_popen(proc)
Beispiel #11
0
def test_running_node_and_mining(project_test04, open_port):
    data_dir = get_geth_data_dir(project_test04, 'default')

    command, proc = run_geth_node(data_dir, rpc_port=open_port, mine=True)
    wait_for_popen(proc)
    rpc_client = Client('127.0.0.1', port=open_port)
    block_num = rpc_client.get_block_number()
    start = time.time()
    while rpc_client.get_block_number() <= block_num:
        time.sleep(0.2)
        if time.time() > start + 20:
            raise Exception('Could not mine block within 20 seconds')
    assert block_num < rpc_client.get_block_number()
    proc.send_signal(signal.SIGINT)
    wait_for_popen(proc)
def test_contract_creation(rpc_server, eth_coinbase):
    client = Client('127.0.0.1', '8545')

    data = "0x60606040525b5b600a8060136000396000f30060606040526008565b00"

    txn_hash = client.send_transaction(
        _from=eth_coinbase,
        value=12345,
        data=data,
    )
    txn_receipt = client.get_transaction_receipt(txn_hash)
    contract_addr = txn_receipt['contractAddress']

    contract_balance = client.get_balance(contract_addr)
    assert contract_balance == 12345
def test_get_transaction_by_hash(rpc_server, eth_coinbase):
    client = Client('127.0.0.1', '8545')

    to_addr = tester.encode_hex(tester.accounts[1])

    txn_hash = client.send_transaction(
        _from=eth_coinbase,
        to=to_addr,
        value=12345,
    )

    txn = client.get_transaction_by_hash(txn_hash)

    assert txn['from'].endswith(eth_coinbase)
    assert txn['to'].endswith(to_addr)
    assert int(txn['value'], 16) == 12345
Beispiel #14
0
def deploy():
    """
    Deploy contracts.
    """
    contracts = utils.load_contracts(os.getcwd())
    client = Client('127.0.0.1', '8545')

    deployed_contracts = utils.deploy_contracts(client, contracts)

    name_padding = max(len(n) + 1 for n in deployed_contracts.keys())
    for name, info in deployed_contracts.items():
        click.echo("{name} @ {addr} via txn:{txn_hash}".format(
            name=name.ljust(name_padding),
            addr=(info.get('addr') or '<pending>').ljust(42),
            txn_hash=info['txn'].ljust(66),
        ))
Beispiel #15
0
def test_get_code(rpc_server, eth_coinbase):
    client = Client('127.0.0.1', '8545')

    data = "0x606060405260f8806100126000396000f30060606040526000357c01000000000000000000000000000000000000000000000000000000009004806316216f3914604b578063a5f3c23b14606a578063dcf537b1146095576049565b005b605460045060e6565b6040518082815260200191505060405180910390f35b607f60048035906020018035906020015060ba565b6040518082815260200191505060405180910390f35b60a460048035906020015060d0565b6040518082815260200191505060405180910390f35b60008183019050805080905060ca565b92915050565b6000600782029050805080905060e1565b919050565b6000600d9050805080905060f5565b9056"
    txn_hash = client.send_transaction(
        _from=eth_coinbase,
        data=data,
    )
    txn_receipt = client.get_transaction_receipt(txn_hash)
    contract_addr = txn_receipt['contractAddress']

    code = client.get_code(contract_addr)
    # TODO: figure out what's going on here and why the two are almost the same
    # but not exactly the same.
    assert len(code) > 100
    assert data.endswith(code[2:])
Beispiel #16
0
def deploy_client(request, populus_config):
    client_type = populus_config.get_value(request, 'deploy_client_type')

    if client_type == 'ethtester':
        from populus.ethtester_client import EthTesterClient
        client = EthTesterClient()
    elif client_type == 'rpc':
        from eth_rpc_client import Client
        rpc_host = populus_config.get_value(request, 'deploy_client_rpc_host')
        rpc_port = populus_config.get_value(request, 'deploy_client_rpc_port')
        client = Client(rpc_host, rpc_port)
    else:
        raise ValueError(
            "Unsupported client type '{0}'.  Supported values are 'tester' and "
            "'rpc'")

    return client
Beispiel #17
0
sys.path += ['.', '..', 'tools', '../populus']

from overlog import ovlg, ovlocal
import overlog
import contract as mycon
from populus import contracts as pocon
from eth_rpc_client import Client

overlog.SELECTED_GROUPS = ['overlog']


class Dummy(object):
    pass


eth = Client(*mycon.RpcHost)
ci = mycon.MainStore.last_ci_named(mycon.ConName)

co_cls = pocon.Contract(eth, ci.name, {
    'info': {
        'abiDefinition': ci.abi,
        'source': ''
    },
    'code': ci.code
})

# contract obj
cobj = co_cls(ci.addr)

eth.accounts = eth.get_accounts()
eth.defaults['from'] = eth.accounts[0]
Beispiel #18
0
from eth_alarm_client import (
    BlockSage,
    PoolManager,
    Scheduler,
)

alarm_addresses = (
    ('0.1.0', '0xb0059e72ae1802fa1e1add5e7d0cb0eec1cc0cc1'),
    ('0.2.0', '0xc1cfa6ac1d7cf99bd1e145dcd04ec462b3b0c4da'),
    ('0.3.0', '0xdb15058402c241b04a03846f6fb104b1fbeea10b'),
    ('0.4.0 (latest)', '0x07307d0b136a79bac718f43388aed706389c4588'),
)

DEFAULT_ADDRESS = '0x07307d0b136a79bac718f43388aed706389c4588'

rpc_client = Client('127.0.0.1', '8545')


def get_contract(contract_name):
    with open(os.path.join(os.path.dirname(__file__),
                           'alarm.json')) as contract_json:
        contracts = json.loads(contract_json.read())
    return Contract(contracts[contract_name], contract_name)


@click.group()
def main():
    pass


@main.command()
Beispiel #19
0
def rpc_client(request, populus_config):
    from eth_rpc_client import Client
    rpc_port = populus_config.get_value(request, 'rpc_client_port')
    rpc_hostname = populus_config.get_value(request, 'rpc_client_host')
    client = Client(rpc_hostname, rpc_port)
    return client
Beispiel #20
0
 def __init__(self, rpc_port):
     self.rpc_ip = '127.0.0.1'
     self.rpc_port = rpc_port
     self.rpc_eth = Client(self.rpc_ip, self.rpc_port)
def test_get_coinbase(rpc_server):
    client = Client('127.0.0.1', '8545')
    cb = client.get_coinbase()

    assert cb == '0x82a978b3f5962a5b0957d9ee9eef472ee55b42f1'
Beispiel #22
0
def test_get_balance(rpc_server, eth_coinbase):
    client = Client('127.0.0.1', '8545')
    balance = client.get_balance(eth_coinbase)

    assert balance == 1000000000000000000000000L
Beispiel #23
0
def rpc_client():
    from eth_rpc_client import Client
    client = Client('127.0.0.1', '8545')
    return client
Beispiel #24
0
def deploy(dry_run, dry_run_chain_name, production, confirm, record,
           contracts_to_deploy):
    """
    Deploys the specified contracts via the RPC client.
    """
    if dry_run is None:
        # If we are doing a production deploy and dry_run was not specified,
        # then default to True
        dry_run = production

    client = Client("127.0.0.1", "8545")
    project_dir = os.getcwd()
    deploy_gas = None

    contracts = package_contracts(utils.load_contracts(project_dir))

    if dry_run:
        dry_run_data_dir = get_geth_data_dir(project_dir, dry_run_chain_name)
        logfile_path = get_geth_logfile_path(
            dry_run_data_dir,
            logfile_name_fmt="deploy-dry-run-{0}.log",
        )

        ensure_account_exists(dry_run_data_dir)

        _, dry_run_proc = run_geth_node(dry_run_data_dir, logfile=logfile_path)
        wait_for_geth_to_start(dry_run_proc)

        message = ("======= Executing Dry Run Deploy ========\n"
                   "Chain Name     : {chain_name}\n"
                   "Data Directory : {data_dir}\n"
                   "Geth Logfile   : {logfile_path}\n\n"
                   "... (deploying)\n").format(
                       chain_name=dry_run_chain_name,
                       data_dir=dry_run_data_dir,
                       logfile_path=logfile_path,
                   )
        click.echo(message)

        # Dry run deploy uses max_gas
        dry_run_contracts = deploy_contracts(
            deploy_client=client,
            contracts=contracts,
            deploy_at_block=1,
            max_wait_for_deploy=60,
            from_address=None,
            max_wait=60,
            contracts_to_deploy=contracts_to_deploy,
            dependencies=None,
            constructor_args=None,
            deploy_gas=None,
        )
        validate_deployed_contracts(client, dry_run_contracts)

        echo_post_deploy_message(client, dry_run_contracts)

        dry_run_proc.send_signal(signal.SIGINT)
        # Give the subprocess a SIGINT and give it a few seconds to
        # cleanup.
        utils.wait_for_popen(dry_run_proc)

        def get_deploy_gas(contract_name, contract_class):
            max_gas = int(client.get_max_gas() * 0.98)
            receipt = dry_run_contracts._deploy_receipts.get(contract_name)
            if receipt is None:
                return max_gas
            gas_used = int(receipt['gasUsed'], 16)
            return min(max_gas, int(gas_used * 1.1))

        deploy_gas = get_deploy_gas

    contracts = package_contracts(utils.load_contracts(project_dir))

    if not production:
        data_dir = get_geth_data_dir(project_dir, "default")
        logfile_path = get_geth_logfile_path(
            data_dir,
            logfile_name_fmt="deploy-dry-run-{0}.log",
        )

        ensure_account_exists(data_dir)
        _, deploy_proc = run_geth_node(data_dir, logfile=logfile_path)
        wait_for_geth_to_start(deploy_proc)
    elif confirm:
        message = (
            "You are about to deploy contracts to a production environment. "
            "You must have an RPC server that is unlocked running for this to "
            "work.\n\n"
            "Would you like to proceed?")
        if not click.confirm(message):
            raise click.Abort()

    if not dry_run:
        message = (
            "You are about to do a production deploy with no dry run.  Without "
            "a dry run, it isn't feasible to know gas costs and thus deployment "
            "may fail due to long transaction times.\n\n"
            "Are you sure you would like to proceed?")
        if confirm and not click.confirm(message):
            raise click.Abort()

    message = ("========== Executing Deploy ===========\n"
               "... (deploying)\n"
               "Chain Name     : {chain_name}\n"
               "Data Directory : {data_dir}\n"
               "Geth Logfile   : {logfile_path}\n\n"
               "... (deploying)\n").format(
                   chain_name="production" if production else "default",
                   data_dir="N/A" if production else data_dir,
                   logfile_path="N/A" if production else logfile_path,
               )
    click.echo(message)

    deployed_contracts = deploy_contracts(
        deploy_client=client,
        contracts=contracts,
        deploy_at_block=1,
        max_wait_for_deploy=120,
        from_address=None,
        max_wait=120,
        contracts_to_deploy=contracts_to_deploy,
        dependencies=None,
        constructor_args=None,
        deploy_gas=deploy_gas,
    )
    validate_deployed_contracts(client, deployed_contracts)

    echo_post_deploy_message(client, deployed_contracts)

    if not production:
        if record:
            add_to_known_contracts(deployed_contracts, data_dir)

        deploy_proc.send_signal(signal.SIGINT)
        # Give the subprocess a SIGINT and give it a few seconds to
        # cleanup.
        utils.wait_for_popen(deploy_proc)
Beispiel #25
0
def attach(active):
    """
    Enter a python shell with contracts and blockchain client
    available.
    """
    project_dir = os.path.abspath(os.getcwd())
    contracts_meta = utils.load_contracts(project_dir)
    client = Client('127.0.0.1', '8545')

    context = {
        'contracts': package_contracts(contracts_meta),
        'client': client,
    }
    data_dir = None
    if active:
        data_dir = get_active_data_dir(project_dir)
        if os.path.islink(data_dir):
            setup_known_instances(context, data_dir)
        else:
            click.echo(
                click.style("No Valid Active Chain Data Directory Found!",
                            fg="red"))

    def redeploy(contracts=[], record=True):
        return (deploy_set(context,
                           client,
                           project_dir,
                           data_dir=data_dir,
                           record=record,
                           contracts_by_name=contracts))

    context["redeploy"] = redeploy

    contract_names = ', '.join(sorted(contracts_meta.keys()))

    banner = textwrap.dedent("""
        Python: {python_version}

        Populus: v{populus_version}

        Project Path: {project_dir}

        contracts  -> Contract classes
        client     -> Blockchain client ({client_type})
        redeploy   -> Method to re-deploy project contracts
                      Example:
                        deployed_cts = redeploy()
                        deployed_cts = redeploy(record = False)
                        deployed_cts = redeploy(contracts = ["Example"])

        Contracts: {contracts}
        Check contracts.<type>.known for deployed contracts.

        """).format(
        python_version=sys.version.partition('\n')[0],
        populus_version=populus.__version__,
        project_dir=project_dir,
        client_type="json-rpc",
        contracts=click.wrap_text(
            contract_names,
            initial_indent='',
            subsequent_indent=' ' * 4,
        ),
    ).strip()

    if is_ipython:
        shell = InteractiveConsole(user_ns=context)
    else:
        shell = InteractiveConsole(context)

    # Start the active directory link observer
    event_handler = ActiveDataDirChangedEventHandler(
        project_dir=project_dir,
        context=context,
    )
    observer = get_active_dir_observer(project_dir, event_handler)

    observer.start()
    shell.interact(banner)
    observer.stop()
    observer.join()
Beispiel #26
0
def repeat_all_messages(message): # Название функции не играет никакой роли, важно не повторяться
    client = Client(host="ubuntu.athex.ru", port="8545")
    bot.send_message(message.chat.id, client.get_balance(client.get_coinbase()))