Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage oriented test-suite #324

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open

Usage oriented test-suite #324

wants to merge 39 commits into from

Conversation

gabrielhdt
Copy link
Contributor

@gabrielhdt gabrielhdt commented Mar 2, 2023

What is this all about

This PR provide a test suite designed around nominal use cases of Cooked. It ought to contain

  • a list of transactions testing different blockchain features (such as reference inputs or inline datums)
  • a list of validators grouped by the type of their datum.

Changes

  • Unit tests have been moved to tests/Cooked/Unit
  • Other, more high level tests (more or less integration tests) have been moved to tests/Cooked/Behaviour.
  • Module Cooked.Behaviour.Validators contains a collection of validators with unit datum and redeemers
  • Module Cooked.Behaviour.Elementary contains some standard-ish traces.

Questionable behaviours revealed so far

  • The balancing mechanism may spend UTxOs that contain reference scripts.
  • Using TxSkelRedeemerForScript when TxSkelRedeemerForReferenceScript yields the following confusing error message

    Validation error
    ( Phase1, CardanoLedgerValidationError "ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (WrappedShelleyEraFailure (ExtraneousScriptWitnessesUTXOW (fromList [ScriptHash "21f2f1c9624f836aded0ea2a7ff72179188ea3c49ae796c2cefbab1a"]))))]" )

  • Although the fee is available in the context, running validators that manipulate them has an undefined and confusing behaviour, see next section.

The problem with validators checking fees

Because the fee of a transaction is available in its context (see the datatype for contexts), one may write validators that succeed upon some condition over the fee. However, because the value of the fee depends on the complexity of the validator, the latter has to be run to compute the former. This leads to a fixpoint algorithm:

  1. set the fee to some arbitrary value $f_0$
  2. run the validator using that value and evaluate the cost of running the validator(s)
  3. fix the fee to $f_1$ and re-iterate until the fee has stabilised.

Therefore, the validator is run in several contexts which differ at least by their fee value. In particular, validators are always run at least once with $f_0$ so one cannot write a validator that succeeds if and only if the transaction it is run in has fees strictly smaller than $f_0$.

See issue #341.

@gabrielhdt gabrielhdt marked this pull request as draft March 9, 2023 11:10
@gabrielhdt gabrielhdt marked this pull request as ready for review March 13, 2023 14:54
Copy link
Contributor

@carlhammann carlhammann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @gabrielhdt, this is already a big improvement! I left a few comments, but I think we're close to getting this merged.

tests/Cooked/Behaviour/Elementary.hs Outdated Show resolved Hide resolved
tests/Cooked/Behaviour/Elementary.hs Outdated Show resolved Hide resolved
tests/Cooked/Behaviour/Elementary.hs Outdated Show resolved Hide resolved
tests/Cooked/Behaviour/Elementary.hs Outdated Show resolved Hide resolved
tests/Cooked/Behaviour/Elementary.hs Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this module! Can we have a few scripts (and tests) about staking as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this module should not live in the Behaviour hierarchy. We might want to use these validators also in unit tests for tweaks (if only to have some script to direct paysScripts to).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can test anything about staking here, it may be the case that some additional fields in the skeleton are needed

tests/Cooked/Unit/Attack/DupTokenSpec.hs Outdated Show resolved Hide resolved
tests/Cooked/Unit/Attack/DoubleSatSpec.hs Outdated Show resolved Hide resolved
tests/Cooked/Unit/Attack/DatumHijackingSpec.hs Outdated Show resolved Hide resolved
Replace walletToScript by walletToScriptHowDatum
Gabriel Hondet and others added 15 commits March 15, 2023 10:52
- Created a new 'Other' module where to put validators that are not Unit
- Moved validators from DoubleSatSpec to the Validators module
Use UTxO when we talk about resulting outputs of a transaction, *submit*
a transaction and *produce* an output or UTxO
Co-authored-by: carlhammann <102371507+carlhammann@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants