-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Additional Checks on Assets Folder #386
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
function assetPath(...paths: string[]) { | ||
return path.join(__dirname, "..", "assets", ...paths); | ||
} | ||
|
||
function versions() { | ||
const files = fs.readdirSync(assetPath()); | ||
return files.filter((file) => file.match(/^v[0-9]+\.[0-9]+\.[0-9]+$/)); | ||
} | ||
|
||
function versionFiles(version: string) { | ||
const files = fs.readdirSync(assetPath(version)); | ||
return files.filter((file) => file.match(/.*\.json$/)); | ||
} | ||
|
||
async function readAsset(version: string, file: string) { | ||
return await fs.promises.readFile(assetPath(version, file), "utf-8"); | ||
} | ||
|
||
async function readAssetJSON(version: string, file: string) { | ||
return JSON.parse(await readAsset(version, file)); | ||
} | ||
|
||
describe("assets/", () => { | ||
for (const version of versions()) { | ||
describe(version, () => { | ||
for (const file of versionFiles(version)) { | ||
describe(file, () => { | ||
describe("networkAddresses", () => { | ||
it("should be sorted by chain ID", async () => { | ||
// We manually parse the JSON here, since ECMA `JSON.parse` will | ||
// always order fields with numeric keys. | ||
const json = await readAsset(version, file); | ||
const networkAddresses = json | ||
.replace( | ||
/^[\s\S]*"networkAddresses" *: *\{([^}]*)\}[\s\S]*$/, | ||
"$1" | ||
) | ||
.trim(); | ||
const keys = networkAddresses.split(",").map((pair) => { | ||
const [key] = pair.split(":"); | ||
return parseInt(key.trim().replace(/^"(.*)"$/, "$1")); | ||
}); | ||
const sorted = [...keys].sort((a, b) => a - b); | ||
expect(keys).toEqual(sorted); | ||
}); | ||
|
||
it("should only contain canonical addresses", async () => { | ||
const { networkAddresses } = await readAssetJSON(version, file); | ||
const canonicalAddresses = [ | ||
// Ethereum Mainnet address | ||
networkAddresses[1], | ||
// For v1.3.0, support alternate address with different | ||
// `CREATE2` deployer, notably used for Optimism Mainnet | ||
...(version === "v1.3.0" ? [networkAddresses[10]] : []), | ||
// zkSync Mainnet address | ||
networkAddresses[324], | ||
].filter((address) => address !== undefined); | ||
|
||
for (const [network, address] of Object.entries( | ||
networkAddresses | ||
)) { | ||
expect( | ||
canonicalAddresses.map((address) => [network, address]) | ||
).toContainEqual([network, address]); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
describe("networkAddresses", () => { | ||
it("should contain the same networks in all files", async () => { | ||
const files = versionFiles(version); | ||
const networkCounts: Record<string, number> = {}; | ||
for (const file of files) { | ||
const { networkAddresses } = await readAssetJSON(version, file); | ||
for (const network of Object.keys(networkAddresses)) { | ||
networkCounts[network] = (networkCounts[network] ?? 0) + 1; | ||
} | ||
} | ||
for (const [network, count] of Object.entries(networkCounts)) { | ||
expect([network, count]).toEqual([network, files.length]); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,7 @@ | |
"167008": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2", | ||
"200101": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2", | ||
"200202": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2", | ||
"333999": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing, but unable to verify. Using what the address should be based on other contracts. |
||
"421611": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2", | ||
"421613": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2", | ||
"421614": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
"336": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da", | ||
"338": "0x727a77a074D1E6c4530e814F89E618a3298FC044", | ||
"420": "0x727a77a074D1E6c4530e814F89E618a3298FC044", | ||
"424": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing address, verified https://explorer.publicgoods.network/address/0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da?tab=contract |
||
"570": "0x727a77a074D1E6c4530e814F89E618a3298FC044", | ||
"588": "0x727a77a074D1E6c4530e814F89E618a3298FC044", | ||
"592": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da", | ||
|
@@ -145,6 +146,7 @@ | |
"54211": "0x727a77a074D1E6c4530e814F89E618a3298FC044", | ||
"56288": "0x727a77a074D1E6c4530e814F89E618a3298FC044", | ||
"57000": "0x727a77a074D1E6c4530e814F89E618a3298FC044", | ||
"58008": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contract is not verified, but was deployed: https://explorer.sepolia.publicgoods.network/address/0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da?tab=contract |
||
"59140": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da", | ||
"59144": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da", | ||
"71401": "0x727a77a074D1E6c4530e814F89E618a3298FC044", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was missing. Verified here: https://explorer.orderly.network/address/0x7cbB62EaA69F79e6873cD1ecB2392971036cFAa4?tab=contract