def ursulas(): URSULAS = make_ursulas(NUMBER_OF_URSULAS_IN_NETWORK, URSULA_PORT) yield URSULAS # Remove the DBs that have been sprayed hither and yon. for _u in range(NUMBER_OF_URSULAS_IN_NETWORK): port = URSULA_PORT + _u os.remove("test-{}".format(port)) blockchain_client._ursulas_on_blockchain.clear()
def ursulas(three_agents): token_agent, miner_agent, policy_agent = three_agents ether_addresses = [ to_checksum_address(os.urandom(20)) for _ in range(constants.NUMBER_OF_URSULAS_IN_NETWORK) ] _ursulas = make_ursulas(ether_addresses=ether_addresses, miner_agent=miner_agent) try: yield _ursulas finally: # Remove the DBs that have been sprayed hither and yon. with contextlib.suppress(FileNotFoundError): for port, ursula in enumerate(_ursulas, start=int( constants.URSULA_PORT_SEED)): os.remove("test-{}".format(port))
def test_new_ursula_announces_herself(): ursula_here, ursula_there = make_ursulas( 2, know_each_other=False, network_middleware=MockRestMiddleware()) # Neither Ursula knows about the other. assert ursula_here._known_nodes == ursula_there._known_nodes == {} ursula_here.remember_node(ursula_there) # OK, now, ursula_here knows about ursula_there, but not vice-versa. assert ursula_there in ursula_here._known_nodes.values() assert not ursula_here in ursula_there._known_nodes.values() # But as ursula_here learns, she'll announce herself to ursula_there. ursula_here.learn_from_teacher_node() assert ursula_there in ursula_here._known_nodes.values() assert ursula_here in ursula_there._known_nodes.values()
def mining_ursulas(three_agents): starting_point = constants.URSULA_PORT_SEED + 500 token_agent, miner_agent, policy_agent = three_agents etherbase, alice, bob, *all_yall = token_agent.blockchain.interface.w3.eth.accounts _receipts = token_airdrop(token_agent=token_agent, origin=etherbase, addresses=all_yall, amount=1000000 * constants.M) ursula_addresses = all_yall[:int(constants.NUMBER_OF_URSULAS_IN_NETWORK)] _ursulas = make_ursulas(ether_addresses=ursula_addresses, miner_agent=miner_agent, miners=True) try: yield _ursulas finally: # Remove the DBs that have been sprayed hither and yon. with contextlib.suppress(FileNotFoundError): for port, ursula in enumerate(_ursulas, start=int(starting_point)): os.remove("test-{}".format(port))
def ursulas(): URSULAS = make_ursulas(NUMBER_OF_URSULAS_IN_NETWORK, URSULA_PORT) yield URSULAS blockchain_client._ursulas_on_blockchain.clear()