Skip to content
Snippets Groups Projects
Unverified Commit 369f2151 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Replace assumptions with guarantees

This makes the tests faster and avoids hypothesis complaints about assumptions
that fail too often.
parent cecb4bef
No related branches found
No related tags found
1 merge request!131Have PaymentController iterate a voucher's redemption counters
...@@ -478,16 +478,15 @@ class RistrettoRedeemerTests(TestCase): ...@@ -478,16 +478,15 @@ class RistrettoRedeemerTests(TestCase):
), ),
) )
@given(voucher_objects(), voucher_counters(), integers(min_value=1, max_value=100)) @given(voucher_objects(), voucher_counters(), integers(min_value=0, max_value=100))
def test_redemption_denied_alreadyspent(self, voucher, counter, num_tokens): def test_redemption_denied_alreadyspent(self, voucher, counter, extra_tokens):
""" """
If the issuer declines to allow the voucher to be redeemed and gives a If the issuer declines to allow the voucher to be redeemed and gives a
reason that the voucher has already been spent, ``RistrettoRedeem`` reason that the voucher has already been spent, ``RistrettoRedeem``
returns a ``Deferred`` that fires with a ``Failure`` wrapping returns a ``Deferred`` that fires with a ``Failure`` wrapping
``AlreadySpent``. ``AlreadySpent``.
""" """
assume(num_tokens >= counter) num_tokens = counter + extra_tokens
issuer = AlreadySpentRedemption() issuer = AlreadySpentRedemption()
treq = treq_for_loopback_ristretto(issuer) treq = treq_for_loopback_ristretto(issuer)
redeemer = RistrettoRedeemer(treq, NOWHERE) redeemer = RistrettoRedeemer(treq, NOWHERE)
...@@ -507,16 +506,15 @@ class RistrettoRedeemerTests(TestCase): ...@@ -507,16 +506,15 @@ class RistrettoRedeemerTests(TestCase):
), ),
) )
@given(voucher_objects(), voucher_counters(), integers(min_value=1, max_value=100)) @given(voucher_objects(), voucher_counters(), integers(min_value=0, max_value=100))
def test_redemption_denied_unpaid(self, voucher, counter, num_tokens): def test_redemption_denied_unpaid(self, voucher, counter, extra_tokens):
""" """
If the issuer declines to allow the voucher to be redeemed and gives a If the issuer declines to allow the voucher to be redeemed and gives a
reason that the voucher has not been paid for, ``RistrettoRedeem`` reason that the voucher has not been paid for, ``RistrettoRedeem``
returns a ``Deferred`` that fires with a ``Failure`` wrapping returns a ``Deferred`` that fires with a ``Failure`` wrapping
``Unpaid``. ``Unpaid``.
""" """
assume(num_tokens >= counter) num_tokens = counter + extra_tokens
issuer = UnpaidRedemption() issuer = UnpaidRedemption()
treq = treq_for_loopback_ristretto(issuer) treq = treq_for_loopback_ristretto(issuer)
redeemer = RistrettoRedeemer(treq, NOWHERE) redeemer = RistrettoRedeemer(treq, NOWHERE)
...@@ -536,15 +534,14 @@ class RistrettoRedeemerTests(TestCase): ...@@ -536,15 +534,14 @@ class RistrettoRedeemerTests(TestCase):
), ),
) )
@given(voucher_objects(), voucher_counters(), integers(min_value=1, max_value=100)) @given(voucher_objects(), voucher_counters(), integers(min_value=0, max_value=100))
def test_bad_ristretto_redemption(self, voucher, counter, num_tokens): def test_bad_ristretto_redemption(self, voucher, counter, extra_tokens):
""" """
If the issuer returns a successful result with an invalid proof then If the issuer returns a successful result with an invalid proof then
``RistrettoRedeemer.redeem`` returns a ``Deferred`` that fires with a ``RistrettoRedeemer.redeem`` returns a ``Deferred`` that fires with a
``Failure`` wrapping ``SecurityException``. ``Failure`` wrapping ``SecurityException``.
""" """
assume(num_tokens >= counter) num_tokens = counter + extra_tokens
signing_key = random_signing_key() signing_key = random_signing_key()
issuer = RistrettoRedemption(signing_key) issuer = RistrettoRedemption(signing_key)
...@@ -572,16 +569,14 @@ class RistrettoRedeemerTests(TestCase): ...@@ -572,16 +569,14 @@ class RistrettoRedeemerTests(TestCase):
), ),
) )
@given(voucher_objects(), voucher_counters(), integers(min_value=1, max_value=100)) @given(voucher_objects(), voucher_counters(), integers(min_value=0, max_value=100))
def test_ristretto_pass_construction(self, voucher, counter, num_tokens): def test_ristretto_pass_construction(self, voucher, counter, extra_tokens):
""" """
The passes constructed using unblinded tokens and messages pass the The passes constructed using unblinded tokens and messages pass the
Ristretto verification check. Ristretto verification check.
""" """
assume(num_tokens >= counter) num_tokens = counter + extra_tokens
message = b"hello world" message = b"hello world"
signing_key = random_signing_key() signing_key = random_signing_key()
issuer = RistrettoRedemption(signing_key) issuer = RistrettoRedemption(signing_key)
treq = treq_for_loopback_ristretto(issuer) treq = treq_for_loopback_ristretto(issuer)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment