Skip to content

docs: fix counter tutorial ownership semantics and add TXE tests#23517

Draft
critesjosh wants to merge 2 commits into
nextfrom
docs/counter-tutorial-msg-sender-and-tests
Draft

docs: fix counter tutorial ownership semantics and add TXE tests#23517
critesjosh wants to merge 2 commits into
nextfrom
docs/counter-tutorial-msg-sender-and-tests

Conversation

@critesjosh
Copy link
Copy Markdown
Contributor

Summary

  • The counter contract 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 from increment and read self.msg_sender() instead so a caller can only increment the counter mapped to their own address. Tutorial prose updated to match.
  • Add a sibling counter_contract_test package (mirroring the existing logging_example_test layout) with TXE tests covering initialize and increment.

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

  • No swap to PrivateMutable<UintNote> / public counters / decrement / #[view]. Those belong in a follow-on tutorial about private-vs-public state.
  • The new counter_contract_test package is type = "lib", matching logging_example_test. docs/examples/bootstrap.sh compile only iterates type = "contract" packages, so the test package is in the workspace for syntax checking and reference but isn't yet invoked via aztec test in CI. Wiring tests into docs CI for both logging_example_test and counter_contract_test is a worthwhile follow-up.

Test plan

  • CI's docs/examples/bootstrap.sh compile builds counter_contract against the new increment() signature
  • aztec test against counter_contract_test passes locally (cannot verify here — the in-repo nargo binary is stale and the docs workspace doesn't compile against current aztec-nr)
  • Docusaurus dev build renders the updated tutorial without #include_code errors

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.
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.

1 participant