diff --git a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Address.hs b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Address.hs index c61a594e0..ea75e492e 100644 --- a/cardano-api/test/cardano-api-test/Test/Cardano/Api/Address.hs +++ b/cardano-api/test/cardano-api-test/Test/Cardano/Api/Address.hs @@ -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) @@ -41,38 +42,57 @@ 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 $ @@ -80,6 +100,34 @@ prop_derivation_is_accurate = H.propertyOnce $ do 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 @@ -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 ]