-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update libs/cardano-ledger-conformance/src/Test/Cardano/Ledger/Confor…
…mance/ExecSpecRule/Core.hs Co-authored-by: Alexey Kuleshevich <[email protected]>
- Loading branch information
Showing
9 changed files
with
111 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
libs/cardano-ledger-conformance/src/Test/Cardano/Ledger/Conformance/ConformanceSpec.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Test.Cardano.Ledger.Conformance.ConformanceSpec (spec) where | ||
|
||
import Cardano.Ledger.Crypto (StandardCrypto) | ||
import Cardano.Ledger.Keys (KeyHash, KeyRole (..)) | ||
import Data.List (isInfixOf) | ||
import Test.Cardano.Ledger.Common | ||
import Test.Cardano.Ledger.Conformance (SpecTranslate (..), runSpecTransM) | ||
import Test.Cardano.Ledger.Conformance.Spec.Conway () | ||
import Test.Cardano.Ledger.Conformance.Utils (agdaHashToBytes) | ||
|
||
spec :: Spec | ||
spec = | ||
describe "Translation" $ do | ||
prop "Hashes are displayed in the same way in the implementation and in the spec" $ do | ||
someHash <- arbitrary @(KeyHash 'Staking StandardCrypto) | ||
let | ||
specRes = | ||
case runSpecTransM () (toTestRep someHash) of | ||
Left e -> error $ "Failed to translate hash: " <> show e | ||
Right x -> agdaHashToBytes x | ||
pure $ show specRes `isInfixOf` showExpr someHash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
libs/cardano-ledger-conformance/src/Test/Cardano/Ledger/Conformance/Utils.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Test.Cardano.Ledger.Conformance.Utils where | ||
|
||
import Cardano.Crypto.Hash (ByteString) | ||
import Cardano.Crypto.Util (naturalToBytes) | ||
import qualified Data.ByteString.Base16 as B16 | ||
import Test.Cardano.Ledger.TreeDiff (Expr, ToExpr (..)) | ||
|
||
agdaHashToBytes :: Integer -> ByteString | ||
agdaHashToBytes = B16.encode . naturalToBytes hashSize . fromInteger | ||
where | ||
-- TODO is there a way to get this from a `Crypto` instead of hard-coding? | ||
hashSize = 28 | ||
|
||
agdaHashToExpr :: Integer -> Expr | ||
agdaHashToExpr = toExpr . agdaHashToBytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Main (main) where | ||
|
||
import Test.Cardano.Ledger.Common | ||
import qualified Test.Cardano.Ledger.Conformance.ConformanceSpec as ConformanceSpec | ||
import qualified Test.Cardano.Ledger.Conformance.Spec.Conway as Conway | ||
|
||
main :: IO () | ||
main = | ||
ledgerTestMain $ | ||
ledgerTestMain $ do | ||
describe "Conformance" $ do | ||
Conway.spec | ||
ConformanceSpec.spec |