Skip to content

Commit

Permalink
Merge pull request #2 from dodger213/chore/fix-ts-lints
Browse files Browse the repository at this point in the history
Chore/fix ts lints
  • Loading branch information
dodger213 authored Aug 18, 2024
2 parents ee42192 + 2f91e02 commit 049a67e
Show file tree
Hide file tree
Showing 14 changed files with 1,940 additions and 1,987 deletions.
18 changes: 0 additions & 18 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: safe-smart-account
on: [push, pull_request]
env:
NODE_VERSION: 18.17.1
NODE_VERSION: 20.16.0

jobs:
lint-solidity:
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ERC20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract ERC20Token is ERC20 {
/**
* @dev Constructor that sets the name and symbol of the token and mints an initial supply to the contract deployer.
*/
constructor() public ERC20("TestToken", "TT") {
constructor() ERC20("TestToken", "TT") {
_mint(msg.sender, 1000000000000000);
}
}
20 changes: 20 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import prettier from "eslint-plugin-prettier/recommended";
import noOnlyTests from "eslint-plugin-no-only-tests";

export default [
eslint.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-unused-vars": ["error", { ignoreRestSiblings: true }],
},
plugins: {
noOnlyTests,
},
},
prettier,
];
3,788 changes: 1,866 additions & 1,922 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"build": "hardhat compile",
"build:ts": "rimraf dist && tsc -p tsconfig.prod.json",
"build:ts:dev": "rimraf dist && tsc -p tsconfig.json",
"test": "hardhat test && npm run test:SafeToL2Setup:L1",
"test": "hardhat test && npm run test:L1",
"test:parallel": "hardhat test --parallel",
"test:SafeToL2Setup:L1": "HARDHAT_CHAIN_ID=1 hardhat test --grep \"SafeToL2Setup\"",
"test:L1": "HARDHAT_CHAIN_ID=1 hardhat test --grep '@L1'",
"coverage": "hardhat coverage",
"codesize": "hardhat codesize",
"benchmark": "npm run test benchmark/*.ts",
Expand Down Expand Up @@ -52,31 +52,32 @@
"url": "https://github.com/safe-global/safe-smart-account/issues"
},
"devDependencies": {
"@eslint/js": "^9.9.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@openzeppelin/contracts": "^3.4.0",
"@safe-global/mock-contract": "^4.1.0",
"@safe-global/safe-singleton-factory": "^1.0.24",
"@types/chai": "^4.3.14",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.7",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"debug": "^4.3.4",
"@safe-global/safe-singleton-factory": "^1.0.31",
"@types/chai": "^4.3.17",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.15",
"@types/yargs": "^17.0.33",
"debug": "^4.3.6",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint": "^9.9.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.1.3",
"hardhat": "^2.22.6",
"eslint-plugin-prettier": "^5.2.1",
"hardhat": "^2.22.8",
"hardhat-deploy": "^0.12.4",
"husky": "^9.0.11",
"prettier": "^3.2.5",
"husky": "^9.1.4",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.3.1",
"rimraf": "^6.0.1",
"solc": "0.7.6",
"solhint": "^4.5.4",
"solhint": "^5.0.3",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"typescript": "^5.5.4",
"typescript-eslint": "^8.1.0",
"yargs": "^17.7.2"
}
}
23 changes: 18 additions & 5 deletions src/utils/execution.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Signer, BigNumberish, BaseContract, ethers } from "ethers";
import { AddressZero } from "@ethersproject/constants";
import { Safe } from "../../typechain-types";
import { PayableOverrides } from "../../typechain-types/common";

