Using data sheet to feed parameters to scenarios

Mod note: As of SDK 1.5.0 Scenarios have been superseded by the more powerful Daml Script. We now recommend using that for all purposes. For more information, and to learn how to use Script please check out @Andreas’ post on our blog.

Hi,

Is there a way to have dynamic scenarios meaning that different parameters would be fed to the written scenario from a data sheet (e.g. csv, xls) for unit testing?

Thanks in advance.

1 Like

Scenarios run DAML, which is a side-effect-free language, so you can’t do I/O. Well, that’s almost true: the only effects you can use are trace and debug, inside of scenarios.

AFAIK the only way to get close to what you want is to use DAML Script with the --input-file option, to supply arguments to a DAML script at startup. Do note that scripts are less powerful than scenarios: you can’t use fetch, or you can’t use the results of an exercise within the same submit block.

2 Likes

To add to @oggy’s response: the JSON input file needs to follow the standard DAML-LF JSON encoding as described here.

I actually think scripts are more powerful than scenarios as you can do query instead of just fetch. I’ve never found the limitation that individual commands in a submit block can’t depend on each other quite… limiting tbh.

EDIT: The only real downside is that you don’t get the interactive IDE experience of exploring the transaction tree or the active contract tables. I’m hoping that we get that integration with scripts eventually, at which point I don’t see any reason for scenarios to continue to exist.

1 Like

Note that you can always work around this by making a template with a single choice that has the things that depend on each other and calling that via createAndExercise.

2 Likes

And the same thing works for fetch.

1 Like