Skip to content

Commit

Permalink
Merge branch 'dev' into tsionyx-1051-zksync-rs-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsionyx committed Dec 2, 2020
2 parents d41b7c8 + bb2be16 commit d595c98
Show file tree
Hide file tree
Showing 159 changed files with 5,453 additions and 1,827 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
RED='\033[0;31m'
NC='\033[0m' # No Color

# Check that `rustfmt` rules are not violated.
# Check that Rust formatting rules are not violated.
if ! cargo fmt -- --check; then
echo -e "${RED}Commit error!${NC}"
echo "Please format the code via 'cargo fmt', cannot commit unformatted code"
Expand Down
14 changes: 14 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
#
# Pre-push hook verifying that inappropriate code will not be pushed.

# Colors for the terminal output
RED='\033[0;31m'
NC='\033[0m' # No Color

# Check that prettier formatting rules are not violated.
if ! zk fmt --check; then
echo -e "${RED}Commit error!${NC}"
echo "Please format the code via 'zk fmt', cannot push unformatted code"
exit 1
fi
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ on:

jobs:
ci-all:
runs-on: self-hosted
# We currently have two self-hosted runners, one of which is marked "DEV-CI" and other one is marder "MAIN".
# "MAIN" is the current CI runner, "DEV-CI" is currently used to experiment with CI optimizing.
runs-on: [self-hosted, MAIN]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/promote-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:

jobs:
build-images:
runs-on: self-hosted
# We currently have two self-hosted runners, one of which is marked "DEV-CI" and other one is marder "MAIN".
# "MAIN" is the current CI runner, "DEV-CI" is currently used to experiment with CI optimizing.
runs-on: [self-hosted, MAIN]

steps:
- uses: actions/checkout@v2
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion contracts/scripts/add-erc20-token.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ArgumentParser } from 'argparse';
import { BigNumber, Wallet, ethers } from 'ethers';
import { Deployer } from '../src.ts/deploy';
import * as fs from 'fs';
import * as path from 'path';

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