export const EIP_DOMAIN = {
EIP712Domain: [
Expand Down Expand Up @@ -175,15 +176,27 @@ export const buildSignatureBytes = (signatures: SafeSignature[]): string => {
return signatureBytes + dynamicBytes;
};

export const logGas = async (message: string, tx: Promise<any>, skip?: boolean): Promise<any> => {
export const logGas = async (
message: string,
tx: Promise<ethers.TransactionResponse>,
skip?: boolean,
): Promise<ethers.TransactionResponse> => {
return tx.then(async (result) => {
const receipt = await result.wait();
if (receipt === null) {
throw new Error("transaction not mined");
}
if (!skip) console.log(" Used", receipt.gasUsed, `gas for >${message}<`);
return result;
});
};

export const executeTx = async (safe: Safe, safeTx: SafeTransaction, signatures: SafeSignature[], overrides?: any): Promise<any> => {
export const executeTx = async (
safe: Safe,
safeTx: SafeTransaction,
signatures: SafeSignature[],
overrides?: PayableOverrides,
): Promise<ethers.ContractTransactionResponse> => {
const signatureBytes = buildSignatureBytes(signatures);
return safe.execTransaction(
safeTx.to,
Expand All @@ -203,7 +216,7 @@ export const executeTx = async (safe: Safe, safeTx: SafeTransaction, signatures:
export const buildContractCall = async (
contract: BaseContract,
method: string,
params: any[],
params: unknown[],
nonce: BigNumberish,
delegateCall?: boolean,
overrides?: Partial<SafeTransaction>,
Expand All @@ -224,7 +237,7 @@ export const buildContractCall = async (
);
};

export const executeTxWithSigners = async (safe: Safe, tx: SafeTransaction, signers: Signer[], overrides?: any) => {
export const executeTxWithSigners = async (safe: Safe, tx: SafeTransaction, signers: Signer[], overrides?: PayableOverrides) => {
const safeAddress = await safe.getAddress();
const sigs = await Promise.all(signers.map((signer) => safeSignTypedData(signer, safeAddress, tx)));
return executeTx(safe, tx, sigs, overrides);
Expand All @@ -234,7 +247,7 @@ export const executeContractCallWithSigners = async (
safe: Safe,
contract: BaseContract,
method: string,
params: any[],
params: unknown[],
signers: Signer[],
delegateCall?: boolean,
overrides?: Partial<SafeTransaction>,
Expand Down
10 changes: 7 additions & 3 deletions src/utils/solc.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import solc from "solc";

const solcCache: Record<string, any> = {};
export interface Solc {
compile(input: string): string;
}

export const loadSolc = async (version: string): Promise<any> => {
const solcCache: Record<string, Solc> = {};

export const loadSolc = async (version: string): Promise<Solc> => {
return await new Promise((resolve, reject) => {
if (solcCache[version] !== undefined) resolve(solcCache[version]);
else
solc.loadRemoteVersion(`v${version}`, (error: any, soljson: any) => {
solc.loadRemoteVersion(`v${version}`, (error: Error, soljson: Solc) => {
solcCache[version] = soljson;
return error ? reject(error) : resolve(soljson);
});
Expand Down
20 changes: 5 additions & 15 deletions test/core/Safe.Execution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,8 @@ describe("Safe", () => {
const userBalance = await hre.ethers.provider.getBalance(user2.address);
expect(await hre.ethers.provider.getBalance(safeAddress)).to.be.eq(ethers.parseEther("1"));

let executedTx: any;
await expect(
executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]).then((tx) => {
executedTx = tx;
return tx;
}),
).to.emit(safe, "ExecutionSuccess");
const executedTx = await executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]);
await expect(executedTx).to.emit(safe, "ExecutionSuccess");

const receipt = await hre.ethers.provider.getTransactionReceipt(executedTx!.hash);
const receiptLogs = receipt?.logs ?? [];
Expand Down Expand Up @@ -249,13 +244,8 @@ describe("Safe", () => {
const userBalance = await hre.ethers.provider.getBalance(user2.address);
await expect(await hre.ethers.provider.getBalance(safeAddress)).to.eq(ethers.parseEther("1"));

let executedTx: any;
await expect(
executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]).then((tx) => {
executedTx = tx;
return tx;
}),
).to.emit(safe, "ExecutionFailure");
const executedTx = await executeTx(safe, tx, [await safeApproveHash(user1, safe, tx, true)]);
await expect(executedTx).to.emit(safe, "ExecutionFailure");
const receipt = await hre.ethers.provider.getTransactionReceipt(executedTx!.hash);
const receiptLogs = receipt?.logs ?? [];
const logIndex = receiptLogs.length - 1;
Expand Down Expand Up @@ -345,7 +335,7 @@ describe("Safe", () => {
for (const log of receiptLogs) {
try {
parsedLogs.push(nativeTokenReceiver.interface.decodeEventLog("BreadReceived", log.data, log.topics));
} catch (e) {
} catch {
continue;
}
}
Expand Down
1 change: 0 additions & 1 deletion test/handlers/CompatibilityFallbackHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ describe("CompatibilityFallbackHandler", () => {
});

describe("simulate", () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
it.skip("can be called for any Safe", async () => {});

it("should revert changes", async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/libraries/SafeToL2Setup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe("SafeToL2Setup", () => {
}
});

it("should be a noop when the chain id is 1", async () => {
it("should be a noop when the chain id is 1 [@L1]", async () => {
const {
safeSingleton,
safeL2,
Expand Down
2 changes: 1 addition & 1 deletion test/migration/UpgradeFromSafe111.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Upgrade from Safe 1.1.1", () => {
const factory = await getFactory();
const saltNonce = 42;
const proxyAddress = await calculateProxyAddress(factory, singleton111, "0x", saltNonce);
await factory.createProxyWithNonce(singleton111, "0x", saltNonce).then((tx: any) => tx.wait());
await factory.createProxyWithNonce(singleton111, "0x", saltNonce).then((tx) => tx.wait());

const safe = await hre.ethers.getContractAt("Safe", proxyAddress);
await safe.setup([user1.address], 1, AddressZero, "0x", mockAddress, AddressZero, 0, AddressZero);
Expand Down
2 changes: 1 addition & 1 deletion test/migration/UpgradeFromSafe120.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("Upgrade from Safe 1.2.0", () => {
const factory = await getFactory();
const saltNonce = 42;
const proxyAddress = await calculateProxyAddress(factory, singleton120, "0x", saltNonce);
await factory.createProxyWithNonce(singleton120, "0x", saltNonce).then((tx: any) => tx.wait());
await factory.createProxyWithNonce(singleton120, "0x", saltNonce).then((tx) => tx.wait());

const safe = await hre.ethers.getContractAt("Safe", proxyAddress);
await safe.setup([user1.address], 1, AddressZero, "0x", mockAddress, AddressZero, 0, AddressZero);
Expand Down
2 changes: 1 addition & 1 deletion test/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const getSafeTemplateWithSingleton = async (singleton: Contract | Safe, s
const singletonAddress = await singleton.getAddress();
const factory = await getFactory();
const template = await factory.createProxyWithNonce.staticCall(singletonAddress, "0x", saltNumber);
await factory.createProxyWithNonce(singletonAddress, "0x", saltNumber).then((tx: any) => tx.wait());
await factory.createProxyWithNonce(singletonAddress, "0x", saltNumber).then((tx) => tx.wait());
return singleton.attach(template) as Safe | SafeL2;
};

Expand Down

0 comments on commit 049a67e

Please sign in to comment.