Skip to content

Commit

Permalink
Try fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbochok committed Feb 4, 2021
1 parent 6c8560a commit 6082632
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 80 deletions.
2 changes: 1 addition & 1 deletion contracts/scripts/deploy-testkit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers, Wallet } from 'ethers';
import { Deployer, readContractCode, readTestContracts, readProductionContracts } from '../src.ts/deploy';
import { Deployer, readContractCode, readProductionContracts } from '../src.ts/deploy';
import { deployContract } from 'ethereum-waffle';
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
Expand Down
1 change: 0 additions & 1 deletion contracts/scripts/query-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const wallet = Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").c
const deployer = new Deployer({ deployWallet: wallet });

async function main() {
const zkSyncContract = deployer.zkSyncContract(wallet);
const governanceContract = deployer.governanceContract(wallet);
console.log('total tokens', await governanceContract.totalTokens());
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/test/unit_tests/governance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ describe('Governance unit tests', function () {

let testContract;
before(async () => {
let governanceAddressDeployed;
const contractFactory = await hardhat.ethers.getContractFactory('Governance');
testContract = await contractFactory.deploy();
await testContract.initialize(
ethers.utils.defaultAbiCoder.encode(['address'], [await testContract.signer.getAddress()])
hardhat.ethers.utils.defaultAbiCoder.encode(['address'], [await testContract.signer.getAddress()])
);
});

Expand Down
4 changes: 2 additions & 2 deletions contracts/test/unit_tests/operations_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function getFullExitPubdata({ accountId, tokenId, amount, owner }) {
]);
}

function getFullExitPriorityQueueData({ accountId, tokenId, amount, owner }) {
function getFullExitPriorityQueueData({ accountId, tokenId, owner }) {
return ethers.utils.concat([
ethers.utils.arrayify('0x06'),
ethers.utils.arrayify(accountId),
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('Operations unit tests', function () {
const amount = '0x101112131415161718191a1b1c1d1e1f';
const owner = '0x823B747710C5bC9b8A47243f2c3d1805F1aA00c5';

const priorityQueueData = getFullExitPriorityQueueData({ accountId, tokenId, amount, owner });
const priorityQueueData = getFullExitPriorityQueueData({ accountId, tokenId, owner });
await testContract.testFullExitPriorityQueue({ accountId, tokenId, amount, owner }, priorityQueueData);
});

Expand Down
27 changes: 14 additions & 13 deletions contracts/test/unit_tests/ownable_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ describe('Ownable unit tests', function () {
this.timeout(50000);

let testContract;
let wallet1, wallet2;
let owner_wallet;
let another_wallet;
before(async () => {
[wallet1, wallet2] = await hardhat.ethers.getSigners();
[owner_wallet, another_wallet] = await hardhat.ethers.getSigners();
const contractFactory = await hardhat.ethers.getContractFactory('Ownable');
testContract = await contractFactory.deploy(wallet1.address);
testContract = await contractFactory.deploy(owner_wallet.address);
});

it('checking correctness of setting mastership in constructor', async () => {
expect(await testContract.getMaster()).to.equal(wallet1.address);
expect(await testContract.getMaster()).to.equal(owner_wallet.address);
});

it('checking correctness of transferring mastership to zero address', async () => {
Expand All @@ -25,19 +26,19 @@ describe('Ownable unit tests', function () {
});

it('checking correctness of transferring mastership', async () => {
/// transfer mastership to wallet2
await testContract.transferMastership(wallet2.address);
expect(await testContract.getMaster()).to.equal(wallet2.address);
/// transfer mastership to another_wallet
await testContract.transferMastership(another_wallet.address);
expect(await testContract.getMaster()).to.equal(another_wallet.address);

/// try to transfer mastership to wallet1 by wallet1 call
/// try to transfer mastership to owner_wallet by owner_wallet call
let { revertReason } = await getCallRevertReason(() =>
testContract.transferMastership(wallet1.address, { gasLimit: '300000' })
testContract.transferMastership(owner_wallet.address, { gasLimit: '300000' })
);
expect(revertReason).equal('1c');

/// transfer mastership back to wallet1
let testContract_with_wallet2_signer = await testContract.connect(wallet2);
await testContract_with_wallet2_signer.transferMastership(wallet1.address);
expect(await testContract.getMaster()).to.equal(wallet1.address);
/// transfer mastership back to owner_wallet
let testContract_with_wallet2_signer = await testContract.connect(another_wallet);
await testContract_with_wallet2_signer.transferMastership(owner_wallet.address);
expect(await testContract.getMaster()).to.equal(owner_wallet.address);
});
});
10 changes: 6 additions & 4 deletions contracts/test/unit_tests/proxy_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { expect } = require('chai');
const { getCallRevertReason } = require('./common');
const hardhat = require('hardhat');

import { Contract, constants } from 'ethers';
import { constants } from 'ethers';

const TX_OPTS = {
gasLimit: 300000
Expand All @@ -12,9 +12,11 @@ describe('Proxy unit tests', function () {

let proxyTestContract;
let dummyFirst;
let wallet, wallet1;
let wallet;
before(async () => {
[wallet, wallet1] = await hardhat.ethers.getSigners();
const wallets = await hardhat.ethers.getSigners();
// Get some wallet different from than the default one.
wallet = wallets[1];

const dummyFactory = await hardhat.ethers.getContractFactory('DummyFirst');
dummyFirst = await dummyFactory.deploy();
Expand All @@ -29,7 +31,7 @@ describe('Proxy unit tests', function () {
});

it('checking that requireMaster calls present', async () => {
const testContract_with_wallet2_signer = await proxyTestContract.connect(wallet1);
const testContract_with_wallet2_signer = await proxyTestContract.connect(wallet);
expect(
(
await getCallRevertReason(() =>
Expand Down
19 changes: 1 addition & 18 deletions contracts/test/unit_tests/specific_tokens_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { Contract, ethers, constants, BigNumber } from 'ethers';
import { parseEther } from 'ethers/lib/utils';
import { ETHProxy } from 'zksync';
import { Address, TokenAddress } from 'zksync/build/types';
import { Deployer, readContractCode, readProductionContracts, readTestContracts } from '../../src.ts/deploy';
import { Deployer, readContractCode, readProductionContracts } from '../../src.ts/deploy';
import { ZkSyncWithdrawalUnitTestFactory } from '../../typechain';

const hardhat = require('hardhat');
const { expect } = require('chai');
const { deployContract } = require('ethereum-waffle');
const { getCallRevertReason, IERC20_INTERFACE, DEFAULT_REVERT_REASON } = require('./common');

let wallet, exitWallet;
Expand Down Expand Up @@ -325,8 +324,6 @@ describe('zkSync process tokens which take fee from recipient', function () {

let zksyncContract;
let tokenContract;
let ethProxy;
let FEE_AMOUNT;
before(async () => {
[wallet, exitWallet] = await hardhat.ethers.getSigners();

Expand All @@ -338,16 +335,10 @@ describe('zkSync process tokens which take fee from recipient', function () {

const tokenContractDeployFactory = await hardhat.ethers.getContractFactory('MintableERC20FeeAndDividendsTest');
tokenContract = await tokenContractDeployFactory.deploy(true, false);
FEE_AMOUNT = BigNumber.from(await tokenContract.FEE_AMOUNT_AS_VALUE());
await tokenContract.mint(wallet.address, parseEther('1000000'));

const govContract = deployer.governanceContract(wallet);
await govContract.addToken(tokenContract.address);

ethProxy = new ETHProxy(wallet.provider, {
mainContract: zksyncContract.address,
govContract: govContract.address
});
});

it('Make a deposit of tokens that should take a fee from recipient contract', async () => {
Expand All @@ -364,8 +355,6 @@ describe('zkSync process tokens which adds dividends to recipient', function ()

let zksyncContract;
let tokenContract;
let ethProxy;
let DIVIDEND_AMOUNT;
before(async () => {
[wallet, exitWallet] = await hardhat.ethers.getSigners();

Expand All @@ -377,16 +366,10 @@ describe('zkSync process tokens which adds dividends to recipient', function ()

const tokenContractDeployFactory = await hardhat.ethers.getContractFactory('MintableERC20FeeAndDividendsTest');
tokenContract = await tokenContractDeployFactory.deploy(false, false);
DIVIDEND_AMOUNT = BigNumber.from(await tokenContract.DIVIDEND_AMOUNT_AS_VALUE());
await tokenContract.mint(wallet.address, parseEther('1000000'));

const govContract = deployer.governanceContract(wallet);
await govContract.addToken(tokenContract.address);

ethProxy = new ETHProxy(wallet.provider, {
mainContract: zksyncContract.address,
govContract: govContract.address
});
});

it('Make a deposit of tokens that should adds dividends to the recipient', async () => {
Expand Down
12 changes: 7 additions & 5 deletions contracts/test/unit_tests/upgradeGatekeeper_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { constants } from 'ethers';
const { expect } = require('chai');
const { wallet2, getCallRevertReason } = require('./common');
const { getCallRevertReason } = require('./common');
const { performance } = require('perf_hooks');
const hardhat = require('hardhat');

Expand All @@ -11,13 +11,15 @@ describe('UpgradeGatekeeper unit tests', function () {
this.timeout(50000);

let provider;
let wallet, wallet1;
let wallet;
let proxyTestContract, proxyDummyInterface;
let dummyFirst, dummySecond;
let upgradeGatekeeperContract;
before(async () => {
provider = hardhat.ethers.provider;
[wallet, wallet1] = await hardhat.ethers.getSigners();
const wallets = await hardhat.ethers.getSigners();
// Get some wallet different from than the default one.
wallet = wallets[1];

const dummy1Factory = await hardhat.ethers.getContractFactory('DummyFirst');
dummyFirst = await dummy1Factory.deploy();
Expand Down Expand Up @@ -47,7 +49,7 @@ describe('UpgradeGatekeeper unit tests', function () {
});

it('checking that requireMaster calls present', async () => {
const UpgradeGatekeeperContract_with_wallet2_signer = await upgradeGatekeeperContract.connect(wallet1);
const UpgradeGatekeeperContract_with_wallet2_signer = await upgradeGatekeeperContract.connect(wallet);
expect(
(
await getCallRevertReason(() =>
Expand All @@ -69,7 +71,7 @@ describe('UpgradeGatekeeper unit tests', function () {
).equal('1c');
});

it('checking UpgradeGatekeeper reverts; activation and cancelation upgrade', async () => {
it('checking UpgradeGatekeeper reverts; activation and cancellation upgrade', async () => {
expect((await getCallRevertReason(() => upgradeGatekeeperContract.cancelUpgrade())).revertReason).equal(
'cpu11'
);
Expand Down
30 changes: 13 additions & 17 deletions contracts/test/unit_tests/zksync_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Contract, ethers, constants, BigNumber, BigNumberish } from 'ethers';
import { Contract, ethers, constants, BigNumber } from 'ethers';
import { keccak256, parseEther } from 'ethers/lib/utils';
import { ETHProxy } from 'zksync';
import { Address, TokenAddress } from 'zksync/build/types';
import { Deployer, readContractCode, readProductionContracts, readTestContracts } from '../../src.ts/deploy';
import { Deployer, readContractCode, readProductionContracts } from '../../src.ts/deploy';

const hardhat = require('hardhat');
const { simpleEncode } = require('ethereumjs-abi');
Expand All @@ -21,15 +21,15 @@ import {
const TEST_PRIORITY_EXPIRATION = 101;
const CHUNK_SIZE = 9;

let wallet, exitWallet;
let wallet;

describe('zkSync signature verification unit tests', function () {
this.timeout(50000);

let testContract: ZKSyncSignatureUnitTest;
const randomWallet = ethers.Wallet.createRandom();
before(async () => {
[wallet, exitWallet] = await hardhat.ethers.getSigners();
[wallet] = await hardhat.ethers.getSigners();

const contracts = readProductionContracts();
contracts.zkSync = readContractCode('dev-contracts/ZKSyncSignatureUnitTest');
Expand Down Expand Up @@ -165,10 +165,8 @@ describe('ZK priority queue ops unit tests', function () {

let zksyncContract;
let tokenContract;
let ethProxy;
let operationTestContract;
before(async () => {
[wallet, exitWallet] = await hardhat.ethers.getSigners();
[wallet] = await hardhat.ethers.getSigners();

const contracts = readProductionContracts();
const deployer = new Deployer({ deployWallet: wallet, contracts });
Expand All @@ -182,13 +180,8 @@ describe('ZK priority queue ops unit tests', function () {
const govContract = deployer.governanceContract(wallet);
await govContract.addToken(tokenContract.address);

ethProxy = new ETHProxy(wallet.provider, {
mainContract: zksyncContract.address,
govContract: govContract.address
});

const opsTestContractFactory = await hardhat.ethers.getContractFactory('OperationsTest');
operationTestContract = await opsTestContractFactory.deploy();
await opsTestContractFactory.deploy();
});

async function performDeposit(to: Address, token: TokenAddress, depositAmount: BigNumber) {
Expand Down Expand Up @@ -295,7 +288,7 @@ describe('zkSync withdraw unit tests', function () {
let incorrectTokenContract;
let ethProxy;
before(async () => {
[wallet, exitWallet] = await hardhat.ethers.getSigners();
[wallet] = await hardhat.ethers.getSigners();
const contracts = readProductionContracts();
contracts.zkSync = readContractCode('dev-contracts/ZkSyncWithdrawalUnitTest');
const deployer = new Deployer({ deployWallet: wallet, contracts });
Expand Down Expand Up @@ -437,7 +430,7 @@ describe('zkSync auth pubkey onchain unit tests', function () {
let zksyncContract;
let tokenContract;
before(async () => {
[wallet, exitWallet] = await hardhat.ethers.getSigners();
[wallet] = await hardhat.ethers.getSigners();

const deployer = new Deployer({ deployWallet: wallet });
await deployer.deployAll({ gasLimit: 6500000 });
Expand Down Expand Up @@ -500,7 +493,7 @@ describe('zkSync auth pubkey onchain unit tests', function () {
for (const pkHash of [shortPubkeyHash, longPubkeyHash]) {
const { revertReason } = await getCallRevertReason(
async () =>
await zksyncContract.setAuthPubkeyHash(shortPubkeyHash, nonce, {
await zksyncContract.setAuthPubkeyHash(pkHash, nonce, {
gasLimit: 300000
})
);
Expand Down Expand Up @@ -531,7 +524,7 @@ describe('zkSync test process next operation', function () {
};

before(async () => {
[wallet, exitWallet] = await hardhat.ethers.getSigners();
[wallet] = await hardhat.ethers.getSigners();

const contracts = readProductionContracts();
contracts.zkSync = readContractCode('dev-contracts/ZkSyncProcessOpUnitTest');
Expand Down Expand Up @@ -752,5 +745,8 @@ describe('zkSync test process next operation', function () {

const expectedHash = keccak256(ethers.utils.concat([EMPTY_KECCAK, pubdata]));
await zksyncContract.collectOnchainOpsExternal(blockData, expectedHash, 0, [1, 0, 0, 0, 0, 0]);

const committedPriorityRequestsAfter = await zksyncContract.totalCommittedPriorityRequests();
expect(committedPriorityRequestsAfter, 'priority request number').eq(committedPriorityRequestsBefore);
});
});
Loading

0 comments on commit 6082632

Please sign in to comment.