Adds Preconditions feature w/ example #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For the purposes of this exercise please do not comment directly on this PR (as we want to use this for several candidates)!
You may use the PR to view the diff nicely, but please instead prepare your feedback in a markdown file
feedback.md
where you can comment on a line of code like:You may also include comments that are not attached to particular file:lines at the top or bottom of your
feedback.md
file.Thank you!
Explanation of the precondition feature below:
We consolidate account / network preconditions under a single field,
this.account
andthis.network
. Using account / network fields looks like this:this.account.balance.get()
does the following: It fetches the balance from chain and creates a variable with that value in it. It does NOT link it to the current balance in the snark circuit. Instead, explicitassertEquals
orassertBetween
is necessary to create that link.To make this not a footgun, we throw an error if the user doesn't add any explicit precondition on the field. The error is thrown when compiling, proving, or running the smart contract method in any other way. Example:
Running this would throw:
The developer would hopefully read the error message and modify their code like this .. which would fix the error, and teach them about preconditions at the same time.