Skip to content
Draft
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
4 changes: 2 additions & 2 deletions src/contractBatch/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const partitionResponses = (responses: string[]): string[][] => {
return [response, ...partitionResponses(remainingResponses)]
}

const extractErrorCallIndex = (e: Error) => {
export const extractErrorCallIndex = (e: Error) => {
try {
const errorCallText = e.toString()

const sequencerErrorIndex = errorCallText.match(
/Error message: multicall (\d+) failed/,
/Error message: multicall (\d+).*failed/,
)?.[1]
if (sequencerErrorIndex) {
return Number(sequencerErrorIndex)
Expand Down
25 changes: 25 additions & 0 deletions src/contractBatch/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, mock, test } from "bun:test"
import { ContractBatchProvider } from "./ContractBatchProvider"
import { MinimalProviderInterface } from "../types"
import { extractErrorCallIndex } from "./aggregate.ts"

function getMockProvider(responses: string[][]): MinimalProviderInterface {
const blockNumber = "0x1"
Expand Down Expand Up @@ -56,3 +57,27 @@ describe("ContractBatchProvider", () => {
expect(provider.callContract).toHaveBeenCalledTimes(1)
})
})

describe("extractErrorCallIndex", () => {
test("should extract call index from error message", () => {
const error = new Error("Error message: multicall 5 failed")
const result = extractErrorCallIndex(error)
expect(result).toBe(5)
})

test("should extract call index from error message with colon ", () => {
const error = new Error("Error message: multicall 12:300 failed")
const result = extractErrorCallIndex(error)
expect(result).toBe(12)
})

test("should throw error when pattern doesn't match", () => {
const error = new Error("Some other error message")
expect(() => extractErrorCallIndex(error)).toThrow()
})

test("should throw error when no index is present", () => {
const error = new Error("Error message: multicall failed")
expect(() => extractErrorCallIndex(error)).toThrow()
})
})