Skip to content

Commit 87bf632

Browse files
committed
chore(tests): use a single local instance, get LA tests passing for v0.8/v0.9
1 parent 8882fd3 commit 87bf632

33 files changed

Lines changed: 678 additions & 599 deletions

.github/workflows/on-pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
with:
206206
repo: alchemyplatform/rundler
207207
platform: linux
208-
tag: v0.9.2
208+
tag: v0.11.0-alpha.2
209209
cache: enable
210210

211211
- name: Build Libraries

.vitest/setupTests.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import fetch from "node-fetch";
55
import { setAutomine } from "viem/actions";
66
import { beforeAll } from "vitest";
77
import { poolId, rundlerBinaryPath } from "./src/constants.js";
8-
import { local060Instance, local070Instance } from "./src/instances.js";
8+
import { localInstance } from "./src/instances.js";
99
import { paymaster060 } from "./src/paymaster/paymaster060.js";
1010
import { paymaster070 } from "./src/paymaster/paymaster070.js";
11+
import { paymaster080 } from "./src/paymaster/paymaster080.js";
1112
import { checkFoundryInstallation } from "./src/utils/checkFoundryInstallation.js";
1213

1314
// @ts-expect-error this does exist but ts is not liking it
@@ -25,27 +26,23 @@ beforeAll(async () => {
2526
throw new Error(baseMessage);
2627
}
2728

28-
const client060 = local060Instance.getClient();
29-
const client070 = local070Instance.getClient();
30-
await setAutomine(client060, true);
31-
await setAutomine(client070, true);
29+
const client = localInstance.getClient();
30+
await setAutomine(client, true);
3231

33-
await paymaster060.deployPaymasterContract(client060);
34-
await paymaster070.deployPaymasterContract(client070);
32+
await paymaster060.deployPaymasterContract(client);
33+
await paymaster070.deployPaymasterContract(client);
34+
await paymaster080.deployPaymasterContract(client);
35+
// TODO paymaster for v0.9
3536
}, 60_000);
3637

3738
afterEach(() => {
3839
onTestFailed(async () => {
3940
console.log(`Logs for failed test [${poolId()}]:`);
40-
console.log(await local060Instance.getLogs("anvil"));
41-
console.log(await local060Instance.getLogs("bundler"));
42-
43-
console.log(await local070Instance.getLogs("anvil"));
44-
console.log(await local070Instance.getLogs("bundler"));
41+
console.log(await localInstance.getLogs("anvil"));
42+
console.log(await localInstance.getLogs("bundler"));
4543
});
4644
});
4745

4846
afterAll(async () => {
49-
await local060Instance.restart();
50-
await local070Instance.restart();
47+
await localInstance.restart();
5148
});

