Skip to content

Commit

Permalink
fix kinto e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed May 29, 2024
1 parent f5d6674 commit 6f98527
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 36 deletions.
7 changes: 5 additions & 2 deletions src/executor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import {
hexToBytes,
numberToHex,
formatTransactionRequest,
RpcRequestError
RpcRequestError,
hexToBigInt
} from "viem"

export function simulatedOpsToResults(
Expand Down Expand Up @@ -203,10 +204,12 @@ export async function filterOpsAndEstimateGas(
...gasOptions
})

gasLimit = await publicClient.request({
const rpcResponse = await publicClient.request({
method: "eth_estimateGas",
params: [tx, blockTag]
})

gasLimit = hexToBigInt(rpcResponse)
}

return { simulatedOps, gasLimit, resubmitAllOps: false }
Expand Down
70 changes: 40 additions & 30 deletions test/kinto-e2e/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
type Address,
type Hex,
createPublicClient,
decodeEventLog,
decodeFunctionData,
http,
parseAbi,
parseAbiItem,
getAddress
slice,
hexToNumber
} from "viem"
import { BundleBulkerAbi, handleOpsAbi } from "./abi"
import { handleOpsAbi } from "./abi"
import { type Pool, createPool } from "@viem/anvil"
import type { UserOperation } from "permissionless"
import { createPimlicoBundlerClient } from "permissionless/clients/pimlico"
Expand All @@ -18,22 +18,13 @@ import {
KINTO_ENTRYPOINT,
kintoMainnet,
prettyPrintTxHash,
sleep
sleep,
type OpInfoType,
type CompressedOp,
isCompressed
} from "./utils"
import { startAlto } from "./setupAlto"

type CompressedOp = {
compressedBytes: Hex
inflator: Address
}

type OpInfoType = {
opHash: Hex
txHash: Hex
blockNum: bigint
opParams: UserOperation | CompressedOp
}

const canReplayUserOperation = async ({
anvilPool,
anvilId,
Expand All @@ -57,15 +48,20 @@ const canReplayUserOperation = async ({
const anvilRpc = `http://${anvil.host}:${anvil.port}`

// spin up new alto instance
const altoProcess = await startAlto(anvilRpc, altoPort.toString())
const altoProcess = await startAlto(
anvilRpc,
altoPort.toString(),
"inflator" in opInfo.opParams
)

// resend userOperation and that it gets mined
const bundlerClient = createPimlicoBundlerClient({
transport: http(altoRpc)
})

let hash: Hex
if ("inflator" in opParams) {
if (isCompressed(opParams)) {
console.log("sending compressed UserOperation")
hash = await bundlerClient.sendCompressedUserOperation({
compressedUserOperation: opParams.compressedBytes,
inflatorAddress: opParams.inflator,
Expand Down Expand Up @@ -122,7 +118,8 @@ const main = async () => {
let userOperationEvents = await publicClient.getLogs({
address: KINTO_ENTRYPOINT,
event: parseAbiItem(userOperationEventAbi),
fromBlock: latestBlock - 10_000n
fromBlock: latestBlock - 10_000n,
toBlock: latestBlock
})
userOperationEvents = userOperationEvents.reverse()

Expand Down Expand Up @@ -163,15 +160,24 @@ const main = async () => {
data: rawTx.input
}).args[0][0]
} catch {
const compressedBytes = decodeFunctionData({
abi: BundleBulkerAbi,
data: rawTx.input
}).args[0]
// Extract first compressedUserOperation (compressedBytes)
// slice of 9 bytes:
// - 4 Bytes BundleBulker Payload (PerOpInflator Id)
// - 1 Bytes PerOpInflator Payload (number of ops)
// - 4 Bytes PerOpInflator Payload (inflator id)
const bytes = slice(rawTx.input, 9, undefined)

const compressedLength = hexToNumber(slice(bytes, 0, 2))

const compressedBytes = slice(
bytes,
2,
2 + compressedLength
)

opParams = {
compressedBytes,
inflator: getAddress(
"0x336a76a7A2a1e97CE20c420F39FC08c441234aa2"
)
inflator: "0x336a76a7A2a1e97CE20c420F39FC08c441234aa2"
}
}

Expand Down Expand Up @@ -229,7 +235,7 @@ const main = async () => {
const endTime = performance.now()
const elapsedTime = (endTime - startTime) / 1000

// biome-ignore lint/suspicious/noConsoleLog: <explanation>
// biome-ignore lint/suspicious/noConsoleLog:
console.log(
`Processed ${processed}/${totalOps} operations. (processed in ${elapsedTime.toFixed(
2
Expand All @@ -240,11 +246,15 @@ const main = async () => {
// if any ops failed, print them and exit with 1
if (failedOps.length > 0) {
for (const f of failedOps) {
let opType = "uncompressed"
if (isCompressed(f.opParams)) {
opType = "compressed"
}
// biome-ignore lint/suspicious/noConsoleLog:
console.log(
`FAILED OP: ${f.opHash} (txhash: ${prettyPrintTxHash(
f.txHash
)})`
`[${opType}] FAILED OP: ${
f.opHash
} (txhash: ${prettyPrintTxHash(f.txHash)})`
)
}
process.exit(1)
Expand Down
13 changes: 10 additions & 3 deletions test/kinto-e2e/src/setupAlto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import waitPort from "wait-port"
import { sleep } from "./utils"

// skip docker wait times, just start locally
export const startAlto = async (rpc: string, altoPort: string) => {
export const startAlto = async (
rpc: string,
altoPort: string,
print?: boolean
) => {
const anvil = createTestClient({
transport: http(rpc),
mode: "anvil"
Expand Down Expand Up @@ -46,9 +50,12 @@ export const startAlto = async (rpc: string, altoPort: string) => {

const alto = spawn(command, args, options)

if (print) {
alto.stdout.on("data", (data) => console.log(data.toString()))
alto.stderr.on("data", (data) => console.log(data.toString()))
}

// [USE FOR DEBUGGING]
//alto.stdout.on("data", (data) => console.log(data.toString()))
//alto.stderr.on("data", (data) => console.log(data.toString()))

await waitPort({
host: "127.0.0.1",
Expand Down
21 changes: 20 additions & 1 deletion test/kinto-e2e/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import { defineChain, type Hash } from "viem"
import type { UserOperation } from "permissionless"
import { defineChain, type Hex, type Hash, type Address } from "viem"

export const prettyPrintTxHash = (hash: Hash) => {
return `https://kintoscan.io/tx/${hash}`
}

export type CompressedOp = {
compressedBytes: Hex
inflator: Address
}

export type OpInfoType = {
opHash: Hex
txHash: Hex
blockNum: bigint
opParams: UserOperation | CompressedOp
}

export const isCompressed = (
op: UserOperation | CompressedOp
): op is CompressedOp => {
return "inflator" in op
}

export const kintoMainnet = defineChain({
id: 7887,
name: "Kinto Mainnet",
Expand Down

0 comments on commit 6f98527

Please sign in to comment.