Couldn't match type 'Scenario' with 'Script'
App Development2 posts563 views2 likesLast activity Feb 2022
NE
nemanjaOP
Feb 2022Hi Damlers ![]()
I have a very simple Daml script that used to work:
test = script do
alice <- allocateParty "Alice"
p <- submit alice $ createCmd $ PersonContract {name = alice, address = Address {street = "RabbitStreet", city = "QueenOfHearts", country = "Wonderland"}, age = 7}
submit alice $ do
c <- fetch p
assert $ c.name == alice
Trying to run it now i get the following error:
/root/organizer/daml/AddressBook.daml:32:3: error:
• Couldn't match type 'Scenario' with 'Script'
arising from a functional dependency between:
constraint 'HasSubmit Script Update' arising from a use of 'submit'
instance 'HasSubmit Scenario Update' at <no location info>
• In the expression: submit alice
In a stmt of a 'do' block:
submit alice
$ do c <- fetch p
assert $ (getField @"name" c) == alice
In the first argument of 'script', namely
'do alice <- allocateParty "Alice"
What’s the reason for it?
CO
cocreature
Feb 2022Hi @nemanja,
First, just to avoid confusion: This was never a valid Daml Script. However, if you replace allocateParty by getParty and createCmd by create and script by scenario it is a valid scenario. So it broke by migrating it to a Script.
The reason for that is documented in the migration guide in point 5.2. Applying that switch from fetch to queryContractId, you end up with
test = script do
alice <- allocateParty "Alice"
p <- submit alice $ createCmd $ PersonContract {name = alice, address = Address {street = "RabbitStreet", city = "QueenOfHearts", country = "Wonderland"}, age = 7}
Some c <- queryContractId alice p
assert $ c.name == alice
You might also want to switch the last line to c.name === alice which provides you with a better error message on failure. Note that you need to add an extra import to DA.Assert for that to compile.