async function main() {
const parser = new ArgumentParser({
Expand All @@ -17,9 +21,10 @@ async function main() {
const args = parser.parseArgs(process.argv.slice(2));

const deployer = new Deployer({ deployWallet: ethers.Wallet.createRandom() });

const governorWallet = args.deployerPrivateKey
? new Wallet(args.deployerPrivateKey, provider)
: Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
: Wallet.fromMnemonic(ethTestConfig.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);

console.log('Adding new ERC20 token to network: ', args.tokenAddress);

Expand Down
19 changes: 17 additions & 2 deletions contracts/scripts/contract-info.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { Contract, ethers } from 'ethers';
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
import * as path from 'path';
import { Wallet } from 'ethers';
import { Deployer } from '../src.ts/deploy';

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

async function main() {
const parser = new ArgumentParser({
version: '0.1.0',
addHelp: true
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });
const args = parser.parseArgs(process.argv.slice(2));

const wallet = args.deployerPrivateKey
? new Wallet(args.deployerPrivateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

const deployer = new Deployer({ deployWallet: wallet });
const upgradeGatekeeper = deployer.upgradeGatekeeperContract(wallet);
const tx = await upgradeGatekeeper.finishUpgrade(['0x', '0x', '0x']);
Expand Down
11 changes: 6 additions & 5 deletions contracts/scripts/deploy-eip1271.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ import { deployContract } from 'ethereum-waffle';
import * as fs from 'fs';
import * as path from 'path';

const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const EIP1271TestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eip1271.json`, { encoding: 'utf-8' }));
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

(async () => {
try {
if (!['test', 'localhost'].includes(process.env.ETH_NETWORK)) {
console.error('This deploy script is only for localhost-test network');
process.exit(1);
}

const testConfigPath = path.join(process.env.ZKSYNC_HOME, `etc/test_config/constant/eip1271.json`);
const testConfig = JSON.parse(fs.readFileSync(testConfigPath, { encoding: 'utf-8' }));

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

const deployWallet = ethers.Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/0").connect(
const deployWallet = ethers.Wallet.fromMnemonic(ethTestConfig.test_mnemonic, "m/44'/60'/0'/0/0").connect(
provider
);
const smartWallet = await deployContract(
deployWallet,
readContractCode('AccountMock'),
[testConfig.owner_address],
[EIP1271TestConfig.owner_address],
{
gasLimit: 5000000
}
Expand Down
11 changes: 9 additions & 2 deletions contracts/scripts/deploy-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import { deployContract } from 'ethereum-waffle';
import { ethers, Wallet } from 'ethers';
import { readContractCode } from '../src.ts/deploy';
import { parseEther } from 'ethers/lib/utils';
import * as fs from 'fs';
import * as path from 'path';

const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const wallet = Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
const wallet = Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

type Token = {
address: string | null;
Expand All @@ -24,7 +29,9 @@ async function deployToken(token: Token): Promise<Token> {

await erc20.mint(wallet.address, parseEther('3000000000'));
for (let i = 0; i < 10; ++i) {
const testWallet = Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/" + i).connect(provider);
const testWallet = Wallet.fromMnemonic(ethTestConfig.test_mnemonic as string, "m/44'/60'/0'/0/" + i).connect(
provider
);
await erc20.mint(testWallet.address, parseEther('3000000000'));
}
token.address = erc20.address;
Expand Down
9 changes: 7 additions & 2 deletions contracts/scripts/deploy-testkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { ethers, Wallet } from 'ethers';
import { Deployer, readContractCode, readTestContracts, readProductionContracts } from '../src.ts/deploy';
import { deployContract } from 'ethereum-waffle';
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
import * as path from 'path';

const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

(async () => {
const parser = new ArgumentParser({
Expand All @@ -26,7 +31,7 @@ import { ArgumentParser } from 'argparse';
const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
provider.pollingInterval = 10;

const deployWallet = ethers.Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/0").connect(provider);
const deployWallet = ethers.Wallet.fromMnemonic(ethTestConfig.test_mnemonic, "m/44'/60'/0'/0/0").connect(provider);
const contracts = args.prodContracts ? readProductionContracts() : readTestContracts();
const deployer = new Deployer({ deployWallet, contracts, verbose: true });
await deployer.deployAll();
Expand All @@ -47,7 +52,7 @@ import { ArgumentParser } from 'argparse';
}

for (let i = 0; i < 10; ++i) {
const testWallet = Wallet.fromMnemonic(process.env.TEST_MNEMONIC, "m/44'/60'/0'/0/" + i).connect(provider);
const testWallet = Wallet.fromMnemonic(ethTestConfig.test_mnemonic, "m/44'/60'/0'/0/" + i).connect(provider);
await (await erc20.mint(testWallet.address, '0x4B3B4CA85A86C47A098A224000000000')).wait();
}
})();
10 changes: 9 additions & 1 deletion contracts/scripts/deploy-testnet-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ 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 * as path from 'path';
import { ArgumentParser } from 'argparse';

const mainnetTokens = require(`${process.env.ZKSYNC_HOME}/etc/tokens/mainnet`);

const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

(async () => {
const parser = new ArgumentParser({
version: '0.1.0',
Expand All @@ -18,10 +22,14 @@ const mainnetTokens = require(`${process.env.ZKSYNC_HOME}/etc/tokens/mainnet`);
action: 'storeTrue',
help: 'Only publish code for deployed tokens'
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });
const args = parser.parseArgs(process.argv.slice(2));

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const wallet = Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
const wallet = args.deployerPrivateKey
? new Wallet(args.deployerPrivateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

const contractCode = readContractCode('TestnetERC20Token');

if (process.env.ETH_NETWORK === 'mainnet') {
Expand Down
6 changes: 5 additions & 1 deletion contracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { ArgumentParser } from 'argparse';
import { ethers, Wallet } from 'ethers';
import { Deployer } from '../src.ts/deploy';
import { formatUnits, parseUnits } from 'ethers/lib/utils';
import * as fs from 'fs';
import * as path from 'path';

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

(async () => {
const parser = new ArgumentParser({
Expand All @@ -24,7 +28,7 @@ const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);

const wallet = args.deployerPrivateKey
? new Wallet(args.deployerPrivateKey, provider)
: Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

const gasPrice = args.gasPrice ? parseUnits(args.gasPrice, 'gwei') : await provider.getGasPrice();
console.log(`Using gas price: ${formatUnits(gasPrice, 'gwei')} gwei`);
Expand Down
27 changes: 23 additions & 4 deletions contracts/scripts/init-faucet-account.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import { ethers } from 'ethers';
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
import * as path from 'path';
import * as zksync from 'zksync';
import { ethers } from 'ethers';

const DEPOSIT_AMOUNT = ethers.utils.parseEther('10000000000');
const network = process.env.ETH_NETWORK;

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const deployerEthWallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
const faucetEthWallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/2").connect(provider);
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

async function main() {
const syncProvider = await zksync.Provider.newHttpProvider(process.env.HTTP_RPC_API_ADDR);
const parser = new ArgumentParser({
version: '0.1.0',
addHelp: true
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });
parser.addArgument('--faucetPrivateKey', { required: false, help: 'Wallet used as faucet' });
const args = parser.parseArgs(process.argv.slice(2));

const deployerEthWallet = args.deployerPrivateKey
? new ethers.Wallet(args.deployerPrivateKey, provider)
: ethers.Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);
const faucetEthWallet = args.faucetPrivateKey
? new ethers.Wallet(args.faucetPrivateKey, provider)
: ethers.Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/2").connect(provider);

const syncProvider = await zksync.getDefaultProvider(network as zksync.types.Network);
const deployerWallet = await zksync.Wallet.fromEthSigner(deployerEthWallet, syncProvider);
const faucetWallet = await zksync.Wallet.fromEthSigner(faucetEthWallet, syncProvider);

Expand Down
19 changes: 17 additions & 2 deletions contracts/scripts/submit-test-proof.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { ArgumentParser } from 'argparse';
import * as fs from 'fs';
import * as path from 'path';
import { deployContract } from 'ethereum-waffle';
import { ethers } from 'ethers';
import { Wallet } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider(process.env.WEB3_URL);
const wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, "m/44'/60'/0'/0/1").connect(provider);
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));

const MAX_CONTRACT_SIZE_BYTES = 24576;
async function main() {
const parser = new ArgumentParser({
version: '0.1.0',
addHelp: true
});
parser.addArgument('--deployerPrivateKey', { required: false, help: 'Wallet used to deploy contracts' });
const args = parser.parseArgs(process.argv.slice(2));

const wallet = args.deployerPrivateKey
? new Wallet(args.deployerPrivateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

const verifierContractCode = require('../build/ConcreteVerifier.json');
const verifier = await deployContract(wallet, verifierContractCode, [], {
gasLimit: 3000000
Expand Down
7 changes: 5 additions & 2 deletions contracts/scripts/test-upgrade-franklin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import { ArgumentParser } from 'argparse';
import { deployContract } from 'ethereum-waffle';
import { constants, ethers } from 'ethers';
import { readTestContracts } from '../src.ts/deploy';
import * as fs from 'fs';
import * as path from 'path';

const { expect } = require('chai');

export const FranklinTestUpgradeTargetContractCode = require(`../build/ZkSyncTestUpgradeTarget`);

const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, `etc/test_config/constant`);
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: 'utf-8' }));
const testContracts = readTestContracts();

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

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

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

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

Expand Down
Loading

0 comments on commit d595c98

Please sign in to comment.