Skip to content

Commit

Permalink
Merge pull request #860 from matter-labs/dvush/multiple-fixes
Browse files Browse the repository at this point in the history
Multiple fixes
  • Loading branch information
dvush authored Aug 11, 2020
2 parents be860c2 + 0d956f5 commit a1e7573
Show file tree
Hide file tree
Showing 63 changed files with 2,495 additions and 2,032 deletions.
143 changes: 143 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ integration-testkit:
@bin/integration-testkit.sh

integration-simple:
@cd js/tests && yarn && yarn simple
@cd js/tests && yarn && yarn simple $(filter-out $@,$(MAKECMDGOALS))

integration-full-exit:
@cd js/tests && yarn && yarn full-exit
Expand Down
2 changes: 2 additions & 0 deletions bin/ci-integration-simple-fullexit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ PROVER_PID=$!
sleep 15
echo "Performing integration-simple test..."
zksync integration-simple
echo "Performing integration-simple test http provider..."
zksync integration-simple http
echo "Performing integration-full-exit test..."
zksync integration-full-exit
echo "Performing api-type-validate test..."
Expand Down
2 changes: 1 addition & 1 deletion bin/prepare-test-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ create_constant_getter() {
}

# Change constants
set_constant MAX_AMOUNT_OF_REGISTERED_TOKENS 4 $OUT_DIR/ConfigTest.sol
set_constant MAX_AMOUNT_OF_REGISTERED_TOKENS 5 $OUT_DIR/ConfigTest.sol
set_constant EXPECT_VERIFICATION_IN 8 $OUT_DIR/ConfigTest.sol
set_constant MAX_UNVERIFIED_BLOCKS 4 $OUT_DIR/ConfigTest.sol
set_constant PRIORITY_EXPIRATION 101 $OUT_DIR/ConfigTest.sol
Expand Down
7 changes: 2 additions & 5 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"argparse": "^1.0.10",
"axios": "^0.19.0",
"chai": "^4.2.0",
"ethereum-waffle": "2.4.1",
"ethereum-waffle": "^3.0.0",
"ethereumjs-abi": "^0.6.8",
"ethers": "4.0.47",
"ethers": "^5.0.0",
"ethjs": "^0.4.0",
"fs": "^0.0.1-security",
"mocha": "^6.2.0",
Expand Down Expand Up @@ -42,8 +42,5 @@
"lint:ts": "tslint -c tslint.json {scripts,test}/**/*.ts",
"lint:ts-fix": "tslint -c tslint.json --fix {scripts,test}/**/*.ts",
"prettier:solidity": "prettier --write contracts/**/*.sol"
},
"resolutions": {
"ethereum-waffle/ethers": "4.0.47"
}
}
5 changes: 2 additions & 3 deletions contracts/scripts/add-erc20-token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ethers} from "ethers";
import {bigNumberify} from "ethers/utils";
import {BigNumber, ethers} from "ethers";
import {Deployer} from "../src.ts/deploy";

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
Expand All @@ -11,7 +10,7 @@ async function main() {
console.log("Adding new ERC20 token to network: ", tokenAddress);
const tx = await deployer
.governanceContract(governorWallet)
.addToken(tokenAddress, {gasLimit: bigNumberify("1000000")});
.addToken(tokenAddress, {gasLimit: BigNumber.from("1000000")});
console.log("tx hash: ", tx.hash);
const receipt = await tx.wait();
console.log("status: ", receipt.status);
Expand Down
4 changes: 2 additions & 2 deletions contracts/scripts/deploy-dev-erc20.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {deployContract} from "ethereum-waffle";
import {ethers, Wallet} from "ethers";
import {parseEther} from "ethers/utils";
import {readContractCode} from "../src.ts/deploy";
import {parseEther} from "ethers/lib/utils";

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);

