Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

More cleanup for account-integrations/safe #87

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion account-integrations/safe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"ethers": "^6.4.0",
"ethers-v5": "npm:[email protected]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I originally copied over these tests and converted them to use ethers v6, I ran into an issue where the bundlerProvider would not work if it wasn't connected to an ethers v5 provider. Hence I added this alias. Did you run into this issue at all? It looks like you just started using ethers v6 for the bundlerProvider with no issues

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. Yeah I didn't run into any trouble, wonder what happened.

"hardhat": "^2.17.1",
"hardhat-gas-reporter": "^1.0.8",
"hardhat-preprocessor": "^0.1.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import hre from "hardhat";
import { expect } from "chai";
import { AddressZero } from "@ethersproject/constants";
import { getBytes, concat, resolveProperties, ethers } from "ethers";
import { ethers as ethersV5 } from "ethers-v5";
import { UserOperationStruct } from "@account-abstraction/contracts";
import { getUserOpHash } from "@account-abstraction/utils";
import { calculateProxyAddress } from "../utils/calculateProxyAddress";
import {
SafeProxyFactory__factory,
Safe__factory,
} from "../../../typechain-types";
import sleep from "../utils/sleep";
import sendUserOpAndWait from "../utils/sendUserOpAndWait";
import receiptOf from "../utils/receiptOf";

const ERC4337_TEST_ENV_VARIABLES_DEFINED =
typeof process.env.ERC4337_TEST_BUNDLER_URL !== "undefined" &&
Expand All @@ -28,7 +28,7 @@ const MNEMONIC = process.env.MNEMONIC;

