forked from AztecProtocol/aztec-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.test.js
91 lines (86 loc) · 2.94 KB
/
bin.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { parse } from "@iarna/toml";
import axios from "axios";
import { execSync } from "child_process";
import fs from "fs/promises";
import path from "path";
import { describe, test, expect, beforeAll } from "vitest";
const getLatestStable = async () => {
try {
const { data } = await axios.get(
`https://api.github.com/repos/AztecProtocol/aztec-packages/releases`,
);
return data[0].tag_name.split("-v")[1];
} catch (error) {
console.error("Error fetching latest stable version:", error);
return;
}
};
const version = await getLatestStable();
const tag = version.match(/^\d+\.\d+\.\d+$/)
? `aztec-packages-v${version}`
: version;
describe("Token contract", () => {
beforeAll(() => {
try {
execSync("npx . new -d -t contract -n token_contract", {
stdio: "inherit",
});
} catch (error) {
console.error("Error executing command:", error);
}
});
test("Paths were updated correctly", async () => {
const replaces = [];
const findAndReplace = async (dir, prefix) => {
const files = await fs.readdir(dir, {
withFileTypes: true,
});
files.forEach(async (file) => {
const filePath = path.join(dir, file.name);
if (file.isDirectory()) {
findAndReplace(filePath, prefix); // Recursively search subdirectories
} else if (file.name === "Nargo.toml") {
replaces.push(
new Promise(async (resolve, reject) => {
let content = parse(await fs.readFile(filePath, "utf8"));
if (!content.dependencies) return;
resolve(
Object.keys(content.dependencies)
.filter((dep) => dep.match("@aztec"))
.every(
(dep) =>
content.dependencies[dep] ===
JSON.stringify({
git: `https://github.com/${AZTEC_REPO}/`,
tag,
directory: `${prefix}${directory}`,
}),
),
);
}),
);
} else if (file.name === "package.json") {
replaces.push(
new Promise(async (resolve, reject) => {
let content = JSON.parse(await fs.readFile(filePath, "utf8"));
if (!content.dependencies) return;
resolve(
Object.keys(content.dependencies)
.filter((deps) => deps.match("@aztec"))
// "master" actually means "latest" for the npm release
.every(
(dep) =>
content.dependencies[dep] ===
`${version === "master" ? "latest" : `^${version}`}`,
),
);
}),
);
}
});
};
await findAndReplace(path.resolve("./token_contract"), "");
const res = await Promise.all(replaces);
expect(res).toEqual([true, true]);
});
});