daml/daml-lf/tests/ConjunctionChoices.daml
Gary Verhaegen 151e12b81a
bump copyright (#16002)
This is the result of:

- Updating `./COPY` to say `2023`.
- Running `./dev-env/bin/dade-copyright-headers update .`
2023-01-04 18:21:15 +01:00

123 lines
3.5 KiB
Haskell

-- Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
-- The `demo` scenario below demonstrates
-- (1) a successful exercise of a choice with two controllers (necessarily in
-- the body of another choice),
-- (2) a failing attempt to exercise a choice with two controllers by the
-- wrong two actors,
-- (3) a failing attempt to exercise a choice with two controllers by just one
-- of them,
-- (4) a successful exercise of a choice with two controllers that actually
-- coincide through a direct commit.
--
-- There's a blog post about this example as well:
-- https://digitalasset.atlassian.net/wiki/spaces/DEL/blog/2018/06/14/595427344/Introducing+Conjunction+Choices
module ConjunctionChoices where
template PaintHouse
with
owner : Party
painter : Party
cleaner : Party
price : Decimal
where
signatory owner
signatory painter
signatory cleaner
template PaintHouseProposal
with
owner : Party
painter : Party
cleaner : Party
price : Decimal
where
signatory owner
observer [painter, cleaner]
choice PaintHouseProposal_Accept : ContractId PaintHouse
controller [painter, cleaner]
do create PaintHouse with owner; painter; cleaner; price
template PainterCleanerRelationship
with
painter : Party
cleaner : Party
threshold : Decimal
where
signatory painter
signatory cleaner
nonconsuming choice AcceptPaintHouse : ContractId PaintHouse
with cid : ContractId PaintHouseProposal
controller painter
do paintHouseProposal <- fetch cid
assert (paintHouseProposal.painter == painter)
assert (paintHouseProposal.cleaner == cleaner)
assert (paintHouseProposal.price >= threshold)
exercise cid PaintHouseProposal_Accept
template PainterCleanerProposal
with
painter : Party
cleaner : Party
threshold : Decimal
where
signatory painter
observer cleaner
choice PainterCleanerProposal_Accept : ContractId PainterCleanerRelationship
controller cleaner
do create PainterCleanerRelationship with painter; cleaner; threshold
demo = scenario do
alice <- getParty "Alice"
bob <- getParty "Bob"
charlie <- getParty "Charlie"
donald <- getParty "Donald"
eric <- getParty "Eric"
painterCleanerProposal <- submit bob do
create PainterCleanerProposal with
painter = bob
cleaner = charlie
threshold = 500.0
painterCleanerRelationship <- submit charlie do
exercise painterCleanerProposal PainterCleanerProposal_Accept
paintAlicesHouseProposal <- submit alice do
create PaintHouseProposal with
owner = alice
painter = bob
cleaner = charlie
price = 1000.0
submit bob do
exercise painterCleanerRelationship AcceptPaintHouse with
cid = paintAlicesHouseProposal
paintDonaldsTowerProposal1 <- submit donald do
create PaintHouseProposal with
owner = donald
painter = bob
cleaner = eric
price = 1000000.0
submitMustFail bob do
exercise painterCleanerRelationship AcceptPaintHouse with
cid = paintDonaldsTowerProposal1
submitMustFail bob do
exercise paintDonaldsTowerProposal1 PaintHouseProposal_Accept
paintDonaldsTowerProposal2 <- submit donald do
create PaintHouseProposal with
owner = donald
painter = bob
cleaner = bob
price = 1500000.0
submit bob do
exercise paintDonaldsTowerProposal2 PaintHouseProposal_Accept