Ejemplo n.º 1
0
def test_apply():
    """Test the apply function."""
    currency_endowment = {"FET": 100}
    good_endowment = {"good_id": 2}
    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": -20},
        tx_sender_fee=5,
        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",
    )
    list_of_transactions = [tx_message]
    state = ownership_state
    new_state = ownership_state.apply_transactions(
        transactions=list_of_transactions)
    assert (
        state != new_state
    ), "after applying a list_of_transactions must have a different state!"
Ejemplo n.º 2
0
 def test_apply(self):
     """Test the apply function."""
     currency_endowment = {"FET": 100}
     good_endowment = {"good_id": 2}
     ownership_state = OwnershipState()
     ownership_state.set(
         amount_by_currency_id=currency_endowment,
         quantities_by_good_id=good_endowment,
     )
     list_of_terms = [self.buyer_terms]
     state = ownership_state
     new_state = ownership_state.apply_transactions(list_of_terms=list_of_terms)
     assert (
         state != new_state
     ), "after applying a list_of_terms must have a different state!"
Ejemplo n.º 3
0
def test_score_diff_from_transaction():
    """Test the difference between the scores."""
    good_holdings = {"good_id": 2}
    currency_holdings = {"FET": 100}
    utility_params = {"good_id": 20.0}
    exchange_params = {"FET": 10.0}
    tx_fee = 3
    ownership_state = OwnershipState()
    ownership_state.set(amount_by_currency_id=currency_holdings,
                        quantities_by_good_id=good_holdings)
    preferences = Preferences()
    preferences.set(
        utility_params_by_good_id=utility_params,
        exchange_params_by_currency_id=exchange_params,
        tx_fee=tx_fee,
    )
    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": -20},
        tx_sender_fee=preferences.seller_transaction_fee,
        tx_counterparty_fee=preferences.buyer_transaction_fee,
        tx_quantities_by_good_id={"good_id": 10},
        info={"some_info_key": "some_info_value"},
        ledger_id="fetchai",
        tx_nonce="transaction nonce",
    )

    cur_score = preferences.utility(quantities_by_good_id=good_holdings,
                                    amount_by_currency_id=currency_holdings)
    new_state = ownership_state.apply_transactions([tx_message])
    new_score = preferences.utility(
        quantities_by_good_id=new_state.quantities_by_good_id,
        amount_by_currency_id=new_state.amount_by_currency_id,
    )
    dif_scores = new_score - cur_score
    score_difference = preferences.utility_diff_from_transaction(
        ownership_state=ownership_state, tx_message=tx_message)
    assert (
        score_difference == dif_scores
    ), "The calculated difference must be equal to the return difference from the function."
Ejemplo n.º 4
0
def test_score_diff_from_transaction():
    """Test the difference between the scores."""
    good_holdings = {"good_id": 2}
    currency_holdings = {"FET": 100}
    utility_params = {"good_id": 20.0}
    exchange_params = {"FET": 10.0}
    ownership_state = OwnershipState()
    ownership_state.set(
        amount_by_currency_id=currency_holdings, quantities_by_good_id=good_holdings
    )
    preferences = Preferences()
    preferences.set(
        utility_params_by_good_id=utility_params,
        exchange_params_by_currency_id=exchange_params,
    )
    terms = Terms(
        ledger_id=ETHEREUM,
        sender_address="agent_1",
        counterparty_address="pk",
        amount_by_currency_id={"FET": -20},
        is_sender_payable_tx_fee=True,
        quantities_by_good_id={"good_id": 10},
        nonce="transaction nonce",
    )
    cur_score = preferences.utility(
        quantities_by_good_id=good_holdings, amount_by_currency_id=currency_holdings
    )
    new_state = ownership_state.apply_transactions([terms])
    new_score = preferences.utility(
        quantities_by_good_id=new_state.quantities_by_good_id,
        amount_by_currency_id=new_state.amount_by_currency_id,
    )
    diff_scores = new_score - cur_score
    score_difference = preferences.utility_diff_from_transaction(
        ownership_state=ownership_state, terms=terms
    )
    assert (
        score_difference == diff_scores
    ), "The calculated difference must be equal to the return difference from the function."
    assert not preferences.is_utility_enhancing(
        ownership_state=ownership_state, terms=terms
    ), "Should not enhance utility."