예제 #1
0
def test_signed_message_encode_decode():
    """Test encoding and decoding of signed_message."""
    class SignedMessageProtobufObject:
        signed_message_bytes = b""

    ledger_id = "some_ledger"
    body = "body"
    sm = SignedMessage(ledger_id, body)
    SignedMessage.encode(SignedMessageProtobufObject, sm)
    recovered_sm = SignedMessage.decode(SignedMessageProtobufObject)
    assert sm == recovered_sm
예제 #2
0
파일: gop.py 프로젝트: zeta1999/agents-aea
    def _handle_message_signing(
        self, signing_msg: SigningMessage, signing_dialogue: SigningDialogue
    ) -> None:
        """
        Handle a message for signing.

        :param signing_msg: the signing message
        :param signing_dialogue: the signing dialogue
        :return: None
        """
        performative = self.signing_msg_class.Performative.ERROR
        kwargs = {
            "error_code": self.signing_msg_class.ErrorCode.UNSUCCESSFUL_MESSAGE_SIGNING,
        }  # type: Dict[str, Any]
        if self._is_acceptable_for_signing(signing_msg):
            signed_message = self.wallet.sign_message(
                signing_msg.raw_message.ledger_id,
                signing_msg.raw_message.body,
                signing_msg.raw_message.is_deprecated_mode,
            )
            if signed_message is not None:
                performative = self.signing_msg_class.Performative.SIGNED_MESSAGE
                kwargs.pop("error_code")
                kwargs["signed_message"] = SignedMessage(
                    signing_msg.raw_message.ledger_id,
                    signed_message,
                    signing_msg.raw_message.is_deprecated_mode,
                )
        signing_msg_response = signing_dialogue.reply(
            performative=performative, target_message=signing_msg, **kwargs,
        )
        self.message_out_queue.put(signing_msg_response)
예제 #3
0
 def test_signed_message(self):
     """Test for an error for a signed message."""
     tx_msg = SigningMessage(
         performative=SigningMessage.Performative.SIGNED_MESSAGE,
         message_id=2,
         target=1,
         signed_message=SignedMessage(self.ledger_id, "message"),
     )
     assert tx_msg._is_consistent()
     encoded_tx_msg = tx_msg.encode()
     decoded_tx_msg = tx_msg.serializer.decode(encoded_tx_msg)
     assert tx_msg == decoded_tx_msg
예제 #4
0
def test_init_signed_message():
    """Test the signed_message object initialization."""
    ledger_id = "some_ledger"
    body = "body"
    sm = SignedMessage(ledger_id, body)
    assert sm.ledger_id == ledger_id
    assert sm.body == body
    assert not sm.is_deprecated_mode
    assert (
        str(sm) ==
        "SignedMessage: ledger_id=some_ledger, body=body, is_deprecated_mode=False"
    )
    assert sm == sm
예제 #5
0
 def test_message_consistency(self):
     """Test for an error in consistency of a message."""
     tx_msg = SigningMessage(
         performative=SigningMessage.Performative.SIGN_TRANSACTION,
         skill_callback_ids=self.skill_callback_ids,
         skill_callback_info=self.skill_callback_info,
         terms=self.terms,
         raw_transaction=RawTransaction(self.ledger_id, "transaction"),
     )
     assert tx_msg._is_consistent()
     tx_msg = SigningMessage(
         performative=SigningMessage.Performative.SIGN_MESSAGE,
         skill_callback_ids=self.skill_callback_ids,
         skill_callback_info=self.skill_callback_info,
         terms=self.terms,
         raw_message=RawMessage(self.ledger_id, "message"),
     )
     assert tx_msg._is_consistent()
     tx_msg = SigningMessage(
         performative=SigningMessage.Performative.SIGNED_TRANSACTION,
         message_id=2,
         target=1,
         skill_callback_ids=self.skill_callback_ids,
         skill_callback_info=self.skill_callback_info,
         signed_transaction=SignedTransaction(self.ledger_id, "signature"),
     )
     assert tx_msg._is_consistent()
     tx_msg = SigningMessage(
         performative=SigningMessage.Performative.SIGNED_MESSAGE,
         message_id=2,
         target=1,
         skill_callback_ids=self.skill_callback_ids,
         skill_callback_info=self.skill_callback_info,
         signed_message=SignedMessage(self.ledger_id, "message"),
     )
     assert tx_msg._is_consistent()
     tx_msg = SigningMessage(
         performative=SigningMessage.Performative.ERROR,
         message_id=2,
         target=1,
         skill_callback_ids=self.skill_callback_ids,
         skill_callback_info=self.skill_callback_info,
         error_code=SigningMessage.ErrorCode.UNSUCCESSFUL_MESSAGE_SIGNING,
     )
     assert tx_msg._is_consistent()
     assert str(tx_msg.performative) == "error"
     assert len(tx_msg.valid_performatives) == 5
예제 #6
0
    def _handle_message_signing(self, signing_msg: SigningMessage,
                                signing_dialogue: SigningDialogue) -> None:
        """
        Handle a message for signing.

        :param signing_msg: the signing message
        :param signing_dialogue: the signing dialogue
        :return: None
        """
        signing_msg_response = SigningMessage(
            performative=SigningMessage.Performative.ERROR,
            dialogue_reference=signing_dialogue.dialogue_label.
            dialogue_reference,
            target=signing_msg.message_id,
            message_id=signing_msg.message_id + 1,
            skill_callback_ids=signing_msg.skill_callback_ids,
            skill_callback_info=signing_msg.skill_callback_info,
            error_code=SigningMessage.ErrorCode.UNSUCCESSFUL_MESSAGE_SIGNING,
        )
        if self._is_acceptable_for_signing(signing_msg):
            signed_message = self.wallet.sign_message(
                signing_msg.raw_message.ledger_id,
                signing_msg.raw_message.body,
                signing_msg.raw_message.is_deprecated_mode,
            )
            if signed_message is not None:
                signing_msg_response = SigningMessage(
                    performative=SigningMessage.Performative.SIGNED_MESSAGE,
                    dialogue_reference=signing_dialogue.dialogue_label.
                    dialogue_reference,
                    target=signing_msg.message_id,
                    message_id=signing_msg.message_id + 1,
                    skill_callback_ids=signing_msg.skill_callback_ids,
                    skill_callback_info=signing_msg.skill_callback_info,
                    signed_message=SignedMessage(
                        signing_msg.raw_message.ledger_id,
                        signed_message,
                        signing_msg.raw_message.is_deprecated_mode,
                    ),
                )
        signing_msg_response.counterparty = signing_msg.counterparty
        signing_dialogue.update(signing_msg_response)
        self.message_out_queue.put(signing_msg_response)