Skip to content

Commit

Permalink
Fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Apr 23, 2024
1 parent 07e2734 commit e9e3213
Show file tree
Hide file tree
Showing 8 changed files with 1,816 additions and 1,957 deletions.
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { HardhatUserConfig, HttpNetworkUserConfig } from "hardhat/types";
import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
import "@matterlabs/hardhat-zksync-verify";
import "@matterlabs/hardhat-zksync-ethers";
import "hardhat-deploy";
import dotenv from "dotenv";
import yargs from "yargs";
Expand Down
3,718 changes: 1,789 additions & 1,929 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
"url": "https://github.com/safe-global/safe-smart-account/issues"
},
"devDependencies": {
"@matterlabs/hardhat-zksync-deploy": "^1.3.0",
"@matterlabs/hardhat-zksync-ethers": "^1.0.0",
"@matterlabs/hardhat-zksync-solc": "^1.1.4",
"@matterlabs/hardhat-zksync-verify": "^1.4.2",
"@matterlabs/hardhat-zksync-deploy": "^1.3.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@openzeppelin/contracts": "^3.4.0",
"@safe-global/mock-contract": "^4.1.0",
Expand All @@ -66,6 +67,7 @@
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"cross-env": "^7.0.3",
"debug": "^4.3.4",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
Expand All @@ -80,8 +82,8 @@
"solc": "0.7.6",
"solhint": "^4.5.2",
"ts-node": "^10.9.2",
"typescript": "^5.4.3",
"yargs": "^17.7.2",
"zksync-ethers": "^6.7.0",
"typescript": "^5.4.3"
"zksync-ethers": "^6.7.0"
}
}
2 changes: 1 addition & 1 deletion test/accessors/SimulateTxAccessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("SimulateTxAccessor", () => {
userBalance + ethers.parseEther("1"),
);
expect(simulation.success).to.be.true;
expect(simulation.estimate.toNumber()).to.be.lte(hre.network.zksync ? 30000n : 15000n);
expect(simulation.estimate).to.be.lte(15000n);
});

it("simulate revert", async () => {
Expand Down
8 changes: 7 additions & 1 deletion test/core/Safe.FallbackManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { expect } from "chai";
import hre, { ethers } from "hardhat";

Check failure on line 2 in test/core/Safe.FallbackManager.spec.ts

View workflow job for this annotation

GitHub Actions / lint-typescript

'ethers' is defined but never used

Check failure on line 2 in test/core/Safe.FallbackManager.spec.ts

View workflow job for this annotation

GitHub Actions / lint-typescript

'ethers' is defined but never used
import { AddressZero } from "@ethersproject/constants";
import { defaultTokenCallbackHandlerDeployment, deployContract, getSafeTemplate, getTokenCallbackHandler, getWallets } from "../utils/setup";
import {
defaultTokenCallbackHandlerDeployment,
deployContract,
getSafeTemplate,
getTokenCallbackHandler,
getWallets,
} from "../utils/setup";
import { executeContractCallWithSigners } from "../../src/utils/execution";

describe("FallbackManager", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/core/Safe.Incoming.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ describe("Safe", () => {
const safeAddress = await safe.getAddress();

if (hre.network.zksync) {
await expect((await user1.sendTransaction({ to: safeAddress, value: 23, data: "0xbaddad", gasLimit: 150000 })).wait()).to
.be.reverted;
await expect((await user1.sendTransaction({ to: safeAddress, value: 23, data: "0xbaddad", gasLimit: 150000 })).wait()).to.be
.reverted;
} else {
await expect(user1.sendTransaction({ to: safeAddress, value: 23, data: "0xbaddad" })).to.be.revertedWith(
"fallback function is not payable and was called with value 23",
Expand Down
12 changes: 6 additions & 6 deletions test/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import solc from "solc";
import * as zk from "zksync-ethers";
import { logGas } from "../../src/utils/execution";
import { safeContractUnderTest } from "./config";
import { getZkContractFactoryByName, zkCompile } from "./zk";
import { zkCompile } from "./zkSync";
import { getRandomIntAsString } from "./numbers";
import { Safe, SafeL2 } from "../../typechain-types";

Expand Down Expand Up @@ -112,13 +112,13 @@ export const migrationContractFrom130To141 = async () => {
export const getMock = async () => {
const contractFactory = await getContractFactoryByName("MockContract");
const contract = await contractFactory.deploy();
return contract.deployed();

return contract;
};

export const getContractFactoryByName = async (contractName: string) => {
export const getContractFactoryByName = async (contractName: string): Promise<ethers.ContractFactory | zk.ContractFactory> => {
if (hre.network.zksync) {
const signers = await getWallets();
return getZkContractFactoryByName(hre, contractName, signers[0] as zk.Wallet);
return hre.zksyncEthers.getContractFactory(contractName);
} else {
return hre.ethers.getContractFactory(contractName);
}
Expand Down Expand Up @@ -237,7 +237,7 @@ export const compile = async (source: string) => {
};
};

export const deployContract = async (deployer: Signer, source: string): Promise<Contract> => {
export const deployContract = async (deployer: Signer, source: string): Promise<ethers.BaseContract> => {
if (!hre.network.zksync) {
const output = await compile(source);
const transaction = await deployer.sendTransaction({ data: output.data, gasLimit: 6000000 });
Expand Down
20 changes: 5 additions & 15 deletions test/utils/zk.ts → test/utils/zkSync.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
import { exec } from "child_process";
import { ContractInterface } from "ethers";
import { JsonFragment } from "ethers";
import { TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD } from "hardhat/builtin-tasks/task-names";
import { Compiler } from "hardhat/internal/solidity/compiler/downloader";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import * as zk from "zksync-ethers";

export const getZkContractFactoryByName = async (hre: HardhatRuntimeEnvironment, contractName: string, signer: zk.Signer | zk.Wallet) => {
const artifact = await hre.artifacts.readArtifact(contractName);

if (artifact.bytecode === "0x") {
throw new Error(
`You are trying to create a contract factory for the contract ${contractName}, which is abstract and can't be deployed.`,
);
}

return new zk.ContractFactory(artifact.abi, artifact.bytecode, signer, "create");
};

let _solcBuild: Compiler;
async function getSolcBuild(hre: HardhatRuntimeEnvironment) {
Expand All @@ -28,7 +15,10 @@ async function getSolcBuild(hre: HardhatRuntimeEnvironment) {
return _solcBuild;
}

export async function zkCompile(hre: HardhatRuntimeEnvironment, source: string): Promise<{ data: string; abi: ContractInterface }> {
export async function zkCompile(
hre: HardhatRuntimeEnvironment,
source: string,
): Promise<{ data: string; abi: ReadonlyArray<JsonFragment> }> {
const zkSolcCompilerPath = hre.config.zksolc.settings.compilerPath;
const solcBuild = await getSolcBuild(hre);

Expand Down

0 comments on commit e9e3213

Please sign in to comment.