Skip to content

Commit b3d222e

Browse files
committed
test: fix broken tests for zk broadcasts
feat: more aliases in justfile feat: script for printing chains fix: fix addresses for Sophon refactor: rename scripts test: rename functions
1 parent 9285078 commit b3d222e

File tree

15 files changed

+158
-239
lines changed

15 files changed

+158
-239
lines changed

TODOs.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@
55

66
# Priority 2
77

8-
- [ ] Check why Sophon tests don't work
9-
- [ ] Add just script for printing available chain names
108
- [ ] Add `@unimplemented` tag for `compilerSettings`

justfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ biome-write:
1616

1717
# Build the project
1818
build: clean tsc-build
19+
alias b := build
1920

2021
# Clean the dist directory
2122
clean:
2223
bun rimraf dist
2324

2425
# Run all code checks
2526
full-check: biome-check prettier-check tsc-check
27+
alias c := full-check
2628

2729
# Run all code fixes
2830
full-write: biome-write prettier-write
@@ -39,13 +41,18 @@ prettier-check:
3941
prettier-write:
4042
bun prettier --cache --write "**/*.{md,yml}"
4143

44+
# Print available chain arguments
45+
@print thing:
46+
bun run scripts/print-{{ thing }}.ts
47+
4248
# Setup Husky
4349
setup:
4450
bun husky
4551

4652
# Run tests
4753
test:
4854
bun vitest run --silent
55+
alias t := test
4956

5057
# Run tests with UI
5158
test-ui:
Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,45 @@
11
import path from "node:path";
22
import type { Sablier } from "@src/types";
3-
import type { Options as GlobbyOptions } from "globby";
4-
import { globby } from "globby";
3+
import * as fs from "fs-extra";
54
import { logInfo } from "./logger";
65

76
const ROOT_DIR = path.join(__dirname, "..");
87

