def condition(self): """ Generate condition corresponding to this fulfillment. An important property of crypto-conditions is that the condition can always be derived from the fulfillment. This makes it very easy to post fulfillments to a system without having to specify which condition the relate to. The system can keep an index of conditions and look up any matching events related to that condition. Return: Condition: Condition corresponding to this fulfillment. """ condition = Condition() condition.type_id = self.type_id condition.hash = self.generate_hash() condition.cost = self.calculate_cost() condition.subtypes = self.subtypes return condition
def test_condition_validate(): from cryptoconditions.condition import Condition # lets set a known type_id so that the TypeRegistry can return the correct # condition type condition = Condition() condition.type_id = 0 # subtypes can have at most 32 bits or else raise a value error condition.subtypes = range(Condition.MAX_SAFE_SUBTYPES + 1) with raises(ValueError): condition.validate() # raises a ValueError if there is unsuported subtype condition.subtypes = set(['magic']) with raises(ValueError): condition.validate() # raises a ValueError if the cost if higher than MAX_COST condition.subtypes = set() condition.cost = Condition.MAX_COST + 1 with raises(ValueError): condition.validate()