Ejemplo n.º 1
0
def tests_transaction_is_affordable_else_statement():
    """Check that the function returns false if we cannot satisfy any if/elif statements."""
    currency_endowment = {"FET": 0}
    good_endowment = {"good_id": 0}
    ownership_state = OwnershipState()
    ownership_state.set(
        amount_by_currency_id=currency_endowment,
        quantities_by_good_id=good_endowment,
    )
    tx_message = TransactionMessage(
        performative=TransactionMessage.Performative.PROPOSE_FOR_SETTLEMENT,
        skill_callback_ids=[PublicId(AUTHOR, "a_skill", "0.1.0")],
        tx_id="transaction0",
        tx_sender_addr="agent_1",
        tx_counterparty_addr="pk",
        tx_amount_by_currency_id={"FET": 10},
        tx_sender_fee=0,
        tx_counterparty_fee=0,
        tx_quantities_by_good_id={"good_id": 50},
        info={"some_info_key": "some_info_value"},
        ledger_id="fetchai",
        tx_nonce="transaction nonce",
    )

    assert not ownership_state.is_affordable_transaction(
        tx_message=tx_message), "We must reject the transaction."
Ejemplo n.º 2
0
def test_transaction_is_affordable_agent_is_buyer():
    """Check if the agent has the money to cover the sender_amount (the agent=sender is the buyer)."""
    currency_endowment = {"FET": 100}
    good_endowment = {"good_id": 20}
    ownership_state = OwnershipState()
    ownership_state.set(
        amount_by_currency_id=currency_endowment,
        quantities_by_good_id=good_endowment,
    )
    tx_message = TransactionMessage(
        performative=TransactionMessage.Performative.PROPOSE_FOR_SETTLEMENT,
        skill_callback_ids=[PublicId(AUTHOR, "a_skill", "0.1.0")],
        tx_id="transaction0",
        tx_sender_addr="agent_1",
        tx_counterparty_addr="pk",
        tx_amount_by_currency_id={"FET": -1},
        tx_sender_fee=0,
        tx_counterparty_fee=0,
        tx_quantities_by_good_id={"good_id": 10},
        info={"some_info_key": "some_info_value"},
        ledger_id="fetchai",
        tx_nonce="transaction nonce",
    )

    assert ownership_state.is_affordable_transaction(
        tx_message=tx_message), "We should have the money for the transaction!"
Ejemplo n.º 3
0
def test_transaction_is_affordable_there_is_no_wealth():
    """Reject the transaction when there is no wealth exchange."""
    currency_endowment = {"FET": 0}
    good_endowment = {"good_id": 0}
    ownership_state = OwnershipState()
    ownership_state.set(
        amount_by_currency_id=currency_endowment,
        quantities_by_good_id=good_endowment,
    )
    tx_message = TransactionMessage(
        performative=TransactionMessage.Performative.PROPOSE_FOR_SETTLEMENT,
        skill_callback_ids=[PublicId(AUTHOR, "a_skill", "0.1.0")],
        tx_id="transaction0",
        tx_sender_addr="agent_1",
        tx_counterparty_addr="pk",
        tx_amount_by_currency_id={"FET": 0},
        tx_sender_fee=0,
        tx_counterparty_fee=0,
        tx_quantities_by_good_id={"good_id": 0},
        info={"some_info_key": "some_info_value"},
        ledger_id="fetchai",
        tx_nonce="transaction nonce",
    )

    assert not ownership_state.is_affordable_transaction(
        tx_message=tx_message), "We must reject the transaction."
Ejemplo n.º 4
0
 def test_transaction_is_affordable_agent_is_seller(self):
     """Check if the agent has the goods (the agent=sender is the seller)."""
     currency_endowment = {"FET": 100}
     good_endowment = {"good_id": 20}
     ownership_state = OwnershipState()
     ownership_state.set(
         amount_by_currency_id=currency_endowment,
         quantities_by_good_id=good_endowment,
     )
     assert ownership_state.is_affordable_transaction(
         terms=self.seller_terms), "We must reject the transaction."
Ejemplo n.º 5
0
 def test_transaction_is_affordable_malformed(self):
     """Reject the transaction when there is no wealth exchange."""
     currency_endowment = {"FET": 100}
     good_endowment = {"good_id": 20}
     ownership_state = OwnershipState()
     ownership_state.set(
         amount_by_currency_id=currency_endowment,
         quantities_by_good_id=good_endowment,
     )
     assert not ownership_state.is_affordable_transaction(
         terms=self.malformed_terms), "We must reject the transaction."