Skip to content

Commit 8b1769d

Browse files
committed
test(docs): assert caller-only increment and align counter test style
Add a TXE test proving a different account cannot mutate the owner's counter, validating the self.msg_sender() ownership fix. Convert assertions to f-strings to match the canonical counter test, and sentence-case the tutorial headings.
1 parent a115d53 commit 8b1769d

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

docs/docs-developers/docs/tutorials/contract_tutorials/counter_contract.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Counter Contract
2+
title: Counter contract
33
description: Code-along tutorial for creating a simple counter contract on Aztec.
44
sidebar_position: 0
55
references: ["docs/examples/contracts/counter_contract/src/main.nr"]
@@ -152,8 +152,8 @@ aztec codegen -o src/artifacts target
152152

153153
You can now use the artifact and/or the TS class in your Aztec.js!
154154

155-
## Next Steps
155+
## Next steps
156156

157-
### Optional: Learn more about concepts mentioned here
157+
### Optional: learn more about concepts mentioned here
158158

159159
- [Functions and annotations like `#[external("private")]`](../../aztec-nr/framework-description/functions/function_transforms.md#private-functions)

docs/examples/contracts/counter_contract_test/src/lib.nr

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ unconstrained fn test_initialize_sets_headstart() {
1717
let (env, contract_address, owner) = setup(headstart);
1818

1919
let value = env.execute_utility(Counter::at(contract_address).get_counter(owner));
20-
assert(value == headstart, "initial counter should equal headstart");
20+
assert(value == headstart, f"Expected {headstart} but got {value}");
2121
}
2222

2323
#[test]
@@ -27,6 +27,22 @@ unconstrained fn test_increment_increases_caller_counter() {
2727

2828
env.call_private(owner, Counter::at(contract_address).increment());
2929

30+
let expected = headstart + 1;
3031
let value = env.execute_utility(Counter::at(contract_address).get_counter(owner));
31-
assert(value == headstart + 1, "counter should be incremented by 1");
32+
assert(value == expected, f"Expected {expected} but got {value}");
33+
}
34+
35+
#[test]
36+
unconstrained fn test_increment_does_not_affect_other_account() {
37+
let headstart = 5;
38+
let (mut env, contract_address, owner) = setup(headstart);
39+
let other = env.create_light_account();
40+
41+
env.call_private(other, Counter::at(contract_address).increment());
42+
43+
let owner_value = env.execute_utility(Counter::at(contract_address).get_counter(owner));
44+
assert(
45+
owner_value == headstart,
46+
f"Expected owner counter unchanged at {headstart} but got {owner_value}",
47+
);
3248
}

0 commit comments

Comments
 (0)