Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce filenames of golden files #271

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading