Skip to content

Commit 09a1b44

Browse files
Only include stakeholder contracts in result of query (#7291)
* Only include stakeholder contracts in result of query This fixes a bug in the script service. We need to filter out divulged contracts since this should behave exactly like the ACS endpoint on the ledger API. changelog_begin changelog_end * Update daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/scenario/ScenarioLedger.scala Co-authored-by: Remy <[email protected]> * Update daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/LedgerInteraction.scala Co-authored-by: Remy <[email protected]> * fmt changelog_begin changelog_end Co-authored-by: Remy <[email protected]>
1 parent f8a82ad commit 09a1b44

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

compiler/damlc/tests/src/DA/Test/ScriptService.hs

+17-1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ main =
281281
" where",
282282
" signatory p1",
283283
" observer p2",
284+
"template Divulger",
285+
" with",
286+
" divulgee : Party",
287+
" sig : Party",
288+
" where",
289+
" signatory divulgee",
290+
" observer sig",
291+
" nonconsuming choice Divulge : T1",
292+
" with cid : ContractId T1",
293+
" controller sig",
294+
" do fetch cid",
284295
"testQueryInactive = do",
285296
" p <- allocateParty \"p\"",
286297
" cid1_1 <- submit p (createCmd (T1 p 42))",
@@ -300,6 +311,7 @@ main =
300311
"testQueryVisibility = do",
301312
" p1 <- allocateParty \"p1\"",
302313
" p2 <- allocateParty \"p2\"",
314+
" divulger <- submit p2 (createCmd (Divulger p2 p1))",
303315
" cidT1p1 <- submit p1 (createCmd (T1 p1 42))",
304316
" cidT1p2 <- submit p2 (createCmd (T1 p2 23))",
305317
" cidSharedp1 <- submit p1 (createCmd (TShared p1 p2))",
@@ -308,6 +320,10 @@ main =
308320
" t1p1 === [(cidT1p1, T1 p1 42)]",
309321
" t1p2 <- query @T1 p2",
310322
" t1p2 === [(cidT1p2, T1 p2 23)]",
323+
-- Divulgence should not influence query result
324+
" submit p1 $ exerciseCmd divulger (Divulge cidT1p1)",
325+
" t1p2 <- query @T1 p2",
326+
" t1p2 === [(cidT1p2, T1 p2 23)]",
311327
" sharedp1 <- query @TShared p1",
312328
" sharedp1 === [(cidSharedp1, TShared p1 p2), (cidSharedp2, TShared p2 p1)]",
313329
" sharedp2 <- query @TShared p2",
@@ -316,7 +332,7 @@ main =
316332
expectScriptSuccess rs (vr "testQueryInactive") $ \r ->
317333
matchRegex r "Active contracts: #2:0, #0:0\n\n"
318334
expectScriptSuccess rs (vr "testQueryVisibility") $ \r ->
319-
matchRegex r "Active contracts: #0:0, #1:0, #2:0, #3:0\n\n"
335+
matchRegex r "Active contracts: #4:0, #3:0, #2:0, #0:0, #1:0\n\n"
320336
pure (),
321337
testCase "submitMustFail" $ do
322338
rs <-

daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/scenario/ScenarioLedger.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,12 @@ case class ScenarioLedger(
593593

594594
def query(
595595
view: View,
596-
effectiveAt: Time.Timestamp): Seq[(ContractId, ContractInst[Tx.Value[ContractId]])] = {
596+
effectiveAt: Time.Timestamp,
597+
): Seq[LookupOk] = {
597598
ledgerData.activeContracts.toList
598599
.map(cid => lookupGlobalContract(view, effectiveAt, cid))
599600
.collect {
600-
case LookupOk(cid, coinst, _) => (cid, coinst)
601+
case l @ LookupOk(_, _, _) => l
601602
}
602603
}
603604

daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/LedgerInteraction.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,10 @@ class IdeClient(val compiledPackages: CompiledPackages) extends ScriptLedgerClie
364364
val acs = scenarioRunner.ledger.query(
365365
view = ScenarioLedger.ParticipantView(party.value),
366366
effectiveAt = scenarioRunner.ledger.currentTime)
367-
// Filter to contracts of the given template id.
368367
val filtered = acs.collect {
369-
case (cid, Value.ContractInst(tpl, arg, _)) if tpl == templateId => (cid, arg)
368+
case ScenarioLedger.LookupOk(cid, Value.ContractInst(tpl, arg, _), stakeholders)
369+
if tpl == templateId && stakeholders.contains(party.value) =>
370+
(cid, arg)
370371
}
371372
Future.successful(filtered.map {
372373
case (cid, c) => ScriptLedgerClient.ActiveContract(templateId, cid, c.value)

0 commit comments

Comments
 (0)