def test_ledger_api_dialogue(self): """Test the LedgerApiDialogue class.""" ledger_api_dialogue = LedgerApiDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=ContractApiDialogue.Role.AGENT, ) # associated_signing_dialogue with pytest.raises(ValueError, match="Associated signing dialogue not set!"): assert ledger_api_dialogue.associated_signing_dialogue signing_dialogue = SigningDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=SigningDialogue.Role.SKILL, ) ledger_api_dialogue.associated_signing_dialogue = signing_dialogue with pytest.raises(AEAEnforceError, match="Associated signing dialogue already set!"): ledger_api_dialogue.associated_signing_dialogue = signing_dialogue assert ledger_api_dialogue.associated_signing_dialogue == signing_dialogue
def test_signing_dialogue(self): """Test the SigningDialogue class.""" signing_dialogue = SigningDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=ContractApiDialogue.Role.AGENT, ) # associated_contract_api_dialogue with pytest.raises(ValueError, match="Associated contract api dialogue not set!"): assert signing_dialogue.associated_contract_api_dialogue contract_api_dialogue = ContractApiDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=ContractApiDialogue.Role.AGENT, ) signing_dialogue.associated_contract_api_dialogue = contract_api_dialogue with pytest.raises( AEAEnforceError, match="Associated contract api dialogue already set!"): signing_dialogue.associated_contract_api_dialogue = contract_api_dialogue assert (signing_dialogue.associated_contract_api_dialogue == contract_api_dialogue)
def test_ledger_api_dialogue(self): """Test the LedgerApiDialogue class.""" ledger_api_dialogue = LedgerApiDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=LedgerApiDialogue.Role.AGENT, ) # associated_fipa_dialogue with pytest.raises(AEAEnforceError, match="FipaDialogue not set!"): assert ledger_api_dialogue.associated_fipa_dialogue fipa_dialogue = FipaDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=FipaDialogue.Role.BUYER, ) ledger_api_dialogue.associated_fipa_dialogue = fipa_dialogue with pytest.raises(AEAEnforceError, match="FipaDialogue already set!"): ledger_api_dialogue.associated_fipa_dialogue = fipa_dialogue assert ledger_api_dialogue.associated_fipa_dialogue == fipa_dialogue
def test_signing_dialogue(self): """Test the SigningDialogue class.""" signing_dialogue = SigningDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=SigningDialogue.Role.SKILL, ) # associated_fipa_dialogue with pytest.raises(AEAEnforceError, match="FipaDialogue not set!"): assert signing_dialogue.associated_fipa_dialogue fipa_dialogue = FipaDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=FipaDialogue.Role.BUYER, ) signing_dialogue.associated_fipa_dialogue = fipa_dialogue with pytest.raises(AEAEnforceError, match="FipaDialogue already set!"): signing_dialogue.associated_fipa_dialogue = fipa_dialogue assert signing_dialogue.associated_fipa_dialogue == fipa_dialogue
def setup(cls): """Setup the test class.""" super().setup() cls.pending_transaction_timeout = 30 cls.transactions = Transactions( pending_transaction_timeout=cls.pending_transaction_timeout, name="transactions", skill_context=cls._skill.skill_context, ) cls.nonce = "125" cls.sender = "some_sender_address" cls.counterparty = "some_counterparty_address" cls.ledger_id = "some_ledger_id" cls.terms = Terms( ledger_id=cls.ledger_id, sender_address=cls.sender, counterparty_address=cls.counterparty, amount_by_currency_id={"1": 10}, quantities_by_good_id={"2": -5}, is_sender_payable_tx_fee=True, nonce=cls.nonce, fee_by_currency_id={"1": 1}, ) cls.dialogue_label = DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, cls._skill.skill_context.agent_address, ) cls.proposal_id = 5 cls.transaction_id = "some_transaction_id"
def test_fipa_dialogue(self): """Test the FipaDialogue class.""" fipa_dialogue = FipaDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=DefaultDialogue.Role.AGENT, ) # terms with pytest.raises(AEAEnforceError, match="Terms not set!"): assert fipa_dialogue.terms terms = Terms( "some_ledger_id", self.skill.skill_context.agent_address, "counterprty", {"currency_id": 50}, {"good_id": -10}, "some_nonce", ) fipa_dialogue.terms = terms with pytest.raises(AEAEnforceError, match="Terms already set!"): fipa_dialogue.terms = terms assert fipa_dialogue.terms == terms
def test_contract_api_dialogue(self): """Test the ContractApiDialogue class.""" contract_api_dialogue = ContractApiDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=ContractApiDialogue.Role.AGENT, ) # associated_register_dialogue with pytest.raises(ValueError, match="Associated register dialogue not set!"): assert contract_api_dialogue.associated_register_dialogue register_dialogue = RegisterDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=RegisterDialogue.Role.AGENT, ) contract_api_dialogue.associated_register_dialogue = register_dialogue with pytest.raises(AEAEnforceError, match="Associated register dialogue already set!"): contract_api_dialogue.associated_register_dialogue = register_dialogue assert contract_api_dialogue.associated_register_dialogue == register_dialogue # terms with pytest.raises(ValueError, match="Terms not set!"): assert contract_api_dialogue.terms terms = Terms( "some_ledger_id", self.skill.skill_context.agent_address, "counterprty", {"currency_id": 50}, {"good_id": -10}, "some_nonce", ) contract_api_dialogue.terms = terms with pytest.raises(AEAEnforceError, match="Terms already set!"): contract_api_dialogue.terms = terms assert contract_api_dialogue.terms == terms
def test_non_initial_incoming_message_dialogue_reference(self): """Test the _non_initial_incoming_message_dialogue_reference method.""" dialogue_incomplete_ref = FipaDialogue( DialogueLabel(("2", ""), "opponent", "self_address"), "self_address", FipaDialogue.Role.BUYER, ) reference_incomplete = self._non_initial_incoming_message_dialogue_reference( dialogue_incomplete_ref) assert reference_incomplete[1] != "" dialogue_complete_ref = FipaDialogue( DialogueLabel(("2", "7"), "opponent", "self_address"), "self_address", FipaDialogue.Role.BUYER, ) reference_complete = self._non_initial_incoming_message_dialogue_reference( dialogue_complete_ref) assert reference_complete[1] == "7"
def test_contract_api_dialogue(self): """Test the ContractApiDialogue class.""" contract_api_dialogue = ContractApiDialogue( DialogueLabel( ("", ""), COUNTERPARTY_ADDRESS, self.skill.skill_context.agent_address, ), self.skill.skill_context.agent_address, role=ContractApiDialogue.Role.AGENT, ) # callable with pytest.raises(ValueError, match="Callable not set!"): assert contract_api_dialogue.callable callable = ContractApiDialogue.Callable.GET_DEPLOY_TRANSACTION contract_api_dialogue.callable = callable with pytest.raises(AEAEnforceError, match="Callable already set!"): contract_api_dialogue.callable = callable assert contract_api_dialogue.callable == callable # terms with pytest.raises(ValueError, match="Terms not set!"): assert contract_api_dialogue.terms terms = Terms( "some_ledger_id", self.skill.skill_context.agent_address, "counterprty", {"currency_id": 50}, {"good_id": -10}, "some_nonce", ) contract_api_dialogue.terms = terms with pytest.raises(AEAEnforceError, match="Terms already set!"): contract_api_dialogue.terms = terms assert contract_api_dialogue.terms == terms
def test_dialogue(dialogue_classes): """Test dialogue initialization.""" dialogue_class, _, role, _ = dialogue_classes dialogue_class( DialogueLabel(("x", "y"), "opponent_addr", "starer_addr"), "agent_address", role )