-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathIndexBlockTask.test.ts
More file actions
59 lines (49 loc) · 1.59 KB
/
IndexBlockTask.test.ts
File metadata and controls
59 lines (49 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import "reflect-metadata";
import {
BlockWithResult,
InMemoryDatabase,
LocalTaskQueue,
LocalTaskWorkerModule,
TaskPayload,
} from "@proto-kit/sequencer";
import { Indexer } from "../src/Indexer";
import { IndexBlockTask } from "../src/tasks/IndexBlockTask";
describe("IndexBlockTask", () => {
const indexer = Indexer.from({
Database: InMemoryDatabase,
TaskQueue: LocalTaskQueue,
LocalTaskWorkerModule: LocalTaskWorkerModule.from({
IndexBlockTask: IndexBlockTask,
}),
});
indexer.configurePartial({
Database: {},
TaskQueue: {},
LocalTaskWorkerModule: {
IndexBlockTask: {},
},
});
it("should listen to block indexing tasks", async () => {
await indexer.start();
const taskQueue = indexer.resolve("TaskQueue");
const localTaskWorker = indexer.resolve("LocalTaskWorkerModule");
const indexBlockTask = localTaskWorker.resolve("IndexBlockTask");
const queue = await taskQueue.getQueue(indexBlockTask.name);
const block = BlockWithResult.createEmpty();
const payload = await indexBlockTask.inputSerializer().toJSON(block);
const task: TaskPayload = {
name: indexBlockTask.name,
payload,
flowId: "",
sequencerId: "test-sequencer",
};
await queue.addTask(task);
// LocalTaskQueue voids all the pending promises, so we need this hack
await new Promise<void>((resolve) => {
setTimeout(resolve, 1000);
});
const storage = indexer.resolve("BlockStorage");
const latestBlock = await storage.getLatestBlock();
expect(latestBlock?.block.hash).toBe(block.block.hash);
});
});