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: only start up indexer for online tests #1322

Merged
merged 1 commit into from
Aug 17, 2023
Merged
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
rework e2e tests for indexer offline
holic committed Aug 17, 2023
commit 69c61ebd8dbe831115f29b7c95b5da00a9495b7d
92 changes: 49 additions & 43 deletions e2e/packages/sync-test/indexerSync.test.ts
Original file line number Diff line number Diff line change
@@ -29,8 +29,6 @@ describe("Sync from indexer", async () => {
let webserver: ViteDevServer;
let browser: Browser;
let page: Page;
let indexerIteration = 1;
let indexer: ReturnType<typeof startIndexer>;

beforeEach(async () => {
await deployContracts(rpcHttpUrl);
@@ -40,67 +38,75 @@ describe("Sync from indexer", async () => {
const browserAndPage = await startBrowserAndPage(asyncErrorHandler.reportError);
browser = browserAndPage.browser;
page = browserAndPage.page;

// Start indexer
const port = 3000 + indexerIteration++;
indexer = startIndexer(port, path.join(__dirname, `anvil-${port}.db`), rpcHttpUrl, asyncErrorHandler.reportError);
await indexer.doneSyncing;
});

afterEach(async () => {
await browser.close();
await webserver.close();
await indexer.kill();
asyncErrorHandler.resetErrors();
});

test("should sync test data", async () => {
await openClientWithRootAccount(page, { indexerUrl: indexer.url });
test("should log error if indexer is offline", async () => {
await openClientWithRootAccount(page, { indexerUrl: `http://127.0.0.1:9999/trpc` });
await waitForInitialSync(page);

// Write data to the contracts, expect the client to be synced
await setContractData(page, testData1);
await expectClientData(page, testData1);
expect(asyncErrorHandler.getErrors()).toHaveLength(1);
expect(asyncErrorHandler.getErrors()[0]).toContain("couldn't get initial state from indexer");
});

// Write more data to the contracts, expect client to update
await setContractData(page, testData2);
await expectClientData(page, mergeTestData(testData1, testData2));
describe("indexer online", () => {
let indexerIteration = 1;
let indexer: ReturnType<typeof startIndexer>;

// Reload the page, expect all data to still be set
await page.reload();
await waitForInitialSync(page);
await expectClientData(page, mergeTestData(testData1, testData2));
beforeEach(async () => {
// Start indexer
const port = 3000 + indexerIteration++;
indexer = startIndexer(port, path.join(__dirname, `anvil-${port}.db`), rpcHttpUrl, asyncErrorHandler.reportError);
await indexer.doneSyncing;
});

asyncErrorHandler.expectNoAsyncErrors();
});
afterEach(async () => {
await indexer.kill();
});

test("should log error if indexer is down", async () => {
await indexer.kill();
test("should sync test data", async () => {
await openClientWithRootAccount(page, { indexerUrl: indexer.url });
await waitForInitialSync(page);

await openClientWithRootAccount(page, { indexerUrl: indexer.url });
await waitForInitialSync(page);
// Write data to the contracts, expect the client to be synced
await setContractData(page, testData1);
await expectClientData(page, testData1);

expect(asyncErrorHandler.getErrors()).toHaveLength(1);
expect(asyncErrorHandler.getErrors()[0]).toContain("couldn't get initial state from indexer");
});
// Write more data to the contracts, expect client to update
await setContractData(page, testData2);
await expectClientData(page, mergeTestData(testData1, testData2));

test("should sync number list modified via system", async () => {
await openClientWithRootAccount(page, { indexerUrl: indexer.url });
await waitForInitialSync(page);
// Reload the page, expect all data to still be set
await page.reload();
await waitForInitialSync(page);
await expectClientData(page, mergeTestData(testData1, testData2));

asyncErrorHandler.expectNoAsyncErrors();
});

test("should sync number list modified via system", async () => {
await openClientWithRootAccount(page, { indexerUrl: indexer.url });
await waitForInitialSync(page);

// Push one element to the array
await push(page, 42);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42] } }] });
// Push one element to the array
await push(page, 42);
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)] } }] });
// Push 5000 elements to the array
await pushRange(page, 0, 5000);
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)] } }] });
// Pop one element from the array
await pop(page);
await expectClientData(page, { NumberList: [{ key: {}, value: { value: [42, ...range(4999, 1, 0)] } }] });

// Should not have thrown errors
asyncErrorHandler.expectNoAsyncErrors();
// Should not have thrown errors
asyncErrorHandler.expectNoAsyncErrors();
});
});
});