Skip to content

Commit

Permalink
Reduce filenames of golden files
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Aug 22, 2024
1 parent dc0bfdc commit 66a982e
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/cardano-addresses.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ test-suite unit
, bytestring
, cardano-addresses
, cardano-crypto
, cryptonite
, containers
, hspec
, hspec-golden >=0.1.0.3 && <0.2
Expand Down
16 changes: 14 additions & 2 deletions core/test/Cardano/Address/Style/ShelleySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ import Codec.Binary.Encoding
( AbstractEncoding (..), encode, fromBase16 )
import Control.Monad
( (<=<) )
import Crypto.Hash
( hashWith )
import Crypto.Hash.Algorithms
( SHA3_256 (SHA3_256) )
import Data.Aeson
( ToJSON, Value (..) )
import Data.ByteArray
Expand Down Expand Up @@ -127,6 +131,7 @@ import qualified Cardano.Address.Style.Shelley as Shelley
import qualified Cardano.Codec.Bech32.Prefixes as CIP5
import qualified Data.Aeson.Encode.Pretty as Aeson
import qualified Data.ByteArray as BA
import qualified Data.ByteArray.Encoding as BAE
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BL
import qualified Data.Char as Char
Expand Down Expand Up @@ -1017,10 +1022,10 @@ testVectors mnemonic = describe (show $ T.unpack <$> mnemonic) $ do
let vec = TestVector {..}
let inspectVec = InspectVector {..}
it "should generate correct addresses" $ do
goldenTextLazy ("addresses_" <> T.intercalate "_" mnemonic)
goldenTextLazy ("addresses_" <> shortHex (T.intercalate "_" mnemonic))
(pShowOpt defaultOutputOptionsNoColor vec)
it "should inspect correctly" $ do
goldenByteStringLazy ("inspects" <> T.intercalate "_" mnemonic) $
goldenByteStringLazy ("inspects_" <> shortHex (T.intercalate "_" mnemonic)) $
goldenEncodeJSON $ toInspect <$> inspectVec
where
getPaymentAddr addrKPrv net = bech32 $ paymentAddress net (PaymentFromExtendedKey (toXPub <$> addrKPrv))
Expand All @@ -1031,6 +1036,13 @@ testVectors mnemonic = describe (show $ T.unpack <$> mnemonic) $ do
toInspect = fromMaybe (String "couldn't inspect") .
(Shelley.inspectAddress Nothing <=< fromBech32)

-- | Make a short name for a mnemonic by hashing it and taking the first 8 characters
shortHex :: Text -> Text
shortHex = T.take 8 . T.decodeUtf8 . BAE.convertToBase BAE.Base16 . hashByteString . T.encodeUtf8
where
hashByteString :: ByteString -> ByteString
hashByteString = BA.convert . hashWith SHA3_256

getExtendedKeyAddr :: Shelley depth XPrv -> Address
getExtendedKeyAddr = unsafeMkAddress . xprvToBytes . getKey

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 66a982e

Please sign in to comment.