Skip to content

Commit

Permalink
LF: Check activeness of cached contracts inside FetchInterface (digit…
Browse files Browse the repository at this point in the history
…al-asset#12698)

Missed in digital-asset#12527.

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored Feb 1, 2022
1 parent aa2494f commit ed1bf24
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
59 changes: 59 additions & 0 deletions compiler/damlc/tests/daml-test-files/InterfaceDoubleSpend.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

-- TODO https://github.com/digital-asset/daml/issues/12697
-- This should be tested as part of evaluation order for FetchInterface
-- Drop this test once it is done

-- @SINCE-LF-FEATURE DAML_INTERFACE
module InterfaceDoubleSpend where

-- | An interface comment.
interface Token where
getIssuer : Party
getOwner : Party
getAmount : Int

transferImpl : Party -> Update (ContractId Token)

ensure (getAmount this >= 0)

choice Transfer : ContractId Token
with
newOwner : Party
controller getIssuer this
do
transferImpl this newOwner

template Asset
with
issuer : Party
owner : Party
amount : Int
where
signatory issuer
observer owner
implements Token where
let getOwner = owner
let getIssuer = issuer
let getAmount = amount
let transferImpl = \newOwner -> do
cid <- create this with owner = newOwner
pure (toInterfaceContractId @Token cid)

main = scenario do
alice <- getParty "Alice"
bob <- getParty "Bob"
charlie <- getParty "Charlie"
cidAsset1 <- alice `submit` do
create Asset with
issuer = alice
owner = alice
amount = 15
_ <- alice `submitMustFail` do
_ <- exercise (toInterfaceContractId @Token cidAsset1) (Transfer bob)
_ <- exercise (toInterfaceContractId @Token cidAsset1) (Transfer charlie)
pure ()
pure ()

-- @ENABLE-SCENARIOS
Original file line number Diff line number Diff line change
Expand Up @@ -1120,11 +1120,17 @@ private[lf] object SBuiltin {
}

onLedger.cachedContracts.get(coid) match {
case Some(cached) => {
case Some(cached) =>
onLedger.ptx.consumedBy
.get(coid)
.foreach(nid =>
throw SErrorDamlException(
IE.ContractNotActive(coid, expectedTemplateIdOpt.getOrElse(ifaceId), nid)
)
)
checkTemplateId(cached.templateId) {
machine.returnValue = cached.value
}
}
case None =>
throw SpeedyHungry(
SResultNeedContract(
Expand Down

0 comments on commit ed1bf24

Please sign in to comment.