Esempio n. 1
0
    def test_packet_enc_dec(self):
        packets_type_data = [
            ( PacketsTestCase.GOOD_STR_TYPE, PacketsTestCase.GOOD_STR_DATA ),
            ( PacketsTestCase.GOOD_BIN_TYPE, PacketsTestCase.GOOD_BIN_DATA ),
        ]

        for i, packet_type_data in enumerate(packets_type_data):
            self.assertEqual(packet_type_data, deceiopacket(enceiopacket(*packet_type_data)), msg='packet_type_data[{}]: {!r}'.format(i, packet_type_data))
Esempio n. 2
0
    def test_packet_dec_enc(self):
        packets = [
            PacketsTestCase.GOOD_STR_PACKET,
            PacketsTestCase.GOOD_BIN_PACKET,
        ]

        for i, packet in enumerate(packets):
            self.assertEqual(packet, enceiopacket(*deceiopacket(packet)), msg='packet[{}]: {!r}'.format(i, packet))
Esempio n. 3
0
    def test_packet_dec_bad_type(self):
        packets = [
            PacketsTestCase.BAD_TYPE_STR_PACKET,
            PacketsTestCase.BAD_TYPE_BIN_PACKET,
        ]

        for i, packet in enumerate(packets):
            with self.assertRaisesRegex(PayloadDecodeError, r'^unrecognized packet type "', msg='packet[{}]: {!r}'.format(i, packet)):
                deceiopacket(packet)

        packets = [
            list(range(10)),
            tuple(range(10)),
            42,
        ]

        for i, packet in enumerate(packets):
            with self.assertRaisesRegex(TypeError, r'^packet type must be one of bytes or str, not .+$', msg='packet[{}]: {!r}'.format(i, packet)):
                deceiopacket(packet)
Esempio n. 4
0
    def test_packet_dec(self):
        packets = [
            PacketsTestCase.GOOD_STR_PACKET,
            PacketsTestCase.GOOD_BIN_PACKET,
        ]
        packets_type_data = [
            ( PacketsTestCase.GOOD_STR_TYPE, PacketsTestCase.GOOD_STR_DATA ),
            ( PacketsTestCase.GOOD_BIN_TYPE, PacketsTestCase.GOOD_BIN_DATA ),
        ]

        for i, zipped in enumerate(zip(packets_type_data, packets)):
            expected, packet = zipped
            self.assertEqual(expected, deceiopacket(packet), msg='packet[{}]: {!r}'.format(i, packet))