Expand All @@ -10,7 +10,7 @@ async function main() {

const result = [];

for (const token of [{symbol: "DAI", decimals: 18}, {symbol: "wBTC", decimals: 8}, {symbol: "BAT", decimals: 18}]) {
for (const token of [{symbol: "DAI", decimals: 18}, {symbol: "wBTC", decimals: 8}, {symbol: "BAT", decimals: 18}, {symbol: "MLTT", decimals: 18}]) {
const erc20 = await deployContract(
wallet,
readContractCode("TEST-ERC20"), [],
Expand Down
1 change: 0 additions & 1 deletion contracts/scripts/deploy-testkit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {ethers, Wallet} from "ethers";
import {Deployer, readContractCode, readTestContracts} from "../src.ts/deploy";
import {deployContract} from "ethereum-waffle";
import {parseEther} from "ethers/utils";

(async () => {
if (process.env.ETH_NETWORK !== "test") {
Expand Down
1 change: 0 additions & 1 deletion contracts/scripts/deploy-testnet-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {ethers, Wallet} from "ethers";
import {readContractCode} from "../src.ts/deploy";
import {encodeConstructorArgs, publishSourceCodeToEtherscan} from "../src.ts/publish-utils";
import * as fs from "fs";
import {formatUnits, parseUnits} from "ethers/utils";
import {ArgumentParser} from "argparse";


Expand Down
3 changes: 1 addition & 2 deletions contracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {ArgumentParser} from "argparse";
import {deployContract} from "ethereum-waffle";
import {ethers, Wallet} from "ethers";
import {formatEther, formatUnits, parseUnits} from "ethers/utils";
import {
Deployer,
} from "../src.ts/deploy";
import {formatUnits, parseUnits} from "ethers/lib/utils";

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);

Expand Down
19 changes: 0 additions & 19 deletions contracts/scripts/exampleDeposits.ts

This file was deleted.

42 changes: 22 additions & 20 deletions contracts/scripts/revert-reason.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {ethers} from "ethers";
import {Interface} from "ethers/utils";
import {readContractCode, readProductionContracts} from "../src.ts/deploy";
import {Interface} from "ethers/lib/utils";
const contracts = readProductionContracts();
const franklinInterface = new Interface(contracts.zkSync.interface);
const governanceInterface = new Interface(contracts.governance.interface);
const verifierInterface = new Interface(contracts.governance.interface);
const deployFactoryInterface = new Interface(readContractCode("DeployFactory").interface);
const franklinInterface = new Interface(contracts.zkSync.abi);
const governanceInterface = new Interface(contracts.governance.abi);
const verifierInterface = new Interface(contracts.governance.abi);
const deployFactoryInterface = new Interface(readContractCode("DeployFactory").abi);

function hex_to_ascii(str1) {
const hex = str1.toString();
Expand Down Expand Up @@ -55,21 +55,23 @@ async function reason() {
}

for (const log of receipt.logs) {
let parsedLog = franklinInterface.parseLog(log);
if (!parsedLog) {
parsedLog = governanceInterface.parseLog(log);
}
if (!parsedLog) {
parsedLog = verifierInterface.parseLog(log);
}
if (!parsedLog) {
parsedLog = deployFactoryInterface.parseLog(log);
}
if (parsedLog) {
console.log(parsedLog);
} else {
console.log(log);
}
try {
let parsedLog = franklinInterface.parseLog(log);
if (!parsedLog) {
parsedLog = governanceInterface.parseLog(log);
}
if (!parsedLog) {
parsedLog = verifierInterface.parseLog(log);
}
if (!parsedLog) {
parsedLog = deployFactoryInterface.parseLog(log);
}
if (parsedLog) {
console.log(parsedLog);
} else {
console.log(log);
}
} catch {}
}

}
Expand Down
12 changes: 5 additions & 7 deletions contracts/scripts/test-upgrade-franklin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {ArgumentParser} from "argparse";
import {deployContract} from "ethereum-waffle";
import {ethers} from "ethers";
import {AddressZero} from "ethers/constants";
import {readContractCode, readTestContracts} from "../src.ts/deploy";
import {constants, ethers} from "ethers";
import {readTestContracts} from "../src.ts/deploy";

const {performance} = require("perf_hooks");
const {expect} = require("chai");

export const FranklinTestUpgradeTargetContractCode = require(`../build/ZkSyncTestUpgradeTarget`);
Expand Down Expand Up @@ -33,13 +31,13 @@ async function main() {

const proxyContract = new ethers.Contract(
args.contractAddress,
testContracts.proxy.interface,
testContracts.proxy.abi,
wallet,
);

const upgradeGatekeeper = new ethers.Contract(
args.upgradeGatekeeperAddress,
testContracts.upgradeGatekeeper.interface,
testContracts.upgradeGatekeeper.abi,
wallet,
);

Expand All @@ -51,7 +49,7 @@ async function main() {
);

console.log("Starting upgrade");
await (await upgradeGatekeeper.startUpgrade([AddressZero, AddressZero, newTargetFranklin.address])).wait();
await (await upgradeGatekeeper.startUpgrade([constants.AddressZero, constants.AddressZero, newTargetFranklin.address])).wait();

// wait notice period
console.log("Waiting notice period");
Expand Down
35 changes: 17 additions & 18 deletions contracts/src.ts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {deployContract} from "ethereum-waffle";
import {Contract, ethers, Signer} from "ethers";
import {formatEther, Interface, parseEther} from "ethers/utils";
import {Contract, ethers, Signer, providers} from "ethers";
import {formatEther, Interface} from "ethers/lib/utils";
import * as fs from "fs";
import {
encodeConstructorArgs,
encodeProxyContstuctorArgs,
publishAbiToTesseracts,
publishSourceCodeToEtherscan,
} from "./publish-utils";
import {Provider} from "ethers/providers";

type ContractName = "Governance" | "ZkSync" | "Verifier" | "Proxy" | "UpgradeGatekeeper";

export interface Contracts {
governance;
Expand Down Expand Up @@ -42,7 +39,6 @@ export function readContractCode(name: string) {
if (name === "TEST-ERC20") {
const contract = require("openzeppelin-solidity/build/contracts/ERC20Mintable");
contract.evm = {bytecode: contract.bytecode};
contract.interface = contract.abi;
return contract;
} else {
return JSON.parse(fs.readFileSync(`build/${name}.json`, {encoding: "utf-8"}));
Expand Down Expand Up @@ -166,15 +162,18 @@ export class Deployer {
{gasLimit: 5000000, ...ethTxOptions},
);
const deployFactoryTx = await deployFactoryContract.deployTransaction.wait();
const deployFactoryInterface = new Interface(this.deployFactoryCode.interface);
const deployFactoryInterface = new Interface(this.deployFactoryCode.abi);

for (const log of deployFactoryTx.logs) {
const parsedLog = deployFactoryInterface.parseLog(log);
if (parsedLog) {
this.addresses.Governance = parsedLog.values.governance;
this.addresses.ZkSync = parsedLog.values.zksync;
this.addresses.Verifier = parsedLog.values.verifier;
this.addresses.UpgradeGatekeeper = parsedLog.values.gatekeeper;
}
try {
const parsedLog = deployFactoryInterface.parseLog(log);
if (parsedLog) {
this.addresses.Governance = parsedLog.args.governance;
this.addresses.ZkSync = parsedLog.args.zksync;
this.addresses.Verifier = parsedLog.args.verifier;
this.addresses.UpgradeGatekeeper = parsedLog.args.gatekeeper;
}
} catch (_) {}
}
const txHash = deployFactoryTx.transactionHash;
const gasUsed = deployFactoryTx.gasUsed;
Expand Down Expand Up @@ -236,19 +235,19 @@ export class Deployer {
await this.deployProxiesAndGatekeeper(ethTxOptions);
}

public governanceContract(signerOrProvider: Signer | Provider): Contract {
public governanceContract(signerOrProvider: Signer | providers.Provider): Contract {
return new ethers.Contract(this.addresses.Governance, this.contracts.governance.abi, signerOrProvider);
}

public zkSyncContract(signerOrProvider: Signer | Provider): Contract {
public zkSyncContract(signerOrProvider: Signer | providers.Provider): Contract {
return new ethers.Contract(this.addresses.ZkSync, this.contracts.zkSync.abi, signerOrProvider);
}

public verifierContract(signerOrProvider: Signer | Provider): Contract {
public verifierContract(signerOrProvider: Signer | providers.Provider): Contract {
return new ethers.Contract(this.addresses.Verifier, this.contracts.verifier.abi, signerOrProvider);
}

public upgradeGatekeeperContract(signerOrProvider: Signer | Provider): Contract {
public upgradeGatekeeperContract(signerOrProvider: Signer | providers.Provider): Contract {
return new ethers.Contract(this.addresses.UpgradeGatekeeper, this.contracts.upgradeGatekeeper.abi, signerOrProvider);
}
}
4 changes: 2 additions & 2 deletions contracts/test/unit_tests/bytes_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { BigNumber } = require("ethers")
const { expect } = require("chai")
const { bigNumberify } = require("ethers/utils");
const { provider, wallet, deployTestContract, getCallRevertReason } = require("./common")

describe("Bytes unit tests", function () {
Expand All @@ -15,7 +15,7 @@ describe("Bytes unit tests", function () {
it("should read bytes", async () => {
let r = await bytesTestContract.read("0x0102030405060708", 4, 2)
expect(r.data).equal("0x0506")
expect(r.new_offset).equal(bigNumberify(6))
expect(r.new_offset).equal(BigNumber.from(6))
});

it("should fail to read bytes beyond range", async () => {
Expand Down
9 changes: 4 additions & 5 deletions contracts/test/unit_tests/common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const ethers = require("ethers")
const { expect, use } = require("chai")
const { createMockProvider, getWallets, solidity, deployContract } = require("ethereum-waffle");
const { bigNumberify, parseEther, hexlify, formatEther } = require("ethers/utils");
const { defaultAccounts, solidity, deployContract, MockProvider } = require("ethereum-waffle");

const IERC20_INTERFACE = require("openzeppelin-solidity/build/contracts/IERC20");
const {rawEncode} = require('ethereumjs-abi')
Expand All @@ -14,8 +13,8 @@ const {rawEncode} = require('ethereumjs-abi')

// For: ganache

const provider = createMockProvider() //{gasLimit: 7000000, gasPrice: 2000000000});
const [wallet, wallet1, wallet2, exitWallet] = getWallets(provider);
const provider = new MockProvider({ ganacheOptions: { gasLimit: "8000000", gasPrice: "1"}});
const [wallet, wallet1, wallet2, exitWallet] = provider.getWallets();

use(solidity);

Expand Down Expand Up @@ -45,7 +44,7 @@ async function deployProxyContract(
gasLimit: 3000000,
});

const returnContract = new ethers.Contract(proxy.address, contractCode.interface, wallet);
const returnContract = new ethers.Contract(proxy.address, contractCode.abi, wallet);
return [returnContract, contract.address];
} catch (err) {
console.log('Error deploying proxy contract: ', err)
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/unit_tests/ownable_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("Ownable unit tests", function () {
});

it("checking correctness of transferring mastership to zero address", async () => {
let {revertReason} = await getCallRevertReason( () => testContract.transferMastership("0x0000000000000000000000000000000000000000") );
let {revertReason} = await getCallRevertReason( () => testContract.transferMastership("0x0000000000000000000000000000000000000000", {gasLimit: "300000"}) );
expect(revertReason).equal("otp11")
});

Expand All @@ -28,7 +28,7 @@ describe("Ownable unit tests", function () {
expect(await testContract.getMaster()).to.equal(wallet2.address)

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

/// transfer mastership back to wallet1
Expand Down
Loading

0 comments on commit a1e7573

Please sign in to comment.