Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Plutus certifying and rewarding script test to cardano-testnet
- Loading branch information
Showing
8 changed files
with
834 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{-# LANGUAGE NumericUnderscores #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Testnet.Utils | ||
( waitUntilEpoch | ||
) where | ||
|
||
import Cardano.Api | ||
|
||
import Control.Concurrent (threadDelay) | ||
import Control.Exception.Safe (MonadCatch) | ||
import Control.Monad | ||
import Control.Monad.IO.Class | ||
import Data.Aeson (fromJSON) | ||
import Data.Eq | ||
import Data.Function | ||
import Data.Int | ||
import Data.Maybe | ||
import GHC.Stack | ||
import System.Directory (doesFileExist, removeFile) | ||
import System.FilePath (FilePath) | ||
import Text.Show | ||
|
||
import Cardano.CLI.Shelley.Output | ||
|
||
import qualified Hedgehog.Extras.Test.Base as H | ||
import qualified Hedgehog.Extras.Test.File as H | ||
import Hedgehog.Extras.Test.Process (ExecConfig) | ||
import Hedgehog.Internal.Property (MonadTest) | ||
import qualified Test.Process as H | ||
|
||
-- | Submit the desired epoch to wait to. | ||
waitUntilEpoch | ||
:: (MonadCatch m, MonadIO m, MonadTest m) | ||
=> FilePath | ||
-- ^ Output file | ||
-> Int | ||
-- ^ Testnet magic | ||
-> ExecConfig | ||
-> EpochNo | ||
-- ^ Desired epoch | ||
-> m EpochNo | ||
waitUntilEpoch fp testnetMagic execConfig desiredEpoch = do | ||
exists <- liftIO $ doesFileExist fp | ||
when exists $ liftIO $ removeFile fp | ||
|
||
void $ H.execCli' execConfig | ||
[ "query", "tip" | ||
, "--testnet-magic", show @Int testnetMagic | ||
, "--out-file", fp | ||
] | ||
|
||
tipJSON <- H.leftFailM $ H.readJsonFile fp | ||
tip <- H.noteShowM $ H.jsonErrorFail $ fromJSON @QueryTipLocalStateOutput tipJSON | ||
case mEpoch tip of | ||
Nothing -> | ||
H.failMessage | ||
callStack "waitUntilEpoch: cardano-cli query tip returned Nothing for EpochNo" | ||
Just currEpoch -> | ||
if currEpoch == desiredEpoch | ||
then return currEpoch | ||
else do liftIO $ threadDelay 10_000_000 | ||
waitUntilEpoch fp testnetMagic execConfig desiredEpoch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.