98
export async function checkBroadcast(
109
release: Sablier.Release,
1110
chain: Sablier.Chain,
12-
contractPath?: string,
11+
innerPath?: string,
1312
): Promise<string | null> {
14-
return chain.isZK
15-
? checkZKBroadcast(release, chain, contractPath)
16-
: checkStandardBroadcast(release, chain, contractPath);
13+
if (chain.isZK) {
14+
return await checkZK(release, chain, innerPath);
15+
} else {
16+
return await checkStandard(release, chain, innerPath);
17+
}
1718
}
1819
/**
1920
* Checks that the broadcast file exists for the specified release and chain.
2021
* @param release - The release to check
2122
* @param chain - The chain to check
22-
* @param contractPath - The inner directory path to the contract to check, e.g. "core" or "periphery"
23+
* @param innerPath - The inner directory path to the contract to check, e.g. "core" or "periphery"
2324
* @returns The path to the broadcast file if it exists, otherwise null
2425
*/
25-
async function checkStandardBroadcast(
26+
async function checkStandard(
2627
release: Sablier.Release,
2728
chain: Sablier.Chain,
28-
contractPath?: string,
29+
innerPath?: string,
2930
): Promise<string | null> {
30-
return checkPath(release, chain, { onlyFiles: true }, contractPath, ".json");
31+
return await checkPathExists(release, chain, innerPath, ".json");
3132
}
3233

3334
/**
3435
* Checks that the ZK broadcast directory exists for the specified release and chain.
3536
* @param release - The release to check
3637
* @param chain - The chain to check
37-
* @param contractPath - The inner directory path to the contract to check, e.g. "core" or "periphery"
38+
* @param innerPath - The inner directory path to the contract to check, e.g. "core" or "periphery"
3839
* @returns The path to the broadcast directory if it exists, otherwise null
3940
*/
40-
async function checkZKBroadcast(
41-
release: Sablier.Release,
42-
chain: Sablier.Chain,
43-
contractPath?: string,
44-
): Promise<string | null> {
45-
return checkPath(release, chain, { onlyDirectories: true }, contractPath, "");
41+
async function checkZK(release: Sablier.Release, chain: Sablier.Chain, innerPath?: string): Promise<string | null> {
42+
return await checkPathExists(release, chain, innerPath, "");
4643
}
4744

4845
/**
@@ -58,30 +55,25 @@ async function checkZKBroadcast(
5855
* └── mainnets/
5956
* └── ethereum.json
6057
*/
61-
async function checkPath(
58+
async function checkPathExists(
6259
release: Sablier.Release,
6360
chain: Sablier.Chain,
64-
options: GlobbyOptions,
65-
contractPath = "",
61+
innerPath = "",
6662
suffix = "",
6763
): Promise<string | null> {
6864
const chainType = chain.isTestnet ? "testnets" : "mainnets";
6965
const chainPath = path.join(chainType, `${chain.slug}${suffix}`);
7066
const basePath = path.join(__dirname, "..", "data", release.protocol, release.version);
71-
const contractPathWithSlashes = contractPath ? `/${contractPath}/` : "";
67+
const contractPathWithSlashes = innerPath ? `/${innerPath}/` : "";
7268
const pathToCheck = path.join(basePath, contractPathWithSlashes, chainPath);
7369

74-
const [pathExists] = await globby(pathToCheck, options);
75-
const found = pathExists ? pathToCheck : null;
76-
77-
if (!pathExists) {
70+
if (!fs.existsSync(pathToCheck)) {
7871
const relativePath = path.relative(ROOT_DIR, pathToCheck);
7972
logInfo({
8073
msg: `No broadcasts for ${chain.name} at ${relativePath}`,
8174
release,
8275
});
83-
return null;
8476
}
8577

86-
return found;
78+
return pathToCheck;
8779
}

scripts/print-chains.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { mainnets, testnets } from "@src/chains";
2+
import _ from "lodash";
3+
4+
if (require.main === module) {
5+
console.log("🌐 Mainnets:");
6+
console.log(
7+
_.values(mainnets)
8+
.map((c) => `- ${c.slug}`)
9+
.join("\n"),
10+
);
11+
12+
console.log("\n🧪 Testnets:");
13+
console.log(
14+
_.values(testnets)
15+
.map((c) => `- ${c.slug}`)
16+
.join("\n"),
17+
);
18+
}

scripts/print-missing-broadcasts.ts renamed to scripts/print-missing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import queries from "@src/queries";
1212
import { releasesByProtocol } from "@src/releases";
1313
import type { Sablier } from "@src/types";
1414
import _ from "lodash";
15-
import { checkBroadcast } from "./check-broadcasts";
15+
import { checkBroadcast } from "./check-broadcast";
1616
import logger, { logAndThrow } from "./logger";
1717

1818
const EMOJIS = {

src/chains/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const config = {
2828
[viem.abstract.id]: true,
2929
[viem.sophon.id]: true,
3030
[viem.zksync.id]: true,
31+
[viem.zksyncSepoliaTestnet.id]: true,
3132
} as ConfigBool,
3233
};
3334

src/releases/lockup/v2.0/deployments.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ export const mainnets: Sablier.Deployment[] = [
168168
}),
169169
get(chains.sophon.id, {
170170
[manifest.HELPERS]: "0x424B27529B49EF4Bfa0727aFcFE4387Ac2932944",
171-
[manifest.LOCKUP_NFT_DESCRIPTOR]: "0xeaFB40669fe3523b073904De76410b46e79a56D7",
172-
[manifest.SABLIER_BATCH_LOCKUP]: "0xAc2E42b520364940c90Ce164412Ca9BA212d014B",
173-
[manifest.SABLIER_LOCKUP]: ["0x0000000000000000000000000000000000001010", 11_275_708],
171+
[manifest.LOCKUP_NFT_DESCRIPTOR]: "0xAc2E42b520364940c90Ce164412Ca9BA212d014B",
172+
[manifest.SABLIER_BATCH_LOCKUP]: "0x7282d83E49363f373102d195F66649eBD6C57B9B",
173+
[manifest.SABLIER_LOCKUP]: ["0x28fCAE6bda2546C93183EeC8638691B2EB184003", 11_275_708],
174174
[manifest.VESTING_MATH]: "0x9971914DA16787F6cCfb27bEfB4404e33C8b869D",
175175
}),
176176
get(chains.superseed.id, {

tests/chains.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import axios from "axios";
1717
import { globby } from "globby";
1818
import _ from "lodash";
1919
import { beforeAll, describe, expect, it } from "vitest";
20+
import { MISSING_CHAINS } from "./setup/missing";
2021

2122
const MALFUNCTIONING_RPC: number[] = [chains.meld.id];
22-
const MISSING_BROADCASTS: string[] = ["iotex", "ronin", "tangle", "ultra"];
2323
const KNOWN_SLUGS = _.values(chains)
24-
.filter((chain) => !MISSING_BROADCASTS.includes(chain.slug))
24+
.filter((chain) => !MISSING_CHAINS.includes(chain.id))
2525
.map((chain) => chain.slug);
2626

2727
describe("Package chains are in sync with broadcasts", () => {
@@ -53,7 +53,7 @@ describe("Package chains are in sync with broadcasts", () => {
5353

5454
it("should not have any unknown chain in broadcasts", () => {
5555
errors.clear();
56-
const allowedSlugs = [...KNOWN_SLUGS, ...MISSING_BROADCASTS];
56+
const allowedSlugs = [...KNOWN_SLUGS, ...MISSING_CHAINS];
5757
const extraChains = _.difference(broadcastSlugs, allowedSlugs);
5858

5959
for (const slug of extraChains) {

tests/contracts/deployment-blocks.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { names } from "@src/contracts";
32
import { Protocol } from "@src/enums";
43
import queries from "@src/queries";

tests/deployments/utils/finders.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import _ from "lodash";
2-
import type { BasicContract, BroadcastJSON, ZKBroadcastJSON } from "../../types";
2+
import type { BasicContract, StandardBroadcast, ZKBroadcast } from "../../types";
33

44
const CONTRACT_PREFIX = "contract ";
55

66
/**
77
* Finds a contract in the broadcast data.
88
*/
9-
export function findContract(data: BroadcastJSON, contractName: string): BasicContract | null {
9+
export function findContract(data: StandardBroadcast, contractName: string): BasicContract | null {
1010
const contractFromReturns = findInReturns(data, contractName);
1111
if (contractFromReturns) return contractFromReturns;
1212

@@ -17,8 +17,8 @@ export function findContract(data: BroadcastJSON, contractName: string): BasicCo
1717
return null;
1818
}
1919

20-
export function findZKContract(zkData: ZKBroadcastJSON[], contractName: string): ZKBroadcastJSON | null {
21-
return zkData.find((zk) => zk.contractName === contractName) ?? null;
20+
export function findZKContract(zkData: ZKBroadcast[], contractName: string): ZKBroadcast | null {
21+
return _.find(zkData, { contractName }) ?? null;
2222
}
2323

2424
/**
@@ -31,8 +31,11 @@ export function findZKContract(zkData: ZKBroadcastJSON[], contractName: string):
3131
* }
3232
* }
3333
*/
34-
export function findInReturns(data: BroadcastJSON, contractName: string): BasicContract | null {
35-
if (!data.returns) return null;
34+
function findInReturns(data: StandardBroadcast, contractName: string): BasicContract | null {
35+
if (!data.returns) {
36+
return null;
37+
}
38+
3639
for (const contractReturn of _.values(data.returns)) {
3740
const sanitizedName = contractReturn.internal_type.replace(CONTRACT_PREFIX, "");
3841
if (contractName === sanitizedName) {
@@ -50,8 +53,10 @@ export function findInReturns(data: BroadcastJSON, contractName: string): BasicC
5053
* "src/libraries/Helpers.sol:Helpers:0xf8076E4Fb5cfE8be1C26E61222DC51828Db8C1dc"
5154
* ]
5255
*/
53-
export function findInLibraries(data: BroadcastJSON, contractName: string): BasicContract | null {
54-
if (!data.libraries) return null;
56+
function findInLibraries(data: StandardBroadcast, contractName: string): BasicContract | null {
57+
if (!data.libraries) {
58+
return null;
59+
}
5560

5661
for (const library of data.libraries) {
5762
// Ensure we have the format "path/to/file.sol:ContractName:0xAddress"

0 commit comments

Comments
 (0)