首页 > 解决方案 > 如何在场景中断言合同处于非活动状态(存档)?

问题描述

如果我想验证合约是否处于活动状态,我可以简单地在场景中获取它:

template Something
  with
    party : Party
  where
    signatory party

    nonconsuming choice DoStuff : ()
      controller party
        do
          return ()


myTest = scenario do
  someone <- getParty "Someone"
  submit someone do
    cid <- create Something with party = someone 
    exercise cid DoStuff
    fetch cid  -- would fail if the DoStuff choice was consuming

我如何断言相反?

template Something
  with
    party : Party
  where
    signatory party

    choice DoStuff : ()
      controller party
        do
          return ()


myTest = scenario do
  someone <- getParty "Someone"
  submit someone do
    cid <- create Something with party = someone 
    exercise cid DoStuff
    fetch cid  -- fails the scenario, as it should, but that's what I want to check for

标签: daml

解决方案


此代码显示您可以将 a 链接cid到适当的范围内,以允许 asubmitMustFail以预期的方式运行:

myTest = scenario do
  someone <- getParty "Someone"
  cid <- submit someone do
    create Something with party = someone
  submit someone do
    exercise cid DoStuff
  submitMustFail someone do
    fetch cid  -- would fail if the DoStuff choice was consuming

推荐阅读