-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* interfaces: lf conversion of preconditions This adds the LF conversion of preconditions from the desugared GHC code to Daml LF for preconditions. This depends on the corresponding patch of the GHC fork. CHANGELOG_BEGIN CHANGELOG_END * pin linux stackage snapshot * added a test CHANGELOG_BEGIN CHANGELOG_END * pinned linux stackage snapshot CHANGELOG_BEGIN CHANGELOG_END * additional InterfacePrecondition test this checks that that conjunction of all preconditions of intererfaces and templates is checked. CHANGELOG_BEGIN CHANGELOG_END * pin stackage snapshot * pin windows stackage snapshot * update compile.yml (again) * pin linux stack snapshot * fix InterfacePrecondition test * pin windows stackage
- Loading branch information
Robin Krom
authored
Nov 9, 2021
1 parent
f722cf1
commit af1bee7
Showing
8 changed files
with
156 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
compiler/damlc/tests/daml-test-files/InterfacePrecondition.daml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
-- Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- @SINCE-LF-FEATURE DAML_INTERFACE | ||
|
||
module InterfacePrecondition where | ||
|
||
interface Token1 where | ||
getOwner1 : Party | ||
getAmount1 : Int | ||
splitImpl : Int -> Update (ContractId Token1, ContractId Token1) | ||
transferImpl : Party -> Update (ContractId Token1) | ||
|
||
ensure (getAmount1 this >= 0 && getAmount1 this <= 7) | ||
|
||
choice Split : (ContractId Token1, ContractId Token1) | ||
with | ||
splitAmount : Int | ||
controller getOwner1 this | ||
do | ||
splitImpl this splitAmount | ||
|
||
choice Transfer : ContractId Token1 | ||
with | ||
newOwner : Party | ||
controller getOwner1 this, newOwner | ||
do | ||
transferImpl this newOwner | ||
|
||
|
||
interface Token2 where | ||
getOwner2 : Party | ||
getAmount2 : Int | ||
noopImpl : () -> Update () | ||
|
||
ensure (getAmount2 this >= 3 && getAmount2 this <= 10) | ||
|
||
nonconsuming choice Noop : () | ||
with | ||
nothing : () | ||
controller getOwner2 this | ||
do | ||
noopImpl this nothing | ||
|
||
template Asset | ||
with | ||
issuer : Party | ||
owner : Party | ||
amount : Int | ||
where | ||
signatory issuer, owner | ||
|
||
ensure (amount >= 5 && amount <= 6) | ||
|
||
implements Token1 where | ||
let getOwner1 = owner | ||
let getAmount1 = amount | ||
let splitImpl = \splitAmount -> do | ||
assert (splitAmount < amount) | ||
cid1 <- create this with amount = splitAmount | ||
cid2 <- create this with amount = amount - splitAmount | ||
pure (toToken1ContractId cid1, toToken1ContractId cid2) | ||
let transferImpl = \newOwner -> do | ||
cid <- create this with owner = newOwner | ||
pure (toToken1ContractId cid) | ||
|
||
|
||
implements Token2 where | ||
let getOwner2 = owner | ||
let getAmount2 = amount | ||
let noopImpl = \nothing -> do | ||
pure () | ||
|
||
main = scenario do | ||
p <- getParty "Alice" | ||
p `submitMustFail` do | ||
create Asset with | ||
issuer = p | ||
owner = p | ||
amount = -1 -- violates ensure of Token1 & Token2 & Asset | ||
|
||
p `submitMustFail` do | ||
create Asset with | ||
issuer = p | ||
owner = p | ||
amount = 1 -- violates ensure of Token2 && Asset | ||
|
||
p `submitMustFail` do | ||
create Asset with | ||
issuer = p | ||
owner = p | ||
amount = 3 -- violates ensure of Asset | ||
|
||
p `submitMustFail` do | ||
create Asset with | ||
issuer = p | ||
owner = p | ||
amount = 7 -- violates ensure of Asset | ||
|
||
p `submitMustFail` do | ||
create Asset with | ||
issuer = p | ||
owner = p | ||
amount = 8 -- violates ensure of Asset & Token2 | ||
|
||
p `submit` do | ||
create Asset with | ||
issuer = p | ||
owner = p | ||
amount = 5 -- works for Token1 & Token2 & Asset | ||
pure () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.