示例#1
0
    def test_duplicate_name(self):
        # Create a mock store and put a participant in it
        participant = participant_update.ParticipantObject(
            participantid='0000000000000000', minfo={
                'name': 'participant',
            })
        store = MarketPlaceGlobalStore()
        store[participant.ObjectID] = participant.dump()

        # Because we have not "registered" any sell offers, the name
        # should not be a duplicate
        update = sell_offer_update.Register(
            input_id='**FAKE**',
            output_id='**FAKE**',
            update_type=sell_offer_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/selloffer')
        self.assertTrue(
            market_place_object_update.global_is_valid_name(
                store, '/selloffer', sell_offer_update.Register.ObjectType,
                participant.ObjectID))

        # Add a sell offer to the store with the creator being the participant
        # we inserted initially
        sell_offer = sell_offer_update.SellOfferObject(
            objectid='0000000000000001',
            minfo={
                'name': '//participant/selloffer',
                'creator': participant.ObjectID
            })
        store[sell_offer.ObjectID] = sell_offer.dump()

        # Because the sell offer name is in the store, trying to register
        # using a relative name based upon creator and a fully-qualified name
        # should not be a valid name as it is a duplicate
        update = sell_offer_update.Register(
            input_id='**FAKE**',
            output_id='**FAKE**',
            update_type=sell_offer_update.Register,
            creator_id=participant.ObjectID,
            name='/selloffer')
        self.assertFalse(
            market_place_object_update.global_is_valid_name(
                store, '/selloffer', sell_offer_update.Register.ObjectType,
                participant.ObjectID))
        update = sell_offer_update.Register(
            update_type=sell_offer_update.Register.UpdateType,
            input_id='**FAKE**',
            output_id='**FAKE**',
            creator_id=participant.ObjectID,
            name='//participant/selloffer')
        self.assertFalse(
            market_place_object_update.global_is_valid_name(
                store, '//participant/selloffer',
                sell_offer_update.Register.ObjectType, participant.ObjectID))
示例#2
0
    def test_duplicate_name(self):
        # Create a mock store and put a participant in it
        participant = participant_update.ParticipantObject(
            participantid='0000000000000000', minfo={
                'name': 'participant',
            })
        store = MockMarketPlaceGlobalStore()
        store[participant.ObjectID] = participant.dump()
        store.bind(store.i2n(participant.ObjectID), participant.ObjectID)

        # Because we have not "registered" any sell offers, the name
        # should not be a duplicate
        update = sell_offer_update.Register(minfo={
            'CreatorID': participant.ObjectID,
            'Name': '/selloffer'
        })
        self.assertTrue(update.is_valid_name(store))

        # Add a sell offer to the store with the creator being the participant
        # we inserted initially
        sell_offer = sell_offer_update.SellOfferObject(
            objectid='0000000000000001',
            minfo={
                'name': '//participant/selloffer',
                'creator': participant.ObjectID
            })
        store[sell_offer.ObjectID] = sell_offer.dump()
        store.bind(store.i2n(sell_offer.ObjectID), sell_offer.ObjectID)

        # Because the sell offer name is in the store, trying to register
        # using a relative name based upon creator and a fully-qualified name
        # should not be a valid name as it is a duplicate
        update = sell_offer_update.Register(minfo={
            'CreatorID': participant.ObjectID,
            'Name': '/selloffer'
        })
        self.assertFalse(update.is_valid_name(store))
        update = sell_offer_update.Register(minfo={
            'CreatorID': participant.ObjectID,
            'Name': '//participant/selloffer'
        })
        self.assertFalse(update.is_valid_name(store))
示例#3
0
    def register_selloffer(self, iliability, oholding, ratio, **kwargs):
        """
        Construct and post a transaction to register an SellOffer object

        :param id iliability: identifier for the input liability (where payment
            is made)
        :param id oholding: identifier for the output holding (where goods are
            given)
        :param str name: an optional name for the asset type, unique for the
            current participant
        :param str description: an optional description for the asset type
        :param int minimum: an optional parameter noting the smallest number of
            input assets
        :param int maximum: an optional parameter noting the largest number of
            input assets
        :param execution: optional flag indicating offer execution modifiers
        :type execution: one of 'Any', 'ExecuteOnce',
            'ExecuteOncePerParticipant'

        :return: exchange offer id
        :rtype: id
        """

        update = sell_offer_update.Register()

        update.CreatorID = self.CreatorID
        update.InputID = iliability
        update.OutputID = oholding
        update.Ratio = float(ratio)

        if 'name' in kwargs:
            update.Name = kwargs['name']

        if 'description' in kwargs:
            update.Description = kwargs['description']

        if 'minimum' in kwargs:
            update.Minimum = int(kwargs['minimum'])

        if 'maximum' in kwargs:
            update.Maximum = int(kwargs['maximum'])

        if 'execution' in kwargs:
            update.Execution = kwargs['execution']

        return self._register(update)