def store_successful(reward_proof_signature=None, **kwargs): request_monitoring = build_request_monitoring(**kwargs) rm_dict = DictSerializer.serialize(request_monitoring) if reward_proof_signature: rm_dict["signature"] = reward_proof_signature request_collector.on_monitor_request(DictSerializer.deserialize(rm_dict)) return ms_database.monitor_request_count() == 1
def test_deserialize_messages_valid_message(request_monitoring_message): message_json = DictSerializer.serialize(request_monitoring_message) messages = deserialize_messages( data=json.dumps(message_json), peer_address=request_monitoring_message.sender) assert len(messages) == 1
def test_deserialize_messages_invalid_message_class( request_monitoring_message): message_json = DictSerializer.serialize(request_monitoring_message) with patch("raiden_libs.matrix.message_from_dict", new=Mock()): messages = deserialize_messages(data=json.dumps(message_json), peer_address=INVALID_PEER_ADDRESS) assert len(messages) == 0
def test_deserialize_messages_with_missing_fields(request_monitoring_message): message_dict = DictSerializer.serialize(request_monitoring_message) list_of_key_words = list(message_dict.keys()) # non closing signature is not required by this message type list_of_key_words.remove("non_closing_signature") for key in list_of_key_words: message_json_broken = deepcopy(message_dict) del message_json_broken[key] messages = deserialize_messages( data=json.dumps(message_json_broken), peer_address=request_monitoring_message.sender) assert len(messages) == 0
def test_message_from_dict(request_monitoring_message): message_json = DictSerializer.serialize(request_monitoring_message) # Test happy path message = message_from_dict(message_json) assert message == request_monitoring_message # Test unknown message type message_json["_type"] = "SomeNonexistantMessage" with pytest.raises(InvalidProtocolMessage) as excinfo: message_from_dict(message_json) assert 'Invalid message type (data["type"]' in str(excinfo.value) # Test non-existant message type del message_json["_type"] with pytest.raises(InvalidProtocolMessage) as excinfo: message_from_dict(message_json) assert "Invalid message data. Can not find the data type" in str( excinfo.value)
def test_deserialize_messages_invalid_sender(request_monitoring_message): message_json = DictSerializer.serialize(request_monitoring_message) messages = deserialize_messages(data=json.dumps(message_json), peer_address=INVALID_PEER_ADDRESS) assert len(messages) == 0