Skip to content

Commit

Permalink
Merge #1390
Browse files Browse the repository at this point in the history
1390: Create a centralized place for reading test configs r=popzxc a=perekopskiy



Co-authored-by: perekopskiy <[email protected]>
  • Loading branch information
bors-matterlabs-dev[bot] and perekopskiy authored Feb 12, 2021
2 parents 513f7bf + a7b7074 commit 7875fd7
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 77 deletions.
2 changes: 2 additions & 0 deletions changelog/infrastructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ components, the logs will have the following format:

### Added

- (`reading-tool`): tool for reading test config.

### Fixed

## Release 2021-02-02
Expand Down
60 changes: 0 additions & 60 deletions core/tests/ts-tests/tests/helpers.ts

This file was deleted.

4 changes: 2 additions & 2 deletions core/tests/ts-tests/tests/withdrawal-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import './priority-ops';
import './change-pub-key';
import './withdrawal-helpers';

import { loadTestConfig } from './helpers';
import { loadTestConfig } from 'reading-tool';

const TX_AMOUNT = utils.parseEther('1');
const DEPOSIT_AMOUNT = TX_AMOUNT.mul(200);

const TEST_CONFIG = loadTestConfig();
const TEST_CONFIG = loadTestConfig(true);

// The token here should have the ERC20 implementation from RevertTransferERC20.sol
const erc20Token = 'wBTC';
Expand Down
24 changes: 22 additions & 2 deletions core/tests/ts-tests/tests/withdrawal-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { expect } from 'chai';
import { Wallet, types, Provider, utils } from 'zksync';
import { BigNumber, ethers } from 'ethers';
import { Address } from 'zksync/build/types';
import { sleep } from 'zksync/build/utils';

import { RevertReceiveAccountFactory, RevertTransferERC20Factory } from '../../../../contracts/typechain';
import { waitForOnchainWithdrawal, loadTestConfig } from './helpers';
import { loadTestConfig } from 'reading-tool';

const TEST_CONFIG = loadTestConfig();
const TEST_CONFIG = loadTestConfig(true);

type TokenLike = types.TokenLike;

Expand All @@ -24,6 +25,25 @@ declare module './tester' {
}
}

async function waitForOnchainWithdrawal(
syncProvider: Provider,
hash: string,
polling_interval: number = 200,
polling_timeout: number = 35000
): Promise<string | null> {
let withdrawalTxHash = null;
const polling_iterations = polling_timeout / polling_interval;
for (let i = 0; i < polling_iterations; i++) {
withdrawalTxHash = await syncProvider.getEthTxForWithdrawal(hash);
if (withdrawalTxHash != null) {
break;
}
await sleep(polling_interval);
}

return withdrawalTxHash;
}

async function setRevertReceive(ethWallet: ethers.Signer, to: Address, value: boolean) {
const revertReceiveContract = RevertReceiveAccountFactory.connect(to, ethWallet);

Expand Down
1 change: 1 addition & 0 deletions infrastructure/reading-tool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
10 changes: 10 additions & 0 deletions infrastructure/reading-tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Tool for reading test config

An utility to read data from test configs for ts-tests and zksync.js. Currently, it reads data from 'etc/test_config/'
and 'etc/tokens/'.

## Compile

```
yarn run build
```
15 changes: 15 additions & 0 deletions infrastructure/reading-tool/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "reading-tool",
"version": "1.0.0",
"license": "MIT",
"main": "build/index.js",
"private": true,
"devDependencies": {
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"scripts": {
"build": "tsc",
"watch": "tsc --watch"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function loadConfig(path: string) {
);
}

export function loadTestConfig() {
export function loadTestConfig(withWithdrawalHelpers: boolean) {
const eipConstantPath = configPath('constant/eip1271.json');
const eipVolatilePath = configPath('volatile/eip1271.json');

Expand All @@ -21,12 +21,22 @@ export function loadTestConfig() {
const eipConfig = Object.assign(eipConstantConfig, eipVolatileConfig);

const ethConstantPath = configPath('constant/eth.json');
let ethConfig = loadConfig(ethConstantPath);

return {
eip1271: eipConfig,
eth: ethConfig
};
const ethConfig = loadConfig(ethConstantPath);

if (withWithdrawalHelpers) {
const withdrawalHelpersConfigPath = configPath('volatile/withdrawal-helpers.json');
const withdrawalHelpersConfig = loadConfig(withdrawalHelpersConfigPath);
return {
eip1271: eipConfig,
eth: ethConfig,
withdrawalHelpers: withdrawalHelpersConfig
};
} else {
return {
eip1271: eipConfig,
eth: ethConfig
};
}
}

export function loadTestVectorsConfig() {
Expand Down
16 changes: 16 additions & 0 deletions infrastructure/reading-tool/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",

"outDir": "./build",
"esModuleInterop": true,
"declaration": true,

"preserveSymlinks": true,
"preserveWatchOutput": true
},
"files": [
"./src/index.ts"
]
}
1 change: 1 addition & 0 deletions infrastructure/zk/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export async function tokenInfo(address: string) {
// installs all dependencies and builds our js packages
export async function yarn() {
await utils.spawn('yarn');
await utils.spawn('yarn reading-tool build');
await utils.spawn('yarn zksync prepublish');
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"infrastructure/explorer",
"infrastructure/zk",
"infrastructure/eth_transfer",
"infrastructure/reading-tool",
"core/tests/ts-tests"
],
"nohoist": [
Expand All @@ -33,7 +34,8 @@
"zcli": "yarn workspace zcli",
"ts-tests": "yarn workspace ts-tests",
"explorer": "yarn workspace sync-explorer",
"zk": "yarn workspace zk"
"zk": "yarn workspace zk",
"reading-tool": "yarn workspace reading-tool"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.10.0",
Expand Down
4 changes: 2 additions & 2 deletions sdk/zksync.js/tests/eip1271.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from 'chai';
import * as ethers from 'ethers';
import { loadTestConfig } from './helpers';
import { loadTestConfig } from 'reading-tool';
import * as zkUtils from '../src/utils';

const testConfig = loadTestConfig();
const testConfig = loadTestConfig(false);
const provider = new ethers.providers.JsonRpcProvider(process.env.ETH_CLIENT_WEB3_URL.split(',')[0]);
const ethSigner = new ethers.Wallet(testConfig.eip1271.owner_private_key).connect(provider);

Expand Down
2 changes: 1 addition & 1 deletion sdk/zksync.js/tests/provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { Provider } from '../src/provider';
import { getTokens } from './helpers';
import { getTokens } from 'reading-tool';

describe('Provider tests', function () {
it('Update token set', async function () {
Expand Down
2 changes: 1 addition & 1 deletion sdk/zksync.js/tests/vectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
parseHexWithPrefix
} from '../src/utils';
import { privateKeyFromSeed, signTransactionBytes } from '../src/crypto';
import { loadTestVectorsConfig } from './helpers';
import { loadTestVectorsConfig } from 'reading-tool';

const vectors = loadTestVectorsConfig();
const cryptoPrimitivesVectors = vectors['cryptoPrimitivesTest'];
Expand Down
2 changes: 1 addition & 1 deletion sdk/zksync.js/tests/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { BigNumber, ethers } from 'ethers';
import { Wallet } from '../src/wallet';
import { getTokens } from './helpers';
import { getTokens } from 'reading-tool';

import { Provider } from '../src/provider';

Expand Down

0 comments on commit 7875fd7

Please sign in to comment.