示例#1
0
def test_condition_hash():
    from cryptoconditions.condition import Condition
    condition = Condition()

    # raises an exception if hash is not 32 bytes long
    with raises(ValueError):
        condition.hash = 'a'

    # raises a ValueError if the hash is not set
    with raises(ValueError):
        condition.hash

    # correctly set the hash
    condition.hash = 'a' * 32
    assert condition.hash == 'a' * 32
示例#2
0
    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 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