Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Produce tests from ContextBuilder alone #208

Open
blamario opened this issue Mar 28, 2022 · 3 comments
Open

Produce tests from ContextBuilder alone #208

blamario opened this issue Mar 28, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@blamario
Copy link

In production Plutus code one creates a transaction by constructing its constraints and lookups. The constraints may specify multiple input UTxOs to consume, and if they are locked by validators every validator script will be run in turn.

The same transaction constraints and lookups are provided by a ContextBuilder. However tasty-plutus insists that the user also specify a particular UTxO that's going to be tested. This is not only confusingly diverging from the Plutus model, but also gets rather annoying if there is more than one input UTxO locked by the same validator. The inFromValidator function already specifies which inputs are testable, but the user has to specify them again with a SpendingTest.

There could easily be a function

shouldValidateAllInputs :: ContextBuilder 'ForSpending n -> WithScript 'ForSpending ()

which would iterate over all ValidatorUTXOs in the given context and run the validator script for each of them in turn. They're even named, so individual tests can be described using those names.

Taking this a bit further and closer to the production code, we could have a variant of inFromValidator that takes a TestScript as an argument; then shouldValidateAllInputs could test multiple different scripts and return a TestTree directly.

@kozross kozross added the enhancement New feature or request label Mar 28, 2022
@maciej-bendkowski
Copy link

I would even suggest additional integration with makeIncompleteContexts for negative test cases. Eg:

shouldn'tValidateAllInputs :: [(ContextBuilder 'ForSpending n, String)] -> Tasty.TestTree

which combines all contexts using makeIncompleteContexts and creates a Tasty.TestTree of negative tests cases.

@kozross
Copy link
Contributor

kozross commented Mar 29, 2022

There's definitely some design there. I'll leave it to @re-xyr on how to best proceed.

@blamario
Copy link
Author

Has there been any progress on this? My opinion of the existing design keeps getting worse as I progress through writing the CardStarter IDO test suite. For evidence see https://github.com/mlabs-haskell/cardstarter-ido/blob/8632ed38a7bcb1de4ca1e835a05dff3fd4d61d89/test/Suites/CardStarterIDO/IDO/OnChain/Participate.hs

The tests in question are for a set of transactions that always have two input UTxOs locked by the same validator script. Among other issues this is causing:

  • Every unit test specifies either stateTestData or registrationTestData (sometimes modified) as its second argument. The choice depends on whether the validator implementation happens to perform the test against one input UTxO or the other. This makes specification-driven black-box testing impossible.
  • Because the input specified by this argument gets inserted into the script context, every test takes care to remove its duplicate from completeContext which already contains it. There may be a way to refactor this in a saner form but it's not obvious.
  • I'd love to be able to use makeIncompleteContexts, but some of the incomplete contexts would need to be tested with one input and some with the other.

If nobody else is working on this issue I can take it up.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants
@maciej-bendkowski @blamario @kozross @re-xyr and others