Skip to content

Commit

Permalink
fix bugs & adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
furkhat committed Jan 22, 2020
1 parent ec9e0da commit 70b55c6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
6 changes: 3 additions & 3 deletions contracts/contracts/Franklin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ contract Franklin {
}

for (uint32 i = firstPendingWithdrawalIndex; i < firstPendingWithdrawalIndex + toProcess; ++i) {
// send fails are ignored hence there is always a direct way to withdraw.
delete pendingWithdrawals[i];

uint16 tokenId = pendingWithdrawals[i].tokenId;
address to = pendingWithdrawals[i].to;
// send fails are ignored hence there is always a direct way to withdraw.
delete pendingWithdrawals[i];

uint128 amount = balancesToWithdraw[to][tokenId];
// amount is zero means funds has been withdrawn with withdrawETH or withdrawERC20
if (amount != 0) {
Expand Down
6 changes: 6 additions & 0 deletions contracts/test/fails_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe("PLANNED FAILS", function () {

const code3 = await provider.call(tx3, tx3.blockNumber);
const reason3 = hex_to_ascii(code3.substr(138));

expect(reason3.substring(0, 5)).equal("fd011");
console.log(" + ERC20 deposit: Wrong tx value (msg.value < fee) passed");

Expand Down Expand Up @@ -533,6 +534,7 @@ describe("PLANNED FAILS", function () {

const code6 = await provider.call(tx6, tx6.blockNumber);
const reason6 = hex_to_ascii(code6.substr(138));

expect(reason6.substring(0, 5)).equal("fvs11");
console.log(" + Wrong priority operation - different data passed");

Expand All @@ -551,6 +553,7 @@ describe("PLANNED FAILS", function () {

const code7 = await provider.call(tx7, tx7.blockNumber);
const reason7 = hex_to_ascii(code7.substr(138));

expect(reason7.substring(0, 5)).equal("grr21");
console.log(" + Not governor passed");
});
Expand All @@ -576,6 +579,7 @@ describe("PLANNED FAILS", function () {

const code1 = await provider.call(tx1, tx1.blockNumber);
const reason1 = hex_to_ascii(code1.substr(138));

expect(reason1.substring(0, 5)).equal("fvk11");
console.log(" + Wrong verify number passed");

Expand All @@ -588,6 +592,7 @@ describe("PLANNED FAILS", function () {

const code2 = await provider.call(tx2, tx2.blockNumber);
const reason2 = hex_to_ascii(code2.substr(138));

expect(reason2.substring(0, 5)).equal("grr21");
console.log(" + Not governor passed");
});
Expand Down Expand Up @@ -636,6 +641,7 @@ describe("PLANNED FAILS", function () {

const code1 = await provider.call(prTx2, prTx2.blockNumber);
const reason1 = hex_to_ascii(code1.substr(138));

expect(reason1.substring(0, 5)).equal("pcs11");
console.log(" + Set franklin address twice will not work passed");
});
Expand Down
1 change: 1 addition & 0 deletions contracts/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import { BigNumber } from "ethers/utils";
import { utils as syncutils } from "zksync";
import { BN } from "bn.js";

Expand Down
43 changes: 14 additions & 29 deletions contracts/test/integration_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {

import { expect, use } from "chai";
import { solidity } from "ethereum-waffle";
import { bigNumberify, parseEther, hexlify, formatEther } from "ethers/utils";
import { createDepositPublicData, createWithdrawPublicData, createFullExitPublicData } from "./helpers";
import { bigNumberify, parseEther, hexlify, formatEther, BigNumber } from "ethers/utils";
import { createDepositPublicData, createWithdrawPublicData, createFullExitPublicData, hex_to_ascii } from "./helpers";

use(solidity);

Expand Down Expand Up @@ -113,6 +113,7 @@ describe("INTEGRATION", function () {

// Commit block with eth partial exit.
const exitValue = parseEther("0.2");

const exitBlockPublicData = createWithdrawPublicData(tokenId, hexlify(exitValue), exitWallet.address);

const partExTx = await franklinDeployedContract.commitBlock(2, 22,
Expand Down Expand Up @@ -163,16 +164,15 @@ describe("INTEGRATION", function () {

expect(verifiedEvent2.blockNumber).equal(2);

let v = await franklinDeployedContract.completeWithdrawals(1);
await v.wait();
await (await franklinDeployedContract.completeWithdrawals(1)).wait();

const afterPartExitBalance = await exitWallet.getBalance();
expect(afterPartExitBalance.sub(beforePartExitBalance)).eq(exitValue);

console.log("Verified partial exit");

// Full exit eth
const fullExitAmount = parseEther("0.096778"); // amount after: tx value - some counted fee - exit amount
const fullExitMinusGas = parseEther("0.096047605");
const accId = 0;
const pubkey = "0x0000000000000000000000000000000000000000000000000000000000000000";
const signature = Buffer.from("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "hex");
Expand Down Expand Up @@ -227,6 +227,7 @@ describe("INTEGRATION", function () {

const verifyFullExTx = await franklinDeployedContract.verifyBlock(3, dummyBlockProof, { gasLimit: bigNumberify("500000") });
const verifyFullExReceipt = await verifyFullExTx.wait();
let gasUsed = verifyFullExReceipt.gasUsed.mul(await provider.getGasPrice());
const verifyEvents = verifyFullExReceipt.events;

const verifiedEvent3 = verifyEvents.pop().args;
Expand All @@ -236,26 +237,15 @@ describe("INTEGRATION", function () {
expect(await priorityQueueDeployedContract.totalOpenPriorityRequests()).equal(0);
expect(await priorityQueueDeployedContract.firstPriorityRequestId()).equal(2);

v = await franklinDeployedContract.completeWithdrawals(1);
await v.wait();
//// Withdraw accumulated fees eth for wallet and other funds
const completeWithdrawalsReceipt = await (await franklinDeployedContract.completeWithdrawals(1)).wait();
gasUsed = gasUsed.add(completeWithdrawalsReceipt.gasUsed.mul(await provider.getGasPrice()));
const accumFees = parseEther("0.006282");
const afterFullExitBalance = await wallet.getBalance();

expect(afterFullExitBalance.sub(beforeFullExitBalance)).eq(fullExitMinusGas); // full exit amount minus gas fee for send transaction
expect(afterFullExitBalance.sub(beforeFullExitBalance.add(accumFees))).eq(fullExitAmount.sub(gasUsed));

console.log("Full exit verified");

// Withdraw accumulated fees eth for wallet
const accumFees = parseEther("0.006282");
const oldBalance = await wallet.getBalance();
const balanceToWithdraw = await franklinDeployedContract.balancesToWithdraw(wallet.address, 0);
const exitTx = await franklinDeployedContract.withdrawETH(balanceToWithdraw);
const exitTxReceipt = await exitTx.wait();
const gasUsed = exitTxReceipt.gasUsed.mul(await provider.getGasPrice());
const newBalance = await wallet.getBalance();
expect(newBalance.sub(oldBalance).add(gasUsed)).eq(accumFees);
expect(await franklinDeployedContract.balancesToWithdraw(wallet.address, 0)).equal(bigNumberify(0));

console.log("Withdrawed to wallet");
console.log("Full exit verified and withdrawed to wallet");

console.log(" + ETH Integration passed")
});
Expand Down Expand Up @@ -362,14 +352,11 @@ describe("INTEGRATION", function () {
const verifyPartExReceipt = await verifyPartExTx.wait();
const verifyPartExEvents = verifyPartExReceipt.events;

console.log("verifyPartExEvents:", verifyPartExEvents);

const verifiedEvent2 = verifyPartExEvents.pop().args;

expect(verifiedEvent2.blockNumber).equal(2);

let v = await franklinDeployedContract.completeWithdrawals(1);
await v.wait();
await (await franklinDeployedContract.completeWithdrawals(1)).wait();
const newBalance1 = await erc20DeployedToken.balanceOf(exitWallet.address);

expect(newBalance1.sub(oldBalance1)).eq(exitValue);
Expand Down Expand Up @@ -440,9 +427,7 @@ describe("INTEGRATION", function () {
expect(await priorityQueueDeployedContract.totalOpenPriorityRequests()).equal(0);
expect(await priorityQueueDeployedContract.firstPriorityRequestId()).equal(2);

v = await franklinDeployedContract.completeWithdrawals(1);
await v.wait();

await (await franklinDeployedContract.completeWithdrawals(1)).wait();
const newBalance2 = await erc20DeployedToken.balanceOf(wallet.address);

expect(newBalance2.sub(oldBalance2)).eq(fullExitAmount);
Expand Down

0 comments on commit 70b55c6

Please sign in to comment.