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): test sync percentage #2264

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<div>
<div id="block" title="block" data-testid="block">-1</div>
<div id="sync-step" title="sync-step" data-testid="sync-step"></div>
<div id="sync-percentage" title="sync-percentage" data-testid="sync-percentage"></div>
</div>
</body>
</html>
8 changes: 6 additions & 2 deletions e2e/packages/client-vanilla/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
network: { components, latestBlock$, worldContract, waitForTransaction },
} = await setup();

const _window = window as any;

Check warning on line 9 in e2e/packages/client-vanilla/src/index.ts

View workflow job for this annotation

GitHub Actions / Run tests

Unexpected any. Specify a different type
_window.worldContract = worldContract;
_window.waitForTransaction = waitForTransaction;

Expand All @@ -29,6 +29,10 @@
// Update initial sync status in the UI
components.SyncProgress.update$.subscribe(({ value }) => {
const syncStep = value[0]?.step;
const element = document.querySelector("#sync-step");
if (element) element.innerHTML = String(syncStep);
const elementStep = document.querySelector("#sync-step");
if (elementStep) elementStep.innerHTML = String(syncStep);

const syncPercentage = value[0]?.percentage;
const elementPercentage = document.querySelector("#sync-percentage");
if (elementPercentage) elementPercentage.innerHTML = String(syncPercentage);
});
2 changes: 1 addition & 1 deletion e2e/packages/contracts/worlds.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"31337": {
"address": "0x7de562d80d6c8672aa32654af67884f411976593"
"address": "0xad97505a508daf984fe60302109e0115e544b267"
}
}
43 changes: 43 additions & 0 deletions e2e/packages/sync-test/createStoreSync.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 } from "viem";
import { getNetworkConfig } from "../client-vanilla/src/mud/getNetworkConfig";

const address = "0xad97505a508daf984fe60302109e0115e544b267";

describe("createStoreSync", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is here because we haven't created all the scaffolding (anvil, database, etc.) in store-sync tests yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - store-sync doesn't have a contracts folder, execa, etc. I kind of like that it is more pure but we do risk e2e getting bloated with tests that are not fully "end to end"

const asyncErrorHandler = createAsyncErrorHandler();

it("creates the sync", async () => {
asyncErrorHandler.resetErrors();

await deployContracts(rpcHttpUrl);

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,
publicClient,
});

expect(getComponentValueStrict(components.SyncProgress, singletonEntity).percentage).toMatchInlineSnapshot(`
100
`);
});
});
2 changes: 2 additions & 0 deletions e2e/packages/sync-test/data/waitForInitialSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import { Page, expect } from "@playwright/test";
export async function waitForInitialSync(page: Page) {
const syncStep = page.locator("#sync-step");
await expect(syncStep).toHaveText("live");
const syncProgress = page.locator("#sync-percentage");
await expect(syncProgress).toHaveText("100");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to test for this?

I kinda wonder about keeping the "live" indicator (caught up) separate from the percentage synced, so you can e.g. hide your load screen (because "live") but potentially show how "up to date" you are (percentage)

Copy link
Contributor Author

@yonadaa yonadaa Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense - in that case I think we can remove this test. createStoreSync.test.ts does it more directly

}
Loading