docs: fix counter tutorial ownership semantics and add TXE tests#23517
Draft
critesjosh wants to merge 2 commits into
Draft
docs: fix counter tutorial ownership semantics and add TXE tests#23517critesjosh wants to merge 2 commits into
critesjosh wants to merge 2 commits into
Conversation
The counter tutorial framed the example as "your own private counter," but `increment(owner: AztecAddress)` let any caller mutate any owner's counter. Drop the `owner` parameter and read `self.msg_sender()` so the caller can only increment the counter mapped to their own address. Also add a sibling `counter_contract_test` package (mirroring `logging_example_test`) with TXE tests covering `initialize` and `increment`. This catches regressions in the example contract via `aztec test` when wired up.
The contract declares `fn log_all_levels(value: Field)` but the test called it with no args, causing nargo to abort. This blocks the entire docs/examples workspace from running TXE tests via `aztec test`. Caught while adding the counter_contract_test package: scoping `aztec test` to `--package counter_contract_test` still compiles the whole workspace and trips on this. One-character fix.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
increment(owner: AztecAddress)let any caller mutate any owner's counter. Drop theownerparameter fromincrementand readself.msg_sender()instead so a caller can only increment the counter mapped to their own address. Tutorial prose updated to match.counter_contract_testpackage (mirroring the existinglogging_example_testlayout) with TXE tests coveringinitializeandincrement.Why
The previous tutorial code taught a bad default — anyone can mutate anyone's counter. For the first contract tutorial that beginners copy-paste, the auth model matters more than any other change we could make to the example. This is a minimal, targeted fix; deliberately not a wholesale swap to the aztec-fundamentals-course version, which expands the surface to 7 functions (private + public + decrement + view) and is more appropriate as material for a follow-on tutorial.
What's not in scope
PrivateMutable<UintNote>/ public counters / decrement /#[view]. Those belong in a follow-on tutorial about private-vs-public state.counter_contract_testpackage istype = "lib", matchinglogging_example_test.docs/examples/bootstrap.sh compileonly iteratestype = "contract"packages, so the test package is in the workspace for syntax checking and reference but isn't yet invoked viaaztec testin CI. Wiring tests into docs CI for bothlogging_example_testandcounter_contract_testis a worthwhile follow-up.Test plan
docs/examples/bootstrap.sh compilebuildscounter_contractagainst the newincrement()signatureaztec testagainstcounter_contract_testpasses locally (cannot verify here — the in-repo nargo binary is stale and the docs workspace doesn't compile against current aztec-nr)#include_codeerrors