@aztec/aztec 0.0.1-commit.808bf7f90 → 0.0.1-commit.8227e42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/cli/cmds/compile.d.ts +1 -1
- package/dest/cli/cmds/compile.d.ts.map +1 -1
- package/dest/cli/cmds/compile.js +92 -0
- package/package.json +34 -34
- package/src/cli/cmds/compile.ts +104 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { LogFn } from '@aztec/foundation/log';
|
|
2
2
|
import type { Command } from 'commander';
|
|
3
3
|
export declare function injectCompileCommand(program: Command, log: LogFn): Command;
|
|
4
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcGlsZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NsaS9jbWRzL2NvbXBpbGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFHbkQsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sV0FBVyxDQUFDO0FBOEp6Qyx3QkFBZ0Isb0JBQW9CLENBQUMsT0FBTyxFQUFFLE9BQU8sRUFBRSxHQUFHLEVBQUUsS0FBSyxHQUFHLE9BQU8sQ0FzQjFFIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/cli/cmds/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/cli/cmds/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8JzC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,GAAG,OAAO,CAsB1E"}
|
package/dest/cli/cmds/compile.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'child_process';
|
|
2
2
|
import { readFile, writeFile } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
3
4
|
import { readArtifactFiles } from './utils/artifacts.js';
|
|
4
5
|
import { run } from './utils/spawn.js';
|
|
5
6
|
/** Returns paths to contract artifacts in the target directory. */ async function collectContractArtifacts() {
|
|
@@ -25,6 +26,95 @@ import { run } from './utils/spawn.js';
|
|
|
25
26
|
await writeFile(path, JSON.stringify(artifact, null, 2) + '\n');
|
|
26
27
|
}
|
|
27
28
|
}
|
|
29
|
+
/** Returns the set of package names that are contract crates in the current workspace. */ async function getContractPackageNames() {
|
|
30
|
+
const contractNames = new Set();
|
|
31
|
+
let rootToml;
|
|
32
|
+
try {
|
|
33
|
+
rootToml = await readFile('Nargo.toml', 'utf-8');
|
|
34
|
+
} catch {
|
|
35
|
+
return contractNames;
|
|
36
|
+
}
|
|
37
|
+
const membersMatch = rootToml.match(/members\s*=\s*\[([^\]]*)\]/);
|
|
38
|
+
if (membersMatch) {
|
|
39
|
+
const members = membersMatch[1].split(',').map((m)=>m.trim().replace(/^"|"$/g, '')).filter((m)=>m.length > 0);
|
|
40
|
+
for (const member of members){
|
|
41
|
+
try {
|
|
42
|
+
const memberToml = await readFile(join(member, 'Nargo.toml'), 'utf-8');
|
|
43
|
+
if (/type\s*=\s*"contract"/.test(memberToml)) {
|
|
44
|
+
const nameMatch = memberToml.match(/name\s*=\s*"([^"]+)"/);
|
|
45
|
+
if (nameMatch) {
|
|
46
|
+
contractNames.add(nameMatch[1]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
// Member directory might not exist or have no Nargo.toml; skip.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
// Single-crate project (no workspace): check if the root Nargo.toml itself is a contract.
|
|
55
|
+
if (/type\s*=\s*"contract"/.test(rootToml)) {
|
|
56
|
+
const nameMatch = rootToml.match(/name\s*=\s*"([^"]+)"/);
|
|
57
|
+
if (nameMatch) {
|
|
58
|
+
contractNames.add(nameMatch[1]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return contractNames;
|
|
63
|
+
}
|
|
64
|
+
/** Checks that no tests exist in contract crates and fails with a helpful message if they do. */ async function checkNoTestsInContracts(nargo, log) {
|
|
65
|
+
const contractPackages = await getContractPackageNames();
|
|
66
|
+
if (contractPackages.size === 0) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let output;
|
|
70
|
+
try {
|
|
71
|
+
// We list tests for all the crates in the workspace
|
|
72
|
+
output = execFileSync(nargo, [
|
|
73
|
+
'test',
|
|
74
|
+
'--list-tests',
|
|
75
|
+
'--silence-warnings'
|
|
76
|
+
], {
|
|
77
|
+
encoding: 'utf-8',
|
|
78
|
+
stdio: [
|
|
79
|
+
'pipe',
|
|
80
|
+
'pipe',
|
|
81
|
+
'inherit'
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
} catch {
|
|
85
|
+
// If listing tests fails (e.g. test crate has compile errors), skip the check.
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// The output of the `nargo test --list-tests` command is as follows:
|
|
89
|
+
// ```
|
|
90
|
+
// crate_name_1 test_name_1
|
|
91
|
+
// crate_name_2 test_name_2
|
|
92
|
+
// ...
|
|
93
|
+
// crate_name_n test_name_n
|
|
94
|
+
// ```
|
|
95
|
+
//
|
|
96
|
+
// We parse the individual lines and then we check if any contract crate appeared in the parsed output.
|
|
97
|
+
const lines = output.trim().split('\n').filter((line)=>line.length > 0);
|
|
98
|
+
const testsInContracts = [];
|
|
99
|
+
for (const line of lines){
|
|
100
|
+
const spaceIndex = line.indexOf(' ');
|
|
101
|
+
if (spaceIndex === -1) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const packageName = line.substring(0, spaceIndex);
|
|
105
|
+
const testName = line.substring(spaceIndex + 1);
|
|
106
|
+
if (contractPackages.has(packageName)) {
|
|
107
|
+
testsInContracts.push({
|
|
108
|
+
packageName,
|
|
109
|
+
testName
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (testsInContracts.length > 0) {
|
|
114
|
+
const details = testsInContracts.map((t)=>` ${t.packageName}::${t.testName}`).join('\n');
|
|
115
|
+
log(`WARNING: Found tests in contract crate(s):\n${details}\n\n` + `Tests should be in a dedicated test crate, not in the contract crate.\n` + `Learn more: https://docs.aztec.network/errors/1`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
28
118
|
/** Compiles Aztec Noir contracts and postprocesses artifacts. */ async function compileAztecContract(nargoArgs, log) {
|
|
29
119
|
const nargo = process.env.NARGO ?? 'nargo';
|
|
30
120
|
const bb = process.env.BB ?? 'bb';
|
|
@@ -32,6 +122,8 @@ import { run } from './utils/spawn.js';
|
|
|
32
122
|
'compile',
|
|
33
123
|
...nargoArgs
|
|
34
124
|
]);
|
|
125
|
+
// Ensure contract crates contain no tests (tests belong in the test crate).
|
|
126
|
+
await checkNoTestsInContracts(nargo, log);
|
|
35
127
|
const artifacts = await collectContractArtifacts();
|
|
36
128
|
if (artifacts.length > 0) {
|
|
37
129
|
log('Postprocessing contracts...');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/aztec",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.8227e42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -28,39 +28,39 @@
|
|
|
28
28
|
"../package.common.json"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@aztec/accounts": "0.0.1-commit.
|
|
32
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
33
|
-
"@aztec/aztec-faucet": "0.0.1-commit.
|
|
34
|
-
"@aztec/aztec-node": "0.0.1-commit.
|
|
35
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
36
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
37
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
38
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
39
|
-
"@aztec/bot": "0.0.1-commit.
|
|
40
|
-
"@aztec/builder": "0.0.1-commit.
|
|
41
|
-
"@aztec/cli": "0.0.1-commit.
|
|
42
|
-
"@aztec/constants": "0.0.1-commit.
|
|
43
|
-
"@aztec/entrypoints": "0.0.1-commit.
|
|
44
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
45
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
46
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
47
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
48
|
-
"@aztec/node-lib": "0.0.1-commit.
|
|
49
|
-
"@aztec/noir-contracts.js": "0.0.1-commit.
|
|
50
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
51
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
52
|
-
"@aztec/p2p-bootstrap": "0.0.1-commit.
|
|
53
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
54
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
55
|
-
"@aztec/prover-node": "0.0.1-commit.
|
|
56
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
57
|
-
"@aztec/sequencer-client": "0.0.1-commit.
|
|
58
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
59
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
60
|
-
"@aztec/txe": "0.0.1-commit.
|
|
61
|
-
"@aztec/validator-ha-signer": "0.0.1-commit.
|
|
62
|
-
"@aztec/wallets": "0.0.1-commit.
|
|
63
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
31
|
+
"@aztec/accounts": "0.0.1-commit.8227e42",
|
|
32
|
+
"@aztec/archiver": "0.0.1-commit.8227e42",
|
|
33
|
+
"@aztec/aztec-faucet": "0.0.1-commit.8227e42",
|
|
34
|
+
"@aztec/aztec-node": "0.0.1-commit.8227e42",
|
|
35
|
+
"@aztec/aztec.js": "0.0.1-commit.8227e42",
|
|
36
|
+
"@aztec/bb-prover": "0.0.1-commit.8227e42",
|
|
37
|
+
"@aztec/bb.js": "0.0.1-commit.8227e42",
|
|
38
|
+
"@aztec/blob-client": "0.0.1-commit.8227e42",
|
|
39
|
+
"@aztec/bot": "0.0.1-commit.8227e42",
|
|
40
|
+
"@aztec/builder": "0.0.1-commit.8227e42",
|
|
41
|
+
"@aztec/cli": "0.0.1-commit.8227e42",
|
|
42
|
+
"@aztec/constants": "0.0.1-commit.8227e42",
|
|
43
|
+
"@aztec/entrypoints": "0.0.1-commit.8227e42",
|
|
44
|
+
"@aztec/ethereum": "0.0.1-commit.8227e42",
|
|
45
|
+
"@aztec/foundation": "0.0.1-commit.8227e42",
|
|
46
|
+
"@aztec/kv-store": "0.0.1-commit.8227e42",
|
|
47
|
+
"@aztec/l1-artifacts": "0.0.1-commit.8227e42",
|
|
48
|
+
"@aztec/node-lib": "0.0.1-commit.8227e42",
|
|
49
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.8227e42",
|
|
50
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.8227e42",
|
|
51
|
+
"@aztec/p2p": "0.0.1-commit.8227e42",
|
|
52
|
+
"@aztec/p2p-bootstrap": "0.0.1-commit.8227e42",
|
|
53
|
+
"@aztec/protocol-contracts": "0.0.1-commit.8227e42",
|
|
54
|
+
"@aztec/prover-client": "0.0.1-commit.8227e42",
|
|
55
|
+
"@aztec/prover-node": "0.0.1-commit.8227e42",
|
|
56
|
+
"@aztec/pxe": "0.0.1-commit.8227e42",
|
|
57
|
+
"@aztec/sequencer-client": "0.0.1-commit.8227e42",
|
|
58
|
+
"@aztec/stdlib": "0.0.1-commit.8227e42",
|
|
59
|
+
"@aztec/telemetry-client": "0.0.1-commit.8227e42",
|
|
60
|
+
"@aztec/txe": "0.0.1-commit.8227e42",
|
|
61
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.8227e42",
|
|
62
|
+
"@aztec/wallets": "0.0.1-commit.8227e42",
|
|
63
|
+
"@aztec/world-state": "0.0.1-commit.8227e42",
|
|
64
64
|
"@types/chalk": "^2.2.0",
|
|
65
65
|
"abitype": "^0.8.11",
|
|
66
66
|
"chalk": "^5.3.0",
|
package/src/cli/cmds/compile.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { LogFn } from '@aztec/foundation/log';
|
|
|
3
3
|
import { execFileSync } from 'child_process';
|
|
4
4
|
import type { Command } from 'commander';
|
|
5
5
|
import { readFile, writeFile } from 'fs/promises';
|
|
6
|
+
import { join } from 'path';
|
|
6
7
|
|
|
7
8
|
import { readArtifactFiles } from './utils/artifacts.js';
|
|
8
9
|
import { run } from './utils/spawn.js';
|
|
@@ -34,6 +35,106 @@ async function stripInternalPrefixes(artifactPaths: string[]): Promise<void> {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/** Returns the set of package names that are contract crates in the current workspace. */
|
|
39
|
+
async function getContractPackageNames(): Promise<Set<string>> {
|
|
40
|
+
const contractNames = new Set<string>();
|
|
41
|
+
|
|
42
|
+
let rootToml: string;
|
|
43
|
+
try {
|
|
44
|
+
rootToml = await readFile('Nargo.toml', 'utf-8');
|
|
45
|
+
} catch {
|
|
46
|
+
return contractNames;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const membersMatch = rootToml.match(/members\s*=\s*\[([^\]]*)\]/);
|
|
50
|
+
if (membersMatch) {
|
|
51
|
+
const members = membersMatch[1]
|
|
52
|
+
.split(',')
|
|
53
|
+
.map(m => m.trim().replace(/^"|"$/g, ''))
|
|
54
|
+
.filter(m => m.length > 0);
|
|
55
|
+
|
|
56
|
+
for (const member of members) {
|
|
57
|
+
try {
|
|
58
|
+
const memberToml = await readFile(join(member, 'Nargo.toml'), 'utf-8');
|
|
59
|
+
if (/type\s*=\s*"contract"/.test(memberToml)) {
|
|
60
|
+
const nameMatch = memberToml.match(/name\s*=\s*"([^"]+)"/);
|
|
61
|
+
if (nameMatch) {
|
|
62
|
+
contractNames.add(nameMatch[1]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
// Member directory might not exist or have no Nargo.toml; skip.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
// Single-crate project (no workspace): check if the root Nargo.toml itself is a contract.
|
|
71
|
+
if (/type\s*=\s*"contract"/.test(rootToml)) {
|
|
72
|
+
const nameMatch = rootToml.match(/name\s*=\s*"([^"]+)"/);
|
|
73
|
+
if (nameMatch) {
|
|
74
|
+
contractNames.add(nameMatch[1]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return contractNames;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Checks that no tests exist in contract crates and fails with a helpful message if they do. */
|
|
83
|
+
async function checkNoTestsInContracts(nargo: string, log: LogFn): Promise<void> {
|
|
84
|
+
const contractPackages = await getContractPackageNames();
|
|
85
|
+
if (contractPackages.size === 0) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let output: string;
|
|
90
|
+
try {
|
|
91
|
+
// We list tests for all the crates in the workspace
|
|
92
|
+
output = execFileSync(nargo, ['test', '--list-tests', '--silence-warnings'], {
|
|
93
|
+
encoding: 'utf-8',
|
|
94
|
+
stdio: ['pipe', 'pipe', 'inherit'],
|
|
95
|
+
});
|
|
96
|
+
} catch {
|
|
97
|
+
// If listing tests fails (e.g. test crate has compile errors), skip the check.
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The output of the `nargo test --list-tests` command is as follows:
|
|
102
|
+
// ```
|
|
103
|
+
// crate_name_1 test_name_1
|
|
104
|
+
// crate_name_2 test_name_2
|
|
105
|
+
// ...
|
|
106
|
+
// crate_name_n test_name_n
|
|
107
|
+
// ```
|
|
108
|
+
//
|
|
109
|
+
// We parse the individual lines and then we check if any contract crate appeared in the parsed output.
|
|
110
|
+
const lines = output
|
|
111
|
+
.trim()
|
|
112
|
+
.split('\n')
|
|
113
|
+
.filter(line => line.length > 0);
|
|
114
|
+
const testsInContracts: { packageName: string; testName: string }[] = [];
|
|
115
|
+
|
|
116
|
+
for (const line of lines) {
|
|
117
|
+
const spaceIndex = line.indexOf(' ');
|
|
118
|
+
if (spaceIndex === -1) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const packageName = line.substring(0, spaceIndex);
|
|
122
|
+
const testName = line.substring(spaceIndex + 1);
|
|
123
|
+
if (contractPackages.has(packageName)) {
|
|
124
|
+
testsInContracts.push({ packageName, testName });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (testsInContracts.length > 0) {
|
|
129
|
+
const details = testsInContracts.map(t => ` ${t.packageName}::${t.testName}`).join('\n');
|
|
130
|
+
log(
|
|
131
|
+
`WARNING: Found tests in contract crate(s):\n${details}\n\n` +
|
|
132
|
+
`Tests should be in a dedicated test crate, not in the contract crate.\n` +
|
|
133
|
+
`Learn more: https://docs.aztec.network/errors/1`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
37
138
|
/** Compiles Aztec Noir contracts and postprocesses artifacts. */
|
|
38
139
|
async function compileAztecContract(nargoArgs: string[], log: LogFn): Promise<void> {
|
|
39
140
|
const nargo = process.env.NARGO ?? 'nargo';
|
|
@@ -41,6 +142,9 @@ async function compileAztecContract(nargoArgs: string[], log: LogFn): Promise<vo
|
|
|
41
142
|
|
|
42
143
|
await run(nargo, ['compile', ...nargoArgs]);
|
|
43
144
|
|
|
145
|
+
// Ensure contract crates contain no tests (tests belong in the test crate).
|
|
146
|
+
await checkNoTestsInContracts(nargo, log);
|
|
147
|
+
|
|
44
148
|
const artifacts = await collectContractArtifacts();
|
|
45
149
|
|
|
46
150
|
if (artifacts.length > 0) {
|