From 229cf9e626d65a585db61890097aee943e6414f9 Mon Sep 17 00:00:00 2001 From: 3commascapital <90629478+3commascapital@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:28:44 -0600 Subject: [PATCH] Refactor indexing store tests for improved type safety - Add non-null assertions to find() results - Update variable names for clarity - Explicitly type undefined balance as unknown --- .../src/indexing-store/historical.test.ts | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/core/src/indexing-store/historical.test.ts b/packages/core/src/indexing-store/historical.test.ts index d3205a039..5b4cf8fe5 100644 --- a/packages/core/src/indexing-store/historical.test.ts +++ b/packages/core/src/indexing-store/historical.test.ts @@ -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", @@ -122,26 +122,26 @@ 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 }, @@ -149,14 +149,14 @@ test("insert", async (context) => { ]) .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", @@ -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", @@ -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", @@ -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);