Ejemplo n.º 1
0
def test_get_raw_transaction_serialization():
    """Test the serialization for 'get_raw_transaction' speech-act works."""
    kwargs_arg = ContractApiMessage.Kwargs({"key_1": 1, "key_2": 2})
    msg = ContractApiMessage(
        message_id=1,
        dialogue_reference=(str(0), ""),
        target=0,
        performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION,
        ledger_id="some_ledger_id",
        contract_id="some_contract_id",
        contract_address="some_contract_address",
        callable="some_callable",
        kwargs=kwargs_arg,
    )
    msg.to = "receiver"
    envelope = Envelope(
        to=msg.to,
        sender="sender",
        message=msg,
    )
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (expected_envelope.protocol_specification_id ==
            actual_envelope.protocol_specification_id)
    assert expected_envelope.message != actual_envelope.message

    actual_msg = ContractApiMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg
Ejemplo n.º 2
0
def test_error_serialization():
    """Test the serialization for 'error' speech-act works."""
    msg = ContractApiMessage(
        performative=ContractApiMessage.Performative.ERROR,
        code=7,
        message="some_error_message",
        data=b"some_error_data",
    )
    msg.to = "receiver"
    envelope = Envelope(
        to=msg.to,
        sender="sender",
        message=msg,
    )
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (expected_envelope.protocol_specification_id ==
            actual_envelope.protocol_specification_id)
    assert expected_envelope.message != actual_envelope.message

    actual_msg = ContractApiMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg
Ejemplo n.º 3
0
def test_raw_transaction_serialization():
    """Test the serialization for 'raw_transaction' speech-act works."""
    raw_transaction_arg = ContractApiMessage.RawTransaction(
        "some_ledger_id", {"body": "some_body"})
    msg = ContractApiMessage(
        message_id=2,
        target=1,
        performative=ContractApiMessage.Performative.RAW_TRANSACTION,
        raw_transaction=raw_transaction_arg,
    )
    msg.to = "receiver"
    envelope = Envelope(
        to=msg.to,
        sender="sender",
        message=msg,
    )
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (expected_envelope.protocol_specification_id ==
            actual_envelope.protocol_specification_id)
    assert expected_envelope.message != actual_envelope.message

    actual_msg = ContractApiMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg
Ejemplo n.º 4
0
def test_raw_message_serialization():
    """Test the serialization for 'raw_message' speech-act works."""
    raw_message_arg = ContractApiMessage.RawMessage("some_ledger_id",
                                                    b"some_body")
    msg = ContractApiMessage(
        performative=ContractApiMessage.Performative.RAW_MESSAGE,
        raw_message=raw_message_arg,
    )
    msg.to = "receiver"
    envelope = Envelope(
        to=msg.to,
        sender="sender",
        message=msg,
    )
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (expected_envelope.protocol_specification_id ==
            actual_envelope.protocol_specification_id)
    assert expected_envelope.message != actual_envelope.message

    actual_msg = ContractApiMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg
Ejemplo n.º 5
0
def test_state_serialization():
    """Test the serialization for 'state' speech-act works."""
    state_arg = ContractApiMessage.State("some_ledger_id",
                                         {"key": "some_body"})
    msg = ContractApiMessage(
        message_id=1,
        dialogue_reference=(str(0), ""),
        target=0,
        performative=ContractApiMessage.Performative.STATE,
        state=state_arg,
    )
    msg.to = "receiver"
    envelope = Envelope(
        to=msg.to,
        sender="sender",
        message=msg,
    )
    envelope_bytes = envelope.encode()

    actual_envelope = Envelope.decode(envelope_bytes)
    expected_envelope = envelope
    assert expected_envelope.to == actual_envelope.to
    assert expected_envelope.sender == actual_envelope.sender
    assert (expected_envelope.protocol_specification_id ==
            actual_envelope.protocol_specification_id)
    assert expected_envelope.message != actual_envelope.message

    actual_msg = ContractApiMessage.serializer.decode(actual_envelope.message)
    actual_msg.to = actual_envelope.to
    actual_msg.sender = actual_envelope.sender
    expected_msg = msg
    assert expected_msg == actual_msg