Skip to content

Commit

Permalink
Fix erc4337 test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Aug 21, 2023
1 parent acdb506 commit 2e3154d
Show file tree
Hide file tree
Showing 9 changed files with 783 additions and 4,638 deletions.
156 changes: 78 additions & 78 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
name: safe-contracts
on: [ push, pull_request ]
on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.7.0
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: yarn --frozen-lockfile
- run: yarn build
- run: yarn coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.7.0
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: yarn --frozen-lockfile
- run: yarn lint:sol
tests-other:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
contract-name: ["SafeL2"]
env:
SAFE_CONTRACT_UNDER_TEST: ${{ matrix.contract-name }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.7.0
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: yarn --frozen-lockfile
- run: yarn build
- run: yarn coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
benchmarks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
solidity: ["0.7.6", "0.8.19"]
include:
- solidity: "0.8.19"
settings: '{"viaIR":true,"optimizer":{"enabled":true,"runs":1000000}}'
env:
SOLIDITY_VERSION: ${{ matrix.solidity }}
SOLIDITY_SETTINGS: ${{ matrix.settings }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16.7.0
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: (yarn --frozen-lockfile && yarn build && yarn hardhat codesize --contractname Safe && yarn benchmark) || echo "Benchmark failed"
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.17.1
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: yarn --frozen-lockfile
- run: yarn build
- run: yarn coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.17.1
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: yarn --frozen-lockfile
- run: yarn lint:sol
tests-other:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
contract-name: ["SafeL2"]
env:
SAFE_CONTRACT_UNDER_TEST: ${{ matrix.contract-name }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.17.1
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: yarn --frozen-lockfile
- run: yarn build
- run: yarn coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
benchmarks:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
solidity: ["0.7.6", "0.8.19"]
include:
- solidity: "0.8.19"
settings: '{"viaIR":true,"optimizer":{"enabled":true,"runs":1000000}}'
env:
SOLIDITY_VERSION: ${{ matrix.solidity }}
SOLIDITY_SETTINGS: ${{ matrix.settings }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 18.17.1
- uses: actions/cache@v2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- run: (yarn --frozen-lockfile && yarn build && yarn hardhat codesize --contractname Safe && yarn benchmark) || echo "Benchmark failed"
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.7.0
v18.17.1
2 changes: 2 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"printWidth": 140,
"tabWidth": 4,
"useTabs": false,
Expand Down
3 changes: 1 addition & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const argv = yargs
})
.help(false)
.version(false)
.parseSync()

.parseSync();

// Load environment variables.
dotenv.config();
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"url": "https://github.com/safe-global/safe-contracts/issues"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "2.0.2",
"@nomiclabs/hardhat-ethers": "2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@nomiclabs/hardhat-waffle": "2.0.1",
"@nomiclabs/hardhat-waffle": "2.0.6",
"@openzeppelin/contracts": "^3.4.0",
"@safe-global/mock-contract": "^4.0.0",
"@safe-global/safe-singleton-factory": "^1.0.15",
Expand All @@ -57,17 +57,16 @@
"@types/yargs": "^17.0.24",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"argv": "^0.0.2",
"chai": "^4.2.0",
"debug": "^4.2.0",
"dotenv": "^16.3.1",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.0.0",
"ethereum-waffle": "^3.3.0",
"ethereum-waffle": "^4.0.10",
"ethers": "5.4.0",
"hardhat": "^2.14.0",
"hardhat": "^2.17.1",
"hardhat-deploy": "0.11.36",
"husky": "^8.0.3",
"prettier": "^3.0.2",
Expand All @@ -77,7 +76,7 @@
"solhint-plugin-prettier": "0.0.5",
"solidity-coverage": "^0.8.4",
"ts-node": "^10.9.1",
"typescript": "^4.2.4",
"typescript": "^5.1.6",
"yargs": "^17.7.2"
},
"peerDependencies": {
Expand Down
8 changes: 2 additions & 6 deletions test/factory/ProxyFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ describe("ProxyFactory", async () => {

it("should revert with invalid initializer", async () => {
const { factory, singleton } = await setupTests();
await expect(factory.createProxyWithNonce(singleton.address, "0x42baddad", saltNonce)).to.be.revertedWith(
"Transaction reverted without a reason",
);
await expect(factory.createProxyWithNonce(singleton.address, "0x42baddad", saltNonce)).to.be.revertedWith("");
});

it("should emit event without initializing", async () => {
Expand Down Expand Up @@ -115,9 +113,7 @@ describe("ProxyFactory", async () => {

it("should revert with invalid initializer", async () => {
const { factory, singleton } = await setupTests();
await expect(factory.createProxyWithNonce(singleton.address, "0x42baddad", saltNonce)).to.be.revertedWith(
"Transaction reverted without a reason",
);
await expect(factory.createProxyWithNonce(singleton.address, "0x42baddad", saltNonce)).to.be.revertedWith("");
});

it("should emit event without initializing", async () => {
Expand Down
19 changes: 11 additions & 8 deletions test/integration/Safe.ERC4337.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type UserOperation = {

const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

describe.only("Safe.ERC4337", () => {
describe("Safe.ERC4337", () => {
const setupTests = async () => {
const factory = await getFactoryContract();
const singleton = await getSafeSingletonContract();
Expand Down Expand Up @@ -75,10 +75,12 @@ describe.only("Safe.ERC4337", () => {
await sleep(10000);

const feeData = await provider.getFeeData();
const maxFeePerGas = feeData.maxFeePerGas.toHexString();
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas.toHexString();
const maxFeePerGas = feeData.maxFeePerGas?.toHexString();
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas?.toHexString();

console.log({ maxFeePerGas, maxPriorityFeePerGas })
if (!maxFeePerGas || !maxPriorityFeePerGas) {
throw new Error("Could not get fee data");
}

const moduleInitializer = erc4337ModuleAndHandler.interface.encodeFunctionData("enableMyself", []);
const encodedInitializer = singleton.interface.encodeFunctionData("setup", [
Expand All @@ -101,7 +103,7 @@ describe.only("Safe.ERC4337", () => {
const userOpCallData = erc4337ModuleAndHandler.interface.encodeFunctionData("execTransaction", [userWallet.address, 0, 0]);

// Native tokens for the pre-fund 💸
await userWallet.sendTransaction({ to: deployedAddress, value: hre.ethers.utils.parseEther("0.001") });
await userWallet.sendTransaction({ to: deployedAddress, value: hre.ethers.utils.parseEther("0.005") });
// The bundler uses a different node, so we need to allow it sometime to sync
await sleep(10000);

Expand All @@ -110,9 +112,9 @@ describe.only("Safe.ERC4337", () => {
nonce: "0x0",
initCode,
callData: userOpCallData,
callGasLimit: "0x7A120",
verificationGasLimit: "0xF4240",
preVerificationGas: "0x186A0",
callGasLimit: "0x1",
verificationGasLimit: "0x1",
preVerificationGas: "0x1",
maxFeePerGas,
maxPriorityFeePerGas,
paymasterAndData: "0x",
Expand All @@ -129,6 +131,7 @@ describe.only("Safe.ERC4337", () => {
console.log(DEBUG_MESSAGE);

const estimatedGas = await bundlerProvider.send("eth_estimateUserOperationGas", [userOperation, ENTRYPOINT_ADDRESS]);
console.log({ estimatedGas });
expect(estimatedGas).to.not.be.undefined;
});
});
4 changes: 3 additions & 1 deletion test/libraries/CreateCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ describe("CreateCall", async () => {
const { createCall, testContract } = await setupTests();
const address = ethers.utils.getCreate2Address(createCall.address, salt, ethers.utils.keccak256(testContract.data));

await expect(createCall.performCreate2(0, testContract.data, salt)).to.emit(createCall, "ContractCreation").withArgs(address);
await expect(createCall.performCreate2(0, testContract.data, salt))
.to.emit(createCall, "ContractCreation")
.withArgs(address);

const newContract = new ethers.Contract(address, testContract.interface, user1);
expect(await newContract.creator()).to.be.eq(createCall.address);
Expand Down
Loading

0 comments on commit 2e3154d

Please sign in to comment.