def test_node_constructor(): privkey = PrivateKeyFactory() address = AddressFactory() enr = ENRFactory(private_key=privkey.to_bytes(), address=address) node = Node(enr) assert node.id == keccak(privkey.public_key.to_bytes()) assert node.address == address
def test_node_from_enr_uri(): privkey = PrivateKeyFactory() address = AddressFactory() enr = ENRFactory(private_key=privkey.to_bytes(), address=address) node = Node.from_uri(repr(enr)) assert node.id == keccak(privkey.public_key.to_bytes()) assert node.address == address
async def test_lookup_and_maybe_update_enr_existing_node(): discovery = MockDiscoveryService([]) privkey = PrivateKeyFactory() address = AddressFactory() # When we have an ENR for the given pubkey, and its address matches the given one, the # existing ENR is returned. enr = ENRFactory(private_key=privkey.to_bytes(), address=address) discovery.enr_db.set_enr(enr) lookedup_enr = discovery.lookup_and_maybe_update_enr(privkey.public_key, address) assert lookedup_enr == enr
async def test_lookup_and_maybe_update_enr_existing_node_different_address(): discovery = MockDiscoveryService([]) privkey = PrivateKeyFactory() address = AddressFactory() # If the address given is different than the one we have in our DB, though, a stub ENR would # be created and stored in our DB, replacing the existing one. enr = ENRFactory(private_key=privkey.to_bytes(), address=address) discovery.enr_db.set_enr(enr) new_address = AddressFactory() lookedup_enr = discovery.lookup_and_maybe_update_enr(privkey.public_key, new_address) assert lookedup_enr != enr assert lookedup_enr.public_key == enr.public_key assert lookedup_enr.sequence_number == 0 assert Node(lookedup_enr).address == new_address assert lookedup_enr == discovery.enr_db.get_enr(enr.node_id)
def test_node_constructor(): privkey = PrivateKeyFactory() ip = socket.inet_aton(IPAddressFactory.generate()) udp_port = tcp_port = 30303 enr = ENRFactory(private_key=privkey.to_bytes(), custom_kv_pairs={ IP_V4_ADDRESS_ENR_KEY: ip, UDP_PORT_ENR_KEY: udp_port }) node = Node(enr) assert node.id == keccak(privkey.public_key.to_bytes()) assert node.address.ip_packed == ip assert node.address.tcp_port == tcp_port assert node.address.udp_port == udp_port