【问题标题】:In DAML scenarios, how do I reuse getParty?DAML场景下,如何复用getParty?
【发布时间】:2019-09-13 15:32:21
【问题描述】:

我正在使用类似的设置编写多个场景:

test0 = scenario do
  bank <- getParty "Bank"
  alice <- getParty "Alice"
  -- ....
  assert True

test1 = scenario do
  bank <- getParty "Bank"
  alice <- getParty "Alice"
  -- ...
  assert True

linter 建议我减少重复:

 /Foo.daml:5:3: Suggestion: Reduce duplication
  Found:
  bank <- getParty "Bank"
  alice <- getParty "Alice"
  assert True
  Perhaps:
  Combine with /Users/shaynefletcher/Foo.daml:11:3

如何从场景中提取设置?

【问题讨论】:

    标签: daml


    【解决方案1】:

    得到了 Shayne F 的回答:

    parties = do
      bank <- getParty "Bank"
      alice <- getParty "Alice"
      return (bank, alice)
    
    test0 = scenario do
      (bank, alice) <- parties
      -- ....
      assert True
    
    test1 = scenario do
      (bank, alice) <- parties
      -- ...
      assert True
    

    为清楚起见,parties 的类型签名是:

    parties : Scenario (Party, Party)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-23
      • 2021-11-15
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      • 2015-05-05
      • 2016-03-03
      • 1970-01-01
      相关资源
      最近更新 更多