Skip to content

Commit bbc760e

Browse files
committed
Merge branch 'master' into gergely/vasil
2 parents 9a60d36 + 03c3597 commit bbc760e

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

cabal.project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ allow-newer:
1212
constraints:
1313
aeson >= 2
1414
, hedgehog >= 1.1
15+
16+
test-show-details: direct

src/Test/Plutip/Contract.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module Test.Plutip.Contract (
132132
import BotPlutusInterface.Types (
133133
LogContext,
134134
LogLevel,
135-
LogLine (LogLine, logLineContext, logLineLevel, logLineMsg),
135+
LogLine (LogLine, logLineContext, logLineLevel),
136136
LogsList (getLogsList),
137137
sufficientLogLevel,
138138
)
@@ -387,7 +387,7 @@ instance
387387
render
388388
. vcat
389389
. zipWith indexedMsg [0 ..]
390-
. map logLineMsg
390+
. map pretty
391391
. filterOrDont
392392
. getLogsList
393393

src/Test/Plutip/Contract/Types.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ instance
5555
result <- runResult
5656
pure $
5757
bool
58-
(testFailed $ debugInfo predicate result)
58+
( testFailed $
59+
debugInfo predicate result
60+
<> "\n\n"
61+
<> "Use assertExecutionWith to show contract logs or budgets."
62+
)
5963
(testPassed "")
6064
(pCheck predicate result)
6165

src/Test/Plutip/Predicate.hs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import Data.Map (Map)
2929
import Data.Map qualified as Map
3030
import Ledger (ExBudget (ExBudget), ExCPU (ExCPU), ExMemory (ExMemory), TxId, Value)
3131
import PlutusCore.Evaluation.Machine.ExMemory (CostingInteger)
32+
import Prettyprinter (Doc, align, defaultLayoutOptions, indent, layoutPretty, viaShow, vsep, (<+>))
33+
import Prettyprinter.Render.String (renderString)
3234
import Test.Plutip.Internal.Types (
33-
ExecutionResult (contractState, outcome),
35+
ExecutionResult (ExecutionResult, contractState, outcome),
3436
FailureReason (CaughtException, ContractExecutionError),
3537
budgets,
3638
isSuccessful,
@@ -83,9 +85,23 @@ shouldSucceed =
8385
Predicate
8486
"Contract should succeed"
8587
"Contract should fail"
86-
(mappend "But it didn't.\nResult: " . show)
88+
(mappend "But it didn't.\nResult: " . renderString . layoutPretty defaultLayoutOptions . prettyExecutionResult)
8789
isSuccessful
8890

91+
-- | Pretty print ExecutionResult hiding budget stats and logs.
92+
prettyExecutionResult :: (Show e, Show w, Show a) => ExecutionResult e w a -> Doc ann
93+
prettyExecutionResult ExecutionResult {outcome, contractState} =
94+
vsep
95+
[ "Execution result {"
96+
, indent 4 $
97+
align $
98+
vsep
99+
[ "outcome:" <+> viaShow outcome
100+
, "final state: " <+> viaShow contractState
101+
]
102+
, "}"
103+
]
104+
89105
-- | Check that Contract didn't succeed.
90106
--
91107
-- @since 0.2

test/Spec/Integration.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ test =
9191
[ShowTraceButOnlyContext ContractLog $ Error [AnyLog]]
9292
"Contract 3"
9393
(initAda [100])
94-
(withContract $ const $ Contract.logInfo @Text "Some contract log with Info level." >> getUtxosThrowsEx)
94+
( withContract $
95+
const $ do
96+
Contract.logInfo @Text "Some contract log with Info level."
97+
Contract.logDebug @Text "Another contract log with debug level." >> getUtxosThrowsEx
98+
)
9599
[ shouldFail
96100
, Predicate.not shouldSucceed
97101
]

0 commit comments

Comments
 (0)