2

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

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

如何从场景中提取设置?

4

1 回答 1

2

得到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)
于 2019-09-13T15:33:57.893 回答