Skip to content

Commit

Permalink
Create reading tool
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Feb 8, 2021
1 parent c9aba14 commit 5d90a1b
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 70 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 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.

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

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

const TX_AMOUNT = utils.parseEther('1');
const DEPOSIT_AMOUNT = TX_AMOUNT.mul(200);
Expand Down
22 changes: 21 additions & 1 deletion core/tests/ts-tests/tests/withdrawal-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ 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 '../../../../etc/reading-tool';

const TEST_CONFIG = loadTestConfig();

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
12 changes: 8 additions & 4 deletions sdk/zksync.js/tests/helpers.ts → etc/reading-tool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';

function configPath(postfix: string) {
return `${process.env.ZKSYNC_HOME}/etc/test_config/${postfix}`;
return `./test_config/${postfix}`;
}

function loadConfig(path: string) {
Expand All @@ -21,11 +21,15 @@ export function loadTestConfig() {
const eipConfig = Object.assign(eipConstantConfig, eipVolatileConfig);

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

const withdrawalHelpersConfigPoth = configPath('volatile/withdrawal-helpers.json');
const withdrawalHelpersConfig = loadConfig(withdrawalHelpersConfigPoth);

return {
eip1271: eipConfig,
eth: ethConfig
eth: ethConfig,
withdrawalHelpers: withdrawalHelpersConfig
};
}

Expand All @@ -35,7 +39,7 @@ export function loadTestVectorsConfig() {
}

export function getTokens(network: string) {
const configPath = `${process.env.ZKSYNC_HOME}/etc/tokens/${network}.json`;
const configPath = `./tokens/${network}.json`;
console.log(configPath);
return JSON.parse(
fs.readFileSync(configPath, {
Expand Down
2 changes: 1 addition & 1 deletion sdk/zksync.js/tests/eip1271.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import * as ethers from 'ethers';
import { loadTestConfig } from './helpers';
import { loadTestConfig } from '../../../etc/reading-tool';
import * as zkUtils from '../src/utils';

const testConfig = loadTestConfig();
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 '../../../etc/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 '../../../etc/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 '../../../etc/reading-tool';

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

Expand Down

0 comments on commit 5d90a1b

Please sign in to comment.