Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): actually sync from MODE in e2e test #1110

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ export async function getNetworkConfig(): Promise<NetworkConfig> {
initialBlockNumber,
snapSync: params.get("snapSync") === "true",
disableCache: params.get("cache") === "false",
cacheAgeThreshold: 0,
};
}
25 changes: 25 additions & 0 deletions e2e/packages/sync-test/modeSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ describe("Sync from MODE", async () => {
anvilProcess?.kill();
});

test("should not throw errors during ingress or querying", async () => {
await openClientWithRootAccount(page, { modeUrl });
await waitForInitialSync(page);
await setContractData(page, testData1);
await page.reload();
await waitForInitialSync(page);

asyncErrorHandler.expectNoAsyncErrors();
});

test("should sync test data", async () => {
await openClientWithRootAccount(page, { modeUrl });
await waitForInitialSync(page);
Expand Down Expand Up @@ -101,14 +111,29 @@ describe("Sync from MODE", async () => {
await push(page, 42);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42] } }] });

// Expect data to still be there after initial sync
await page.reload();
await waitForInitialSync(page);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42] } }] });

// Push 5000 elements to the array
await pushRange(page, 0, 5000);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42, ...range(5000, 1, 0)] } }] });

// Expect data to still be there after initial sync
await page.reload();
await waitForInitialSync(page);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42, ...range(5000, 1, 0)] } }] });

// Pop one element from the array
await pop(page);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42, ...range(4999, 1, 0)] } }] });

// Expect data to still be there after initial sync
await page.reload();
await waitForInitialSync(page);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42, ...range(4999, 1, 0)] } }] });

// Should not have thrown errors
asyncErrorHandler.expectNoAsyncErrors();
});
Expand Down
5 changes: 5 additions & 0 deletions e2e/packages/sync-test/rpcSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ describe("Sync from RPC", async () => {
await pop(page);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42, ...range(4999, 1, 0)] } }] });

// Expect data to still be there after initial sync
await page.reload();
await waitForInitialSync(page);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42, ...range(4999, 1, 0)] } }] });

// Should not have thrown errors
asyncErrorHandler.expectNoAsyncErrors();
});
Expand Down
10 changes: 8 additions & 2 deletions e2e/packages/sync-test/setup/syncMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export function syncMode(reportError: (error: string) => void) {

modeProcess.stdout?.on("data", (data) => {
const dataString = data.toString();
const errors = extractLineContaining("ERROR", dataString).join("\n");
const errors = [
...extractLineContaining("ERROR", dataString),
...extractLineContaining("error while serializing", dataString),
].join("\n");
if (errors) {
console.log(chalk.magenta("[mode error]:", errors));
reject(errors);
Expand All @@ -31,7 +34,10 @@ export function syncMode(reportError: (error: string) => void) {

modeProcess.stderr?.on("data", (data) => {
const dataString = data.toString();
const modeErrors = extractLineContaining("ERROR", dataString).join("\n");
const modeErrors = [
...extractLineContaining("ERROR", dataString),
...extractLineContaining("error while serializing", dataString),
].join("\n");
if (modeErrors) {
const errorMessage = chalk.magenta("[mode error]:", modeErrors);
console.log(errorMessage);
Expand Down
2 changes: 1 addition & 1 deletion packages/network/src/workers/SyncWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class SyncWorker<C extends Components> implements DoWork<Input, NetworkEv
devObservables.worldAddress$.next(worldContract.address);

// Set default values for cacheAgeThreshold and cacheInterval
const cacheAgeThreshold = config.cacheAgeThreshold || 100;
const cacheAgeThreshold = config.cacheAgeThreshold ?? 100;
const cacheInterval = config.cacheInterval || 1;

// Set up
Expand Down
39 changes: 39 additions & 0 deletions packages/protocol-parser/src/abiTypesToSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import { abiTypesToSchema } from "./abiTypesToSchema";

describe("hexToSchema", () => {
it("converts hex to schema", () => {
expect(abiTypesToSchema(["bool"])).toMatchInlineSnapshot(`
{
"dynamicFields": [],
"staticFields": [
"bool",
],
}
`);
expect(abiTypesToSchema(["bool", "bool[]"])).toMatchInlineSnapshot(`
{
"dynamicFields": [
"bool[]",
],
"staticFields": [
"bool",
],
}
`);
expect(abiTypesToSchema(["bytes32", "int32", "uint256[]", "address[]", "bytes", "string"])).toMatchInlineSnapshot(`
{
"dynamicFields": [
"uint256[]",
"address[]",
"bytes",
"string",
],
"staticFields": [
"bytes32",
"int32",
],
}
`);
});
});
12 changes: 12 additions & 0 deletions packages/protocol-parser/src/abiTypesToSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DynamicAbiType, SchemaAbiType, StaticAbiType, isDynamicAbiType } from "@latticexyz/schema-type";
import { Schema } from "./common";

export function abiTypesToSchema(abiTypes: SchemaAbiType[]): Schema {
const staticFields: StaticAbiType[] = [];
const dynamicFields: DynamicAbiType[] = [];
for (const abiType of abiTypes) {
if (isDynamicAbiType(abiType)) dynamicFields.push(abiType);
else staticFields.push(abiType);
}
return { staticFields, dynamicFields };
}
1 change: 1 addition & 0 deletions packages/protocol-parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./abiTypesToSchema";
export * from "./common";
export * from "./decodeDynamicField";
export * from "./decodeKeyTuple";
Expand Down