Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only include stakeholder contracts in result of query #7291

Merged
merged 4 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
cocreature committed Sep 1, 2020
commit 354073a12355aef58eb03891ba050226121c6e37
18 changes: 17 additions & 1 deletion compiler/damlc/tests/src/DA/Test/ScriptService.hs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,17 @@ main =
" where",
" signatory p1",
" observer p2",
"template Divulger",
" with",
" divulgee : Party",
" sig : Party",
" where",
" signatory divulgee",
" observer sig",
" nonconsuming choice Divulge : T1",
" with cid : ContractId T1",
" controller sig",
" do fetch cid",
"testQueryInactive = do",
" p <- allocateParty \"p\"",
" cid1_1 <- submit p (createCmd (T1 p 42))",
Expand All @@ -300,6 +311,7 @@ main =
"testQueryVisibility = do",
" p1 <- allocateParty \"p1\"",
" p2 <- allocateParty \"p2\"",
" divulger <- submit p2 (createCmd (Divulger p2 p1))",
" cidT1p1 <- submit p1 (createCmd (T1 p1 42))",
" cidT1p2 <- submit p2 (createCmd (T1 p2 23))",
" cidSharedp1 <- submit p1 (createCmd (TShared p1 p2))",
Expand All @@ -308,6 +320,10 @@ main =
" t1p1 === [(cidT1p1, T1 p1 42)]",
" t1p2 <- query @T1 p2",
" t1p2 === [(cidT1p2, T1 p2 23)]",
-- Divulgence should not influence query result
" submit p1 $ exerciseCmd divulger (Divulge cidT1p1)",
" t1p2 <- query @T1 p2",
" t1p2 === [(cidT1p2, T1 p2 23)]",
" sharedp1 <- query @TShared p1",
" sharedp1 === [(cidSharedp1, TShared p1 p2), (cidSharedp2, TShared p2 p1)]",
" sharedp2 <- query @TShared p2",
Expand All @@ -316,7 +332,7 @@ main =
expectScriptSuccess rs (vr "testQueryInactive") $ \r ->
matchRegex r "Active contracts: #2:0, #0:0\n\n"
expectScriptSuccess rs (vr "testQueryVisibility") $ \r ->
matchRegex r "Active contracts: #0:0, #1:0, #2:0, #3:0\n\n"
matchRegex r "Active contracts: #4:0, #3:0, #2:0, #0:0, #1:0\n\n"
pure (),
testCase "submitMustFail" $ do
rs <-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,11 @@ case class ScenarioLedger(

def query(
view: View,
effectiveAt: Time.Timestamp): Seq[(ContractId, ContractInst[Tx.Value[ContractId]])] = {
effectiveAt: Time.Timestamp): Seq[LookupOk] = {
cocreature marked this conversation as resolved.
Show resolved Hide resolved
ledgerData.activeContracts.toList
.map(cid => lookupGlobalContract(view, effectiveAt, cid))
.collect {
case LookupOk(cid, coinst, _) => (cid, coinst)
case l @ LookupOk(_ , _, _) => l
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class IdeClient(val compiledPackages: CompiledPackages) extends ScriptLedgerClie
effectiveAt = scenarioRunner.ledger.currentTime)
// Filter to contracts of the given template id.
cocreature marked this conversation as resolved.
Show resolved Hide resolved
val filtered = acs.collect {
case (cid, Value.ContractInst(tpl, arg, _)) if tpl == templateId => (cid, arg)
case ScenarioLedger.LookupOk(cid, Value.ContractInst(tpl, arg, _), stakeholders) if tpl == templateId && stakeholders.contains(party.value) => (cid, arg)
}
Future.successful(filtered.map {
case (cid, c) => ScriptLedgerClient.ActiveContract(templateId, cid, c.value)
Expand Down