From 2903987a61c75432d028d0ee6e4ab6709cb1eaa0 Mon Sep 17 00:00:00 2001 From: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com> Date: Mon, 17 Aug 2020 15:46:41 +0200 Subject: [PATCH] Handle all scenario results in DAML Script IDE client (#7154) * Handle all scenario results in DAML Script IDE client changelog_begin changelog_end * Address review comment Consistent error messages * DAML Script getTime in choice * Handle `SResultNeedTime` in DAML Script IdeClient * fmt Co-authored-by: Andreas Herrmann --- .../damlc/tests/src/DA/Test/ScriptService.hs | 23 ++++++++++++++++ .../lf/engine/script/LedgerInteraction.scala | 27 ++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/compiler/damlc/tests/src/DA/Test/ScriptService.hs b/compiler/damlc/tests/src/DA/Test/ScriptService.hs index ff2c3a3bbd..21c7620902 100644 --- a/compiler/damlc/tests/src/DA/Test/ScriptService.hs +++ b/compiler/damlc/tests/src/DA/Test/ScriptService.hs @@ -410,13 +410,36 @@ main = "import Daml.Script", "import DA.Date", "import DA.Time", + "template T", + " with", + " p : Party", + " where", + " signatory p", + " nonconsuming choice GetTime : Time", + " controller p", + " do getTime", "testTime = do", " t0 <- getTime", " setTime (time (date 2000 Feb 2) 0 1 2)", " t1 <- getTime", + " pure (t0, t1)", + "testChoiceTime = do", + " p <- allocateParty \"p\"", + " cid <- submit p $ createCmd T with p", + " t0 <- submit p $ exerciseCmd cid GetTime", + " setTime (time (date 2000 Feb 2) 0 1 2)", + " t1 <- submit p $ exerciseCmd cid GetTime", " pure (t0, t1)" ] expectScriptSuccess rs (vr "testTime") $ \r -> + matchRegex r $ + T.unlines + [ "Return value:", + " DA\\.Types:Tuple2@[a-z0-9]+ with", + " _1 = 1970-01-01T00:00:00Z; _2 = 2000-02-02T00:01:02Z", + "" + ] + expectScriptSuccess rs (vr "testChoiceTime") $ \r -> matchRegex r $ T.unlines [ "Return value:", diff --git a/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/LedgerInteraction.scala b/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/LedgerInteraction.scala index 5fe2705b56..915724faa0 100644 --- a/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/LedgerInteraction.scala +++ b/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/LedgerInteraction.scala @@ -441,16 +441,35 @@ class IdeClient(val compiledPackages: CompiledPackages) extends ScriptLedgerClie result = Success(Right(results.toSeq)) } } + case SResultFinalValue(v) => + // The final result should always be unit. + result = Failure(new RuntimeException(s"FATAL: Unexpected non-unit final result: $v")) case SResultScenarioCommit(_, _, _, _) => result = Failure( new RuntimeException("FATAL: Encountered scenario commit in DAML Script")) case SResultError(err) => // Capture the error and exit. result = Failure(err) - case err => - // TODO: Figure out when we hit this - // Capture the error (but not as SError) and exit. - result = Failure(new RuntimeException(s"FAILED: $err")) + case SResultNeedTime(callback) => + callback(scenarioRunner.ledger.currentTime) + case SResultNeedPackage(pkg, callback @ _) => + result = Failure( + new RuntimeException( + s"FATAL: Missing package $pkg should have been reported at Script compilation")) + case SResultScenarioInsertMustFail(committers @ _, optLocation @ _) => + result = Failure( + new RuntimeException( + "FATAL: Encountered scenario instruction for submitMustFail in DAML script")) + case SResultScenarioMustFail(ptx @ _, committers @ _, callback @ _) => + result = Failure( + new RuntimeException( + "FATAL: Encountered scenario instruction for submitMustFail in DAML Script")) + case SResultScenarioPassTime(relTime @ _, callback @ _) => + result = Failure( + new RuntimeException("FATAL: Encountered scenario instruction setTime in DAML Script")) + case SResultScenarioGetParty(partyText @ _, callback @ _) => + result = Failure( + new RuntimeException("FATAL: Encountered scenario instruction getParty in DAML Script")) } } Future.fromTry(result)