def test_iiss_data_converter_encode_decode_none_raise_exception(self):
     with self.assertRaises(InvalidParamsException) as cm:
         none_value = "wrong_data"
         data: bytes = MsgPackForIpc.encode(none_value)
         MsgPackForIpc.decode(TypeTag.NIL, data)
     self.assertEqual(cm.exception.message,
                      f"Invalid tag type:{TypeTag.NIL} value: {data}")
Beispiel #2
0
    def from_list(items: list) -> 'QueryResponse':
        msg_id: int = items[1]
        payload: list = items[2]

        address: 'Address' = MsgPackForIpc.decode(TypeTag.ADDRESS, payload[0])
        iscore: int = MsgPackForIpc.decode(TypeTag.INT, payload[1])
        block_height: int = payload[2]

        return QueryResponse(msg_id, address, block_height, iscore)
Beispiel #3
0
    def from_list(items: list) -> 'ClaimResponse':
        msg_id: int = items[1]
        payload: list = items[2]

        address: 'Address' = MsgPackForIpc.decode(TypeTag.ADDRESS, payload[0])
        block_height: int = payload[1]
        block_hash: bytes = payload[2]
        iscore: int = MsgPackForIpc.decode(TypeTag.INT, payload[3])

        return ClaimResponse(msg_id, address, block_height, block_hash, iscore)
Beispiel #4
0
    def test_msgpack_loads_dumps(self):
        expected_struct: list = [
            1, -1, b'123456', b'', [1, 2, 3, 4, 5], {
                1: 2,
                3: 4
            }, True, False, None
        ]

        data: bytes = MsgPackForIpc.dumps(expected_struct)
        struct: list = MsgPackForIpc.loads(data)
        self.assertEqual(expected_struct, struct)
Beispiel #5
0
    def from_list(items: list) -> 'QueryCalculateResultResponse':
        msg_id: int = items[1]
        payload: list = items[2]

        status: int = payload[0]
        block_hegiht: int = payload[1]
        iscore: int = MsgPackForIpc.decode(TypeTag.INT, payload[2])
        state_hash: bytes = payload[3]

        return QueryCalculateResultResponse(msg_id, status, block_hegiht,
                                            iscore, state_hash)
Beispiel #6
0
    def from_list(items: list) -> 'CalculateDoneNotification':
        msg_id: int = items[1]
        payload: list = items[2]

        success: bool = payload[0]
        block_hegiht: int = payload[1]
        iscore: int = MsgPackForIpc.decode(TypeTag.INT, payload[2])
        state_hash: bytes = payload[3]

        return CalculateDoneNotification(msg_id, success, block_hegiht, iscore,
                                         state_hash)
Beispiel #7
0
    def _encode_msg(self, obj: Any):

        if isinstance(obj, (int, bytes, str, Address, bool)):
            return MsgPackForIpc.encode(obj)
        elif isinstance(obj, list):
            tmp: list = []
            for i in obj:
                tmp.append(self._encode_msg(i))
            return tmp
        elif isinstance(obj, dict):
            tmp: dict = {}
            for k, v in obj.items():
                tmp[self._encode_msg(k)] = self._encode_msg(v)
            return tmp
 def test_iiss_data_converter_encode_decode_any_str(self):
     str_value: str = "str_value"
     data: tuple = MsgPackForIpc.encode_any(str_value)
     ret_str = MsgPackForIpc.decode_any(data)
     self.assertEqual(str_value, ret_str)
 def test_iiss_data_converter_encode_decode_any_int(self):
     int_value: int = 10
     data: tuple = MsgPackForIpc.encode_any(int_value)
     ret_int = MsgPackForIpc.decode_any(data)
     self.assertEqual(int_value, ret_int)
 def test_msg_pack_for_ipc_encode_decode_any_list(self):
     list_value: list = [1, 2, [3, 4, [5, 6]]]
     data: tuple = MsgPackForIpc.encode_any(list_value)
     ret_list = MsgPackForIpc.decode_any(data)
     self.assertEqual(list_value, ret_list)
 def test_iiss_data_converter_encode_decode_none(self):
     none_value = None
     data: bytes = MsgPackForIpc.encode(none_value)
     ret_none = MsgPackForIpc.decode(TypeTag.NIL, data)
     self.assertEqual(none_value, ret_none)
 def test_msg_pack_for_ipc_encode_decode_int(self):
     int_value: int = 10
     data: bytes = MsgPackForIpc.encode(int_value)
     ret_int: int = MsgPackForIpc.decode(TypeTag.INT, data)
     self.assertEqual(int_value, ret_int)
 def test_iiss_data_converter_encode_decode_any_list(self):
     list_value: list = [1, 2, [3, 4, [5, 6]]]
     data: tuple = MsgPackForIpc.encode_any(list_value)
     ret_list = MsgPackForIpc.decode_any(data)
     self.assertEqual(list_value, ret_list)
 def test_msg_pack_for_ipc_encode_decode_none(self):
     none_value = None
     data: bytes = MsgPackForIpc.encode(none_value)
     ret_none = MsgPackForIpc.decode(TypeTag.NIL, data)
     self.assertEqual(none_value, ret_none)
