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 holdings, the name # should not be a duplicate update = holding_update.Register( update_type=holding_update.Register.UpdateType, creator_id=participant.ObjectID, name='/holding' ) self.assertTrue(market_place_object_update.global_is_valid_name( store, name='/holding', object_type=update.ObjectType, creator_id=participant.ObjectID, )) # Add a holding to the store with the creator being the participant # we inserted initially holding = holding_update.HoldingObject( objectid='0000000000000001', minfo={ 'name': '//participant/holding', 'creator': participant.ObjectID }) store[holding.ObjectID] = holding.dump() # Because the holding 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 = holding_update.Register( update_type=holding_update.Register.UpdateType, creator_id=participant.ObjectID, name='/holding' ) self.assertFalse(market_place_object_update.global_is_valid_name( store, name='/holding', object_type=update.ObjectType, creator_id=participant.ObjectID )) update = holding_update.Register( update_type=holding_update.Register.UpdateType, creator_id=participant.ObjectID, name='//participant/holding' ) self.assertFalse(market_place_object_update.global_is_valid_name( store, name='//participant/holding', object_type=update.ObjectType, creator_id=participant.ObjectID ))
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))
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 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))
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 liabilities, the name # should not be a duplicate update = liability_update.Register( update_type=liability_update.Register.UpdateType, creator_id=participant.ObjectID, name='/liability' ) self.assertTrue(global_is_valid_name( store, '/liability', liability_update.Register.ObjectType, participant.ObjectID)) # Add a liability to the store with the creator being the participant # we inserted initially liability = liability_update.LiabilityObject( objectid='0000000000000001', minfo={ 'name': '//participant/liability', 'creator': participant.ObjectID }) store[liability.ObjectID] = liability.dump() # Because the liability 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 = liability_update.Register( update_type=liability_update.Register.UpdateType, creator_id=participant.ObjectID, name='/liability' ) self.assertFalse(global_is_valid_name( store, '/liability', liability_update.Register.ObjectType, participant.ObjectID)) update = liability_update.Register( update_type=liability_update.Register.UpdateType, creator_id=participant.ObjectID, name='//participant/liability' ) self.assertFalse(global_is_valid_name( store, '//participant/liability', liability_update.Register.ObjectType, participant.ObjectID))
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError("ObjectId already in store") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): raise InvalidTransactionError( "Creator address is different from txn.OriginatorID") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError( "Name, {}, is not valid".format(self._name)) if not liability_update.LiabilityObject.is_valid_object( store, self._input_id): raise InvalidTransactionError( "{} is not a Liability".format(self._input_id)) obj = liability_update.LiabilityObject.get_valid_object(store, self._input_id) if not self.CreatorType.is_valid_creator(store, obj.get('creator'), txn.OriginatorID): logger.info('%s does not have permission to modify liability %s', txn.OriginatorID, self._input_id) raise InvalidTransactionError( "Txn.OriginatorID not allowed to modify liability") if not holding_update.HoldingObject.is_valid_object(store, self._output_id): raise InvalidTransactionError( "OutputId is not a valid Holding") obj = holding_update.HoldingObject.get_valid_object( store, self._output_id) if not self.CreatorType.is_valid_creator(store, obj.get('creator'), txn.OriginatorID): logger.info('%s does not have permission to modify liability %s', txn.OriginatorID, self._output_id) raise InvalidTransactionError( "Txn.OriginatorID does not have permission to modify " "liability") if self._ratio <= 0: logger.debug('invalid ratio %s in offer %s', self._ratio, txn.Identifier) raise InvalidTransactionError( "Ratio < 0") if self._minimum < 0 or self._maximum < 0 or \ self._maximum < self._minimum: logger.debug('inconsistent range %s < %s in offer %s', self._minimum, self._maximum, txn.Identifier) raise InvalidTransactionError( "Minimum and Maximum are inconsistent") if self._execution not in SellOfferObject.ExecutionStyle: logger.debug('invalid execution style %s in offer %s', self._execution, txn.Identifier) raise InvalidTransactionError( "Execution not a valid ExecutionStyle")
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError("ObjectId already in store") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError("Name is not valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): raise InvalidTransactionError( "Creator Address not the same as txn.OriginatorID") assettype = asset_type_update.AssetTypeObject.load_from_store( store, self._asset_type_id) if not assettype: logger.debug('missing asset type %s', self._asset_type_id) raise InvalidTransactionError( "AssetTypeId does not reference an AssetType") # if the asset type is restricted then the creator of the asset type # is the only one who can create assets of that type if assettype.Restricted and assettype.CreatorID != self._creator_id: logger.debug('no permission to create an asset of type %s', self._asset_type_id) raise InvalidTransactionError( "AssetType is restricted and the creator is not the same " "as txn creator")
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError( "ObjectId already in store") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError( "Name is not valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): raise InvalidTransactionError( "Creator Address not the same as txn.OriginatorID") assettype = asset_type_update.AssetTypeObject.load_from_store( store, self._asset_type_id) if not assettype: logger.debug('missing asset type %s', self._asset_type_id) raise InvalidTransactionError( "AssetTypeId does not reference an AssetType") # if the asset type is restricted then the creator of the asset type # is the only one who can create assets of that type if assettype.Restricted and assettype.CreatorID != self._creator_id: logger.debug('no permission to create an asset of type %s', self._asset_type_id) raise InvalidTransactionError( "AssetType is restricted and the creator is not the same " "as txn creator")
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError( "ObjectId alread in store") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError( "Name isn't valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): raise InvalidTransactionError( "Creator Address not the same as txn.OriginatorID") if not account_update.AccountObject.is_valid_object(store, self._account_id): raise InvalidTransactionError( "AccountID does not reference an Account") if self._count < 0: raise InvalidTransactionError( "Count is less than 0") # make sure we have a valid asset asset = asset_update.AssetObject.load_from_store(store, self._asset_id) if not asset: logger.debug('invalid asset %s in holding', self._asset_id) raise InvalidTransactionError( "AssetId does not reference an Asset") # if the asset is restricted, then only the creator of the asset can # create holdings with a count greater than 0 if asset.Restricted: if self._creator_id != asset.CreatorID and 0 < self._count: logger.debug( 'instances of a restricted asset %s can only be created ' 'by the owner', self._asset_id) raise InvalidTransactionError( "Instances of a restricted asset {} can only be created " "by the owner".format(self._asset_id)) # if the asset is not consumable then counts dont matter, the only # valid counts are 0 or 1 if not asset.Consumable: if 1 < self._count: logger.debug( 'non consumable assets of type %s are retricted to ' 'a single instance', self._asset_id) raise InvalidTransactionError( "Non consumable assets are restricted to a single " "instance")
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError("Object Id is already in store") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError("Name isn't valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): raise InvalidTransactionError( "Creator address is not the same as txn.OriginatorID")
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError("ObjectId alread in store") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError("Name isn't valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): raise InvalidTransactionError( "Creator Address not the same as txn.OriginatorID") if not account_update.AccountObject.is_valid_object( store, self._account_id): raise InvalidTransactionError( "AccountID does not reference an Account") if self._count < 0: raise InvalidTransactionError("Count is less than 0") # make sure we have a valid asset asset = asset_update.AssetObject.load_from_store(store, self._asset_id) if not asset: logger.debug('invalid asset %s in holding', self._asset_id) raise InvalidTransactionError( "AssetId does not reference an Asset") # if the asset is restricted, then only the creator of the asset can # create holdings with a count greater than 0 if asset.Restricted: if self._creator_id != asset.CreatorID and 0 < self._count: logger.debug( 'instances of a restricted asset %s can only be created ' 'by the owner', self._asset_id) raise InvalidTransactionError( "Instances of a restricted asset {} can only be created " "by the owner".format(self._asset_id)) # if the asset is not consumable then counts dont matter, the only # valid counts are 0 or 1 if not asset.Consumable: if 1 < self._count: logger.debug( 'non consumable assets of type %s are retricted to ' 'a single instance', self._asset_id) raise InvalidTransactionError( "Non consumable assets are restricted to a single " "instance")
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError( "ObjectId is already used") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError( "Name isn't valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): raise InvalidTransactionError( "Creator Address not the same as txn.OriginatorId")
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError( "ObjectId already in store") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError( "Name is not valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): raise InvalidTransactionError( "Creator Address not the same as txn.OriginatorID") if not account_update.AccountObject.is_valid_object(store, self._account_id): raise InvalidTransactionError( "AccountId does not reference an Account") if not asset_type_update.AssetTypeObject.is_valid_object( store, self._asset_type_id): raise InvalidTransactionError( "AssetTypeid not a valid AssetType") if not participant_update.ParticipantObject.is_valid_object( store, self._guarantor_id): raise InvalidTransactionError( "GuarantorID not a valid Participant") if self._count < 0: raise InvalidTransactionError( "Count < 0") return True
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError( "ObjectId already in store") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError( "Name isn't valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): logger.debug('failed permission check on offer %s', txn.Identifier) raise InvalidTransactionError( "Creator address not the same as txn.OriginatorID") if not liability_update.LiabilityObject.is_valid_object( store, self._input_id): logger.debug('input liability %s is not valid in offer %s ', self._input_id, txn.Identifier) raise InvalidTransactionError( "InputId, {}, is not a liability".format(str(self._input_id))) obj = liability_update.LiabilityObject.get_valid_object( store, self._input_id) if not self.CreatorType.is_valid_creator(store, obj.get('creator'), txn.OriginatorID): logger.info('%s does not have permission to modify liability %s', txn.OriginatorID, self._input_id) raise InvalidTransactionError( "txn.OriginatorID is not liability creator") if not liability_update.LiabilityObject.is_valid_object( store, self._output_id): logger.debug('output liability %s is not valid in offer %s ', self._output_id, txn.Identifier) raise InvalidTransactionError( "OutputID is not a valid liability") obj = liability_update.LiabilityObject.get_valid_object( store, self._output_id) if not self.CreatorType.is_valid_creator(store, obj.get('creator'), txn.OriginatorID): logger.info('%s does not have permission to modify liability %s', txn.OriginatorID, self._output_id) raise InvalidTransactionError( "Output Liability creator is not the same as " "txn.OriginatorID") if self._ratio <= 0: logger.debug('invalid ratio %s in offer %s', self._ratio, txn.Identifier) raise InvalidTransactionError( "Ratio is less than or equal to 0") if self._minimum < 0 or self._maximum < 0 or \ self._maximum < self._minimum: logger.debug('inconsistent range %s < %s in offer %s', self._minimum, self._maximum, txn.Identifier) raise InvalidTransactionError( "Minimum and Maximum are inconsistent") if self._execution not in ExchangeOfferObject.ExecutionStyle: logger.debug('invalid execution style %s in offer %s', self._execution, txn.Identifier) raise InvalidTransactionError( "Execution not a valid ExecutionStyle")
def check_valid(self, store, txn): if txn.Identifier in store: raise InvalidTransactionError("ObjectId already in store") if not market_place_object_update.global_is_valid_name( store, self._name, self.ObjectType, self._creator_id): raise InvalidTransactionError("Name isn't valid") if not market_place_object_update.global_is_permitted( store, txn, self._creator_id, self.CreatorType): logger.debug('failed permission check on offer %s', txn.Identifier) raise InvalidTransactionError( "Creator address not the same as txn.OriginatorID") if not liability_update.LiabilityObject.is_valid_object( store, self._input_id): logger.debug('input liability %s is not valid in offer %s ', self._input_id, txn.Identifier) raise InvalidTransactionError( "InputId, {}, is not a liability".format(str(self._input_id))) obj = liability_update.LiabilityObject.get_valid_object( store, self._input_id) if not self.CreatorType.is_valid_creator(store, obj.get('creator'), txn.OriginatorID): logger.info('%s does not have permission to modify liability %s', txn.OriginatorID, self._input_id) raise InvalidTransactionError( "txn.OriginatorID is not liability creator") if not liability_update.LiabilityObject.is_valid_object( store, self._output_id): logger.debug('output liability %s is not valid in offer %s ', self._output_id, txn.Identifier) raise InvalidTransactionError("OutputID is not a valid liability") obj = liability_update.LiabilityObject.get_valid_object( store, self._output_id) if not self.CreatorType.is_valid_creator(store, obj.get('creator'), txn.OriginatorID): logger.info('%s does not have permission to modify liability %s', txn.OriginatorID, self._output_id) raise InvalidTransactionError( "Output Liability creator is not the same as " "txn.OriginatorID") if self._ratio <= 0: logger.debug('invalid ratio %s in offer %s', self._ratio, txn.Identifier) raise InvalidTransactionError("Ratio is less than or equal to 0") if self._minimum < 0 or self._maximum < 0 or \ self._maximum < self._minimum: logger.debug('inconsistent range %s < %s in offer %s', self._minimum, self._maximum, txn.Identifier) raise InvalidTransactionError( "Minimum and Maximum are inconsistent") if self._execution not in ExchangeOfferObject.ExecutionStyle: logger.debug('invalid execution style %s in offer %s', self._execution, txn.Identifier) raise InvalidTransactionError( "Execution not a valid ExecutionStyle")