def send_tx(endpoint, sending_address, receiving_address, value, gas, data): log_event('sending_transaction', show=False, sender=sending_address, to=receiving_address, value=value) tx = transact(endpoint, sender=sending_address, to=receiving_address, value=value, gas=gas, data=data) log_event('sending_transaction.done', show=False, result=tx) return tx
def run(run_clients, on_testnet): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event('started') if not run_clients: return inventory = Inventory() clients = list(inventory.clients) fillnode = clients.pop() len_clients = len(clients) total_txs = txs_per_client * len_clients log_event('starting.clients') start_clients(clients=clients, enable_mining=not on_testnet, testnet=on_testnet) log_event('starting.clients.done') # Fill testnodes with ether log_event('filling.clients') filler_privkey = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4" start_clients(clients=[fillnode], enable_mining=False, privkey=filler_privkey, testnet=on_testnet) if on_testnet: time.sleep(time_to_sync_on_testnet) else: time.sleep(15) rpc_host = inventory.clients[fillnode] rpc_port = 8545 # hard coded FIXME if we get multiple clients per ec endpoint = 'http://%s:%d' % (rpc_host, rpc_port) sender = "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826" fill_successful = 0 for client in clients: to = "0x%s" % nodeid_tool.coinbase(str(client)) tx = transact(endpoint, sender=sender, to=to, value=100000000000000000000) if tx: fill_successful += 1 time.sleep(3) log_event('filling.result', successful=fill_successful, total_txs_tried=len_clients) time.sleep(max_time_to_reach_consensus) start = time.time() # Client futures with tx loop with futures.ThreadPoolExecutor(max_workers=len_clients) as executor: future_to_client = dict( (executor.submit(client_tx, client, clients, inventory), client) for client in clients) for future in futures.as_completed(future_to_client, 300): client = future_to_client[future] if future.exception() is not None: print '%s generated an exception: %r' % (client, future.exception()) log_event('txs_result', successful=successful, total_txs_tried=total_txs_tried, max_total_txs=total_txs) log_event('waiting', delay=max_time_to_reach_consensus) time.sleep(max_time_to_reach_consensus) log_event('waiting.done') if stop_clients_at_scenario_end: log_event('stopping_clients') stop_clients(clients=clients) log_event('stopping_clients.done') global offset offset += time.time() - start print "Total offset: %s" % offset
def run(run_clients): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event('started') if not run_clients: return inventory = Inventory() clients = list(inventory.clients) log_event('starting_one_client') start_clients(clients=clients[:1], impls=impls) log_event('starting_one_client.done') print 'mine a bit' blocktime = 12 # intitial difficulty is very high, takes around 2 minutes for initial mined block delay = blocktime * 14 log_event('waiting', delay=delay) time.sleep(delay) # start other clients log_event('starting_other_clients') start_clients(clients=clients[1:], impls=impls) log_event('starting_other_clients.done') # create tx sender = clients[0] recipient = clients[1] rpc_host = inventory.clients[sender] rpc_port = 8545 # hard coded FIXME if we get multiple clients per ec endpoint = 'http://%s:%d' % (rpc_host, rpc_port) sending_address = coinbase(endpoint) receiving_address = "0x%s" % nodeid_tool.coinbase(str(recipient)) print 'sending addr %s, receiving addr %s' % (sending_address, receiving_address) value = 100 # print balance(endpoint, sending_address) # this fails randomly, why ? assert value < balance(endpoint, sending_address) start = time.time() log_event('sending_transaction', show=False, sender=sending_address, to=receiving_address, value=value) tx = transact(endpoint, sender=sending_address, to=receiving_address, value=value) log_event('sending_transaction.done', show=False, result=tx) log_event('waiting', delay=max_time_to_reach_consensus) time.sleep(max_time_to_reach_consensus) log_event('waiting.done') if stop_clients_at_scenario_end: log_event('stopping_clients') stop_clients(clients=clients, impls=impls) log_event('stopping_clients.done') global offset offset += time.time() - start print "Total offset: %s" % offset
def run(run_clients, on_testnet): """Run the clients. Because of ``autouse=True`` this method is executed before everything else in this module. The `run_clients` fixture is defined in ``conftest.py``. It is true by default but false if the --norun command line flag is set. """ log_event("started") if not run_clients: return inventory = Inventory() clients = list(inventory.clients) fillnode = clients.pop() len_clients = len(clients) total_txs = txs_per_client * len_clients log_event("starting.clients") start_clients(clients=clients, enable_mining=not on_testnet, testnet=on_testnet) log_event("starting.clients.done") # Fill testnodes with ether log_event("filling.clients") filler_privkey = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4" start_clients(clients=[fillnode], enable_mining=False, privkey=filler_privkey, testnet=on_testnet) if on_testnet: time.sleep(time_to_sync_on_testnet) else: time.sleep(15) rpc_host = inventory.clients[fillnode] rpc_port = 8545 # hard coded FIXME if we get multiple clients per ec endpoint = "http://%s:%d" % (rpc_host, rpc_port) sender = "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826" fill_successful = 0 for client in clients: to = "0x%s" % nodeid_tool.coinbase(str(client)) tx = transact(endpoint, sender=sender, to=to, value=100000000000000000000) if tx: fill_successful += 1 time.sleep(3) log_event("filling.result", successful=fill_successful, total_txs_tried=len_clients) time.sleep(max_time_to_reach_consensus) start = time.time() # Client futures with tx loop with futures.ThreadPoolExecutor(max_workers=len_clients) as executor: future_to_client = dict((executor.submit(client_tx, client, clients, inventory), client) for client in clients) for future in futures.as_completed(future_to_client, 300): client = future_to_client[future] if future.exception() is not None: print "%s generated an exception: %r" % (client, future.exception()) log_event("txs_result", successful=successful, total_txs_tried=total_txs_tried, max_total_txs=total_txs) log_event("waiting", delay=max_time_to_reach_consensus) time.sleep(max_time_to_reach_consensus) log_event("waiting.done") if stop_clients_at_scenario_end: log_event("stopping_clients") stop_clients(clients=clients) log_event("stopping_clients.done") global offset offset += time.time() - start print "Total offset: %s" % offset
def send_tx(endpoint, sending_address, receiving_address, value, gas, data): log_event("sending_transaction", show=False, sender=sending_address, to=receiving_address, value=value) tx = transact(endpoint, sender=sending_address, to=receiving_address, value=value, gas=gas, data=data) log_event("sending_transaction.done", show=False, result=tx) return tx