Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into alvrs/resource-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Aug 17, 2023
2 parents 26e9b47 + 5a6e164 commit 28a0268
Showing 1 changed file with 49 additions and 43 deletions.
92 changes: 49 additions & 43 deletions e2e/packages/sync-test/indexerSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
});
});
});

0 comments on commit 28a0268

Please sign in to comment.