diff --git a/src/_zkapauthorizer/model.py b/src/_zkapauthorizer/model.py index 329d0b8bc0159ba4fc367748b278cd7f51465801..636c3a1b5a49b06ed8aa44ab2bc3361b991d7361 100644 --- a/src/_zkapauthorizer/model.py +++ b/src/_zkapauthorizer/model.py @@ -793,6 +793,7 @@ class Redeeming(object): return { u"name": u"redeeming", u"started": self.started.isoformat(), + u"counter": self.counter, } @@ -981,7 +982,7 @@ class Voucher(object): elif state_name == u"redeeming": state = Redeeming( started=parse_datetime(state_json[u"started"]), - counter=0, + counter=state_json[u"counter"], ) elif state_name == u"double-spend": state = DoubleSpend( diff --git a/src/_zkapauthorizer/tests/strategies.py b/src/_zkapauthorizer/tests/strategies.py index 9a4c325df7cddf5db27e930be326748d196348fc..13ea72ac349a1b1d04aaf44d45c148260ad7359d 100644 --- a/src/_zkapauthorizer/tests/strategies.py +++ b/src/_zkapauthorizer/tests/strategies.py @@ -77,6 +77,7 @@ from ..model import ( DoubleSpend, Unpaid, Error, + Redeeming, Redeemed, ) @@ -297,6 +298,7 @@ def vouchers(): lambda voucher: voucher.decode("ascii"), ) + def redeemed_states(): """ Build ``Redeemed`` instances. @@ -308,6 +310,20 @@ def redeemed_states(): public_key=dummy_ristretto_keys(), ) + +def voucher_counters(): + """ + Build integers usable as counters in the voucher redemption process. + """ + return integers( + min_value=0, + # This may or may not be the actual maximum value accepted by a + # PaymentServer. If it is not exactly the maximum, it's probably at + # least in the same ballpark. + max_value=256, + ) + + def voucher_states(): """ Build Python objects representing states a Voucher can be in. @@ -315,7 +331,12 @@ def voucher_states(): return one_of( builds( Pending, - integers(min_value=0), + counter=integers(min_value=0), + ), + builds( + Redeeming, + started=datetimes(), + counter=voucher_counters(), ), redeemed_states(), builds( @@ -347,19 +368,6 @@ def voucher_objects(states=voucher_states()): ) -def voucher_counters(): - """ - Build integers usable as counters in the voucher redemption process. - """ - return integers( - min_value=0, - # This may or may not be the actual maximum value accepted by a - # PaymentServer. If it is not exactly the maximum, it's probably at - # least in the same ballpark. - max_value=256, - ) - - def redemption_group_counts(): """ Build integers which can represent the number of groups in the redemption