Skip to content

Commit

Permalink
test: fixes part one
Browse files Browse the repository at this point in the history
  • Loading branch information
pcheremu committed Jul 24, 2024
1 parent 6ad6b15 commit 139cb94
Show file tree
Hide file tree
Showing 20 changed files with 3,631 additions and 2,797 deletions.
4,209 changes: 2,915 additions & 1,294 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@
},
"devDependencies": {
"@matterlabs/eslint-config-vue": "^1.1.4",
"@matterlabs/hardhat-zksync-deploy": "^0.6.3",
"@matterlabs/hardhat-zksync-solc": "^0.3.14",
"@matterlabs/prettier-config": "^1.0.2",
"@matterlabs/hardhat-zksync-deploy": "^1.5.0",
"@matterlabs/hardhat-zksync-solc": "^1.2.1",
"@matterlabs/prettier-config": "^1.0.3",
"@matterlabs/zksync-contracts": "^0.6.1",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@openzeppelin/contracts": "^4.6.0",
"@openzeppelin/contracts-upgradeable": "^4.6.0",
"@playwright/test": "^1.37.1",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/jest": "^29.2.4",
"@types/node": "^18.15.0",
"dotenv": "^16.0.3",
"dotenv": "^16.4.5",
"eslint": "^8.31.0",
"ethers": "^5.7.2",
"hardhat": "^2.12.0",
"ethers": "^6.13.1",
"jest": "^29.6.2",
"lint-staged": "^13.1.0",
"prettier": "^2.8.2",
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"zksync-web3": "^0.17.1"
"ts-node": "^10.9.2",
"typechain": "^8.3.2",
"typescript": "^5.5.4",
"zksync-ethers": "^6.10.0"
},
"dependencies": {
"ts-jest-resolver": "^2.0.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/integration-tests/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ethers } from "ethers";
import { promises as fs } from "fs";
import * as path from "path";
import * as request from "supertest";
import { Provider } from "zksync-web3";
import { Provider } from "zksync-ethers";

import { environment, localConfig } from "./config";
import { Logger } from "./entities";
Expand Down Expand Up @@ -44,17 +44,17 @@ export class Helper {

async getBalanceETH(walletAddress: string, layer: string) {
let network: string;
let provider: BaseProvider;
let provider: Provider;
if (layer == "L1") {
network = localConfig.L1Network;
provider = ethers.getDefaultProvider(network);
provider = new Provider(network);
} else if (layer == "L2") {
network = localConfig.L2Network;
provider = new Provider(network);
} else {
console.log(`Wrong layer: ${layer}`);
}
return ethers.utils.formatUnits(await provider.getBalance(walletAddress), "wei");
return ethers.formatUnits(await provider.getBalance(walletAddress), "wei");
}

async delay(ms: number) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Sources flattened with hardhat v2.17.3 https://hardhat.org
// Sources flattened with hardhat v2.22.6 https://hardhat.org



Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { promises as fs } from "fs";

import { localConfig } from "../../config";
// import { localConfig } from "../../config";
import { Buffer } from "../../entities";
import getWallet from "../utils/getWallet";

Expand All @@ -12,8 +12,8 @@ export default async function (hre: HardhatRuntimeEnvironment) {

const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("Greeter");
const contract = await deployer.deploy(artifact, [], localConfig.gasLimit);
const contractAddress = contract.address;
const contract = await deployer.deploy(artifact, [""]);
const contractAddress = await contract.getAddress();
console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
await fs.writeFile(Buffer.greeterL2, contractAddress);
}
22 changes: 12 additions & 10 deletions packages/integration-tests/src/playbook/deploy/deploy-paymaster.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import * as ethers from "ethers";
import { parseEther } from "ethers";
import { promises as fs } from "fs";
import { Wallet } from "zksync-web3";
import { Wallet } from "zksync-ethers";

import { Buffer, Wallets } from "../../entities";

Expand All @@ -21,22 +21,24 @@ export default async function (hre: HardhatRuntimeEnvironment) {
// Deploying the ERC20 token
const erc20Artifact = await deployer.loadArtifact("MyERC20");
const erc20 = await deployer.deploy(erc20Artifact, ["MyToken", "MyToken", 18]);
console.log(`ERC20 address: ${erc20.address}`);
await fs.writeFile(Buffer.customToken, erc20.address);
const erc20Address = await erc20.getAddress();
console.log(`ERC20 address: ${erc20Address}`);
await fs.writeFile(Buffer.customToken, erc20Address);

const paymasterArtifact = await deployer.loadArtifact("MyPaymaster");
const paymaster = await deployer.deploy(paymasterArtifact, [erc20.address]);
console.log(`Paymaster address: ${paymaster.address}`);
await fs.writeFile(Buffer.paymaster, paymaster.address);
const paymaster = await deployer.deploy(paymasterArtifact, [erc20Address]);
const paymasterAddress = await paymaster.getAddress();
console.log(`Paymaster address: ${paymasterAddress}`);
await fs.writeFile(Buffer.paymaster, paymasterAddress);

const deployTransaction = await paymaster.deployTransaction;
const deployTransaction = await paymaster.deploymentTransaction();
console.log(`Paymaster deploy transaction: ${deployTransaction.hash}`);
await fs.writeFile(Buffer.paymasterDeployTx, deployTransaction.hash);

await (
await deployer.zkWallet.sendTransaction({
to: paymaster.address,
value: ethers.utils.parseEther("0.03"),
to: paymasterAddress,
value: parseEther("0.03"),
})
).wait();

Expand Down
4 changes: 2 additions & 2 deletions packages/integration-tests/src/playbook/deploy/erc20toL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ async function main() {
const MyERC20Factory = new ethers.ContractFactory(MyERC20Artifact.abi, MyERC20Artifact.bytecode, deployer);

const token = await MyERC20Factory.deploy(Wallets.richWalletAddress, localConfig.gasLimit);
console.log("Contract deployed to L1 address:", token.address);
console.log("Contract deployed to L1 address:", await token.getAddress());

await fs.writeFile(Buffer.L1, token.address);
await fs.writeFile(Buffer.L1, await token.getAddress());
}

main()
Expand Down
4 changes: 2 additions & 2 deletions packages/integration-tests/src/playbook/deploy/erc20toL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default async function (hre: HardhatRuntimeEnvironment) {

const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("L2");
const contract = await deployer.deploy(artifact, [], localConfig.gasLimit);
const contractAddress = contract.address;
const contract = await deployer.deploy(artifact, []);
const contractAddress = await contract.getAddress();
console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
await fs.writeFile(Buffer.L2, contractAddress);
}
28 changes: 14 additions & 14 deletions packages/integration-tests/src/playbook/deploy/nftToL1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ import { ethers } from "hardhat";
import * as hardhatConfig from "hardhat";

import { Buffer, Wallets } from "../../entities";
import getWallet from "../utils/getWallet";

// import getWallet from "../utils/getWallet";
import type { HardhatRuntimeEnvironment } from "hardhat/types";

async function main() {
const hre: HardhatRuntimeEnvironment = hardhatConfig;
const wallet = await getWallet(hre);
const deployer = wallet.connect(hre.ethers.provider);

const MyNFTArtifact = await hre.artifacts.readArtifact("MyNFT");
const deployer = new ethers.Wallet(Wallets.richWalletPrivateKey, hre.ethers.provider);
const MyNFTFactory = new ethers.ContractFactory(MyNFTArtifact.abi, MyNFTArtifact.bytecode, deployer);

const myNFT = await MyNFTFactory.deploy();
console.log("Contract deployed to L1 address:", myNFT.address);

const mintNFT = await myNFT.mintNFT(myNFT.address, Wallets.richWalletAddress);
if (mintNFT) {
console.log(`Contract mint for us!`);
} else {
console.error(`The NFT minting has been unsuccessful: ${mintNFT}`);
}

await fs.writeFile(Buffer.NFTtoL1, myNFT.address);
const address = await myNFT.getAddress();
console.log("Contract deployed to L1 address:", address);

// TODO: ProviderError: nonce too high
// const mintNFT = await myNFT.mintNFT(address, Wallets.richWalletAddress);
// if (mintNFT) {
// console.log(`Contract mint for us!`);
// } else {
// console.error(`The NFT minting has been unsuccessful: ${mintNFT}`);
// }

await fs.writeFile(Buffer.NFTtoL1, address);
}

main()
Expand Down
7 changes: 4 additions & 3 deletions packages/integration-tests/src/playbook/deploy/nftToL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ export default async function (hre: HardhatRuntimeEnvironment) {
console.log(`Arguments for the contract constructor: ${JSON.stringify(contractConstructorArguments)}`);

const myNFT = await deployer.deploy(artifact, contractConstructorArguments);
const address = `${await myNFT.getAddress()}`;

console.log(`Contract "${artifact.contractName}" was deployed to ${myNFT.address}`);
console.log(`Contract "${artifact.contractName}" was deployed to ${address}`);

const mintNFT = await myNFT.mintNFT(myNFT.address, Wallets.richWalletAddress);
const mintNFT = await myNFT.mintNFT(address, Wallets.richWalletAddress);
if (mintNFT) {
console.log(`Contract mint for us!`);
} else {
Expand All @@ -30,5 +31,5 @@ export default async function (hre: HardhatRuntimeEnvironment) {

displayVerificationInfo({ hre, contract: myNFT, contractConstructorArguments, artifact });

await fs.writeFile(Buffer.NFTtoL2, myNFT.address);
await fs.writeFile(Buffer.NFTtoL2, address);
}
9 changes: 5 additions & 4 deletions packages/integration-tests/src/playbook/deploy/use-greeter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import { Provider, Wallet } from "zksync-web3";
import { Provider, Wallet } from "zksync-ethers";

import { localConfig } from "../../config";
import { Wallets } from "../../entities";
Expand Down Expand Up @@ -30,10 +30,11 @@ export default async function (hre: HardhatRuntimeEnvironment) {
const newGreeting = "New Greetings!";
const transaction = await executeGreetings.setGreeting(newGreeting);
const transactionReceipt = await transaction.wait(1);
const transactionHash = transactionReceipt.hash;

console.log(`Transaction hash: ${transactionReceipt.transactionHash}`);
console.log(`Transaction hash: ${transactionHash}`);

await fs.writeFile(Buffer.executeGreeterTx, transactionReceipt.transactionHash);
await fs.writeFile(Buffer.executeGreeterTx, transactionHash);

return transactionReceipt.transactionHash;
return transactionHash;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import { Provider } from "zksync-web3";
import { Provider } from "zksync-ethers";

import { localConfig } from "../../config";
import { Buffer } from "../../entities";
Expand Down
16 changes: 8 additions & 8 deletions packages/integration-tests/src/playbook/deploy/use-paymaster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ethers from "ethers";
import { promises as fs } from "fs";
import { Provider, utils, Wallet } from "zksync-web3";
import { Provider, utils, Wallet } from "zksync-ethers";

import { localConfig } from "../../config";
import { Buffer } from "../../entities";
Expand All @@ -25,7 +25,7 @@ export default async function (hre: HardhatRuntimeEnvironment) {
}

const ethBalance = await emptyWallet.getBalance();
if (!ethBalance.eq(0)) {
if (ethBalance > 0) {
throw new Error("The wallet is not empty");
}

Expand All @@ -38,18 +38,18 @@ export default async function (hre: HardhatRuntimeEnvironment) {
const paymasterParams = utils.getPaymasterParams(PAYMASTER_ADDRESS, {
type: "ApprovalBased",
token: TOKEN_ADDRESS,
minimalAllowance: ethers.BigNumber.from(1),
minimalAllowance: 1,
innerInput: new Uint8Array(),
});

const gasLimit = await erc20.estimateGas.mint(emptyWallet.address, 100, {
const gasLimit = await erc20.mint(emptyWallet.address, 100, {
customData: {
gasPerPubdata: utils.DEFAULT_GAS_PER_PUBDATA_LIMIT,
paymasterParams: paymasterParams,
},
});

gasPrice.mul(gasLimit.toString());
// gasPrice.mul(gasLimit.toString());

const mintTx = await erc20.mint(emptyWallet.address, 90, {
customData: {
Expand All @@ -64,8 +64,8 @@ export default async function (hre: HardhatRuntimeEnvironment) {

console.log(`Balance of the user after mint: ${await emptyWallet.getBalance(TOKEN_ADDRESS)}`);

await fs.writeFile(Buffer.paymasterTx, receipt.transactionHash);
console.log(`Transaction hash: ${receipt.transactionHash}`);
await fs.writeFile(Buffer.paymasterTx, receipt.hash);
console.log(`Transaction hash: ${receipt.hash}`);

return receipt.transactionHash;
return receipt.hash;
}
27 changes: 14 additions & 13 deletions packages/integration-tests/src/playbook/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ require("dotenv").config({ path: __dirname + "/.env" });

import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
import "@nomiclabs/hardhat-ethers";
import "@nomicfoundation/hardhat-ethers";

import { task } from "hardhat/config";
// import { task } from "hardhat/config";

import { localConfig } from "../config";

import type { HardhatUserConfig } from "hardhat/types";
import type { HardhatUserConfig } from "hardhat/config";

// Define the custom task
task("accounts", "Prints the list of accounts and their balances", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
import "@nomicfoundation/hardhat-toolbox";
// // Define the custom task
// task("accounts", "Prints the list of accounts and their balances", async (taskArgs, hre) => {
// const accounts = await hre.ethers.getSigners();

for (const account of accounts) {
const balance = await account.getBalance();
console.log(`${account.address}: ${hre.ethers.utils.formatEther(balance)} ETH`);
}
});
// for (const account of accounts) {
// const balance = await account.getBalance();
// console.log(`${account.address}: ${hre.ethers.formatEther(balance)} ETH`);
// }
// });

const config: HardhatUserConfig = {
zksolc: {
version: "1.3.9",
version: "1.4.1",
compilerSource: "binary",
settings: {},
},
Expand All @@ -37,7 +38,7 @@ const config: HardhatUserConfig = {
},
},
solidity: {
version: "0.8.18",
version: "0.8.24",
settings: {
optimizer: {
enabled: true,
Expand Down
Loading

0 comments on commit 139cb94

Please sign in to comment.