Esempio n. 5
0
    def test_regression_long_payload(self):
        # This is raw data from Insight API (on or about 2015-11-05) that
        # we choked on because we (erroneously) didn't allow for payloads
        # longer than 310 characters
        raw = b'\x00\x02\x01\x05\xff42["tx",{"txid":"e9772f1171fb16c3461a545b320cf9882a3d60e8fe58af6058f14230cda5d493","valueOut":74.6768726,"vout":[{"1JzddE9RdGaxWbJgfBM15J3Xj6hzKX3o3f":1200000000},{"1GJ9AnmcwwCGSJyksX8thqRvnuAfS1ZB6C":6267687260}]}]\x00\x01\x01\x02\x05\xff42["tx",{"txid":"5c3264d64107f5398745bdbd2c6a2c40ee3ea022eb4bbacc79271ce0fc91e8ea","valueOut":31.47905388,"vout":[{"1BKLefgfSQjRWRHSkirEKPz9y5Z5VwUKYT":25257121},{"1BGv1vWNjvekSFD6SoyNQJvCDGbhCfyknp":24046431},{"1GMcQBw7NHL17Xw8b1ueDzP1fuCESCgDfy":70226431},{"1DZxmrAMnRssRNjqNTp5XsCACwQXte3fdz":25247121},{"1QA7FTnqvHabS979u19UvWzgLRxThH3vMP":42800000},{"176yohfzuRWw9PWXaKwxZuGZana5EJj4Wi":535262879},{"15iQFJNjprPNHhdFwHpg3NxYBQH4rqAis8":1200690},{"1L7kTokjjCsLhmTwBeTUaw3zZX5cmAZgey":688940},{"1HKugLe1iFnHFUdTNGtm1K8vCMjjhgfvKB":324710000},{"1F8LtvqAhMEFkcfYHvqLVDMPFQv8ncZoZ6":118062879},{"1CjLvNRipzdq6hUWJ14iE72TfXFL6hBgUu":254362879},{"137Em62DLiYoWtvYbZoe396XaQ1iwYJLnd":433500000},{"17hD8cgNetd6G4L4nLUmJeD7PxgjfSMhdk":460000000},{"14uP5jHc26Kmt9xKs8CJwXSWDFuZAkz47S":144562879},{"1GxscjUdN9Ntxo68zGXYJCq5p2dXLb1Q68":10000},{"13rgFRQqTuxTUBCsgBGonXKQXSSf6ThDxW":323700000},{"1PTDGyzVGkjgL3VTKXZjDSGkSyd5SquuvZ":24056431},{"17jJiNJiRwaZmwtsAU8BdCua3RNwK8c8DZ":71427121},{"1MPv7Px7BRzVXJQyYB1Fn5nFVMKt5TnXVz":511750},{"13LErEoUYp9HxGX9jYoZedPShXgTasUy5J":253352879},{"1KYLZwc939EJUz1y45YqbtbSqarjhtqJbi":14918957}]}]'

        expected = [
            (
                b'4',
                '2["tx",{"txid":"e9772f1171fb16c3461a545b320cf9882a3d60e8fe58af6058f14230cda5d493","valueOut":74.6768726,"vout":[{"1JzddE9RdGaxWbJgfBM15J3Xj6hzKX3o3f":1200000000},{"1GJ9AnmcwwCGSJyksX8thqRvnuAfS1ZB6C":6267687260}]}]',
            ),
            (
                b'4',
                '2["tx",{"txid":"5c3264d64107f5398745bdbd2c6a2c40ee3ea022eb4bbacc79271ce0fc91e8ea","valueOut":31.47905388,"vout":[{"1BKLefgfSQjRWRHSkirEKPz9y5Z5VwUKYT":25257121},{"1BGv1vWNjvekSFD6SoyNQJvCDGbhCfyknp":24046431},{"1GMcQBw7NHL17Xw8b1ueDzP1fuCESCgDfy":70226431},{"1DZxmrAMnRssRNjqNTp5XsCACwQXte3fdz":25247121},{"1QA7FTnqvHabS979u19UvWzgLRxThH3vMP":42800000},{"176yohfzuRWw9PWXaKwxZuGZana5EJj4Wi":535262879},{"15iQFJNjprPNHhdFwHpg3NxYBQH4rqAis8":1200690},{"1L7kTokjjCsLhmTwBeTUaw3zZX5cmAZgey":688940},{"1HKugLe1iFnHFUdTNGtm1K8vCMjjhgfvKB":324710000},{"1F8LtvqAhMEFkcfYHvqLVDMPFQv8ncZoZ6":118062879},{"1CjLvNRipzdq6hUWJ14iE72TfXFL6hBgUu":254362879},{"137Em62DLiYoWtvYbZoe396XaQ1iwYJLnd":433500000},{"17hD8cgNetd6G4L4nLUmJeD7PxgjfSMhdk":460000000},{"14uP5jHc26Kmt9xKs8CJwXSWDFuZAkz47S":144562879},{"1GxscjUdN9Ntxo68zGXYJCq5p2dXLb1Q68":10000},{"13rgFRQqTuxTUBCsgBGonXKQXSSf6ThDxW":323700000},{"1PTDGyzVGkjgL3VTKXZjDSGkSyd5SquuvZ":24056431},{"17jJiNJiRwaZmwtsAU8BdCua3RNwK8c8DZ":71427121},{"1MPv7Px7BRzVXJQyYB1Fn5nFVMKt5TnXVz":511750},{"13LErEoUYp9HxGX9jYoZedPShXgTasUy5J":253352879},{"1KYLZwc939EJUz1y45YqbtbSqarjhtqJbi":14918957}]}]',
            ),
        ]

        actual = [ deceiopacket(pckt) for pckt in decbinpayloadsgen(raw) ]
        self.assertEqual(expected, actual)
Esempio n. 6
0
 def test_packet_dec_bad_len(self):
     with self.assertRaisesRegex(PayloadDecodeError, r'^packet truncated$'):
         deceiopacket(PacketsTestCase.BAD_TRUNC_PACKET)
Esempio n. 7
0
 def test_enc_dec(self, packet_type, packet_data):
     args = ( packet_type, packet_data )
     self.assertEqual(args, deceiopacket(enceiopacket(*args)))