mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
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:
parent
37d74287f1
commit
2903987a61
@ -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:",
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user