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}")
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)
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)
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 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)
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)
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_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_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_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_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_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)
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_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)