def test_serialization_apply(self): """Test serialization of apply message.""" currency_change = {"FET": 10} good_change = {"a_good": 1} msg = StateUpdateMessage( performative=StateUpdateMessage.Performative.APPLY, amount_by_currency_id=currency_change, quantities_by_good_id=good_change, ) assert msg._is_consistent() assert len(msg.valid_performatives) == 2 encoded_msg = msg.serializer.encode(msg) decoded_msg = msg.serializer.decode(encoded_msg) assert msg == decoded_msg
def test_message_inconsistency(self): """Test for an error in consistency of a message.""" currency_endowment = {"FET": 100} good_endowment = {"a_good": 2} exchange_params = {"UNKNOWN": 10.0} utility_params = {"a_good": 20.0} tx_fee = 10 stum = StateUpdateMessage( performative=StateUpdateMessage.Performative.INITIALIZE, amount_by_currency_id=currency_endowment, quantities_by_good_id=good_endowment, exchange_params_by_currency_id=exchange_params, utility_params_by_good_id=utility_params, tx_fee=tx_fee, ) assert not stum._is_consistent()
def test_message_consistency(self): """Test for an error in consistency of a message.""" currency_endowment = {"FET": 100} good_endowment = {"a_good": 2} exchange_params = {"FET": 10.0} utility_params = {"a_good": 20.0} assert StateUpdateMessage( performative=StateUpdateMessage.Performative.INITIALIZE, amount_by_currency_id=currency_endowment, quantities_by_good_id=good_endowment, exchange_params_by_currency_id=exchange_params, utility_params_by_good_id=utility_params, ) currency_change = {"FET": 10} good_change = {"a_good": 1} stum = StateUpdateMessage( performative=StateUpdateMessage.Performative.APPLY, amount_by_currency_id=currency_change, quantities_by_good_id=good_change, ) assert stum._is_consistent() assert len(stum.valid_performatives) == 2