-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b99f419
commit 634019c
Showing
8 changed files
with
442 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
import type { StreamDataResponse } from "@apibara/protocol"; | ||
import { type MockBlock, MockClient } from "@apibara/protocol/testing"; | ||
import { describe, expect, it } from "vitest"; | ||
import { run } from "./indexer"; | ||
import { vcr } from "./testing"; | ||
import { type MockRet, mockIndexer } from "./testing/indexer"; | ||
|
||
describe("Run Test", () => { | ||
const client = new MockClient(messages, [{}]); | ||
|
||
it("should stream messages", async () => { | ||
const sink = vcr<MockRet>(); | ||
await run(client, mockIndexer, sink); | ||
|
||
expect(sink.result).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000000, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000000n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000001, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000001n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000002, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000002n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000003, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000003n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000004, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000004n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000005, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000005n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000006, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000006n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000007, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000007n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000008, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000008n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000009, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000009n, | ||
}, | ||
}, | ||
{ | ||
"data": [ | ||
{ | ||
"block_number": 5000010, | ||
}, | ||
], | ||
"endCursor": { | ||
"orderKey": 5000010n, | ||
}, | ||
}, | ||
] | ||
`); | ||
}); | ||
}); | ||
|
||
const messages: StreamDataResponse<MockBlock>[] = [ | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_000n }], | ||
endCursor: { orderKey: 5_000_000n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_001n }], | ||
endCursor: { orderKey: 5_000_001n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_002n }], | ||
endCursor: { orderKey: 5_000_002n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_003n }], | ||
endCursor: { orderKey: 5_000_003n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_004n }], | ||
endCursor: { orderKey: 5_000_004n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_005n }], | ||
endCursor: { orderKey: 5_000_005n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_006n }], | ||
endCursor: { orderKey: 5_000_006n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_007n }], | ||
endCursor: { orderKey: 5_000_007n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_008n }], | ||
endCursor: { orderKey: 5_000_008n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_009n }], | ||
endCursor: { orderKey: 5_000_009n }, | ||
}, | ||
}, | ||
{ | ||
_tag: "data", | ||
data: { | ||
finality: "accepted", | ||
data: [{ block_number: 5_000_010n }], | ||
endCursor: { orderKey: 5_000_010n }, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { MockStream } from "@apibara/protocol/testing"; | ||
import { createIndexer, defineIndexer } from "../indexer"; | ||
|
||
export const mockIndexer = createIndexer( | ||
defineIndexer(MockStream)({ | ||
streamUrl: "https://sepolia.ethereum.a5a.ch", | ||
finality: "accepted", | ||
filter: {}, | ||
transform({ block: { block_number } }) { | ||
if (!block_number) return []; | ||
|
||
const res: MockRet[] = [{ block_number: Number(block_number) }]; | ||
|
||
return res; | ||
}, | ||
}), | ||
); | ||
|
||
export type MockRet = { | ||
block_number: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
syntax = "proto3"; | ||
|
||
package dna.v2.testing; | ||
|
||
message MockFilter {} | ||
|
||
message MockBlock { | ||
uint64 block_number = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * as common from "./common"; | ||
export * as stream from "./stream"; | ||
export * as stream from "./stream"; | ||
export * as testing from './testing' |
Oops, something went wrong.