Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Krom committed Oct 25, 2021
1 parent 54528e7 commit e2b0dc4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions compiler/damlc/daml-stdlib-src/DA/Internal/Desugar.daml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module DA.Internal.Desugar (
Party, ContractId, Update, Any,
NonConsuming(..), PreConsuming(..), PostConsuming(..), Consuming(..),
Implements(..),
TypeRep,
) where

import DA.Internal.Prelude
Expand Down
5 changes: 5 additions & 0 deletions compiler/damlc/tests/daml-test-files/InterfaceDesugared.daml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
module InterfaceDesugared where

import DA.Assert ((===))
import DA.Action (unless)

data Split = Split { splitAmount : Int }

Expand All @@ -28,6 +29,7 @@ class
fromToken : Token -> Optional t
toTokenContractId : ContractId t -> ContractId Token
fromTokenContractId : ContractId Token -> Update (Optional (ContractId t))
tokenTypeRep : t -> DA.Internal.Desugar.TypeRep
getOwner : t -> Party
getAmount : t -> Int
setAmount : t -> Int -> Token
Expand Down Expand Up @@ -56,6 +58,7 @@ instance IsToken Token where
fromToken = GHC.Types.primitive @"EFromInterface"
toTokenContractId = GHC.Types.primitive @"EToInterfaceContractId"
fromTokenContractId = GHC.Types.primitive @"UFromInterfaceContractId"
tokenTypeRep = GHC.Types.primitive @"$TO_TYPE_REP"
getOwner = GHC.Types.primitiveInterface @"getOwner"
getAmount = GHC.Types.primitiveInterface @"getAmount"
setAmount = GHC.Types.primitiveInterface @"setAmount"
Expand Down Expand Up @@ -114,6 +117,7 @@ instance IsToken Asset where
fromToken = GHC.Types.primitive @"EFromInterface"
toTokenContractId = GHC.Types.primitive @"EToInterfaceContractId"
fromTokenContractId = GHC.Types.primitive @"UFromInterfaceContractId"
tokenTypeRep = GHC.Types.primitive @"$TO_TYPE_REP"
getOwner Asset{..} = owner
getAmount Asset{..} = amount
setAmount this x = toToken (this with amount = x)
Expand Down Expand Up @@ -242,5 +246,6 @@ main = scenario do
None -> abort "expected Asset"
Some Asset {amount} ->
amount === 25
unless (tokenTypeRep token3 == tokenTypeRep token4) $ error "Type representations are different."

pure ()
28 changes: 26 additions & 2 deletions compiler/damlc/tests/daml-test-files/InterfaceExperimental.daml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ template NotAsset
where
signatory p

implements Token where
let getAmount = error "getAmount"

choice Split : (ContractId Token, ContractId Token)
with
splitAmount : Int
controller p
do
error "Split"

choice Transfer : ContractId Token
with
newOwner : Party
controller p
do
error "Transfer"

nonconsuming choice Noop : ()
with
nothing : ()
controller p
do
error "Noop"

main = scenario do
alice <- getParty "Alice"
bob <- getParty "Bob"
Expand All @@ -79,6 +103,6 @@ main = scenario do
interfaceCreate token
interfaceSignatory token === [alice]
interfaceObserver token === [bob, alice]
unless (toTypeRep token == toTypeRep asset) $ abort "TypeReps are not equal"
unless (toTypeRep token /= toTypeRep notAsset) $ abort "TypeReps are equal"
unless (tokenTypeRep token == tokenTypeRep asset) $ abort "TypeReps are not equal"
unless (tokenTypeRep token /= tokenTypeRep notAsset) $ abort "TypeReps are equal"
pure ()

0 comments on commit e2b0dc4

Please sign in to comment.