Skip to content

Commit

Permalink
Refactor indexing store tests for improved type safety
Browse files Browse the repository at this point in the history
- Add non-null assertions to find() results
- Update variable names for clarity
- Explicitly type undefined balance as unknown
  • Loading branch information
3commascapital committed Dec 11, 2024
1 parent 2f12876 commit 229cf9e
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions packages/core/src/indexing-store/historical.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,42 +78,42 @@ test("insert", async (context) => {

// single

let result: any = await indexingStore
let result = await indexingStore
.insert(schema.account)
.values({ address: zeroAddress, balance: 10n });

expect(result).toStrictEqual({ address: zeroAddress, balance: 10n });

result = await indexingStore.find(schema.account, {
result = (await indexingStore.find(schema.account, {
address: zeroAddress,
});
}))!;

expect(result).toStrictEqual({ address: zeroAddress, balance: 10n });

// multiple

result = await indexingStore.insert(schema.account).values([
const results = await indexingStore.insert(schema.account).values([
{ address: "0x0000000000000000000000000000000000000001", balance: 12n },
{ address: "0x0000000000000000000000000000000000000002", balance: 52n },
]);

expect(result).toStrictEqual([
expect(results).toStrictEqual([
{ address: "0x0000000000000000000000000000000000000001", balance: 12n },
{ address: "0x0000000000000000000000000000000000000002", balance: 52n },
]);

result = await indexingStore.find(schema.account, {
result = (await indexingStore.find(schema.account, {
address: "0x0000000000000000000000000000000000000001",
});
}))!;

expect(result).toStrictEqual({
address: "0x0000000000000000000000000000000000000001",
balance: 12n,
});

result = await indexingStore.find(schema.account, {
result = (await indexingStore.find(schema.account, {
address: "0x0000000000000000000000000000000000000002",
});
}))!;

expect(result).toStrictEqual({
address: "0x0000000000000000000000000000000000000002",
Expand All @@ -122,41 +122,41 @@ test("insert", async (context) => {

// on conflict do nothing

result = await indexingStore
result = (await indexingStore
.insert(schema.account)
.values({
address: "0x0000000000000000000000000000000000000001",
balance: 44n,
})
.onConflictDoNothing();
.onConflictDoNothing())!;

expect(result).toBe(null);

result = await indexingStore.find(schema.account, {
result = (await indexingStore.find(schema.account, {
address: "0x0000000000000000000000000000000000000001",
});
}))!;

expect(result).toStrictEqual({
address: "0x0000000000000000000000000000000000000001",
balance: 12n,
});

result = await indexingStore
const resultsPossiblyNull = await indexingStore
.insert(schema.account)
.values([
{ address: "0x0000000000000000000000000000000000000001", balance: 44n },
{ address: "0x0000000000000000000000000000000000000003", balance: 0n },
])
.onConflictDoNothing();

expect(result).toStrictEqual([
expect(resultsPossiblyNull).toStrictEqual([
null,
{ address: "0x0000000000000000000000000000000000000003", balance: 0n },
]);

result = await indexingStore.find(schema.account, {
result = (await indexingStore.find(schema.account, {
address: "0x0000000000000000000000000000000000000001",
});
}))!;

expect(result).toStrictEqual({
address: "0x0000000000000000000000000000000000000001",
Expand All @@ -175,9 +175,9 @@ test("insert", async (context) => {
balance: 16n,
});

result = await indexingStore.find(schema.account, {
result = (await indexingStore.find(schema.account, {
address: "0x0000000000000000000000000000000000000001",
});
}))!;

expect(result).toStrictEqual({
address: "0x0000000000000000000000000000000000000001",
Expand All @@ -194,9 +194,9 @@ test("insert", async (context) => {
balance: row.balance + 16n,
}));

result = await indexingStore.find(schema.account, {
result = (await indexingStore.find(schema.account, {
address: "0x0000000000000000000000000000000000000001",
});
}))!;

expect(result).toStrictEqual({
address: "0x0000000000000000000000000000000000000001",
Expand Down Expand Up @@ -431,7 +431,7 @@ test("sql", async (context) => {
.insert(schema.account)
.values({
address: "0x0000000000000000000000000000000000000001",
balance: undefined,
balance: undefined as unknown as bigint,
})
.catch((error) => error);

Expand Down

0 comments on commit 229cf9e

Please sign in to comment.