chore: Add checks for addresses.json
[TKR-519] (#549)
This commit is contained in:
parent
8aa313a437
commit
08e0c2ebb9
@ -128,6 +128,7 @@ jobs:
|
|||||||
keys:
|
keys:
|
||||||
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
- repo-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run: yarn wsrun -p @0x/contracts-test-utils -m --serial -c test:circleci
|
- run: yarn wsrun -p @0x/contracts-test-utils -m --serial -c test:circleci
|
||||||
|
- run: yarn wsrun -p @0x/contract-addresses -m --serial -c test:circleci
|
||||||
- run: yarn wsrun -p @0x/contract-artifacts -m --serial -c test:circleci
|
- run: yarn wsrun -p @0x/contract-artifacts -m --serial -c test:circleci
|
||||||
- run: yarn wsrun -p @0x/contract-wrappers-test -m --serial -c test:circleci
|
- run: yarn wsrun -p @0x/contract-wrappers-test -m --serial -c test:circleci
|
||||||
- run: yarn wsrun -p @0x/order-utils -m --serial -c test:circleci
|
- run: yarn wsrun -p @0x/order-utils -m --serial -c test:circleci
|
||||||
@ -195,7 +196,7 @@ workflows:
|
|||||||
# - build
|
# - build
|
||||||
- test-foundry:
|
- test-foundry:
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
- test-contracts-rest-ganache:
|
- test-contracts-rest-ganache:
|
||||||
requires:
|
requires:
|
||||||
- build
|
- build
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn tsc -b",
|
"build": "yarn tsc -b",
|
||||||
"build:ci": "yarn build",
|
"build:ci": "yarn build",
|
||||||
|
"test": "mocha --require source-map-support/register 'lib/test/**/*_test.js' --timeout 10000 --bail --exit",
|
||||||
|
"test:circleci": "yarn test",
|
||||||
"clean": "shx rm -rf lib",
|
"clean": "shx rm -rf lib",
|
||||||
"publish:private": "yarn build && gitpkg publish"
|
"publish:private": "yarn build && gitpkg publish"
|
||||||
},
|
},
|
||||||
@ -28,7 +30,11 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/0xProject/protocol/tree/main/packages/contract-addresses",
|
"homepage": "https://github.com/0xProject/protocol/tree/main/packages/contract-addresses",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/mocha": "^5.2.7",
|
||||||
|
"chai": "^4.0.1",
|
||||||
|
"ethereumjs-util": "^7.1.5",
|
||||||
"gitpkg": "https://github.com/0xProject/gitpkg.git",
|
"gitpkg": "https://github.com/0xProject/gitpkg.git",
|
||||||
|
"mocha": "^6.2.0",
|
||||||
"shx": "^0.2.2",
|
"shx": "^0.2.2",
|
||||||
"typescript": "4.6.3"
|
"typescript": "4.6.3"
|
||||||
},
|
},
|
||||||
|
70
packages/contract-addresses/test/addresses_test.ts
Normal file
70
packages/contract-addresses/test/addresses_test.ts
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import * as chai from 'chai';
|
||||||
|
import 'mocha';
|
||||||
|
|
||||||
|
import { ChainId, getContractAddressesForChainOrThrow } from '../src';
|
||||||
|
import { bufferToHex, rlphash } from 'ethereumjs-util';
|
||||||
|
|
||||||
|
const expect = chai.expect;
|
||||||
|
|
||||||
|
function toDeployedAddress(deployerAddress: string, nonce: number): string {
|
||||||
|
return bufferToHex(rlphash([deployerAddress, nonce]).slice(12));
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidDeployedAddress(deployerAddress: string, deployedAddress: string): boolean {
|
||||||
|
for (let i = 0; i < 256; i++) {
|
||||||
|
const address = toDeployedAddress(deployerAddress, i);
|
||||||
|
if (address.toLowerCase() === deployedAddress.toLowerCase()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('addresses.json sanity test', () => {
|
||||||
|
const allChainIds = Object.values(ChainId).filter(chainId => !isNaN(Number(chainId))) as ChainId[];
|
||||||
|
allChainIds.forEach(chainId => {
|
||||||
|
describe(`addresses of chain id ${chainId}`, () => {
|
||||||
|
const contractAddresses = getContractAddressesForChainOrThrow(chainId);
|
||||||
|
it('all addresses are lowercased', async () => {
|
||||||
|
const addresses = [
|
||||||
|
contractAddresses.zrxToken,
|
||||||
|
contractAddresses.etherToken,
|
||||||
|
contractAddresses.zeroExGovernor,
|
||||||
|
contractAddresses.zrxVault,
|
||||||
|
contractAddresses.staking,
|
||||||
|
contractAddresses.erc20BridgeProxy,
|
||||||
|
contractAddresses.erc20BridgeSampler,
|
||||||
|
contractAddresses.exchangeProxyGovernor,
|
||||||
|
contractAddresses.exchangeProxy,
|
||||||
|
contractAddresses.exchangeProxyTransformerDeployer,
|
||||||
|
contractAddresses.exchangeProxyFlashWallet,
|
||||||
|
contractAddresses.exchangeProxyLiquidityProviderSandbox,
|
||||||
|
contractAddresses.zrxTreasury,
|
||||||
|
contractAddresses.transformers.wethTransformer,
|
||||||
|
contractAddresses.transformers.payTakerTransformer,
|
||||||
|
contractAddresses.transformers.fillQuoteTransformer,
|
||||||
|
contractAddresses.transformers.affiliateFeeTransformer,
|
||||||
|
contractAddresses.transformers.positiveSlippageFeeTransformer,
|
||||||
|
];
|
||||||
|
addresses.forEach(address => {
|
||||||
|
expect(address).to.eq(address.toLowerCase());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('all transformer addresses are valid', async () => {
|
||||||
|
const transformerAddresses = [
|
||||||
|
contractAddresses.transformers.wethTransformer,
|
||||||
|
contractAddresses.transformers.payTakerTransformer,
|
||||||
|
contractAddresses.transformers.fillQuoteTransformer,
|
||||||
|
contractAddresses.transformers.affiliateFeeTransformer,
|
||||||
|
contractAddresses.transformers.positiveSlippageFeeTransformer,
|
||||||
|
].filter(address => address !== '0x0000000000000000000000000000000000000000');
|
||||||
|
transformerAddresses.forEach(transformerAddress => {
|
||||||
|
expect(
|
||||||
|
isValidDeployedAddress(contractAddresses.exchangeProxyTransformerDeployer, transformerAddress),
|
||||||
|
).to.true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -6,6 +6,6 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true
|
||||||
},
|
},
|
||||||
"include": ["./src/**/*"],
|
"include": ["./src/**/*", "./test/**/*"],
|
||||||
"files": ["./addresses.json"]
|
"files": ["./addresses.json"]
|
||||||
}
|
}
|
||||||
|
17
yarn.lock
17
yarn.lock
@ -3788,9 +3788,9 @@ bigi@1.4.2, bigi@^1.1.0:
|
|||||||
resolved "https://registry.yarnpkg.com/bigi/-/bigi-1.4.2.tgz#9c665a95f88b8b08fc05cfd731f561859d725825"
|
resolved "https://registry.yarnpkg.com/bigi/-/bigi-1.4.2.tgz#9c665a95f88b8b08fc05cfd731f561859d725825"
|
||||||
|
|
||||||
bignumber.js@7.2.1, bignumber.js@^9.0.0, bignumber.js@^9.0.2, bignumber.js@~4.1.0, bignumber.js@~9.0.0, bignumber.js@~9.0.2:
|
bignumber.js@7.2.1, bignumber.js@^9.0.0, bignumber.js@^9.0.2, bignumber.js@~4.1.0, bignumber.js@~9.0.0, bignumber.js@~9.0.2:
|
||||||
version "9.0.2"
|
version "9.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.2.tgz#71c6c6bed38de64e24a65ebe16cfcf23ae693673"
|
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.0.tgz#8d340146107fe3a6cb8d40699643c302e8773b62"
|
||||||
integrity sha512-GAcQvbpsM0pUb0zw1EI0KhQEZ+lRwR5fYaAp3vPOYuP7aDvGy6cVN6XHLauvF8SOga2y0dcLcjt3iQDTSEliyw==
|
integrity sha512-4LwHK4nfDOraBCtst+wOWIHbu1vhvAPJK8g8nROd4iuc3PSEjWif/qwbkh8jwCJz6yDBvtU4KPynETgrfh7y3A==
|
||||||
|
|
||||||
binary-extensions@^2.0.0:
|
binary-extensions@^2.0.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
@ -6184,6 +6184,17 @@ ethereumjs-util@^7.1.0:
|
|||||||
ethjs-util "0.1.6"
|
ethjs-util "0.1.6"
|
||||||
rlp "^2.2.4"
|
rlp "^2.2.4"
|
||||||
|
|
||||||
|
ethereumjs-util@^7.1.5:
|
||||||
|
version "7.1.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.5.tgz#9ecf04861e4fbbeed7465ece5f23317ad1129181"
|
||||||
|
integrity sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg==
|
||||||
|
dependencies:
|
||||||
|
"@types/bn.js" "^5.1.0"
|
||||||
|
bn.js "^5.1.2"
|
||||||
|
create-hash "^1.1.2"
|
||||||
|
ethereum-cryptography "^0.1.3"
|
||||||
|
rlp "^2.2.4"
|
||||||
|
|
||||||
ethereumjs-vm@4.2.0, ethereumjs-vm@^4.2.0:
|
ethereumjs-vm@4.2.0, ethereumjs-vm@^4.2.0:
|
||||||
version "4.2.0"
|
version "4.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/ethereumjs-vm/-/ethereumjs-vm-4.2.0.tgz#e885e861424e373dbc556278f7259ff3fca5edab"
|
resolved "https://registry.yarnpkg.com/ethereumjs-vm/-/ethereumjs-vm-4.2.0.tgz#e885e861424e373dbc556278f7259ff3fca5edab"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user