Beispiel #15
0
    def _prt_length_info(self, tag: str, data: list):
        new_expected_struct: list = self._encode_msg(data)
        data: bytes = MsgPackForIpc.dumps(new_expected_struct)

        print(f"{tag} data: {new_expected_struct}")
        print(f"{tag} length: {len(data)}")
 def test_msg_pack_for_ipc_encode_decode_bool(self):
     bool_value: bool = True
     data: bytes = MsgPackForIpc.encode(bool_value)
     ret_bool: bool = bool(MsgPackForIpc.decode(TypeTag.INT, data))
     self.assertEqual(bool_value, ret_bool)
 def test_msg_pack_for_ipc_encode_decode_bytes(self):
     bytes_value: bytes = b'byte_value'
     data: bytes = MsgPackForIpc.encode(bytes_value)
     ret_bytes: bytes = MsgPackForIpc.decode(TypeTag.BYTES, data)
     self.assertEqual(bytes_value, ret_bytes)
 def test_msg_pack_for_ipc_encode_decode_str(self):
     str_value: str = "str_value"
     data: bytes = MsgPackForIpc.encode(str_value)
     ret_str: str = MsgPackForIpc.decode(TypeTag.STRING, data)
     self.assertEqual(str_value, ret_str)
 def test_iiss_data_converter_encode_decode_any_byte(self):
     bytes_value: str = b"byte_value"
     data: tuple = MsgPackForIpc.encode_any(bytes_value)
     ret_bytes = MsgPackForIpc.decode_any(data)
     self.assertEqual(bytes_value, ret_bytes)
 def test_iiss_data_converter_encode_decode_int(self):
     int_value: int = 10
     data: bytes = MsgPackForIpc.encode(int_value)
     ret_int: int = MsgPackForIpc.decode(TypeTag.INT, data)
     self.assertEqual(int_value, ret_int)
 def test_iiss_data_converter_encode_decode_any_none(self):
     none_value = None
     data: tuple = MsgPackForIpc.encode_any(none_value)
     ret_none = MsgPackForIpc.decode_any(data)
     self.assertEqual(none_value, ret_none)
 def test_iiss_data_converter_encode_decode_bytes(self):
     bytes_value: bytes = b'byte_value'
     data: bytes = MsgPackForIpc.encode(bytes_value)
     ret_bytes: bytes = MsgPackForIpc.decode(TypeTag.BYTES, data)
     self.assertEqual(bytes_value, ret_bytes)
 def test_iiss_data_converter_encode_decode_any_dict(self):
     dict_value: dict = {"a": 1, "b": 2, "c": {"d": 3}}
     data: tuple = MsgPackForIpc.encode_any(dict_value)
     ret_dict = MsgPackForIpc.decode_any(data)
     self.assertEqual(dict_value, ret_dict)
 def test_msg_pack_for_ipc_encode_decode_any_dict(self):
     dict_value: dict = {"a": 1, "b": 2, "c": {"d": 3}}
     data: tuple = MsgPackForIpc.encode_any(dict_value)
     ret_dict = MsgPackForIpc.decode_any(data)
     self.assertEqual(dict_value, ret_dict)
 def test_iiss_data_converter_encode_decode_str(self):
     str_value: str = "str_value"
     data: bytes = MsgPackForIpc.encode(str_value)
     ret_str: str = MsgPackForIpc.decode(TypeTag.STRING, data)
     self.assertEqual(str_value, ret_str)
Beispiel #26
0
    def test_msgpack_for_ipc_encode_deoode(self):
        expected_struct: list = [
            1, -1, b'123456', b'', "hello", "",
            create_address(), None
        ]

        data_list: list = []
        for value in expected_struct:
            data_list.append(MsgPackForIpc.encode(value))

        data: bytes = MsgPackForIpc.dumps(data_list)
        struct: list = MsgPackForIpc.loads(data)

        actual_struct: list = [
            MsgPackForIpc.decode(TypeTag.INT, struct[0]),
            MsgPackForIpc.decode(TypeTag.INT, struct[1]),
            MsgPackForIpc.decode(TypeTag.BYTES, struct[2]),
            MsgPackForIpc.decode(TypeTag.BYTES, struct[3]),
            MsgPackForIpc.decode(TypeTag.STRING, struct[4]),
            MsgPackForIpc.decode(TypeTag.STRING, struct[5]),
            MsgPackForIpc.decode(TypeTag.ADDRESS, struct[6]),
            MsgPackForIpc.decode(TypeTag.NIL, struct[7])
        ]

        self.assertEqual(expected_struct, actual_struct)
 def test_iiss_data_converter_encode_decode_bool(self):
     bool_value: bool = True
     data: bytes = MsgPackForIpc.encode(bool_value)
     ret_bool: bool = bool(MsgPackForIpc.decode(TypeTag.INT, data))
     self.assertEqual(bool_value, ret_bool)
 def test_msg_pack_for_ipc_encode_decode_any_str(self):
     str_value: str = "str_value"
     data: tuple = MsgPackForIpc.encode_any(str_value)
     ret_str = MsgPackForIpc.decode_any(data)
     self.assertEqual(str_value, ret_str)
 def test_msg_pack_for_ipc_encode_decode_any_byte(self):
     bytes_value: str = b"byte_value"
     data: tuple = MsgPackForIpc.encode_any(bytes_value)
     ret_bytes = MsgPackForIpc.decode_any(data)
     self.assertEqual(bytes_value, ret_bytes)
 def test_msg_pack_for_ipc_encode_decode_any_none(self):
     none_value = None
     data: tuple = MsgPackForIpc.encode_any(none_value)
     ret_none = MsgPackForIpc.decode_any(data)
     self.assertEqual(none_value, ret_none)