Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Increase the delay of awaiting in plutus-pab-executables tests #565

Merged
4 commits merged into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion plutus-chain-index-core/src/Plutus/ChainIndex/TxIdState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Plutus.ChainIndex.Types (BlockNumber (..), Depth (..), Point (..), Rollba
import Plutus.ChainIndex.UtxoState (RollbackFailed (..), RollbackResult (..), UtxoIndex, UtxoState (..), rollbackWith,
tip, utxoState, viewTip)


-- | The 'TxStatus' of a transaction right after it was added to the chain
initialStatus :: OnChainTx -> TxStatus
initialStatus tx =
Expand Down
3 changes: 1 addition & 2 deletions plutus-contract/src/Wallet/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import Control.Monad (unless, void)
import Control.Monad.Freer (Eff, Member)
import Control.Monad.Freer.Error (Error, throwError)
import Control.Monad.Freer.Extras.Log (LogMsg, logDebug, logWarn)
import Data.Default (Default (def))
import Data.List.NonEmpty qualified as NonEmpty
import Data.Maybe (mapMaybe)
import Data.Text (Text)
Expand Down Expand Up @@ -125,7 +124,7 @@ payToPaymentPublicKeyHash ::
=> Params -> SlotRange -> Value -> PaymentPubKeyHash -> Eff effs CardanoTx
payToPaymentPublicKeyHash params range v pk = do
let constraints = Constraints.mustPayToPubKey pk v
<> Constraints.mustValidateIn (TimeSlot.slotRangeToPOSIXTimeRange def range)
<> Constraints.mustValidateIn (TimeSlot.slotRangeToPOSIXTimeRange (pSlotConfig params) range)
utx <- either (throwError . PaymentMkTxError)
pure
(Constraints.mkTx @Void mempty constraints)
Expand Down
18 changes: 13 additions & 5 deletions plutus-pab-executables/test/full/Plutus/PAB/CoreSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ runScenario sim = do
Left err -> error (show err)
Right _ -> pure ()

-- To run scenarios with the slot's length to 1s to make the awaiting tests stable
runScenarioWithSecondSlot :: Simulation (Builtin TestContracts) a -> IO ()
runScenarioWithSecondSlot sim = do
let params = Ledger.allowBigTransactions def
result <- Simulator.runSimulationWithParams params sim
case result of
Left err -> error (show err)
Right _ -> pure ()

defaultWallet :: Wallet
defaultWallet = knownWallet 1

Expand Down Expand Up @@ -134,9 +143,8 @@ executionTests =
, currencyTest
, testCase "wait for update" waitForUpdateTest
, testCase "stop contract instance" stopContractInstanceTest
-- TODO: Commented temporarly until PR#565 is merged
-- , testCase "can wait for tx status change" waitForTxStatusChangeTest
-- , testCase "can wait for tx output status change" waitForTxOutStatusChangeTest
, testCase "can wait for tx status change" waitForTxStatusChangeTest
, testCase "can wait for tx output status change" waitForTxOutStatusChangeTest
, testCase "can subscribe to slot updates" slotChangeTest
, testCase "can query wallet funds" valueAtTest
, testCase "can subscribe to observable state changes" observableStateChangeTest
Expand Down Expand Up @@ -183,7 +191,7 @@ slotChangeTest = runScenario $ do
-- | Testing whether state of a tx correctly goes from 'TentativelyConfirmed'
-- to 'Committed'.
waitForTxStatusChangeTest :: IO ()
waitForTxStatusChangeTest = runScenario $ do
waitForTxStatusChangeTest = runScenarioWithSecondSlot $ do
-- Add funds to a wallet and create a new transaction which we will observe
-- for a status change.
(w1, pk1) <- Simulator.addWallet
Expand Down Expand Up @@ -217,7 +225,7 @@ waitForTxStatusChangeTest = runScenario $ do
-- | Testing whether state of a tx correctly goes from 'TentativelyConfirmed'
-- to 'Committed'.
waitForTxOutStatusChangeTest :: IO ()
waitForTxOutStatusChangeTest = runScenario $ do
waitForTxOutStatusChangeTest = runScenarioWithSecondSlot $ do
-- Add funds to a wallet and create a new transaction which we will observe
-- for a status change.
(w1, pk1) <- Simulator.addWallet
Expand Down
16 changes: 9 additions & 7 deletions plutus-pab-executables/test/full/Plutus/PAB/Simulator/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A 'Simulator' for the test contracts

-}
module Plutus.PAB.Simulator.Test(runSimulation) where
module Plutus.PAB.Simulator.Test(runSimulation, runSimulationWithParams) where

import Control.Monad.Freer (interpret)
import Data.Default (Default (def))
Expand All @@ -20,15 +20,17 @@ import Plutus.PAB.Types (PABError)

-- | Run the PAB simulator with the test contracts
runSimulation :: Simulation (Builtin TestContracts) a -> IO (Either PABError a)
runSimulation = runSimulationWith simulatorHandlers
runSimulation = runSimulationWithParams $
allowBigTransactions def { pSlotConfig = def { scSlotLength = 1 } }

-- | Run the PAB simulator with the test contracts with provided params
runSimulationWithParams :: Params -> Simulation (Builtin TestContracts) a -> IO (Either PABError a)
runSimulationWithParams params = runSimulationWith (simulatorHandlers params)

-- | 'EffectHandlers' for running the PAB as a simulator (no connectivity to
-- out-of-process services such as wallet backend, node, etc.)
simulatorHandlers :: EffectHandlers (Builtin TestContracts) (SimulatorState (Builtin TestContracts))
simulatorHandlers = mkSimulatorHandlers params handler
simulatorHandlers :: Params -> EffectHandlers (Builtin TestContracts) (SimulatorState (Builtin TestContracts))
simulatorHandlers params = mkSimulatorHandlers params handler
where
params :: Params
params = allowBigTransactions $ def { pSlotConfig = def { scSlotLength = 1 } }

handler :: SimulatorContractHandler (Builtin TestContracts)
handler = interpret (contractHandler handleBuiltin)
5 changes: 2 additions & 3 deletions plutus-pab/src/Plutus/PAB/Simulator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ mkSimulatorHandlers params handleContractEffect =
$ interpret (Core.handleBlockchainEnvReader @t @(SimulatorState t))
$ advanceClock @t
Core.waitUntilSlot 1
, onShutdown = do
handleDelayEffect $ delayThread (500 :: Millisecond) -- need to wait a little to avoid garbled terminal output in GHCi.
, onShutdown = handleDelayEffect $ delayThread (500 :: Millisecond) -- need to wait a little to avoid garbled terminal output in GHCi.
}

handleLogSimulator ::
Expand Down Expand Up @@ -341,7 +340,7 @@ activateContract = Core.activateContract
callEndpointOnInstance :: forall a t. (JSON.ToJSON a) => ContractInstanceId -> String -> a -> Simulation t (Maybe NotificationError)
callEndpointOnInstance = Core.callEndpointOnInstance'

-- | Wait 1 second, then add a new block.
-- | Wait 1 slot length, then add a new block.
makeBlock ::
forall t effs.
( LastMember IO effs
Expand Down