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 asset types, the name
        # should not be a duplicate
        update = asset_type_update.Register(
            update_type=asset_type_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/assettype'
        )
        self.assertTrue(market_place_object_update.global_is_valid_name(
            store,
            name='/assettype',
            object_type=update.ObjectType,
            creator_id=participant.ObjectID))

        # Add an asset type to the store with the creator being the
        # participant we inserted initially
        asset_type = asset_type_update.AssetTypeObject(
            objectid='0000000000000001',
            minfo={
                'name': '//participant/assettype',
                'creator': participant.ObjectID
            })
        store[asset_type.ObjectID] = asset_type.dump()

        # Because the asset type 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
        asset_type = asset_type_update.Register(
            update_type=asset_type_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/assettype'
        )
        self.assertFalse(market_place_object_update.global_is_valid_name(
            store,
            name='/assettype',
            object_type=asset_type.ObjectType,
            creator_id=participant.ObjectID))

        update = asset_type_update.Register(
            update_type=asset_type_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='//participant/assettype'
        )
        self.assertFalse(market_place_object_update.global_is_valid_name(
            store,
            name='//participant/assettype',
            object_type=update.ObjectType,
            creator_id=participant.ObjectID))
    def register_assettype(self, name='', description='', restricted=True):
        """
        Register an asset type.

        :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

        :return: asset type id
        :rtype: id
        """
        update = asset_type_update.Register()

        update.CreatorID = self.CreatorID
        update.Name = name
        update.Description = description
        update.Restricted = restricted

        return self._register(update)
Example #3
0
def _prepare_genesis_transactions(journal):
    logger.debug('prepare marketplace transactions for genesis block')

    # Set up a random key for generating the genesis objects, we
    # "trust" that the key is not kept. At some point this should be
    # revisited, suggestions about "burning" the private key
    signingkey = signed_object.generate_signing_key()
    identifier = signed_object.generate_identifier(signingkey)
    signnode = node.Node(identifier=identifier, signingkey=signingkey)

    # Create a participant for the global market
    txn = MarketPlaceTransaction()
    update = participant_update.Register(txn)
    update.Name = 'marketplace'
    update.Description = 'The ROOT participant for the marketplace'

    txn.Update = update

    txn.sign_from_node(signnode)
    journal.add_pending_transaction(txn)
    logger.info('Created market participant: %s', txn.Identifier)
    lasttxn = txn.Identifier

    mktid = update.ObjectID

    # Create an asset type for participants
    txn = MarketPlaceTransaction()
    update = asset_type_update.Register(txn)

    update.CreatorID = mktid

    # anyone can create participant assets for themselves
    update.Restricted = False

    update.Name = '/asset-type/participant'
    update.Description = 'Canonical type for participant assets'

    txn.Update = update
    txn.Dependencies = [lasttxn]
    txn.sign_from_node(signnode)

    journal.add_pending_transaction(txn)
    logger.info('Created participant asset type: %s', txn.Identifier)
    lasttxn = txn.Identifier

    assettypeid = update.ObjectID

    # Create an asset type for random tokens
    txn = MarketPlaceTransaction()
    update = asset_type_update.Register(txn)

    update.CreatorID = mktid
    update.Restricted = True  # there is only one asset based on the token type
    update.Name = '/asset-type/token'
    update.Description = 'Canonical type for meaningless tokens that are ' \
                         'very useful for bootstrapping'

    txn.Update = update
    txn.Dependencies = [lasttxn]
    txn.sign_from_node(signnode)

    journal.add_pending_transaction(txn)
    logger.info('Created token asset type: %s', txn.Identifier)
    lasttxn = txn.Identifier

    assettypeid = update.ObjectID

    # Create an asset for the tokens
    txn = MarketPlaceTransaction()
    update = asset_update.Register(txn)

    update.CreatorID = mktid
    update.AssetTypeID = assettypeid

    # anyone can create holdings with token instances
    update.Restricted = False

    # and these are infinitely replaceable
    update.Consumable = False

    update.Divisible = False
    update.Name = '/asset/token'
    update.Description = 'Canonical asset for tokens'

    txn.Update = update
    txn.Dependencies = [lasttxn]
    txn.sign_from_node(signnode)

    journal.add_pending_transaction(txn)
    logger.info('Created token asset: %s', txn.Identifier)

    # Create an asset for the validation tokens
    txn = MarketPlaceTransaction()
    update = asset_update.Register(txn)

    update.CreatorID = mktid
    update.AssetTypeID = assettypeid
    update.Restricted = True  # these assets are only created by the market
    update.Consumable = True
    update.Divisible = False
    update.Name = '/asset/validation-token'
    update.Description = 'Canonical asset for validation tokens'

    txn.Update = update
    txn.Dependencies = [lasttxn]
    txn.sign_from_node(signnode)

    journal.add_pending_transaction(txn)
    logger.info('Created validation token asset: %s', txn.Identifier)