Skip to content

Commit af8019f

Browse files
committed
rm yarn-project changes
1 parent a032a90 commit af8019f

5 files changed

Lines changed: 7 additions & 36 deletions

File tree

  • docs
  • yarn-project/aztec/scripts/templates/counter

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ Now let's implement an `increment` function to increase the counter.
118118

119119
#include_code increment /docs/examples/contracts/counter_contract/src/main.nr rust
120120

121-
The `increment` function uses `self.msg_sender()` so each caller can only increment the counter mapped to their own address. It logs a debug message, then adds 1 to that counter and delivers the note onchain.
122-
123-
Only this mutating action derives the owner from the caller. The one-time `constructor` and the `get_counter` read still take an explicit `owner`: the constructor can seed a chosen account, and a read selects which counter to view (only its owner can decrypt it).
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.
124122

125123
## Getting a counter
126124

docs/examples/contracts/counter_contract/src/main.nr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ pub contract Counter {
3535

3636
// docs:start:increment
3737
#[external("private")]
38-
fn increment() {
39-
let owner = self.msg_sender();
38+
fn increment(owner: AztecAddress) {
4039
debug_log_format("Incrementing counter for owner {0}", [owner.to_field()]);
4140
self.storage.counters.at(owner).add(1).deliver(MessageDelivery::onchain_constrained());
4241
}

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,13 @@ unconstrained fn test_constructor_sets_initial_value() {
2121
}
2222

2323
#[test]
24-
unconstrained fn test_increment_increases_caller_counter() {
24+
unconstrained fn test_increment() {
2525
let initial_value = 5;
2626
let (mut env, contract_address, owner) = setup(initial_value);
2727

28-
env.call_private(owner, Counter::at(contract_address).increment());
28+
env.call_private(owner, Counter::at(contract_address).increment(owner));
2929

3030
let expected = initial_value + 1;
3131
let value = env.execute_utility(Counter::at(contract_address).get_counter(owner));
3232
assert(value == expected, f"Expected {expected} but got {value}");
3333
}
34-
35-
#[test]
36-
unconstrained fn test_stranger_increment_does_not_affect_owner() {
37-
let initial_value = 5;
38-
let (mut env, contract_address, owner) = setup(initial_value);
39-
let stranger = env.create_light_account();
40-
41-
// `increment` derives the owner from msg_sender, so a different caller can
42-
// only ever touch its own counter, never the owner's.
43-
env.call_private(stranger, Counter::at(contract_address).increment());
44-
45-
// The stranger's increment lands on their own counter, which started at 0.
46-
let stranger_value = env.execute_utility(Counter::at(contract_address).get_counter(stranger));
47-
assert(stranger_value == 1, f"Expected stranger counter at 1 but got {stranger_value}");
48-
49-
// The owner's counter is untouched by another account's increment.
50-
let owner_value = env.execute_utility(Counter::at(contract_address).get_counter(owner));
51-
assert(
52-
owner_value == initial_value,
53-
f"Expected owner counter unchanged at {initial_value} but got {owner_value}",
54-
);
55-
}

yarn-project/aztec/scripts/templates/counter/contract/src/main.nr

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ pub contract Counter {
3131
);
3232
}
3333

34-
// Adds 1 to the caller's own counter.
35-
//
36-
// The owner is read from self.msg_sender(), so a caller can only ever
37-
// increment the counter mapped to their own address.
34+
// Adds 1 to the owner's counter.
3835
#[external("private")]
39-
fn increment() {
40-
let owner = self.msg_sender();
36+
fn increment(owner: AztecAddress) {
4137
self.storage.counters.at(owner).add(1).deliver(MessageDelivery::onchain_constrained());
4238
}
4339

yarn-project/aztec/scripts/templates/counter/test/src/lib.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ unconstrained fn test_increment() {
2525
let initial_value = 5;
2626
let (mut env, contract_address, owner) = setup(initial_value);
2727

28-
env.call_private(owner, Counter::at(contract_address).increment());
28+
env.call_private(owner, Counter::at(contract_address).increment(owner));
2929

3030
let counter = env.execute_utility(Counter::at(contract_address).get_counter(owner));
3131
assert_eq(counter, initial_value + 1);

0 commit comments

Comments
 (0)