44{-# OPTIONS_GHC -Wno-orphans #-}
55
66module Spec.MockContract (
7+ -- Mock private and public keys etc.
78 signingKey1 ,
89 signingKey2 ,
9- runContractPure ,
10+ signingKey3 ,
11+ verificationKey1 ,
12+ verificationKey2 ,
13+ verificationKey3 ,
1014 toSigningKeyFile ,
11- runContractPure' ,
12- MockContractState (.. ),
15+ toVerificationKeyFile ,
1316 pubKey1 ,
1417 pubKey2 ,
1518 pubKey3 ,
@@ -28,6 +31,10 @@ module Spec.MockContract (
2831 pkhAddr1 ,
2932 pkhAddr2 ,
3033 pkhAddr3 ,
34+ -- Test interpreter
35+ runContractPure ,
36+ runContractPure' ,
37+ MockContractState (.. ),
3138 commandHistory ,
3239 instanceUpdateHistory ,
3340 logHistory ,
@@ -52,13 +59,15 @@ import Cardano.Api (
5259 AsType ,
5360 FileError (FileError , FileIOError ),
5461 HasTextEnvelope ,
62+ Key (VerificationKey , getVerificationKey ),
5563 NetworkId (Mainnet ),
5664 PaymentKey ,
5765 SigningKey (PaymentSigningKey ),
5866 TextEnvelope ,
5967 TextEnvelopeDescr ,
6068 TextEnvelopeError (TextEnvelopeAesonDecodeError ),
6169 deserialiseFromTextEnvelope ,
70+ getVerificationKey ,
6271 serialiseToTextEnvelope ,
6372 )
6473import Cardano.Crypto.DSIGN (genKeyDSIGN )
@@ -116,10 +125,15 @@ signingKey1 = PaymentSigningKey $ genKeyDSIGN $ mkSeedFromBytes $ ByteString.rep
116125signingKey2 = PaymentSigningKey $ genKeyDSIGN $ mkSeedFromBytes $ ByteString. replicate 32 1
117126signingKey3 = PaymentSigningKey $ genKeyDSIGN $ mkSeedFromBytes $ ByteString. replicate 32 2
118127
128+ verificationKey1 , verificationKey2 , verificationKey3 :: VerificationKey PaymentKey
129+ verificationKey1 = getVerificationKey signingKey1
130+ verificationKey2 = getVerificationKey signingKey2
131+ verificationKey3 = getVerificationKey signingKey3
132+
119133pubKey1 , pubKey2 , pubKey3 :: PubKey
120- pubKey1 = toPubKey signingKey1
121- pubKey2 = toPubKey signingKey2
122- pubKey3 = toPubKey signingKey3
134+ pubKey1 = skeyToPubKey signingKey1
135+ pubKey2 = skeyToPubKey signingKey2
136+ pubKey3 = skeyToPubKey signingKey3
123137
124138pkh1 , pkh2 , pkh3 :: PubKeyHash
125139pkh1 = Ledger. pubKeyHash pubKey1
@@ -146,19 +160,32 @@ addr1 = unsafeSerialiseAddress Mainnet (Ledger.pubKeyHashAddress paymentPkh1 Not
146160addr2 = unsafeSerialiseAddress Mainnet (Ledger. pubKeyHashAddress paymentPkh2 Nothing )
147161addr3 = unsafeSerialiseAddress Mainnet (Ledger. pubKeyHashAddress paymentPkh3 Nothing )
148162
149- toPubKey :: SigningKey PaymentKey -> PubKey
150- toPubKey =
163+ skeyToPubKey :: SigningKey PaymentKey -> PubKey
164+ skeyToPubKey =
151165 Ledger. toPublicKey
152166 . Files. unDummyPrivateKey
153167 . fromRight (error " Impossible happened" )
154168 . Files. skeyToDummyPrivKey
155169
170+ vkeyToPubKey :: VerificationKey PaymentKey -> PubKey
171+ vkeyToPubKey =
172+ Ledger. toPublicKey
173+ . Files. unDummyPrivateKey
174+ . fromRight (error " Impossible happened" )
175+ . Files. vkeyToDummyPrivKey
176+
156177toSigningKeyFile :: FilePath -> SigningKey PaymentKey -> (FilePath , MockFile )
157178toSigningKeyFile signingKeyFileDir sKey =
158- ( signingKeyFileDir ++ " /signing-key-" ++ show (Ledger. pubKeyHash (toPubKey sKey)) ++ " .skey"
179+ ( signingKeyFileDir ++ " /signing-key-" ++ show (Ledger. pubKeyHash (skeyToPubKey sKey)) ++ " .skey"
159180 , TextEnvelopeFile $ serialiseToTextEnvelope Nothing sKey
160181 )
161182
183+ toVerificationKeyFile :: FilePath -> VerificationKey PaymentKey -> (FilePath , MockFile )
184+ toVerificationKeyFile signingKeyFileDir vKey =
185+ ( signingKeyFileDir ++ " /signing-key-" ++ show (Ledger. pubKeyHash (vkeyToPubKey vKey)) ++ " .vkey"
186+ , TextEnvelopeFile $ serialiseToTextEnvelope Nothing vKey
187+ )
188+
162189data MockFile
163190 = TextEnvelopeFile TextEnvelope
164191 | JsonFile JSON. Value
0 commit comments