Exemplo n.º 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 accounts, the name
        # should not be a duplicate
        update = account_update.Register(
            update_type=account_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/account')
        self.assertTrue(
            global_is_valid_name(store, '/account',
                                 account_update.Register.ObjectType,
                                 participant.ObjectID))

        # Add an account to the store with the creator being the participant
        # we inserted initially
        account = account_update.AccountObject(objectid='0000000000000001',
                                               minfo={
                                                   'name':
                                                   '//participant/account',
                                                   'creator':
                                                   participant.ObjectID
                                               })
        store[account.ObjectID] = account.dump()

        # Because the account 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 = account_update.Register(
            update_type=account_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/account')
        self.assertFalse(
            global_is_valid_name(store, '/account',
                                 account_update.Register.ObjectType,
                                 participant.ObjectID))
        update = account_update.Register(
            update_type=account_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='//participant/account')
        self.assertFalse(
            global_is_valid_name(store, '//participant/account',
                                 account_update.Register.ObjectType,
                                 participant.ObjectID))
Exemplo n.º 2
0
    def register_account(self, name='', description=''):
        """
        Register an account with the ledger.

        :param str name: an optional name for the asset, unique for the current
            participant
        :param str description: an optional description for the asset

        :return: account id
        :rtype: id
        """
        update = account_update.Register()

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

        return self._register(update)