@@ -9,13 +9,17 @@ module Cardano.Testnet.Test.Cli.Transaction.RegisterDeregisterStakeAddress
99 ) where
1010
1111import Cardano.Api as Api
12+ import Cardano.Api.Address (StakeCredential (.. ), toShelleyStakeCredential )
1213
14+ import Cardano.CLI.Types.Key (SomeSigningKey (AStakeSigningKey ))
15+ import qualified Cardano.Ledger.UMap as L
1316import Cardano.Testnet
1417
1518import Prelude
1619
1720import Control.Monad
1821import Data.Default.Class
22+ import qualified Data.Map as M
1923import qualified Data.Text as Text
2024import System.FilePath ((</>) )
2125
@@ -30,6 +34,7 @@ import Testnet.Start.Types
3034import Testnet.Types
3135
3236import Hedgehog
37+ import qualified Hedgehog as H
3338import qualified Hedgehog.Extras as H
3439
3540-- | Execute me with:
@@ -75,11 +80,20 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
7580 stakeKeys = KeyPair { verificationKey = File $ work </> " stake.vkey"
7681 , signingKey = File $ work </> " stake.skey"
7782 }
83+
7884 cliStakeAddressKeyGen stakeKeys
7985 keyDeposit <- getKeyDeposit epochStateView ceo
8086 createStakeKeyRegistrationCertificate
8187 tempAbsPath (AnyShelleyBasedEra sbe) (verificationKey stakeKeys) keyDeposit stakeCertFp
8288
89+ -- obtain stake key hash as ledger's Credential
90+ AStakeSigningKey key <- H. leftFailM . H. evalIO $
91+ readKeyFileAnyOf
92+ [FromSomeType (AsSigningKey AsStakeKey ) AStakeSigningKey ]
93+ [FromSomeType (AsSigningKey AsStakeKey ) AStakeSigningKey ]
94+ (signingKey stakeKeys)
95+ stakeKeyHash <- H. noteShow . toShelleyStakeCredential . StakeCredentialByKey . verificationKeyHash $ getVerificationKey key
96+
8397 stakeCertTxBodyFp <- H. note $ work </> " stake.registration.txbody"
8498 stakeCertTxSignedFp <- H. note $ work </> " stake.registration.tx"
8599
@@ -105,12 +119,23 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
105119 , " --out-file" , stakeCertTxSignedFp
106120 ]
107121
122+ H. note_ " Check that stake address isn't registered yet"
123+ getDelegationState epochStateView >>=
124+ flip H. assertWith
125+ (M. notMember stakeKeyHash . L. scDeposits)
126+
108127 void $ execCli' execConfig
109128 [ eraName, " transaction" , " submit"
110129 , " --tx-file" , stakeCertTxSignedFp
111130 ]
112131
113- H. noteShowM_ $ waitForBlocks epochStateView 1
132+
133+ _ <- waitForBlocks epochStateView 1
134+
135+ H. note_ " Check that stake address is registered"
136+ getDelegationState epochStateView >>=
137+ flip H. assertWith
138+ (M. member stakeKeyHash . L. scDeposits)
114139
115140 -- deregister stake address
116141 createStakeKeyDeregistrationCertificate
@@ -145,3 +170,11 @@ hprop_tx_register_deregister_stake_address = integrationWorkspace "register-dere
145170 [ eraName, " transaction" , " submit"
146171 , " --tx-file" , stakeCertDeregTxSignedFp
147172 ]
173+
174+ _ <- waitForBlocks epochStateView 1
175+
176+ H. note_ " Check that stake address is deregistered"
177+ getDelegationState epochStateView >>=
178+ flip H. assertWith
179+ (M. notMember stakeKeyHash . L. scDeposits)
180+
0 commit comments