You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: align counter tutorial example with the aztec init template and add TXE tests (#23517)
## Summary
Align the counter contract tutorial's example with the canonical `aztec
init` counter template, add TXE tests, and run them in docs CI.
- **Naming aligned with the template.** The docs example's initializer
is renamed from `initialize`/`headstart` to
`constructor`/`initial_value` to match the counter scaffold that `aztec
init` generates (`yarn-project/aztec/scripts/templates/counter/`). The
`increment(owner)` and `get_counter(owner)` signatures already match the
template and are unchanged. This PR does not modify the CLI template
itself; the docs example follows it.
- **TXE tests.** Adds a `counter_contract_test` package (mirroring
`logging_example_test`) with tests for the constructor and increment,
matching the template's test layout.
- **CI.** A new `test-contracts` step in `docs/examples/bootstrap.sh`
starts a TXE and runs `nargo test` for both `counter_contract_test` and
`logging_example_test`, so these tests run in docs CI rather than
sitting unexecuted.
- **Tutorial polish.** Sentence-case headings, a more accurate privacy
description (the count is confidential; dropped the overstated "no one
knows when you increment"), and prose updated for the `constructor`
naming.
## What's not in scope
- No change to the `aztec init` counter template; the docs example is
aligned to it.
- No change to the example's authorization model: `increment(owner)`
matches the template.
## Test plan
- CI's `docs/examples/bootstrap.sh compile` builds `counter_contract`
against the `constructor` signature.
- The new `docs/examples/bootstrap.sh test-contracts` step runs `nargo
test` for `counter_contract_test` and `logging_example_test` against a
TXE. This could not be run locally (stale in-repo nargo, and the step
needs a built `yarn-project/txe`), so the first real validation is this
PR's CI run.
- Docusaurus dev build renders the updated tutorial without
`#include_code` errors.
In this guide, we will create our first Aztec.nr smart contract. We will build a simple private counter, where you can keep your own private counter - so no one knows what ID you are at or when you increment! This contract will get you started with the basic setup and syntax of Aztec.nr, but doesn't showcase all of the awesome stuff Aztec is capable of.
10
+
In this guide, we will create our first Aztec.nr smart contract. We will build a simple private counter, where each account keeps its own counter as encrypted private state, so the count stays known only to you. This contract will get you started with the basic setup and syntax of Aztec.nr, but doesn't showcase all of the awesome stuff Aztec is capable of.
11
11
12
12
This tutorial is compatible with the Aztec version `#include_aztec_version`. Install the correct version with `VERSION=#include_version_without_prefix bash -i <(curl -sL https://install.aztec.network/#include_version_without_prefix)`. Or if you'd like to use a different version, you can find the relevant tutorial by clicking the version dropdown at the top of the page.
13
13
@@ -104,11 +104,11 @@ Add this below the imports. It declares the storage variables for our contract.
104
104
105
105
Now we’ve got a mechanism for storing our private state, we can start using it to ensure the privacy of balances.
106
106
107
-
Let’s create a constructor method to run on deployment that assigns an initial count to a specified owner. This function is called `initialize`, but behaves like a constructor. It is the `#[initializer]` decorator that specifies that this function behaves like a constructor. Write this:
107
+
Let’s create a constructor method to run on deployment that assigns an initial count to a specified owner. We name it `constructor` here, but the name is arbitrary; it is the `#[initializer]` decorator that marks it to run once when the contract is deployed. Write this:
This function accesses the counters from storage. It adds the `headstart` value to the `owner`'s counter using `at().add()`, then calls `.deliver(MessageDelivery::onchain_constrained())` to ensure the note is delivered onchain.
111
+
This function accesses the counters from storage. It adds the `initial_value` to the `owner`'s counter using `at().add()`, then calls `.deliver(MessageDelivery::onchain_constrained())` to ensure the note is delivered onchain.
112
112
113
113
We have annotated this and other functions with `#[external("private")]` which are ABI macros so the compiler understands it will handle private inputs.
114
114
@@ -118,7 +118,7 @@ Now let's implement an `increment` function to increase the counter.
The `increment` function works similarly to the `initialize` function. It logs a debug message, then adds 1 to the owner's counter and delivers the note onchain.
121
+
The `increment` function works similarly to the `constructor`. It logs a debug message, then adds 1 to the `owner`'s counter and delivers the note onchain.
0 commit comments