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

Adding errors to actions to help negative testing #58

Merged
merged 14 commits into from
Feb 16, 2024

Conversation

MaximilianAlgehed
Copy link
Collaborator

@MaximilianAlgehed MaximilianAlgehed commented Sep 19, 2023

Adding errors to action types makes it easier to build clean models that deal with negative testing by allowing you to clearly distinguish the failing and correct cases. The thing I'm not yet happy about is having to sprinkle Rights in the results. Suggestions welcome!

Checklist:

  • Check source-code formatting is consistent

@MaximilianAlgehed MaximilianAlgehed requested review from UlfNorell and a user and removed request for UlfNorell September 19, 2023 12:17
@MaximilianAlgehed
Copy link
Collaborator Author

@abailly-iohk any input on this would be welcome.

@MaximilianAlgehed MaximilianAlgehed force-pushed the PR-negative-testing-errors branch from 6d9582f to 42b4f55 Compare September 25, 2023 11:37
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

This is a significant (eg. breaking) change the advantages of which are not clear to me: From the RegistryModel I don't see what the added complexity in additional type parameters and mandatory Either results improves in the DX. It seems the only significant change is in the postCondition and postConditionOnFailure implementations and the added value does not seem to be worth the effort to my eyes.
Is there a model somewhere, perhaps in Plutus land, where this way of "first-class" handling of errors would be more beneficial?

@MaximilianAlgehed
Copy link
Collaborator Author

MaximilianAlgehed commented Oct 9, 2023

This is a significant (eg. breaking) change the advantages of which are not clear to me: From the RegistryModel I don't see what the added complexity in additional type parameters and mandatory Either results improves in the DX.

The mandatory Either result is annoying - I agree. I would like to find a nice way to get around that. One way would be to have a monad transformer RunMonad e that is basically an error transformer that would hide this.

It seems the only significant change is in the postCondition and postConditionOnFailure implementations

Yes, this is the idea. The point is that in the case where there can be errors in the model you can add those errors without having to clutter the model with the possibility of error. The whole point is that actions can fail but that failure shouldn't appear in the model - so nextState shouldn't have to deal with the fact that an action can fail.

the added value does not seem to be worth the effort to my eyes.

Well, the effort has already been made 😅 and the migration guide is basically "add Right and a type parameter" so I don't see that as being very onerous.

Is there a model somewhere ... where this ... would be more beneficial?

There are examples in djed that we can't show yet. But let's do a hypothetical example. You have some action InitNewThing :: SomeParameters -> Action MyModel ThingHandle (by the old model) and your nextState uses the symbolic Var ThingHandle to associate something in SomeParameters to ThingHandle (e.g. a name in SomeParameters is associated with a contract instance in ThingHandle, or a hash in ThingHandle or whatever). Consequently, your MyModel contains a bunch of references to Var ThingHandle that you use in various places in perform (e.g. in the case for some DoThing :: Var ThingHandle -> Action MyModel () action). Imagine you want to add negative testing to this, now every Var ThingHandle will be a Var (Either SomeError ThingHandle) - which will clutter your entire model! Yuck! With this change, you don't have this any more, the action will be InitNewThing :: SomeParameters -> Action MyModel SomeError ThingHandle and all the Var ThingHandle will remain as such.

@ghost
Copy link

ghost commented Oct 10, 2023

Well, if this ship has sailed already, then no need to wait for me :)

@abailly abailly force-pushed the PR-negative-testing-errors branch from 42b4f55 to 96ee628 Compare December 4, 2023 21:30
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

How about having an ActionError s associated type family instead of an additional type parameter? Seems to me the blast radius of the change would be smaller and in general more consistent with the overall approach we have so far followed. WDYT @MaximilianAlgehed ?

@MaximilianAlgehed
Copy link
Collaborator Author

@abailly-iohk I'm off for the next ~2 weeks so I'll let @UlfNorell handle this.

@MaximilianAlgehed
Copy link
Collaborator Author

But without having tried ut our thought about it I think it sounds like a good idea!

@ghost
Copy link

ghost commented Jan 22, 2024

Great, I will give it a shot as I might have some bandwidth available for the rest of the week :)

@ghost
Copy link

ghost commented Jan 26, 2024

I had a quick stab at replacing class' type variable with an associated type-family but did not go far yet. Will try again today.

@UlfNorell
Copy link
Collaborator

We had a go at the associated type and it seems to work quite well. Now you don't get the Either in perform unless you have defined an error type.

Some documentation still todo.

@MaximilianAlgehed
Copy link
Collaborator Author

@abailly-iohk what do you think about this now?

@MaximilianAlgehed MaximilianAlgehed requested a review from a user February 15, 2024 12:11
@MaximilianAlgehed MaximilianAlgehed force-pushed the PR-negative-testing-errors branch from 9c358af to 28a4965 Compare February 15, 2024 12:12
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

I like the way this is now done much more, thanks for taking into account my suggestion. Minor comments left which could be addressed later.

quickcheck-dynamic/src/Test/QuickCheck/StateModel.hs Outdated Show resolved Hide resolved
quickcheck-dynamic/quickcheck-dynamic.cabal Show resolved Hide resolved
@MaximilianAlgehed MaximilianAlgehed merged commit 5ebbf12 into main Feb 16, 2024
7 checks passed
@MaximilianAlgehed MaximilianAlgehed deleted the PR-negative-testing-errors branch February 16, 2024 10:56
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.

2 participants