.vitest/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ export const accounts = {
2828

2929
export const entrypoint060 = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
3030
export const entrypoint070 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
31+
export const entrypoint080 = "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108";

.vitest/src/instances.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,20 @@ import { poolId, rundlerBinaryPath } from "./constants";
1111
import { paymasterTransport } from "./paymaster/transport";
1212
import { rundler } from "./rundler/instance";
1313

14-
export const local060Instance = defineInstance({
14+
export const localInstance = defineInstance({
1515
chain: localhost,
16-
forkBlockNumber: 6381303,
16+
forkBlockNumber: 10043061,
1717
forkUrl:
1818
process.env.VITEST_SEPOLIA_FORK_URL ??
1919
"https://ethereum-sepolia-rpc.publicnode.com",
20-
entryPointVersion: "0.6.0",
21-
anvilPort: 8545,
22-
bundlerPort: 8645,
23-
});
24-
25-
export const local070Instance = defineInstance({
26-
chain: localhost,
27-
forkBlockNumber: 8805588,
28-
forkUrl:
29-
process.env.VITEST_SEPOLIA_FORK_URL ??
30-
"https://ethereum-sepolia-rpc.publicnode.com",
31-
entryPointVersion: "0.7.0",
32-
anvilPort: 8345,
33-
bundlerPort: 8445,
20+
anvilPort: 18545,
21+
bundlerPort: 18546,
3422
});
3523

3624
type DefineInstanceParams = {
3725
chain: Chain;
3826
forkUrl: string;
3927
forkBlockNumber?: number;
40-
entryPointVersion: "0.6.0" | "0.7.0";
4128
anvilPort: number;
4229
bundlerPort: number;
4330
useLocalRunningInstance?: boolean;
@@ -148,9 +135,6 @@ function defineInstance(params: DefineInstanceParams) {
148135
rundler(
149136
{
150137
binary: rundlerBinaryPath,
151-
// ...(entryPointVersion === "0.6.0"
152-
// ? { disableEntryPointV0_7: true }
153-
// : { disableEntryPointV0_6: true }),
154138
nodeHttp: `http://127.0.0.1:${anvilPort}/${key}`,
155139
rpc: {
156140
api: "eth,rundler,debug",

.vitest/src/paymaster/base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import { accounts, create2deployer } from "../constants";
2222
import { ERC1967ProxyAbi } from "../Proxy";
2323
import type { Paymaster } from "./types";
2424
import type { VerifyingPaymaster060Abi } from "./VerifyingPaymaster060";
25-
import type { VerifyingPaymaster070Abi } from "./VerifyingPaymaster070";
25+
import { VerifyingPaymaster070Abi } from "./VerifyingPaymaster070";
2626

2727
type ToPaymasterArgs = {
28-
entryPointVersion: "0.6.0" | "0.7.0";
28+
entryPointVersion: "0.6.0" | "0.7.0" | "0.8.0";
2929
entryPointAddress: Address;
3030
abi: typeof VerifyingPaymaster060Abi | typeof VerifyingPaymaster070Abi;
3131
dummyData: Hex;
@@ -52,6 +52,7 @@ export const toPaymaster = (args: ToPaymasterArgs): Paymaster => {
5252

5353
const paymaster: Paymaster = {
5454
...rest,
55+
isV07Abi: abi === VerifyingPaymaster070Abi,
5556
getPaymasterData(uo, client) {
5657
return getPaymasterData_(paymaster, uo, client);
5758
},
@@ -139,7 +140,6 @@ export const toPaymaster = (args: ToPaymasterArgs): Paymaster => {
139140
abi: abi.abi,
140141
functionName: "initialize",
141142
args: [
142-
// for now this just deploy 0.6.0
143143
entrypoint,
144144
// signer, owner, pauser
145145
accounts.paymasterOwner.address,
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import {
2+
deepHexlify,
3+
resolveProperties,
4+
type UserOperationRequest_v7,
5+
} from "@aa-sdk/core";
6+
import { concat, encodeAbiParameters, keccak256, pad, toHex } from "viem";
7+
import { accounts, entrypoint080 } from "../constants";
8+
import { toPaymaster } from "./base";
9+
import type { Paymaster } from "./types";
10+
import { VerifyingPaymaster070Abi } from "./VerifyingPaymaster070";
11+
12+
export const paymaster080: Paymaster = toPaymaster({
13+
entryPointVersion: "0.8.0",
14+
entryPointAddress: entrypoint080,
15+
abi: VerifyingPaymaster070Abi,
16+
dummyData: concat([
17+
"0xffffffffffffffffffffffff",
18+
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
19+
]),
20+
getPaymasterStubData(self) {
21+
const { address, dummyData } = self.getPaymasterDetails();
22+
23+
return { paymaster: address, paymasterData: dummyData };
24+
},
25+
async getPaymasterData(self, uo_, client) {
26+
const { address } = self.getPaymasterDetails();
27+
const uo = deepHexlify(
28+
// @ts-ignore
29+
await resolveProperties(uo_),
30+
) as UserOperationRequest_v7;
31+
32+
const validUntil = 0n;
33+
const validFrom = 0n;
34+
const expiryPacked =
35+
(validUntil << BigInt(160)) | (validFrom << BigInt(160 + 48));
36+
37+
const encoding = keccak256(
38+
encodeAbiParameters(
39+
[
40+
{ type: "address" },
41+
{ type: "uint256" },
42+
{ type: "bytes32" },
43+
{ type: "bytes32" },
44+
{ type: "bytes32" },
45+
{ type: "uint256" },
46+
{ type: "bytes32" },
47+
{ type: "bytes32" },
48+
{ type: "address" },
49+
{ type: "uint" },
50+
{ type: "uint256" },
51+
],
52+
[
53+
uo.sender,
54+
BigInt(uo.nonce),
55+
keccak256(uo.factory ? concat([uo.factory, uo.factoryData!]) : "0x"),
56+
keccak256(uo.callData),
57+
concat([
58+
pad(uo.verificationGasLimit, { dir: "left", size: 16 }),
59+
pad(uo.callGasLimit, { dir: "left", size: 16 }),
60+
]),
61+
BigInt(uo.preVerificationGas),
62+
concat([
63+
pad(uo.maxPriorityFeePerGas, { dir: "left", size: 16 }),
64+
pad(uo.maxFeePerGas, { dir: "left", size: 16 }),
65+
]),
66+
concat([
67+
pad(uo.paymasterVerificationGasLimit ?? "0x0", {
68+
dir: "left",
69+
size: 16,
70+
}),
71+
pad(uo.paymasterPostOpGasLimit ?? "0x0", { dir: "left", size: 16 }),
72+
]),
73+
entrypoint080,
74+
BigInt(client.chain!.id),
75+
expiryPacked,
76+
],
77+
),
78+
);
79+
80+
const signature = await accounts.paymasterOwner.signMessage({
81+
message: { raw: encoding },
82+
});
83+
84+
const paymasterData = concat([
85+
toHex(validFrom, { size: 6 }),
86+
toHex(validUntil, { size: 6 }),
87+
signature,
88+
]);
89+
90+
return { paymaster: address, paymasterData };
91+
},
92+
});

.vitest/src/paymaster/transport.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "viem";
1515
import { paymaster060 } from "./paymaster060";
1616
import { paymaster070 } from "./paymaster070";
17+
import { paymaster080 } from "./paymaster080";
1718
import { estimateUserOperationGas } from "../../../aa-sdk/core/src/actions/bundler/estimateUserOperationGas";
1819

1920
export const paymasterTransport = (
@@ -35,14 +36,8 @@ export const paymasterTransport = (
3536
}
3637

3738
try {
38-
if (
39-
entrypoint.toLowerCase() ===
40-
paymaster060.entryPointAddress.toLowerCase()
41-
) {
42-
return paymaster060.getPaymasterStubData();
43-
} else {
44-
return paymaster070.getPaymasterStubData();
45-
}
39+
const paymaster = getPaymasterForAddress(entrypoint);
40+
return paymaster.getPaymasterStubData();
4641
} catch (e) {
4742
console.log(e);
4843
throw e;
@@ -60,14 +55,8 @@ export const paymasterTransport = (
6055
}
6156

6257
try {
63-
if (
64-
entrypoint.toLowerCase() ===
65-
paymaster060.entryPointAddress.toLowerCase()
66-
) {
67-
return paymaster060.getPaymasterData(uo, client);
68-
} else {
69-
return paymaster070.getPaymasterData(uo, client);
70-
}
58+
const paymaster = getPaymasterForAddress(entrypoint);
59+
return paymaster.getPaymasterData(uo, client);
7160
} catch (e) {
7261
console.log(e);
7362
throw e;
@@ -92,9 +81,8 @@ export const paymasterTransport = (
9281
};
9382
},
9483
];
95-
const isPMv7 =
96-
entryPoint.toLowerCase() ===
97-
paymaster070.entryPointAddress.toLowerCase();
84+
85+
const paymaster = getPaymasterForAddress(entryPoint);
9886

9987
let uo = {
10088
...userOperation,
@@ -120,9 +108,7 @@ export const paymasterTransport = (
120108
params: [],
121109
});
122110

123-
const stubData = isPMv7
124-
? paymaster070.getPaymasterStubData()
125-
: paymaster060.getPaymasterStubData();
111+
const stubData = paymaster.getPaymasterStubData();
126112

127113
uo = {
128114
...uo,
@@ -141,16 +127,14 @@ export const paymasterTransport = (
141127
uo = {
142128
...uo,
143129
...gasEstimates,
144-
...(isPMv7
130+
...(paymaster.isV07Abi
145131
? {
146132
paymasterPostOpGasLimit: toHex(0),
147133
}
148134
: {}),
149135
};
150136

151-
const pmFields = isPMv7
152-
? await paymaster070.getPaymasterData(uo, client)
153-
: await paymaster060.getPaymasterData(uo, client);
137+
const pmFields = await paymaster.getPaymasterData(uo, client);
154138

155139
return {
156140
...uo,
@@ -166,3 +150,18 @@ export const paymasterTransport = (
166150
throw new Error("Method not found");
167151
},
168152
});
153+
154+
const getPaymasterForAddress = (address: Address) => {
155+
if (address.toLowerCase() === paymaster060.entryPointAddress.toLowerCase()) {
156+
return paymaster060;
157+
} else if (
158+
address.toLowerCase() === paymaster070.entryPointAddress.toLowerCase()
159+
) {
160+
return paymaster070;
161+
} else if (
162+
address.toLowerCase() === paymaster080.entryPointAddress.toLowerCase()
163+
) {
164+
return paymaster080;
165+
}
166+
throw new Error(`Paymaster not found for address ${address}`);
167+
};

.vitest/src/paymaster/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { UserOperationRequest } from "@aa-sdk/core";
22
import type { Address, Client, Hex } from "viem";
33

44
export type Paymaster = {
5-
entryPointVersion: "0.6.0" | "0.7.0";
5+
entryPointVersion: "0.6.0" | "0.7.0" | "0.8.0";
66
entryPointAddress: Address;
77
getPaymasterStubData: () =>
88
| {
@@ -31,4 +31,5 @@ export type Paymaster = {
3131
bytecode: Hex;
3232
calldata: Hex;
3333
};
34+
isV07Abi: boolean;
3435
};

.vitest/src/rundler/binary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function cleanupRundler(rundlerPath: string) {
2222

2323
export async function downloadLatestRundlerRelease(
2424
filePath: string,
25-
version = "v0.9.2",
25+
version = "v0.11.0-alpha.2",
2626
) {
2727
const repoUrl =
2828
"https://api.github.com/repos/alchemyplatform/rundler/releases";

.vitest/src/rundler/instance.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export const rundlerOptions = ({
5959
privateKeys: [
6060
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
6161
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
62+
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
63+
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6",
6264
],
6365
},
6466
});

0 commit comments

Comments
 (0)