describe("SafeECDSAPlugin", () => {
const setupTests = async () => {
const bundlerProvider = new ethersV5.providers.JsonRpcProvider(BUNDLER_URL);
const bundlerProvider = new ethers.JsonRpcProvider(BUNDLER_URL);
const provider = new ethers.JsonRpcProvider(NODE_URL);
const userWallet = ethers.Wallet.fromPhrase(MNEMONIC!).connect(provider);

Expand Down Expand Up @@ -87,8 +87,7 @@ describe("SafeECDSAPlugin", () => {
userWallet.address,
{ gasLimit: 1_000_000 },
);
// The bundler uses a different node, so we need to allow it sometime to sync
await sleep(5000);
await safeECDSAPlugin.deploymentTransaction()?.wait();

const feeData = await provider.getFeeData();
if (!feeData.maxFeePerGas || !feeData.maxPriorityFeePerGas) {
Expand Down Expand Up @@ -147,12 +146,12 @@ describe("SafeECDSAPlugin", () => {
);

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

const unsignedUserOperation: UserOperationStruct = {
sender: deployedAddress,
Expand Down Expand Up @@ -193,12 +192,7 @@ describe("SafeECDSAPlugin", () => {

const recipientBalanceBefore = await provider.getBalance(recipientAddress);

await bundlerProvider.send("eth_sendUserOperation", [
userOperation,
ENTRYPOINT_ADDRESS,
]);
// The bundler uses a different node, so we need to allow it sometime to sync
await sleep(5000);
await sendUserOpAndWait(userOperation, ENTRYPOINT_ADDRESS, bundlerProvider);

const recipientBalanceAfter = await provider.getBalance(recipientAddress);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import hre from "hardhat";
import { expect } from "chai";
import { AddressZero } from "@ethersproject/constants";
import { concat, ethers, BigNumberish } from "ethers";
import { ethers as ethersV5 } from "ethers-v5";
import { UserOperationStruct } from "@account-abstraction/contracts";
import { calculateProxyAddress } from "../utils/calculateProxyAddress";
import {
SafeProxyFactory__factory,
Safe__factory,
} from "../../../typechain-types";
import sleep from "../utils/sleep";
import sendUserOpAndWait from "../utils/sendUserOpAndWait";
import receiptOf from "../utils/receiptOf";

const ERC4337_TEST_ENV_VARIABLES_DEFINED =
typeof process.env.ERC4337_TEST_BUNDLER_URL !== "undefined" &&
Expand All @@ -27,7 +27,7 @@ const MNEMONIC = process.env.MNEMONIC;

describe("SafeWebAuthnPlugin", () => {
const setupTests = async () => {
const bundlerProvider = new ethersV5.providers.JsonRpcProvider(BUNDLER_URL);
const bundlerProvider = new ethers.JsonRpcProvider(BUNDLER_URL);
const provider = new ethers.JsonRpcProvider(NODE_URL);
const userWallet = ethers.Wallet.fromPhrase(MNEMONIC!).connect(provider);

Expand Down Expand Up @@ -128,8 +128,7 @@ describe("SafeWebAuthnPlugin", () => {
publicKey,
{ gasLimit: 2_000_000 },
);
// The bundler uses a different node, so we need to allow it sometime to sync
await sleep(5000);
await safeWebAuthnPlugin.deploymentTransaction()?.wait();

const feeData = await provider.getFeeData();
if (!feeData.maxFeePerGas || !feeData.maxPriorityFeePerGas) {
Expand Down Expand Up @@ -188,12 +187,12 @@ describe("SafeWebAuthnPlugin", () => {
);

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

const userOperationWithoutGasFields = {
sender: deployedAddress,
Expand Down Expand Up @@ -248,12 +247,7 @@ describe("SafeWebAuthnPlugin", () => {

const recipientBalanceBefore = await provider.getBalance(recipientAddress);

await bundlerProvider.send("eth_sendUserOperation", [
userOperation,
ENTRYPOINT_ADDRESS,
]);
// The bundler uses a different node, so we need to allow it sometime to sync
await sleep(5000);
await sendUserOpAndWait(userOperation, ENTRYPOINT_ADDRESS, bundlerProvider);

const recipientBalanceAfter = await provider.getBalance(recipientAddress);

Expand Down
10 changes: 10 additions & 0 deletions account-integrations/safe/test/hardhat/utils/receiptOf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ethers } from "ethers";

export default async function receiptOf(
txResponseOrPromise:
| ethers.TransactionResponse
| Promise<ethers.TransactionResponse>,
) {
const txResponse = await txResponseOrPromise;
return await txResponse.wait();
}
36 changes: 36 additions & 0 deletions account-integrations/safe/test/hardhat/utils/sendUserOpAndWait.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { UserOperationStruct } from "@account-abstraction/contracts";
import { ethers } from "ethers";
import sleep from "./sleep";

export default async function sendUserOpAndWait(
userOp: UserOperationStruct,
entryPoint: string,
bundlerProvider: ethers.JsonRpcProvider,
pollingDelay = 100,
maxAttempts = 200,
) {
const userOpHash = (await bundlerProvider.send("eth_sendUserOperation", [
userOp,
entryPoint,
])) as string;

let receipt: { success: boolean } | null = null;

let attempts = 0;

while (attempts < maxAttempts && receipt === null) {
await sleep(pollingDelay);

receipt = (await bundlerProvider.send("eth_getUserOperationReceipt", [
userOpHash,
])) as { success: boolean } | null;

attempts++;
}

if (receipt === null) {
throw new Error(`Could not get receipt after ${maxAttempts} attempts`);
}

return receipt;
}
32 changes: 16 additions & 16 deletions account-integrations/safe/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2627,7 +2627,22 @@ ethereumjs-util@^7.1.0, ethereumjs-util@^7.1.4:
ethereum-cryptography "^0.1.3"
rlp "^2.2.4"

"ethers-v5@npm:[email protected]", ethers@^5.5.3, ethers@^5.7.0, ethers@^5.7.1:
ethers@^4.0.40:
version "4.0.49"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.49.tgz#0eb0e9161a0c8b4761be547396bbe2fb121a8894"
integrity sha512-kPltTvWiyu+OktYy1IStSO16i2e7cS9D9OxZ81q2UUaiNPVrm/RTcbxamCXF9VUSKzJIdJV68EAIhTEVBalRWg==
dependencies:
aes-js "3.0.0"
bn.js "^4.11.9"
elliptic "6.5.4"
hash.js "1.1.3"
js-sha3 "0.5.7"
scrypt-js "2.0.4"
setimmediate "1.0.4"
uuid "2.0.1"
xmlhttprequest "1.8.0"

ethers@^5.5.3, ethers@^5.7.0, ethers@^5.7.1:
version "5.7.2"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.7.2.tgz#3a7deeabbb8c030d4126b24f84e525466145872e"
integrity sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==
Expand Down Expand Up @@ -2663,21 +2678,6 @@ ethereumjs-util@^7.1.0, ethereumjs-util@^7.1.4:
"@ethersproject/web" "5.7.1"
"@ethersproject/wordlists" "5.7.0"

ethers@^4.0.40:
version "4.0.49"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.49.tgz#0eb0e9161a0c8b4761be547396bbe2fb121a8894"
integrity sha512-kPltTvWiyu+OktYy1IStSO16i2e7cS9D9OxZ81q2UUaiNPVrm/RTcbxamCXF9VUSKzJIdJV68EAIhTEVBalRWg==
dependencies:
aes-js "3.0.0"
bn.js "^4.11.9"
elliptic "6.5.4"
hash.js "1.1.3"
js-sha3 "0.5.7"
scrypt-js "2.0.4"
setimmediate "1.0.4"
uuid "2.0.1"
xmlhttprequest "1.8.0"

ethers@^6.4.0:
version "6.6.7"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.6.7.tgz#9cf773bcbc0ca56d783d4774e9b73b4d1aff9962"
Expand Down