-
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.
indexer: add test for sqlite persistence
- Loading branch information
1 parent
e5eeb7f
commit 27d3bde
Showing
2 changed files
with
62 additions
and
1 deletion.
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,61 @@ | ||
import type { Cursor } from "@apibara/protocol"; | ||
import { type Database, open } from "sqlite"; | ||
import sqlite3 from "sqlite3"; | ||
import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
import { SqlitePersistence } from "./persistence"; | ||
|
||
describe("Sqlite Persistence", () => { | ||
let db: Database<sqlite3.Database, sqlite3.Statement>; | ||
let store: SqlitePersistence; | ||
|
||
beforeAll(async () => { | ||
db = await open({ driver: sqlite3.Database, filename: ":memory:" }); | ||
await SqlitePersistence.initialize(db); | ||
store = new SqlitePersistence(db); | ||
}); | ||
|
||
afterAll(async () => { | ||
await db.close(); | ||
}); | ||
|
||
it("should store a cursor", async () => { | ||
const cursor: Cursor = { | ||
orderKey: 5_000_000n, | ||
}; | ||
await store.put(cursor); | ||
}); | ||
|
||
it("should get the last cursor", async () => { | ||
const latest = await store.get(); | ||
|
||
expect(latest).toEqual({ | ||
orderKey: 5_000_000n, | ||
uniqueKey: null, | ||
}); | ||
}); | ||
|
||
it("should update last cursor", async () => { | ||
const cursor: Cursor = { | ||
orderKey: 5_000_010n, | ||
uniqueKey: "0x1234567890", | ||
}; | ||
await store.put(cursor); | ||
}); | ||
|
||
it("should get updated cursor", async () => { | ||
const latest = await store.get(); | ||
|
||
expect(latest).toEqual({ | ||
orderKey: 5_000_010n, | ||
uniqueKey: "0x1234567890", | ||
}); | ||
}); | ||
|
||
it("should delete persisted cursor", async () => { | ||
await store.del(); | ||
|
||
const latest = await store.get(); | ||
|
||
expect(latest).toBeUndefined(); | ||
}); | ||
}); |
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