Skip to content

Commit

Permalink
test(e2e): test sync percentage (#2264)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa authored Feb 16, 2024
1 parent ad891f2 commit a0cd05c
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions e2e/packages/sync-test/syncToRecs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, expect, it } from "vitest";
import { rpcHttpUrl } from "./setup/constants";
import { deployContracts } from "./setup";
import { createAsyncErrorHandler } from "./asyncErrors";
import { createWorld, getComponentValueStrict } from "@latticexyz/recs";
import { singletonEntity, syncToRecs } from "@latticexyz/store-sync/recs";
import mudConfig from "../contracts/mud.config";
import { transportObserver } from "@latticexyz/common";
import { ClientConfig, createPublicClient, http, isHex } from "viem";
import { getNetworkConfig } from "../client-vanilla/src/mud/getNetworkConfig";

describe("syncToRecs", () => {
const asyncErrorHandler = createAsyncErrorHandler();

it("has the correct sync progress percentage", async () => {
asyncErrorHandler.resetErrors();

const { stdout } = await deployContracts(rpcHttpUrl);

const [, worldAddress] = stdout.match(/worldAddress: '(0x[0-9a-f]+)'/i) ?? [];
if (!isHex(worldAddress)) {
throw new Error("world address not found in output, did the deploy fail?");
}

const networkConfig = await getNetworkConfig();
const clientOptions = {
chain: networkConfig.chain,
transport: transportObserver(http(rpcHttpUrl ?? undefined)),
pollingInterval: 1000,
} as const satisfies ClientConfig;

const publicClient = createPublicClient(clientOptions);

const world = createWorld();

const { components } = await syncToRecs({
world,
config: mudConfig,
address: worldAddress,
publicClient,
});

expect(getComponentValueStrict(components.SyncProgress, singletonEntity).percentage).toMatchInlineSnapshot(`
100
`);
});
});

0 comments on commit a0cd05c

Please sign in to comment.