2

I'm writing multiple scenarios, with a similar setup:

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

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

The linter is suggesting I reduce duplication:

 /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

How can I extract the setup from the scenario?

1 Answers1

2

Got an answer from 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

For clarity, the type signature for parties is:

parties : Scenario (Party, Party)