def test_tools_error(self): c_nodes = message._compact_nodes(tc.NODES) # Compact nodes is one byte short assert_raises(MsgError, message._uncompact_nodes, c_nodes[:-1]) # IP size is weird assert_raises(MsgError, bin_to_ip, '123') # Port is 0 ( eq_(message._uncompact_nodes(c_nodes), tc.NODES) n = tc.NODES[0] tc.NODES[0] = node.Node((n.addr[0], 0), n.id) c_nodes = message._compact_nodes(tc.NODES) eq_(message._uncompact_nodes(c_nodes), tc.NODES[1:]) c_nodes2 = message._compact_nodes2(tc.NODES) eq_(message._uncompact_nodes2(c_nodes2), tc.NODES[1:]) tc.NODES[0] = n
def test_tools_error(self): c_nodes = message._compact_nodes(tc.NODES) # Compact nodes is one byte short assert_raises(MsgError, message._uncompact_nodes, c_nodes[:-1]) # IP size is weird assert_raises(MsgError, bin_to_ip, "123") # Port is 0 ( eq_(message._uncompact_nodes(c_nodes), tc.NODES) n = tc.NODES[0] tc.NODES[0] = node.Node((n.addr[0], 0), n.id) c_nodes = message._compact_nodes(tc.NODES) eq_(message._uncompact_nodes(c_nodes), tc.NODES[1:]) c_nodes2 = message._compact_nodes2(tc.NODES) eq_(message._uncompact_nodes2(c_nodes2), tc.NODES[1:]) tc.NODES[0] = n
def test_sanitize(self): self.ping_r.sanitize_response(PING) del self.fn2_r._msg_dict[RESPONSE][NODES2] # No NODES and no NODES2 assert_raises(MsgError, self.fn2_r.sanitize_response, FIND_NODE) self.fn2_r._msg_dict[RESPONSE][NODES] = message._compact_nodes(tc.NODES) # Just NODES self.fn2_r.sanitize_response(FIND_NODE) self.fn2_r._msg_dict[RESPONSE][NODES2] = message._compact_nodes2(tc.NODES) # Both NODES and NODES2 self.fn2_r.sanitize_response(FIND_NODE) # Both NODES and PEERS in response self.gp_r._msg_dict[RESPONSE][NODES] = message._compact_nodes(tc.NODES) self.gp_r.sanitize_response(GET_PEERS) # No NODES and no PEERS del self.gp_r._msg_dict[RESPONSE][NODES] del self.gp_r._msg_dict[RESPONSE][VALUES] assert_raises(MsgError, self.gp_r.sanitize_response, GET_PEERS)
def test_sanitize(self): self.ping_r.sanitize_response(PING) del self.fn2_r._msg_dict[RESPONSE][NODES2] # No NODES and no NODES2 assert_raises(MsgError, self.fn2_r.sanitize_response, FIND_NODE) self.fn2_r._msg_dict[RESPONSE][NODES] = \ message._compact_nodes(tc.NODES) # Just NODES self.fn2_r.sanitize_response(FIND_NODE) self.fn2_r._msg_dict[RESPONSE][NODES2] = \ message._compact_nodes2(tc.NODES) # Both NODES and NODES2 self.fn2_r.sanitize_response(FIND_NODE) # Both NODES and PEERS in response self.gp_r._msg_dict[RESPONSE][NODES] = \ message._compact_nodes(tc.NODES) self.gp_r.sanitize_response(GET_PEERS) # No NODES and no PEERS del self.gp_r._msg_dict[RESPONSE][NODES] del self.gp_r._msg_dict[RESPONSE][VALUES] assert_raises(MsgError, self.gp_r.sanitize_response, GET_PEERS)
def test_tools(self): bin_strs = ['23', '\1\5', 'a\3'] for bs in bin_strs: i = bin_to_int(bs) bs2 = int_to_bin(i) log.debug('bs: %s, bin_to_int(bs): %d, bs2: %s' % (bs, i, bs2)) assert bs == bs2 ips = ['127.0.0.1', '222.222.222.222', '1.2.3.4'] ports = [12345, 99, 54321] for addr in zip(ips, ports): c_addr = compact_addr(addr) addr2 = uncompact_addr(c_addr) assert addr == addr2 c_peers = message._compact_peers(tc.PEERS) peers = message._uncompact_peers(c_peers) for p1, p2 in zip(tc.PEERS, peers): assert p1[0] == p2[0] assert p1[0] == p2[0] c_nodes = message._compact_nodes(tc.NODES) nodes = message._uncompact_nodes(c_nodes) for n1, n2 in zip(tc.NODES, nodes): assert n1 == n2 bin_ipv6s = ['\x00' * 10 + '\xff\xff' + '\1\2\3\4', '\x22' * 16, ] assert bin_to_ip(bin_ipv6s[0]) == '1.2.3.4' assert_raises(AddrError, bin_to_ip, bin_ipv6s[1]) PORT = 7777 BIN_PORT = int_to_bin(PORT) c_nodes2 = [tc.CLIENT_ID.bin_id + ip + BIN_PORT for ip in bin_ipv6s] nodes2 = [node.Node(('1.2.3.4', PORT), tc.CLIENT_ID)] log.debug(message._uncompact_nodes2(c_nodes2)) assert message._uncompact_nodes2(c_nodes2) == nodes2 log.warning( "**IGNORE WARNING LOG** This exception was raised by a test")
def test_tools(self): bin_strs = ['23', '\1\5', 'a\3'] for bs in bin_strs: i = bin_to_int(bs) bs2 = int_to_bin(i) logger.debug('bs: %s, bin_to_int(bs): %d, bs2: %s' % (bs, i, bs2)) assert bs == bs2 ips = ['127.0.0.1', '222.222.222.222', '1.2.3.4'] ports = [12345, 99, 54321] for addr in zip(ips, ports): c_addr = compact_addr(addr) addr2 = uncompact_addr(c_addr) assert addr == addr2 c_peers = message._compact_peers(tc.PEERS) peers = message._uncompact_peers(c_peers) for p1, p2 in zip(tc.PEERS, peers): assert p1[0] == p2[0] assert p1[0] == p2[0] c_nodes = message._compact_nodes(tc.NODES) nodes = message._uncompact_nodes(c_nodes) for n1, n2 in zip(tc.NODES, nodes): assert n1 == n2 bin_ipv6s = ['\x00' * 10 + '\xff\xff' + '\1\2\3\4', '\x22' * 16, ] assert bin_to_ip(bin_ipv6s[0]) == '1.2.3.4' assert_raises(AddrError, bin_to_ip, bin_ipv6s[1]) PORT = 7777 BIN_PORT = int_to_bin(PORT) c_nodes2 = [tc.CLIENT_ID.bin_id + ip + BIN_PORT for ip in bin_ipv6s] nodes2 = [node.Node(('1.2.3.4', PORT), tc.CLIENT_ID)] logger.debug(message._uncompact_nodes2(c_nodes2)) assert message._uncompact_nodes2(c_nodes2) == nodes2 logger.warning( "**IGNORE WARNING LOG** This exception was raised by a test")
def test_tools(self): bin_strs = ["23", "\1\5", "a\3"] for bs in bin_strs: i = bin_to_int(bs) bs2 = int_to_bin(i) log.debug("bs: %s, bin_to_int(bs): %d, bs2: %s" % (bs, i, bs2)) assert bs == bs2 ips = ["127.0.0.1", "222.222.222.222", "1.2.3.4"] ports = [12345, 99, 54321] for addr in zip(ips, ports): c_addr = compact_addr(addr) addr2 = uncompact_addr(c_addr) assert addr == addr2 c_peers = message._compact_peers(tc.PEERS) peers = message._uncompact_peers(c_peers) for p1, p2 in zip(tc.PEERS, peers): assert p1[0] == p2[0] assert p1[0] == p2[0] c_nodes = message._compact_nodes(tc.NODES) nodes = message._uncompact_nodes(c_nodes) for n1, n2 in zip(tc.NODES, nodes): assert n1 == n2 bin_ipv6s = ["\x00" * 10 + "\xff\xff" + "\1\2\3\4", "\x22" * 16] assert bin_to_ip(bin_ipv6s[0]) == "1.2.3.4" assert_raises(AddrError, bin_to_ip, bin_ipv6s[1]) PORT = 7777 BIN_PORT = int_to_bin(PORT) c_nodes2 = [tc.CLIENT_ID.bin_id + ip + BIN_PORT for ip in bin_ipv6s] nodes2 = [node.Node(("1.2.3.4", PORT), tc.CLIENT_ID)] log.debug(message._uncompact_nodes2(c_nodes2)) assert message._uncompact_nodes2(c_nodes2) == nodes2 log.warning("**IGNORE WARNING LOG** This exception was raised by a test")