-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): test sync percentage (#2264)
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
`); | ||
}); | ||
}); |