Skip to content
Open
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
10 changes: 0 additions & 10 deletions packages/cluster-tool/src/clients/ethereum/EthereumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ export class EthereumClient {
return this.queryEvents(opp, EthereumClient.OppEnvelopeEvent, fromBlock)
}

/** Query `OPPEpoch` events from a contract. */
getOPPEpochs(
opp: ethers.Contract,
fromBlock = 0
): Promise<ethers.EventLog[]> {
return this.queryEvents(opp, EthereumClient.OppEpochEvent, fromBlock)
}

private async queryEvents(
contract: ethers.Contract,
eventName: string,
Expand All @@ -108,6 +100,4 @@ export namespace EthereumClient {
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
/** OPP envelope event name on the outpost contract. */
export const OppEnvelopeEvent = "OPPEnvelope"
/** OPP epoch event name on the outpost contract. */
export const OppEpochEvent = "OPPEpoch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,42 @@ describe("EthereumClient", () => {
expect(b).not.toBe(a)
})
})

describe("OPP events", () => {
it("queries and filters the canonical OPPEnvelope event stream", async () => {
const client = new EthereumClient(rpcUrl)
const filter = {}
const envelopeEvent = Object.create(
ethers.EventLog.prototype
) as ethers.EventLog
const filters = {
[EthereumClient.OppEnvelopeEvent]: jest.fn(() => filter)
}
const queryFilter = jest
.fn()
.mockResolvedValue([envelopeEvent, { eventName: "unparsed" }])
const opp = { filters, queryFilter } as unknown as ethers.Contract

await expect(client.getOPPEnvelopes(opp, 7)).resolves.toEqual([
envelopeEvent
])
expect(filters.OPPEnvelope).toHaveBeenCalledTimes(1)
expect(queryFilter).toHaveBeenCalledWith(filter, 7)
})

it("propagates query failures and exposes no retired epoch helper", async () => {
const client = new EthereumClient(rpcUrl)
const error = new Error("RPC unavailable")
const opp = {
filters: {
[EthereumClient.OppEnvelopeEvent]: jest.fn(() => ({}))
},
queryFilter: jest.fn().mockRejectedValue(error)
} as unknown as ethers.Contract

await expect(client.getOPPEnvelopes(opp)).rejects.toBe(error)
expect("getOPPEpochs" in client).toBe(false)
expect("OppEpochEvent" in EthereumClient).toBe(false)
})
})
})