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 <andreas.herrmann@tweag.io>
This commit is contained in:
Andreas Herrmann 2020-08-17 15:46:41 +02:00 committed by GitHub
parent 37d74287f1
commit 2903987a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 4 deletions

View File

@ -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:",

View File

@ -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)