Skip to content

Commit

Permalink
Add Additional Checks on Assets Folder (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlordell authored Feb 19, 2024
1 parent fa33010 commit f396380
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 73 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
],
"scripts": {
"build": "yarn rimraf dist && tsc",
"lint": "eslint --max-warnings 0 .",
"lint": "yarn lint:ts && yarn lint:json",
"lint:ts": "eslint --max-warnings 0 .",
"lint:json": "prettier -c src/assets/*/*.json",
"prepack": "yarn build",
"prepare": "husky install",
"test": "jest"
Expand Down Expand Up @@ -45,7 +47,7 @@
"eslint-plugin-prettier": "^3.1.4",
"husky": "^5.1.3",
"jest": "^28.1.0",
"prettier": "^2.1.2",
"prettier": "^3.2.5",
"ts-jest": "^28.0.2",
"ts-node": "^9.1.1",
"typescript": "^4.9.4"
Expand Down
91 changes: 91 additions & 0 deletions src/__tests__/assets.test.ts
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]);
}
});
});
});
}
});
106 changes: 53 additions & 53 deletions src/assets/v1.0.0/proxy_factory.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,94 +12,94 @@
},
"abi": [
{
"constant":false,
"inputs":[
"constant": false,
"inputs": [
{
"name":"_mastercopy",
"type":"address"
"name": "_mastercopy",
"type": "address"
},
{
"name":"initializer",
"type":"bytes"
"name": "initializer",
"type": "bytes"
},
{
"name":"saltNonce",
"type":"uint256"
"name": "saltNonce",
"type": "uint256"
}
],
"name":"createProxyWithNonce",
"outputs":[
"name": "createProxyWithNonce",
"outputs": [
{
"name":"proxy",
"type":"address"
"name": "proxy",
"type": "address"
}
],
"payable":false,
"stateMutability":"nonpayable",
"type":"function"
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant":true,
"inputs":[],
"name":"proxyCreationCode",
"outputs":[
"constant": true,
"inputs": [],
"name": "proxyCreationCode",
"outputs": [
{
"name":"",
"type":"bytes"
"name": "",
"type": "bytes"
}
],
"payable":false,
"stateMutability":"pure",
"type":"function"
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant":false,
"inputs":[
"constant": false,
"inputs": [
{
"name":"masterCopy",
"type":"address"
"name": "masterCopy",
"type": "address"
},
{
"name":"data",
"type":"bytes"
"name": "data",
"type": "bytes"
}
],
"name":"createProxy",
"outputs":[
"name": "createProxy",
"outputs": [
{
"name":"proxy",
"type":"address"
"name": "proxy",
"type": "address"
}
],
"payable":false,
"stateMutability":"nonpayable",
"type":"function"
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant":true,
"inputs":[],
"name":"proxyRuntimeCode",
"outputs":[
"constant": true,
"inputs": [],
"name": "proxyRuntimeCode",
"outputs": [
{
"name":"",
"type":"bytes"
"name": "",
"type": "bytes"
}
],
"payable":false,
"stateMutability":"pure",
"type":"function"
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"anonymous":false,
"inputs":[
"anonymous": false,
"inputs": [
{
"indexed":false,
"name":"proxy",
"type":"address"
"indexed": false,
"name": "proxy",
"type": "address"
}
],
"name":"ProxyCreation",
"type":"event"
"name": "ProxyCreation",
"type": "event"
}
]
}
1 change: 1 addition & 0 deletions src/assets/v1.3.0/create_call.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"255": "0xB19D6FFc2182150F8Eb585b79D4ABcd7C5640A9d",
"280": "0xcB8e5E438c5c2b45FbE17B02Ca9aF91509a8ad56",
"288": "0xB19D6FFc2182150F8Eb585b79D4ABcd7C5640A9d",
"291": "0x7cbB62EaA69F79e6873cD1ecB2392971036cFAa4",
"300": "0x7cbB62EaA69F79e6873cD1ecB2392971036cFAa4",
"321": "0x7cbB62EaA69F79e6873cD1ecB2392971036cFAa4",
"322": "0x7cbB62EaA69F79e6873cD1ecB2392971036cFAa4",
Expand Down
1 change: 1 addition & 0 deletions src/assets/v1.3.0/sign_message_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
"167008": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2",
"200101": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2",
"200202": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2",
"333999": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2",
"421611": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2",
"421613": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2",
"421614": "0xA65387F16B013cf2Af4605Ad8aA5ec25a2cbA3a2",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/v1.3.0/simulate_tx_accessor.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"336": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da",
"338": "0x727a77a074D1E6c4530e814F89E618a3298FC044",
"420": "0x727a77a074D1E6c4530e814F89E618a3298FC044",
"424": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da",
"570": "0x727a77a074D1E6c4530e814F89E618a3298FC044",
"588": "0x727a77a074D1E6c4530e814F89E618a3298FC044",
"592": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da",
Expand Down Expand Up @@ -145,6 +146,7 @@
"54211": "0x727a77a074D1E6c4530e814F89E618a3298FC044",
"56288": "0x727a77a074D1E6c4530e814F89E618a3298FC044",
"57000": "0x727a77a074D1E6c4530e814F89E618a3298FC044",
"58008": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da",
"59140": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da",
"59144": "0x59AD6735bCd8152B84860Cb256dD9e96b85F69Da",
"71401": "0x727a77a074D1E6c4530e814F89E618a3298FC044",
Expand Down
4 changes: 2 additions & 2 deletions src/assets/v1.4.1/compatibility_fallback_handler.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
"8192": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"8194": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"8453": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"84532": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"10243": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"13337": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"11235": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"13337": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"17000": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"42161": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"42220": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"54211": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"80001": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"84531": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"84532": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99",
"11155111": "0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99"
},
"abi": [
Expand Down
4 changes: 2 additions & 2 deletions src/assets/v1.4.1/create_call.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
"8192": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"8194": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"8453": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"84532": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"10243": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"13337": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"11235": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"13337": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"17000": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"42161": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"42220": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"54211": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"80001": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"84531": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"84532": "0x9b35Af71d77eaf8d7e40252370304687390A1A52",
"11155111": "0x9b35Af71d77eaf8d7e40252370304687390A1A52"
},
"abi": [
Expand Down
4 changes: 2 additions & 2 deletions src/assets/v1.4.1/multi_send.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
"8192": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"8194": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"8453": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"84532": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"10243": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"13337": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"11235": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"13337": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"17000": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"42161": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"42220": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"54211": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"80001": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"84531": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"84532": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526",
"11155111": "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526"
},
"abi": [
Expand Down
4 changes: 2 additions & 2 deletions src/assets/v1.4.1/multi_send_call_only.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
"8192": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"8194": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"8453": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"84532": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"10243": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"13337": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"11235": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"13337": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"17000": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"42161": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"42220": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"54211": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"80001": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"84531": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"84532": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2",
"11155111": "0x9641d764fc13c8B624c04430C7356C1C7C8102e2"
},
"abi": [
Expand Down
4 changes: 2 additions & 2 deletions src/assets/v1.4.1/safe.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
"8192": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"8194": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"8453": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"84532": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"10243": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"13337": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"11235": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"13337": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"17000": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"42161": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"42220": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"54211": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"80001": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"84531": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"84532": "0x41675C099F32341bf84BFc5382aF534df5C7461a",
"11155111": "0x41675C099F32341bf84BFc5382aF534df5C7461a"
},
"abi": [
Expand Down
Loading

0 comments on commit f396380

Please sign in to comment.