Skip to content

Commit

Permalink
Merge branch 'master' into gergely/vasil
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekeke committed Aug 18, 2022
2 parents 9a60d36 + 03c3597 commit bbc760e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ allow-newer:
constraints:
aeson >= 2
, hedgehog >= 1.1

test-show-details: direct
4 changes: 2 additions & 2 deletions src/Test/Plutip/Contract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module Test.Plutip.Contract (
import BotPlutusInterface.Types (
LogContext,
LogLevel,
LogLine (LogLine, logLineContext, logLineLevel, logLineMsg),
LogLine (LogLine, logLineContext, logLineLevel),
LogsList (getLogsList),
sufficientLogLevel,
)
Expand Down Expand Up @@ -387,7 +387,7 @@ instance
render
. vcat
. zipWith indexedMsg [0 ..]
. map logLineMsg
. map pretty
. filterOrDont
. getLogsList

Expand Down
6 changes: 5 additions & 1 deletion src/Test/Plutip/Contract/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ instance
result <- runResult
pure $
bool
(testFailed $ debugInfo predicate result)
( testFailed $
debugInfo predicate result
<> "\n\n"
<> "Use assertExecutionWith to show contract logs or budgets."
)
(testPassed "")
(pCheck predicate result)

Expand Down
20 changes: 18 additions & 2 deletions src/Test/Plutip/Predicate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import Data.Map (Map)
import Data.Map qualified as Map
import Ledger (ExBudget (ExBudget), ExCPU (ExCPU), ExMemory (ExMemory), TxId, Value)
import PlutusCore.Evaluation.Machine.ExMemory (CostingInteger)
import Prettyprinter (Doc, align, defaultLayoutOptions, indent, layoutPretty, viaShow, vsep, (<+>))
import Prettyprinter.Render.String (renderString)
import Test.Plutip.Internal.Types (
ExecutionResult (contractState, outcome),
ExecutionResult (ExecutionResult, contractState, outcome),
FailureReason (CaughtException, ContractExecutionError),
budgets,
isSuccessful,
Expand Down Expand Up @@ -83,9 +85,23 @@ shouldSucceed =
Predicate
"Contract should succeed"
"Contract should fail"
(mappend "But it didn't.\nResult: " . show)
(mappend "But it didn't.\nResult: " . renderString . layoutPretty defaultLayoutOptions . prettyExecutionResult)
isSuccessful

-- | Pretty print ExecutionResult hiding budget stats and logs.
prettyExecutionResult :: (Show e, Show w, Show a) => ExecutionResult e w a -> Doc ann
prettyExecutionResult ExecutionResult {outcome, contractState} =
vsep
[ "Execution result {"
, indent 4 $
align $
vsep
[ "outcome:" <+> viaShow outcome
, "final state: " <+> viaShow contractState
]
, "}"
]

-- | Check that Contract didn't succeed.
--
-- @since 0.2
Expand Down
6 changes: 5 additions & 1 deletion test/Spec/Integration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ test =
[ShowTraceButOnlyContext ContractLog $ Error [AnyLog]]
"Contract 3"
(initAda [100])
(withContract $ const $ Contract.logInfo @Text "Some contract log with Info level." >> getUtxosThrowsEx)
( withContract $
const $ do
Contract.logInfo @Text "Some contract log with Info level."
Contract.logDebug @Text "Another contract log with debug level." >> getUtxosThrowsEx
)
[ shouldFail
, Predicate.not shouldSucceed
]
Expand Down

0 comments on commit bbc760e

Please sign in to comment.