Skip to content
This repository was archived by the owner on Jul 10, 2026. It is now read-only.

Commit cb6b81b

Browse files
authored
feat: upgrade to 2.0.3 (#19)
1 parent 77c792c commit cb6b81b

11 files changed

Lines changed: 1062 additions & 919 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,21 @@ jobs:
103103
VERSION=${{ steps.basever.outputs.ver }} aztec-up
104104
105105
- name: Start sandbox (BASE, background)
106-
run: aztec start --sandbox &
106+
run: VERSION=${{ steps.basever.outputs.ver }} aztec start --sandbox &
107107

108108
- name: Start PXE node (BASE, background)
109109
run: |
110-
VERSION=${{ steps.basever.outputs.ver }} aztec \
111-
start --port 8081 --pxe --pxe.nodeUrl=http://localhost:8080/ \
110+
VERSION=${{ steps.basever.outputs.ver }} aztec start \
111+
--port 8081 --pxe --pxe.nodeUrl=http://localhost:8080/ \
112112
--pxe.proverEnabled false &
113113
114114
- name: Cache node_modules (BASE)
115115
uses: actions/cache@v4
116116
with:
117117
path: node_modules
118-
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
118+
key: ${{ runner.os }}-node-modules-${{ steps.basever.outputs.ver }}-${{ hashFiles('yarn.lock') }}
119119
restore-keys: |
120-
${{ runner.os }}-node-modules-
120+
${{ runner.os }}-node-modules-${{ steps.basever.outputs.ver }}-
121121
122122
- name: Install deps (BASE)
123123
run: yarn install --frozen-lockfile
@@ -129,15 +129,13 @@ jobs:
129129
path: |
130130
target/
131131
src/artifacts/
132-
key: ${{ runner.os }}-noir-${{ env.AZTEC_VERSION }}-${{ hashFiles('src/nr/**/*', 'Nargo.toml') }}
132+
key: ${{ runner.os }}-noir-${{ steps.basever.outputs.ver }}-${{ hashFiles('src/nr/**/*', 'Nargo.toml') }}
133133

134134
- name: Compile contracts (BASE)
135-
if: steps.cache-noir-base.outputs.cache-hit != 'true'
136-
run: script -e -c "${AZTEC_NARGO:-aztec-nargo} compile"
135+
run: yarn compile
137136

138137
- name: Codegen wrappers (BASE)
139-
if: steps.cache-noir-base.outputs.cache-hit != 'true'
140-
run: script -e -c "aztec codegen target --outdir src/artifacts --force"
138+
run: yarn codegen
141139

142140
- name: Benchmark (BASE)
143141
run: |
@@ -190,22 +188,27 @@ jobs:
190188
191189
- name: Start sandbox (PR, background)
192190
if: steps.prver.outputs.ver_diff == 'true'
193-
run: aztec start --sandbox &
191+
run: |
192+
VERSION=${{ steps.prver.outputs.ver }} aztec start --sandbox &
193+
sleep 60
194194
195195
- name: Start PXE node (PR, background)
196196
if: steps.prver.outputs.ver_diff == 'true'
197197
run: |
198-
VERSION=${{ steps.prver.outputs.ver }} aztec \
199-
start --port 8081 --pxe --pxe.nodeUrl=http://localhost:8080/ \
198+
VERSION=${{ steps.prver.outputs.ver }} aztec start \
199+
--port 8081 --pxe --pxe.nodeUrl=http://localhost:8080/ \
200200
--pxe.proverEnabled false &
201-
201+
202+
- name: Clean project from BASE stage
203+
run: rm -rf node_modules yarn.lock
204+
202205
- name: Cache node_modules (PR)
203206
uses: actions/cache@v4
204207
with:
205208
path: node_modules
206-
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
209+
key: ${{ runner.os }}-node-modules-${{ steps.prver.outputs.ver }}-${{ hashFiles('yarn.lock') }}
207210
restore-keys: |
208-
${{ runner.os }}-node-modules-
211+
${{ runner.os }}-node-modules-${{ steps.prver.outputs.ver }}-
209212
210213
- name: Install deps (PR)
211214
run: yarn install --frozen-lockfile
@@ -217,15 +220,13 @@ jobs:
217220
path: |
218221
target/
219222
src/artifacts/
220-
key: ${{ runner.os }}-noir-${{ env.AZTEC_VERSION }}-${{ hashFiles('src/nr/**/*', 'Nargo.toml') }}
223+
key: ${{ runner.os }}-noir-${{ steps.prver.outputs.ver }}-${{ hashFiles('src/nr/**/*', 'Nargo.toml') }}
221224

222225
- name: Compile contracts (PR)
223-
if: steps.cache-noir-pr.outputs.cache-hit != 'true'
224-
run: script -e -c "${AZTEC_NARGO:-aztec-nargo} compile"
226+
run: yarn compile
225227

226228
- name: Codegen wrappers (PR)
227-
if: steps.cache-noir-pr.outputs.cache-hit != 'true'
228-
run: script -e -c "aztec codegen target --outdir src/artifacts --force"
229+
run: yarn codegen
229230

230231
# ──────────────────────────────────────────────────────────────
231232
# 3️⃣ DIFF & UPLOAD ARTIFACTS

.github/workflows/tests.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ jobs:
6161

6262
- name: Compile contracts
6363
if: steps.cache-noir.outputs.cache-hit != 'true'
64-
run: script -e -c "${AZTEC_NARGO:-aztec-nargo} compile"
64+
run: yarn compile
6565

6666
- name: Generate artifacts
6767
if: steps.cache-noir.outputs.cache-hit != 'true'
68-
run: script -e -c "aztec codegen target --outdir src/artifacts"
68+
run: yarn codegen -f
69+
70+
- name: Postprocess contracts
71+
run: aztec-postprocess-contract
6972

7073
- name: Run nr tests
7174
run: yarn test:nr

benchmarks/counter.benchmark.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { getInitialTestAccountsWallets } from "@aztec/accounts/testing";
55
import {
66
Benchmark,
77
type BenchmarkContext,
8-
type BenchmarkedInteraction,
98
} from "@defi-wonderland/aztec-benchmark";
9+
import { NamedBenchmarkedInteraction } from "@defi-wonderland/aztec-benchmark/dist/types.js";
1010

1111
import { CounterContract } from "../src/artifacts/Counter.js";
1212
import { deployCounter } from "../src/ts/utils.js";
@@ -44,13 +44,16 @@ export default class CounterContractBenchmark extends Benchmark {
4444
/**
4545
* Returns the list of CounterContract methods to be benchmarked.
4646
*/
47-
getMethods(context: CounterBenchmarkContext): BenchmarkedInteraction[] {
47+
getMethods(context: CounterBenchmarkContext): NamedBenchmarkedInteraction[] {
4848
const { counterContract, accounts } = context;
4949
const [alice] = accounts;
5050

5151
const methods = [
52-
counterContract.withWallet(alice).methods.increment(),
53-
] as BenchmarkedInteraction[];
52+
{
53+
interaction: counterContract.withWallet(alice).methods.increment(),
54+
name: "increment",
55+
},
56+
] as NamedBenchmarkedInteraction[];
5457

5558
return methods.filter(Boolean);
5659
}

package.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,31 @@
77
"type": "module",
88
"scripts": {
99
"clean": "rm -rf ./src/artifacts ./target codegenCache.json",
10-
"codegen": "aztec codegen target --outdir src/artifacts",
11-
"compile": "aztec-nargo compile",
10+
"codegen": "aztec codegen target --outdir src/artifacts -f",
11+
"compile": "aztec-nargo compile && aztec-postprocess-contract",
1212
"test": "yarn test:nr && yarn test:js",
1313
"test:js": "vitest run",
1414
"test:nr": "aztec test",
1515
"lint:prettier": "prettier '**/*.{js,ts}' --write",
16-
"build": "yarn compile && yarn codegen -f",
16+
"ccc": "yarn clean && yarn compile && yarn codegen -f",
1717
"prepare": "husky"
1818
},
1919
"lint-staged": {
2020
"*.ts": "prettier --write -u"
2121
},
2222
"dependencies": {
23-
"@aztec/accounts": "1.2.1",
24-
"@aztec/aztec.js": "1.2.1",
25-
"@aztec/noir-contracts.js": "1.2.1",
26-
"@defi-wonderland/aztec-benchmark": "1.0.1"
23+
"@aztec/accounts": "2.0.3",
24+
"@aztec/aztec.js": "2.0.3",
25+
"@aztec/noir-contracts.js": "2.0.3",
26+
"@defi-wonderland/aztec-benchmark": "2.0.0",
27+
"@types/node": "22.5.1"
2728
},
2829
"devDependencies": {
29-
"@types/node": "22.5.1",
3030
"@commitlint/cli": "19.8.1",
3131
"@commitlint/config-conventional": "19.8.1",
32+
"@types/jest": "29.5.11",
33+
"@types/mocha": "10.0.6",
34+
"@types/node": "22.5.1",
3235
"husky": "9.1.7",
3336
"tsx": "4.20.4",
3437
"lint-staged": "16.1.5",
@@ -37,7 +40,7 @@
3740
"vitest": "3.2.4"
3841
},
3942
"config": {
40-
"aztecVersion": "1.2.1"
43+
"aztecVersion": "2.0.3"
4144
},
4245
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
4346
"engines": {

src/nr/counter_contract/Nargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ compiler_version = ">=1.0.0"
55
authors = [""]
66

77
[dependencies]
8-
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v1.2.1", directory = "noir-projects/aztec-nr/aztec" }
8+
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v2.0.3", directory = "noir-projects/aztec-nr/aztec" }

src/nr/counter_contract/src/main.nr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ pub mod test;
55
pub contract Counter {
66
// aztec library imports
77
use aztec::{
8-
macros::{functions::{initializer, internal, private, public}, storage::storage},
9-
prelude::{AztecAddress, PublicImmutable, PublicMutable},
8+
macros::{functions::{initializer, internal, private, public, view}, storage::storage},
9+
protocol_types::address::AztecAddress,
10+
state_vars::{PublicImmutable, PublicMutable},
1011
};
1112

1213
// @param owner The address of the owner
@@ -41,6 +42,7 @@ pub contract Counter {
4142
/// @dev Retrieves the counter value
4243
/// @return The current counter value
4344
#[public]
45+
#[view]
4446
fn get_counter() -> u128 {
4547
storage.counter.read()
4648
}

src/nr/counter_contract/src/test/increment.nr

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ use crate::{Counter, test::utils};
44
unconstrained fn increment_success() {
55
let (env, contract_address, owner, _) = utils::setup_contract(false);
66

7-
env.impersonate(owner);
8-
Counter::at(contract_address).increment().call(&mut env.private());
7+
env.call_private(owner, Counter::at(contract_address).increment());
8+
9+
let counter = env.view_public(Counter::at(contract_address).get_counter());
10+
assert(counter == 1);
11+
}
12+
13+
#[test]
14+
unconstrained fn does_it_fail_to_call_the_initializer() {
15+
let mut env = aztec::test::helpers::test_environment::TestEnvironment::new();
16+
17+
let owner = env.create_light_account();
18+
19+
let initializer_call_interface = Counter::interface().constructor(owner);
20+
let counter_deployer = env.deploy("@counter_contract/Counter");
21+
let contract_address =
22+
counter_deployer.with_public_initializer(owner, initializer_call_interface);
23+
24+
env.call_private(owner, Counter::at(contract_address).increment());
25+
26+
let counter = env.view_public(Counter::at(contract_address).get_counter());
27+
assert(counter == 1);
928
}
Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::Counter;
22
use aztec::{
3-
prelude::AztecAddress, protocol_types::contract_instance::ContractInstance,
4-
test::helpers::test_environment::TestEnvironment,
3+
protocol_types::address::AztecAddress, test::helpers::test_environment::TestEnvironment,
54
};
65

76
pub unconstrained fn setup_contract(
@@ -10,29 +9,27 @@ pub unconstrained fn setup_contract(
109
// Setup env, generate keys
1110
let mut env = TestEnvironment::new();
1211
let (owner, user) = if with_account_contracts {
13-
let owner = env.create_account_contract(1);
14-
let user = env.create_account_contract(2);
12+
let owner = env.create_contract_account();
13+
let user = env.create_contract_account();
1514
(owner, user)
1615
} else {
17-
let owner = env.create_account(1);
18-
let user = env.create_account(2);
16+
let owner = env.create_light_account();
17+
let user = env.create_light_account();
1918
(owner, user)
2019
};
2120

22-
let acontract = deploy_contract(&mut env, owner);
21+
let contract_address = deploy_contract(&mut env, owner);
2322

24-
(&mut env, acontract.to_address(), owner, user)
23+
(&mut env, contract_address, owner, user)
2524
}
2625

2726
pub unconstrained fn deploy_contract(
2827
env: &mut TestEnvironment,
2928
owner: AztecAddress,
30-
) -> ContractInstance {
29+
) -> AztecAddress {
3130
let initializer_call_interface = Counter::interface().constructor(owner);
32-
let contract_instance = env
33-
.deploy("./@counter_contract", "Counter")
34-
.with_public_void_initializer(owner, initializer_call_interface);
35-
env.advance_block_by(1);
31+
let contract_address =
32+
env.deploy("Counter").with_public_initializer(owner, initializer_call_interface);
3633

37-
contract_instance
34+
contract_address
3835
}

src/ts/counter.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,28 @@ describe("Counter Contract", () => {
3939
});
4040

4141
it("e2e", async () => {
42-
const owner = await counter.methods.get_owner().simulate();
42+
const owner = await counter.methods.get_owner().simulate({
43+
from: alice.getAddress(),
44+
});
4345
expect(owner).toStrictEqual(alice.getAddress());
4446
// default counter's value is 0
45-
expect(await counter.methods.get_counter().simulate()).toBe(0n);
47+
expect(
48+
await counter.methods.get_counter().simulate({
49+
from: alice.getAddress(),
50+
}),
51+
).toBe(0n);
4652
// call to `increment`
47-
await counter.methods.increment().send().wait();
53+
await counter.methods
54+
.increment()
55+
.send({
56+
from: alice.getAddress(),
57+
})
58+
.wait();
4859
// now the counter should be incremented.
49-
expect(await counter.methods.get_counter().simulate()).toBe(1n);
60+
expect(
61+
await counter.methods.get_counter().simulate({
62+
from: alice.getAddress(),
63+
}),
64+
).toBe(1n);
5065
});
5166
});

src/ts/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export async function deployCounter(
3838
[owner],
3939
"constructor", // not actually needed since it's the default constructor
4040
)
41-
.send()
41+
.send({
42+
from: deployer.getAddress(),
43+
})
4244
.deployed();
4345
return contract as CounterContract;
4446
}

0 commit comments

Comments
 (0)