Skip to content

Commit 7b18e04

Browse files
Merge pull request #5415 from IntersectMBO/fd/epoch-spec-rule
Run the specification rules of EPOCH and NEWEPOCH in conformance tests
2 parents f58e490 + 5194421 commit 7b18e04

File tree

9 files changed

+71
-60
lines changed

9 files changed

+71
-60
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,11 @@ Below are instructions for some common use cases and workflow examples.
292292

293293
- Extract the Haskell package using:
294294
```shell
295-
nix develop --command fls-shake hs
295+
rm -rf dist/hs _build; nix develop --command fls-shake hs
296296
```
297297
This generates the `cardano-ledger-executable-spec` Haskell package in `REPO/dist/hs`
298+
Removing the `dist/hs` and `_build` folders ensures that no obsolete
299+
modules are left together with the extracted code.
298300

299301
In a local copy of `cardano-ledger` (with the `cabal.project` file _unmodified_):
300302

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ source-repository-package
1616
subdir: hs
1717
-- !WARNING!:
1818
-- MAKE SURE THIS POINTS TO A COMMIT IN `*-artifacts` BEFORE MERGE!
19-
tag: d84538c1ad6d8dc3cff4e59ead574daf84c88117
19+
tag: 7a4c75d285595b7d21228a6208a99ca436aa88f4
2020

2121
source-repository-package
2222
type: git

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/DelegSpec.hs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ spec = do
331331
expectNotDelegatedVote cred
332332
expectNotDelegatedToAnyPool cred
333333

334-
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/917
335-
-- TODO: Re-enable after issue is resolved, by removing this override
336-
disableInConformanceIt "Delegate vote and unregister after hardfork" $ do
334+
it "Delegate vote and unregister after hardfork" $ do
337335
let
338336
bootstrapVer = ProtVer (natVersion @9) 0
339337
setProtVer pv = modifyNES $ nesEsL . curPParamsEpochStateL . ppProtocolVersionL .~ pv
@@ -382,9 +380,7 @@ spec = do
382380
.~ Withdrawals (Map.singleton rewardAccount withdrawalAmount)
383381
expectStakeCredNotRegistered cred
384382
expectNotDelegatedVote cred
385-
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/916
386-
-- TODO: Re-enable after issue is resolved, by removing this override
387-
disableInConformanceIt "Delegate vote and undelegate after delegating to some stake pools" $ do
383+
it "Delegate vote and undelegate after delegating to some stake pools" $ do
388384
(khSPO, _, _) <- setupPoolWithStake $ Coin 1_000_000
389385
expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
390386
cred <- KeyHashObj <$> freshKeyHash
@@ -412,9 +408,7 @@ spec = do
412408
expectStakeCredNotRegistered cred
413409
expectNotDelegatedVote cred
414410

415-
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/640
416-
-- TODO: Re-enable after issue is resolved, by removing this override
417-
disableInConformanceIt "Delegate, retire and re-register pool" $ do
411+
it "Delegate, retire and re-register pool" $ do
418412
expectedDeposit <- getsNES $ nesEsL . curPParamsEpochStateL . ppKeyDepositL
419413
cred <- KeyHashObj <$> freshKeyHash
420414
poolKh <- freshKeyHash

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/EnactSpec.hs

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ treasuryWithdrawalsSpec =
104104
]
105105
ensTreasury enactState'' `shouldBe` Coin 1
106106

107-
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/911
108-
-- TODO: Re-enable after issues are resolved, by removing this override
109-
disableInConformanceIt "Withdrawals exceeding treasury submitted in a single proposal" $ whenPostBootstrap $ do
107+
it "Withdrawals exceeding treasury submitted in a single proposal" $ whenPostBootstrap $ do
110108
disableTreasuryExpansion
111109
committeeCs <- registerInitialCommittee
112110
(drepC, _, _) <- setupSingleDRep 1_000_000
@@ -138,43 +136,40 @@ treasuryWithdrawalsSpec =
138136
void $ enactTreasuryWithdrawals withdrawals drepC committeeCs
139137
checkNoWithdrawal initialTreasury withdrawals
140138

