-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce validators for building custom contracts (#1970)
* Add validator as a form of custom contract * Support validators in %contract/apply% * Add from_validator primop and stdlib function * Add tests for custom contract constructors * Migrate stdlib to use validators * Add documentation on validators * Fix manual snippets * Apply suggestions from code review Co-authored-by: jneem <[email protected]> --------- Co-authored-by: jneem <[email protected]>
- Loading branch information
Showing
23 changed files
with
444 additions
and
174 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
cli/tests/snapshot/inputs/errors/validator_custom_error.ncl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# capture = 'stderr' | ||
# command = ['eval'] | ||
let Is42 = std.contract.from_validator (fun value => | ||
if value == 42 then | ||
'Ok value | ||
else | ||
'Error { | ||
message = "Value must be 42", | ||
notes = ["This is a first custom note", "This is a second custom note"] | ||
} | ||
) in | ||
43 | Is42 |
15 changes: 15 additions & 0 deletions
15
cli/tests/snapshot/snapshots/snapshot__eval_stderr_validator_custom_error.ncl.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
source: cli/tests/snapshot/main.rs | ||
expression: err | ||
--- | ||
error: contract broken by a value | ||
Value must be 42 | ||
┌─ [INPUTS_PATH]/errors/validator_custom_error.ncl:12:1 | ||
│ | ||
12 │ 43 | Is42 | ||
│ ^^ ---- expected type | ||
│ │ | ||
│ applied to this expression | ||
│ | ||
= This is a first custom note | ||
= This is a second custom note |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.