Skip to content

Commit

Permalink
zk fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Jan 21, 2021
1 parent 7935aeb commit dc4925a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
30 changes: 15 additions & 15 deletions contracts/scripts/test-upgrade-franklin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, {
const testContracts = readProductionContracts();

async function main() {
try {
const parser = new ArgumentParser({
version: '0.0.1',
addHelp: true,
description: 'Contract upgrade'
});
parser.addArgument('contractAddress');
parser.addArgument('upgradeGatekeeperAddress');
const args = parser.parseArgs(process.argv.slice(2));
if (process.env.CHAIN_ETH_NETWORK !== 'test') {
console.log('Upgrading test contract not on test network is not allowed');
process.exit(1);
}
const parser = new ArgumentParser({
version: '0.0.1',
addHelp: true,
description: 'Contract upgrade'
});
parser.addArgument('contractAddress');
parser.addArgument('upgradeGatekeeperAddress');
const args = parser.parseArgs(process.argv.slice(2));
if (process.env.CHAIN_ETH_NETWORK !== 'test') {
console.log('Upgrading test contract not on test network is not allowed');
process.exit(1);
}

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

const wallet = ethers.Wallet.fromMnemonic(ethTestConfig.test_mnemonic, "m/44'/60'/0'/0/0").connect(provider);

Expand Down Expand Up @@ -66,4 +65,5 @@ main()
.catch((err) => {
console.error('Error:', err.message || err);
process.exit(1);
});
})
.finally(() => {});
4 changes: 2 additions & 2 deletions contracts/test/unit_tests/bytes_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const hardhat = require("hardhat");
const hardhat = require('hardhat');
const { BigNumber } = require('ethers');
const { expect } = require('chai');
const { getCallRevertReason } = require('./common');
Expand All @@ -8,7 +8,7 @@ describe('Bytes unit tests', function () {

let bytesTestContract;
before(async () => {
const contractFactory = await hardhat.ethers.getContractFactory("BytesTest");
const contractFactory = await hardhat.ethers.getContractFactory('BytesTest');
bytesTestContract = await contractFactory.deploy();
});

Expand Down
10 changes: 5 additions & 5 deletions contracts/test/unit_tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const ethers = require('ethers');
const { use } = require('chai');
const { solidity, deployContract, MockProvider } = require('ethereum-waffle');

const IERC20_INTERFACE = require("@openzeppelin/contracts/build/contracts/IERC20");
const IERC20_INTERFACE = require('@openzeppelin/contracts/build/contracts/IERC20');
const { rawEncode } = require('ethereumjs-abi');
const DEFAULT_REVERT_REASON = 'VM did not revert';

Expand Down Expand Up @@ -51,16 +51,16 @@ async function getCallRevertReason(f) {
let result;
try {
result = await f();
} catch(e) {
} catch (e) {
try {
const data = e.stackTrace[e.stackTrace.length - 1].message.slice(4);
revertReason = ethers.utils.defaultAbiCoder.decode(["string"], data)[0];
revertReason = ethers.utils.defaultAbiCoder.decode(['string'], data)[0];
} catch (err2) {
throw e;
}
// revertReason = (e.reason && e.reason[0]) || e.results[e.hashes[0]].reason
}
return {revertReason, result};
}
return { revertReason, result };
}

module.exports = {
Expand Down
10 changes: 6 additions & 4 deletions contracts/test/unit_tests/governance_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const hardhat = require("hardhat");
const hardhat = require('hardhat');
const { expect } = require('chai');
const { getCallRevertReason } = require('./common');

Expand All @@ -8,9 +8,11 @@ describe('Governance unit tests', function () {
let testContract;
before(async () => {
let governanceAddressDeployed;
const contractFactory = await hardhat.ethers.getContractFactory("Governance");
const contractFactory = await hardhat.ethers.getContractFactory('Governance');
testContract = await contractFactory.deploy();
await testContract.initialize(ethers.utils.defaultAbiCoder.encode(["address"], [await testContract.signer.getAddress()]));
await testContract.initialize(
ethers.utils.defaultAbiCoder.encode(['address'], [await testContract.signer.getAddress()])
);
});

it('checking correctness of using MAX_AMOUNT_OF_REGISTERED_TOKENS constant', async () => {
Expand All @@ -21,7 +23,7 @@ describe('Governance unit tests', function () {
);
if (step !== MAX_AMOUNT_OF_REGISTERED_TOKENS + 1) {
expect(revertReason).equal('VM did not revert');
} else{
} else {
expect(revertReason).not.equal('VM did not revert');
}
}
Expand Down
38 changes: 20 additions & 18 deletions contracts/test/unit_tests/ownable_test.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
const { expect } = require("chai")
const { getCallRevertReason } = require("./common")
const hardhat = require("hardhat");
const { expect } = require('chai');
const { getCallRevertReason } = require('./common');
const hardhat = require('hardhat');


describe("Ownable unit tests", function () {
describe('Ownable unit tests', function () {
this.timeout(50000);

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

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

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

it("checking correctness of transferring mastership", async () => {
it('checking correctness of transferring mastership', async () => {
/// transfer mastership to wallet2
await testContract.transferMastership(wallet2.address);
expect(await testContract.getMaster()).to.equal(wallet2.address)
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, {gasLimit: "300000"}) );
expect(revertReason).equal("1c")
let { revertReason } = await getCallRevertReason(() =>
testContract.transferMastership(wallet1.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)
expect(await testContract.getMaster()).to.equal(wallet1.address);
});

});
6 changes: 3 additions & 3 deletions etc/js/env-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export default {
API_SERVER: 'https://rinkeby-beta-api.zksync.io',
ETH_NETWORK: 'rinkeby',
WS_API_ADDR: 'wss://rinkeby-beta-api.zksync.io/jsrpc-ws',
HTTP_RPC_API_ADDR: 'https://rinkeby-beta-api.zksync.io/jsrpc',
HTTP_RPC_API_ADDR: 'https://rinkeby-beta-api.zksync.io/jsrpc'
},
'https://ropsten-beta.zkscan.io': {
API_SERVER: 'https://ropsten-beta-api.zksync.io',
ETH_NETWORK: 'ropsten',
WS_API_ADDR: 'wss://ropsten-beta-api.zksync.io/jsrpc-ws',
HTTP_RPC_API_ADDR: 'https://ropsten-beta-api.zksync.io/jsrpc',
HTTP_RPC_API_ADDR: 'https://ropsten-beta-api.zksync.io/jsrpc'
},
'https://zkscan.io': {
API_SERVER: 'https://api.zksync.io',
ETH_NETWORK: 'mainnet',
WS_API_ADDR: 'wss://api.zksync.io/jsrpc-ws',
HTTP_RPC_API_ADDR: 'https://api.zksync.io/jsrpc',
HTTP_RPC_API_ADDR: 'https://api.zksync.io/jsrpc'
},
'https://dev.zksync.dev': {
API_SERVER: 'https://dev-api.zksync.dev',
Expand Down

0 comments on commit dc4925a

Please sign in to comment.