Skip to content

Commit

Permalink
Add extra tests for two other types of address
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Nov 12, 2024
1 parent c34cf64 commit d7f6ec9
Showing 1 changed file with 83 additions and 31 deletions.
114 changes: 83 additions & 31 deletions cardano-api/test/cardano-api-test/Test/Cardano/Api/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Cardano.Api.Address (StakeCredential (StakeCredentialByKey))

import Control.Monad (void)
import qualified Data.Aeson as Aeson
import Data.Text (Text)

import Test.Gen.Cardano.Api.Typed (genAddressByron, genAddressShelley)

Expand Down Expand Up @@ -41,45 +42,92 @@ prop_derive_key_from_mnemonic = H.property $ do
void $ H.evalEither $ signingKeyFromMnemonic AsStakeExtendedKey mnemonic Nothing 0 0
H.success

prop_derivation_is_accurate :: Property
prop_derivation_is_accurate = H.propertyOnce $ do
let mnemonic =
[ "captain"
, "kick"
, "bundle"
, "address"
, "forest"
, "cube"
, "skirt"
, "pepper"
, "captain"
, "now"
, "crop"
, "matrix"
, "virus"
, "shallow"
, "bless"
, "throw"
, "spice"
, "smoke"
, "over"
, "proud"
, "minimum"
, "coconut"
, "virus"
, "suspect"
]
signingKey <- H.evalEither $ signingKeyFromMnemonic AsStakeExtendedKey mnemonic Nothing 0 0
exampleMnemonic :: [Text]
exampleMnemonic =
[ "captain"
, "kick"
, "bundle"
, "address"
, "forest"
, "cube"
, "skirt"
, "pepper"
, "captain"
, "now"
, "crop"
, "matrix"
, "virus"
, "shallow"
, "bless"
, "throw"
, "spice"
, "smoke"
, "over"
, "proud"
, "minimum"
, "coconut"
, "virus"
, "suspect"
]

prop_payment_derivation_is_accurate :: Property
prop_payment_derivation_is_accurate = H.propertyOnce $ do
signingKey <- H.evalEither $ signingKeyFromMnemonic AsPaymentExtendedKey exampleMnemonic Nothing 0 0
let verificationKey =
getVerificationKey (signingKey :: SigningKey PaymentExtendedKey)
:: VerificationKey PaymentExtendedKey
addr =
serialiseToBech32 $
makeShelleyAddress
Mainnet
( PaymentCredentialByKey $
verificationKeyHash $
castVerificationKey verificationKey
)
NoStakeAddress
addr H.=== "addr1v86y48z2h38ale0s9r2mfkaw7wp5ysyemnrp0azpy8z4ejg93879q"

prop_stake_derivation_is_accurate :: Property
prop_stake_derivation_is_accurate = H.propertyOnce $ do
signingKey <- H.evalEither $ signingKeyFromMnemonic AsStakeExtendedKey exampleMnemonic Nothing 0 0
let verificationKey =
getVerificationKey (signingKey :: SigningKey StakeExtendedKey) :: VerificationKey StakeExtendedKey
let addr =
addr =
serialiseToBech32 $
makeStakeAddress Mainnet $
StakeCredentialByKey $
verificationKeyHash $
castVerificationKey verificationKey
addr H.=== "stake1u97tzhttvsz5n6fej6g05trus39x5uvl0y0k56dyhsc23xcexrk27"

prop_payment_with_stake_derivation_is_accurate :: Property
prop_payment_with_stake_derivation_is_accurate = H.propertyOnce $ do
paymentSigningKey <-
H.evalEither $ signingKeyFromMnemonic AsPaymentExtendedKey exampleMnemonic Nothing 0 0
stakeSigningKey <-
H.evalEither $ signingKeyFromMnemonic AsStakeExtendedKey exampleMnemonic Nothing 0 0
let paymentVerificationKey =
getVerificationKey (paymentSigningKey :: SigningKey PaymentExtendedKey)
:: VerificationKey PaymentExtendedKey
stakeVerificationKey =
getVerificationKey (stakeSigningKey :: SigningKey StakeExtendedKey)
:: VerificationKey StakeExtendedKey
addr =
serialiseToBech32 $
makeShelleyAddress
Mainnet
( PaymentCredentialByKey $
verificationKeyHash $
castVerificationKey paymentVerificationKey
)
( StakeAddressByValue $
StakeCredentialByKey $
verificationKeyHash $
castVerificationKey stakeVerificationKey
)
addr
H.=== "addr1q86y48z2h38ale0s9r2mfkaw7wp5ysyemnrp0azpy8z4ejtuk9wkkeq9f85nn95slgk8epz2dfce77gldf56f0ps4zds0dx2p0"

-- -----------------------------------------------------------------------------

roundtrip_serialise_address
Expand Down Expand Up @@ -116,5 +164,9 @@ tests =
, testProperty "roundtrip byron address JSON" prop_roundtrip_byron_address_JSON
, testProperty "roundtrip shelley address JSON" prop_roundtrip_shelley_address_JSON
, testProperty "key derivation from random mnemonic" prop_derive_key_from_mnemonic
, testProperty "address from key derivation is accurate" prop_derivation_is_accurate
, testProperty "payment address from key derivation is accurate" prop_payment_derivation_is_accurate
, testProperty "stake address from key derivation is accurate" prop_stake_derivation_is_accurate
, testProperty
"payment address with stake from key derivation is accurate"
prop_payment_with_stake_derivation_is_accurate
]

0 comments on commit d7f6ec9

Please sign in to comment.