Exemplo n.º 1
0
    def test_04_accept_offer(self):
        """Tests the AcceptOffer validation rules.

        Notes
            AcceptOffer
                - The Offer exists and is Open.
                - The Source Asset has enough Quantity for the transaction.
                - The Receiver Source Asset exists and has enough
                  Quantity for the transaction.
                - The Source Asset and Receiver Target Asset are of the
                  same resource.
                - The Target Asset and Receiver Source Asset are of the
                  same resource.
        """

        offerer = transaction_creation.OfferParticipant(
            source=self.signer1_sawbucks,
            source_resource=self.sawbucks,
            target=self.signer1_pickles,
            target_resource=self.pickles)
        receiver = transaction_creation.OfferParticipant(
            source=self.signer2_pickles,
            source_resource=self.pickles,
            target=self.signer2_sawbucks,
            target_resource=self.sawbucks)

        self.assertEqual(
            self.client.accept_offer(
                key=self.signer2,
                identifier=str(uuid4()),
                receiver=receiver,
                offerer=offerer,
                count=1)[0]['status'],
            "INVALID",
            "The offer must exist")

        self.assertEqual(
            self.client.accept_offer(
                key=self.signer2,
                identifier=self.sawbucks_for_pickles,
                offerer=offerer,
                receiver=receiver,
                count=20)[0]['status'],
            "INVALID",
            "There are not enough source quantities for the AcceptOffer.")

        self.assertEqual(
            self.client.accept_offer(
                key=self.signer2,
                identifier=self.sawbucks_for_pickles,
                receiver=receiver,
                offerer=offerer,
                count=2)[0]['status'],
            "COMMITTED")
Exemplo n.º 2
0
def _create_offer_participants(body, offer, offer_holdings):
    input_asset = offer_holdings['source']['asset']
    if offer.get('target'):
        output_asset = offer_holdings['target']['asset']
    else:
        output_asset = None

    offerer = transaction_creation.OfferParticipant(source=offer['source'],
                                                    target=offer.get('target'),
                                                    source_asset=input_asset,
                                                    target_asset=output_asset)

    receiver = transaction_creation.OfferParticipant(source=body.get('source'),
                                                     target=body['target'],
                                                     source_asset=output_asset,
                                                     target_asset=input_asset)

    return (offerer, receiver)