Skip to content

Commit 553efb0

Browse files
committed
Add more test cases for reusing VRF keys
1 parent f119c14 commit 553efb0

File tree

1 file changed

+77
-1
lines changed
  • eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Imp

1 file changed

+77
-1
lines changed

eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Imp/PoolSpec.hs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,78 @@ spec = describe "POOL" $ do
123123
expectFuturePool kh (Just vrfNew)
124124
passEpoch
125125
expectPool kh (Just vrfNew)
126+
expectVRFs [vrfNew]
127+
-- now the original VRF can be reused
128+
khNew <- freshKeyHash
129+
registerPoolTx <$> poolParams khNew vrf >>= submitTx_
130+
expectVRFs [vrf, vrfNew]
131+
132+
it "register a new pool with the VRF of a re-registered pool " $ do
133+
pv <- getsPParams ppProtocolVersionL
134+
(kh, _) <- registerNewPool
135+
vrfNew <- freshKeyHashVRF
136+
-- re-register pool with a new vrf
137+
registerPoolTx <$> poolParams kh vrfNew >>= submitTx_
138+
passEpoch
139+
-- try to register a new pool with the new vrf
140+
khNew <- freshKeyHash
141+
registerPoolTx <$> poolParams khNew vrfNew >>= \tx ->
142+
if pvMajor pv < natVersion @11
143+
then do
144+
submitTx_ tx
145+
expectPool kh (Just vrfNew)
146+
expectPool khNew (Just vrfNew)
147+
else
148+
submitFailingTx tx [injectFailure $ VRFKeyHashAlreadyRegistered khNew vrfNew]
149+
150+
it "after the epoch changes, reuse VRFs that get overwritten" $ do
151+
(kh, vrf) <- registerNewPool
152+
vrf1 <- freshKeyHashVRF
153+
registerPoolTx <$> poolParams kh vrf1 >>= submitTx_
154+
expectVRFs [vrf, vrf1]
155+
vrf2 <- freshKeyHashVRF
156+
registerPoolTx <$> poolParams kh vrf2 >>= submitTx_
157+
expectVRFs [vrf, vrf2]
158+
vrf3 <- freshKeyHashVRF
159+
registerPoolTx <$> poolParams kh vrf3 >>= submitTx_
160+
expectVRFs [vrf, vrf3]
161+
passEpoch
162+
expectPool kh (Just vrf3)
163+
expectVRFs [vrf3]
164+
-- reuse VRFs that didn't get used
165+
khNew <- freshKeyHash
166+
registerPoolTx <$> poolParams khNew vrf1 >>= submitTx_
167+
expectPool khNew (Just vrf1)
168+
expectVRFs [vrf1, vrf3]
169+
-- the original pool can be re-registered with one of the discarded VRFs too
170+
registerPoolTx <$> poolParams kh vrf2 >>= submitTx_
171+
expectVRFs [vrf1, vrf2, vrf3]
172+
passEpoch
173+
expectVRFs [vrf1, vrf2]
174+
-- the original pool can be re-registered with the original VRF too
175+
registerPoolTx <$> poolParams kh vrf >>= submitTx_
176+
expectVRFs [vrf, vrf1, vrf2]
177+
passEpoch
178+
expectVRFs [vrf, vrf1]
179+
180+
it "before the epoch changes, try to reuse VRFs that get overwritten" $ do
181+
pv <- getsPParams ppProtocolVersionL
182+
(kh, vrf) <- registerNewPool
183+
vrfNew <- freshKeyHashVRF
184+
registerPoolTx <$> poolParams kh vrfNew >>= submitTx_
185+
-- try to register a pool with the original VRF that got overwritten
186+
khNew <- freshKeyHash
187+
registerPoolTx <$> poolParams khNew vrf >>= \tx ->
188+
if pvMajor pv < natVersion @11
189+
then do
190+
submitTx_ tx
191+
expectPool kh (Just vrf)
192+
expectPool khNew (Just vrf)
193+
passEpoch
194+
expectPool kh (Just vrfNew)
195+
expectPool khNew (Just vrf)
196+
else do
197+
submitFailingTx tx [injectFailure $ VRFKeyHashAlreadyRegistered khNew vrf]
126198

127199
describe "Retiring pools" $ do
128200
it "retire an unregistered pool" $ do
@@ -189,14 +261,18 @@ spec = describe "POOL" $ do
189261
expectRetiring False kh
190262

191263
it "re-register a retiring pool with a fresh VRF" $ do
192-
(kh, _) <- registerNewPool
264+
(kh, vrf) <- registerNewPool
193265
retirePoolTx kh (EpochInterval 10) >>= submitTx_
194266
vrfNew <- freshKeyHashVRF
195267
registerPoolTx <$> poolParams kh vrfNew >>= submitTx_
196268
expectRetiring False kh
197269
expectFuturePool kh (Just vrfNew)
198270
passEpoch
199271
expectPool kh (Just vrfNew)
272+
expectVRFs [vrfNew]
273+
-- now the original VRF can be reused
274+
khNew <- freshKeyHash
275+
registerPoolTx <$> poolParams khNew vrf >>= submitTx_
200276

201277
it "register a pool with the VRF of a retiring pool" $ do
202278
pv <- getsPParams ppProtocolVersionL

0 commit comments

Comments
 (0)