141-
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/912
142-
-- TODO: Re-enable after issues are resolved, by removing this override
143-
disableInConformanceIt
144-
"Withdrawals exceeding treasury submitted in several proposals within the same epoch"
145-
$ whenPostBootstrap
146-
$ do
147-
disableTreasuryExpansion
148-
committeeCs <- registerInitialCommittee
149-
(drepC, _, _) <- setupSingleDRep 1_000_000
150-
donateToTreasury $ Coin 5_000_000
151-
initialTreasury <- getsNES treasuryL
152-
numWithdrawals <- choose (1, 10)
153-
withdrawals <- genWithdrawalsExceeding initialTreasury numWithdrawals
154-
155-
impAnn "submit in individual proposals in the same epoch" $ do
156-
traverse_
157-
( \w -> do
158-
gaId <- submitTreasuryWithdrawals @era [w]
159-
submitYesVote_ (DRepVoter drepC) gaId
160-
submitYesVoteCCs_ committeeCs gaId
161-
)
162-
withdrawals
163-
passNEpochs 2
139+
it "Withdrawals exceeding treasury submitted in several proposals within the same epoch" $
140+
whenPostBootstrap $
141+
do
142+
disableTreasuryExpansion
143+
committeeCs <- registerInitialCommittee
144+
(drepC, _, _) <- setupSingleDRep 1_000_000
145+
donateToTreasury $ Coin 5_000_000
146+
initialTreasury <- getsNES treasuryL
147+
numWithdrawals <- choose (1, 10)
148+
withdrawals <- genWithdrawalsExceeding initialTreasury numWithdrawals
149+
150+
impAnn "submit in individual proposals in the same epoch" $ do
151+
traverse_
152+
( \w -> do
153+
gaId <- submitTreasuryWithdrawals @era [w]
154+
submitYesVote_ (DRepVoter drepC) gaId
155+
submitYesVoteCCs_ committeeCs gaId
156+
)
157+
withdrawals
158+
passNEpochs 2
159+
160+
let expectedTreasury =
161+
F.foldl'
162+
( \acc (_, x) ->
163+
if acc >= x
164+
then acc <-> x
165+
else acc
166+
)
167+
initialTreasury
168+
withdrawals
164169

165-
let expectedTreasury =
166-
F.foldl'
167-
( \acc (_, x) ->
168-
if acc >= x
169-
then acc <-> x
170-
else acc
171-
)
172-
initialTreasury
173-
withdrawals
174-
175-
getsNES treasuryL `shouldReturn` expectedTreasury
176-
-- check that the sum of the rewards matches what was spent from the treasury
177-
sumRewardAccounts withdrawals `shouldReturn` (initialTreasury <-> expectedTreasury)
170+
getsNES treasuryL `shouldReturn` expectedTreasury
171+
-- check that the sum of the rewards matches what was spent from the treasury
172+
sumRewardAccounts withdrawals `shouldReturn` (initialTreasury <-> expectedTreasury)
178173
where
179174
sumRewardAccounts withdrawals = mconcat <$> traverse (getAccountBalance . fst) withdrawals
180175
genWithdrawalsExceeding (Coin val) n = do

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Imp/UtxoSpec.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ import Test.Cardano.Ledger.Plutus.Examples (alwaysSucceedsNoDatum)
4040
spec :: forall era. ConwayEraImp era => SpecWith (ImpInit (LedgerSpec era))
4141
spec = do
4242
describe "Certificates" $ do
43-
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/926
44-
-- TODO: Re-enable after issues are resolved, by removing this override
45-
disableInConformanceIt "Reg/UnReg collect and refund correct amounts" $ do
43+
it "Reg/UnReg collect and refund correct amounts" $ do
4644
utxoStart <- getUTxO
4745
accountDeposit <- getsPParams ppKeyDepositL
4846
stakePoolDeposit <- getsPParams ppPoolDepositL

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,7 @@ spec = do
189189
)
190190
[injectFailure $ StakeKeyNotRegisteredDELEG (KeyHashObj kh)]
191191

