Skip to content

Commit

Permalink
Make plutus spending script less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed May 10, 2024
1 parent e918562 commit 34094e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 55 deletions.
16 changes: 8 additions & 8 deletions cardano-testnet/src/Testnet/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ data TestnetRuntime = TestnetRuntime
poolSprockets :: TestnetRuntime -> [Sprocket]
poolSprockets = fmap (nodeSprocket . poolRuntime) . poolNodes

data PoolNode = PoolNode
{ poolRuntime :: NodeRuntime
, poolKeys :: PoolNodeKeys
}

poolNodeStdout :: PoolNode -> FilePath
poolNodeStdout = nodeStdout . poolRuntime

data NodeRuntime = NodeRuntime
{ nodeName :: !String
, nodeIpv4 :: !Text
Expand All @@ -120,14 +128,6 @@ data NodeRuntime = NodeRuntime
nodeSocketPath :: NodeRuntime -> SocketPath
nodeSocketPath = File . H.sprocketSystemName . nodeSprocket

data PoolNode = PoolNode
{ poolRuntime :: NodeRuntime
, poolKeys :: PoolNodeKeys
}

poolNodeStdout :: PoolNode -> FilePath
poolNodeStdout = nodeStdout . poolRuntime

data ColdPoolKey
data StakingKey
data SpoColdKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ module Cardano.Testnet.Test.Cli.Conway.Plutus
) where

import Cardano.Api
import qualified Cardano.Api.Ledger as L

import Cardano.Testnet

import Prelude

import Control.Monad (void)
import qualified Data.Map.Strict as Map
import qualified Data.Text as Text
import System.FilePath ((</>))
import qualified System.Info as SYS

import Testnet.Components.Configuration
import Testnet.Components.Query
import Testnet.Components.SPO
import Testnet.Components.TestWatchdog
import Testnet.Defaults
Expand Down Expand Up @@ -56,37 +57,27 @@ hprop_plutus_v3 = H.integrationWorkspace "all-plutus-script-purposes" $ \tempAbs
era = toCardanoEra sbe
anyEra = AnyCardanoEra era
options = cardanoDefaultTestnetOptions
{ cardanoNodes = cardanoDefaultTestnetNodeOptions
, cardanoSlotLength = 0.1
, cardanoNodeEra = anyEra -- TODO: We should only support the latest era and the upcoming era
}
{ cardanoNodeEra = anyEra -- TODO: We should only support the latest era and the upcoming era
}

TestnetRuntime
{ testnetMagic
{ configurationFile
, testnetMagic
, poolNodes
, wallets=wallet0:wallet1:_
} <- cardanoTestnetDefault options conf

poolNode1 <- H.headM poolNodes
poolSprocket1 <- H.noteShow $ nodeSprocket $ poolRuntime poolNode1
PoolNode{poolRuntime} <- H.headM poolNodes
poolSprocket1 <- H.noteShow $ nodeSprocket poolRuntime
execConfig <- H.mkExecConfig tempBaseAbsPath poolSprocket1 testnetMagic
H.noteShow_ wallet0
let utxoAddr = Text.unpack $ paymentKeyInfoAddr wallet0
utxoAddr2 = Text.unpack $ paymentKeyInfoAddr wallet1
utxoSKeyFile = signingKeyFp $ paymentKeyInfoPair wallet0
utxoSKeyFile2 = signingKeyFp $ paymentKeyInfoPair wallet1
socketPath = nodeSocketPath poolRuntime

void $ H.execCli' execConfig
[ anyEraToString anyEra, "query", "utxo"
, "--address", utxoAddr
, "--cardano-mode"
, "--out-file", work </> "utxo-1.json"
]
utxo1Json <- H.leftFailM . H.readJsonFile $ work </> "utxo-1.json"
UTxO utxo1 <- H.noteShowM $ decodeEraUTxO sbe utxo1Json

let keys1 = Map.keys utxo1
H.note_ $ "keys1: " <> show (length keys1)
txin1 <- H.noteShowM $ H.headM keys1
epochStateView <- getEpochStateView configurationFile socketPath
txin1 <- findLargestUtxoForPaymentKey epochStateView sbe wallet0

plutusMintingScript <- H.note $ work </> "always-succeeds-non-spending-script.plutusV3"
H.writeFile plutusMintingScript $ Text.unpack plutusV3NonSpendingScript
Expand Down Expand Up @@ -152,34 +143,13 @@ hprop_plutus_v3 = H.integrationWorkspace "all-plutus-script-purposes" $ \tempAbs
, "--tx-file", sendAdaToScriptAddressTx
]

H.threadDelay 10_000_000
-- 2. Successfully spend conway spending script
void $ H.execCli' execConfig
[ anyEraToString anyEra, "query", "utxo"
, "--address", utxoAddr2
, "--cardano-mode"
, "--out-file", work </> "utxo-2.json"
]
utxo2Json <- H.leftFailM . H.readJsonFile $ work </> "utxo-2.json"
UTxO utxo2 <- H.noteShowM $ decodeEraUTxO sbe utxo2Json

let keys2 = Map.keys utxo2
H.note_ $ "keys2: " <> show (length keys2)
txinCollateral <- H.noteShowM $ H.headM keys2

void $ H.execCli' execConfig
[ anyEraToString anyEra, "query", "utxo"
, "--address", plutusSpendingScriptAddr
, "--cardano-mode"
, "--out-file", work </> "plutus-script-utxo.json"
]
utxoPlutusJson <- H.leftFailM . H.readJsonFile $ work </> "plutus-script-utxo.json"
UTxO utxoPlutus <- H.noteShowM $ decodeEraUTxO sbe utxoPlutusJson
_ <- waitForEpochs epochStateView (L.EpochInterval 1)

let keys3 = Map.keys utxoPlutus
H.note_ $ "keys3: " <> show (length keys3)
-- 2. Successfully spend conway spending script
txinCollateral <- findLargestUtxoForPaymentKey epochStateView sbe wallet1
plutusScriptTxIn <- fmap fst . H.nothingFailM $
findLargestUtxoWithAddress epochStateView sbe $ Text.pack plutusSpendingScriptAddr

plutusScriptTxIn <- H.noteShowM $ H.headM keys3
let spendScriptUTxOTxBody = work </> "spend-script-utxo-tx-body"
spendScriptUTxOTx = work </> "spend-script-utxo-tx"
mintValue = mconcat ["5 ", mintingPolicyId, ".", assetName]
Expand Down

0 comments on commit 34094e2

Please sign in to comment.