forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Eq instances for AnyTemplate, AnyChoice and AnyContractKey (digit…
…al-asset#3816) * Add Eq instances for AnyTemplate, AnyChoice and AnyContractKey CHANGELOG_BEGIN - [DAML Standard Library] Add ``Eq`` instances for ``AnyTemplate``, ``AnyChoice`` and ``AnyContractKey``. CHANGELOG_END * Add DAML_ANY_TYPE to the CPP guard
- Loading branch information
1 parent
ac47a84
commit 013d668
Showing
2 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- Copyright (c) 2019, Digital Asset (Switzerland) GmbH and/or its affiliates. | ||
-- All rights reserved. | ||
|
||
-- @SINCE-LF 1.8 | ||
daml 1.2 | ||
module AnyEq where | ||
|
||
import DA.Action | ||
|
||
template T1 | ||
with | ||
x : Int | ||
p : Party | ||
where | ||
signatory p | ||
key p : Party | ||
maintainer key | ||
choice C : () | ||
controller p | ||
do pure () | ||
|
||
template T1' | ||
with | ||
x : Int | ||
p : Party | ||
where | ||
signatory p | ||
key p : Party | ||
maintainer key | ||
|
||
template T2 | ||
with | ||
y : Text | ||
p : Party | ||
where | ||
signatory p | ||
key (p, y) : (Party, Text) | ||
maintainer key._1 | ||
|
||
-- We don’t have a Show instance for AnyTemplate so we cannot use === | ||
|
||
assertBool : CanAbort m => Text -> Bool -> m () | ||
assertBool err success = unless success $ abort ("Failure: " <> show err) | ||
|
||
main = scenario do | ||
p <- getParty "alice" | ||
let t1A = T1 0 p | ||
let t1B = T1 1 p | ||
let t1'A = T1' 0 p | ||
assertBool (show (t1A, t1A)) (toAnyTemplate t1A == toAnyTemplate t1A) | ||
assertBool (show (t1A, t1B)) (toAnyTemplate t1A /= toAnyTemplate t1B) | ||
assertBool (show (t1'A, t1'A)) (toAnyTemplate t1'A == toAnyTemplate t1'A) | ||
assertBool (show (t1A, t1'A)) (toAnyTemplate t1A /= toAnyTemplate t1'A) | ||
assertBool (show (C, C)) (toAnyChoice @T1 C == toAnyChoice @T1 C) | ||
assertBool (show (C, Archive)) (toAnyChoice @T1 C /= toAnyChoice @T1 Archive) | ||
assertBool ("T1, T2" <> show (Archive, Archive)) (toAnyChoice @T1 C /= toAnyChoice @T2 Archive) | ||
assertBool ("T1, T1'" <> show (p, p)) (toAnyContractKey @T1 p /= toAnyContractKey @T1' p) | ||
assertBool ("T1, T1" <> show (p, p)) (toAnyContractKey @T1 p == toAnyContractKey @T1 p) |