192-
-- https://github.com/IntersectMBO/formal-ledger-specifications/issues/917
193-
-- impacts `registerAndRetirePoolToMakeReward`
194-
-- TODO: Re-enable after issue is resolved, by removing this override
195-
disableInConformanceIt "With non-zero reward balance" $ do
192+
it "With non-zero reward balance" $ do
196193
cred <- KeyHashObj <$> freshKeyHash
197194
regTxCert <- genRegTxCert cred
198195

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/cardano-ledger-conformance/src/Test/Cardano/Ledger/Conformance/SpecTranslate/Conway/Cert.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,17 @@ instance
253253
toSpecRep (NewEpochState {..}) =
254254
Agda.MkNewEpochState
255255
<$> toSpecRep nesEL
256+
<*> toSpecRep nesBprev
257+
<*> toSpecRep nesBcur
256258
<*> toSpecRep nesEs
257259
<*> toSpecRep nesRu
260+
<*> (filterZeroEntries <$> toSpecRep nesPd)
261+
where
262+
-- The specification does not include zero entries in general
263+
-- while the implementation might. So we filter them out here for the sake
264+
-- of comparing results.
265+
--
266+
-- The discrepancy is discussed here:
267+
-- https://github.com/IntersectMBO/cardano-ledger/issues/5306
268+
filterZeroEntries (Agda.MkHSMap lst) =
269+
Agda.MkHSMap $ filter ((/= 0) . snd) lst

libs/cardano-ledger-conformance/src/Test/Cardano/Ledger/Conformance/SpecTranslate/Core.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Cardano.Crypto.DSIGN (DSIGNAlgorithm (..), SignedDSIGN (..))
2424
import Cardano.Crypto.Util (bytesToNatural, naturalToBytes)
2525
import Cardano.Ledger.Address (Addr (..), BootstrapAddress (..), RewardAccount (..))
2626
import Cardano.Ledger.BaseTypes (
27+
BlocksMade (..),
2728
EpochInterval (..),
2829
EpochNo (..),
2930
Network (..),
@@ -57,10 +58,13 @@ import Cardano.Ledger.Plutus.CostModels (CostModels)
5758
import Cardano.Ledger.Plutus.Data (BinaryData, Data, Datum (..), hashBinaryData)
5859
import Cardano.Ledger.Plutus.ExUnits (ExUnits (..), Prices)
5960
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
61+
import Control.Monad (forM)
6062
import Control.Monad.Except (throwError)
6163
import Data.Functor.Identity (Identity (..))
6264
import Data.Map (Map)
65+
import qualified Data.Map as Map
6366
import Data.Maybe.Strict (StrictMaybe (..))
67+
import GHC.Natural (naturalToInteger)
6468
import qualified MAlonzo.Code.Ledger.Foreign.API as Agda
6569
import Test.Cardano.Ledger.Conformance.SpecTranslate.Base (
6670
SpecTranslate (..),
@@ -271,3 +275,12 @@ instance SpecTranslate ctx PoolDistr where
271275
type SpecRep PoolDistr = Agda.HSMap (SpecRep (KeyHash StakePool)) Agda.Coin
272276

273277
toSpecRep (PoolDistr ps _) = toSpecRep ps
278+
279+
instance SpecTranslate ctx BlocksMade where
280+
type SpecRep BlocksMade = Agda.HSMap Integer Integer
281+
282+
toSpecRep (BlocksMade m) = do
283+
xs <- forM (Map.toList m) $ \(k, v) -> do
284+
k' <- toSpecRep k
285+
pure (k', naturalToInteger v)
286+
pure $ Agda.MkHSMap xs

0 commit comments

Comments
 (0)