Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 14, 2023
1 parent e4c2892 commit 7c6f2af
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 180 deletions.
8 changes: 4 additions & 4 deletions packages/store-sync/src/blockLogsToStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("blockLogsToStorage", () => {
removed: false,
args: {
tableId: "0x6d756473746f726500000000000000005461626c657300000000000000000000",
key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
keyTuple: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
data: "0x0004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000",
},
eventName: "StoreSetRecord",
Expand All @@ -77,7 +77,7 @@ describe("blockLogsToStorage", () => {
removed: false,
args: {
tableId: "0x00000000000000000000000000000000496e76656e746f727900000000000000",
key: [
keyTuple: [
"0x000000000000000000000000796eb990a3f9c431c69149c7a168b91596d87f60",
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down Expand Up @@ -110,7 +110,7 @@ describe("blockLogsToStorage", () => {
"address": "0x5fbdb2315678afecb367f032d93f642f64180aa3",
"args": {
"data": "0x00000008",
"key": [
"keyTuple": [
"0x000000000000000000000000796eb990a3f9c431c69149c7a168b91596d87f60",
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down Expand Up @@ -164,7 +164,7 @@ describe("blockLogsToStorage", () => {
"address": "0x5fbdb2315678afecb367f032d93f642f64180aa3",
"args": {
"data": "0x00000008",
"key": [
"keyTuple": [
"0x000000000000000000000000796eb990a3f9c431c69149c7a168b91596d87f60",
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down
4 changes: 2 additions & 2 deletions packages/store-sync/src/blockLogsToStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function blockLogsToStorage<TConfig extends StoreConfig = StoreConfig>({
// TODO: refactor encode/decode to use Record<string, SchemaAbiType> schemas
// TODO: refactor to decode key with protocol-parser utils

const [tableId, ...otherKeys] = log.args.key;
const [tableId, ...otherKeys] = log.args.keyTuple;
if (otherKeys.length) {
console.warn("registerSchema event is expected to have only one key in key tuple, but got multiple", log);
}
Expand Down Expand Up @@ -115,7 +115,7 @@ export function blockLogsToStorage<TConfig extends StoreConfig = StoreConfig>({
const keyNames = Object.keys(table.keySchema);
const keyValues = decodeKeyTuple(
{ staticFields: Object.values(table.keySchema), dynamicFields: [] },
log.args.key
log.args.keyTuple
);
const key = Object.fromEntries(keyValues.map((value, i) => [keyNames[i], value])) as Key<
TConfig,
Expand Down
7 changes: 4 additions & 3 deletions packages/store-sync/src/postgres/postgresStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as transformSchemaNameExports from "./transformSchemaName";
import { getTables } from "./getTables";
import { PostgresStorageAdapter, postgresStorage } from "./postgresStorage";
import { buildTable } from "./buildTable";
import { StoreEventsLog } from "../common";

vi.spyOn(transformSchemaNameExports, "transformSchemaName").mockImplementation(
(schemaName) => `${process.pid}_${process.env.VITEST_POOL_ID}__${schemaName}`
Expand Down Expand Up @@ -47,7 +48,7 @@ describe("postgresStorage", async () => {
removed: false,
args: {
tableId: "0x000000000000000000000000000000005265736f757263655479706500000000",
key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
keyTuple: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
schemaIndex: 0,
data: "0x02",
},
Expand All @@ -65,12 +66,12 @@ describe("postgresStorage", async () => {
removed: false,
args: {
tableId: "0x6d756473746f726500000000000000005461626c657300000000000000000000",
key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
keyTuple: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
data: "0x0004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000",
},
eventName: "StoreSetRecord",
},
],
] satisfies StoreEventsLog[],
});

expect(await db.select().from(storageAdapter.internalTables.chain)).toMatchInlineSnapshot(`
Expand Down
2 changes: 2 additions & 0 deletions packages/store-sync/src/recs/recsStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const worldLogs = worldRpcLogs.map((log) => {
return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog;
});

console.log("world logs", worldLogs);

describe("recsStorage", () => {
it("creates components", async () => {
const world = createWorld();
Expand Down
7 changes: 4 additions & 3 deletions packages/store-sync/src/sqlite/sqliteStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { drizzle } from "drizzle-orm/sql-js";
import { createPublicClient, http } from "viem";
import { foundry } from "viem/chains";
import { blockLogsToStorage } from "../blockLogsToStorage";
import { StoreEventsLog } from "../common";

describe("sqliteStorage", async () => {
const SqlJs = await initSqlJs();
Expand Down Expand Up @@ -53,7 +54,7 @@ describe("sqliteStorage", async () => {
removed: false,
args: {
tableId: "0x000000000000000000000000000000005265736f757263655479706500000000",
key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
keyTuple: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
schemaIndex: 0,
data: "0x02",
},
Expand All @@ -71,12 +72,12 @@ describe("sqliteStorage", async () => {
removed: false,
args: {
tableId: "0x6d756473746f726500000000000000005461626c657300000000000000000000",
key: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
keyTuple: ["0x00000000000000000000000000000000496e76656e746f727900000000000000"],
data: "0x0004010004000000000000000000000000000000000000000000000000000000001c030061030300000000000000000000000000000000000000000000000000000401000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000001600000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000056f776e657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046974656d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b6974656d56617269616e740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000006616d6f756e740000000000000000000000000000000000000000000000000000",
},
eventName: "StoreSetRecord",
},
],
] satisfies StoreEventsLog[],
});

expect(db.select().from(chainState).all()).toMatchInlineSnapshot(`
Expand Down
Loading

0 comments on commit 7c6f2af

Please sign in to comment.