-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
483 additions
and
119 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
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
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
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
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
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
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
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
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
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
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,2 @@ | ||
// This file exists to have proper namespace for the web bundle | ||
export * from "./transport/index.js"; |
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,2 @@ | ||
// This file exists to have proper namespace for the web bundle | ||
export * from "./utils/index.js"; |
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,19 @@ | ||
import {getClient, Api} from "@lodestar/api"; | ||
import {ChainForkConfig, createChainForkConfig} from "@lodestar/config"; | ||
import {NetworkName, networksChainConfig} from "@lodestar/config/networks"; | ||
|
||
export function getApiFromUrl(url: string, network: NetworkName): Api { | ||
if (!(network in networksChainConfig)) { | ||
throw Error(`Invalid network name "${network}". Valid options are: ${Object.keys(networksChainConfig).join()}`); | ||
} | ||
|
||
return getClient({urls: [url]}, {config: createChainForkConfig(networksChainConfig[network])}); | ||
} | ||
|
||
export function getChainForkConfigFromNetwork(network: NetworkName): ChainForkConfig { | ||
if (!(network in networksChainConfig)) { | ||
throw Error(`Invalid network name "${network}". Valid options are: ${Object.keys(networksChainConfig).join()}`); | ||
} | ||
|
||
return createChainForkConfig(networksChainConfig[network]); | ||
} |
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
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
63 changes: 63 additions & 0 deletions
63
packages/light-client/test/unit/webEsmBundle.browser.test.ts
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,63 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call */ | ||
import {expect, describe, it, beforeEach, vi} from "vitest"; | ||
import "../../dist/lightclient.min.mjs"; | ||
|
||
describe("web bundle for lightclient", () => { | ||
vi.setConfig({testTimeout: 20_000}); | ||
|
||
let lightclient: any; | ||
|
||
beforeEach(() => { | ||
lightclient = (window as any)["lodestar"]["lightclient"]; | ||
}); | ||
|
||
it("should have a global interface", () => { | ||
expect(lightclient).toBeDefined(); | ||
}); | ||
|
||
it("should have all relevant exports", () => { | ||
expect(lightclient).toHaveProperty("Lightclient"); | ||
expect(lightclient).toHaveProperty("LightclientEvent"); | ||
expect(lightclient).toHaveProperty("RunStatusCode"); | ||
expect(lightclient).toHaveProperty("upgradeLightClientFinalityUpdate"); | ||
expect(lightclient).toHaveProperty("upgradeLightClientOptimisticUpdate"); | ||
expect(lightclient).toHaveProperty("utils"); | ||
expect(lightclient).toHaveProperty("transport"); | ||
expect(lightclient).toHaveProperty("validation"); | ||
|
||
expect(lightclient.Lightclient).toBeTypeOf("function"); | ||
}); | ||
|
||
it("should start the lightclient and sync", async () => { | ||
const {Lightclient, LightclientEvent, transport, utils} = lightclient; | ||
|
||
const logger = utils.getConsoleLogger({logDebug: true}); | ||
const config = utils.getChainForkConfigFromNetwork("mainnet"); | ||
|
||
// TODO: Decide to check which node to use in testing | ||
// We have one node in CI, but that only starts with e2e tests | ||
const api = utils.getApiFromUrl("https://lodestar-mainnet.chainsafe.io", "mainnet"); | ||
|
||
const lc = await Lightclient.initializeFromCheckpointRoot({ | ||
config, | ||
logger, | ||
transport: new transport.LightClientRestTransport(api), | ||
genesisData: await utils.getGenesisData(api), | ||
checkpointRoot: await utils.getFinalizedSyncCheckpoint(api), | ||
opts: { | ||
allowForcedUpdates: true, | ||
updateHeadersOnForcedUpdate: true, | ||
}, | ||
}); | ||
|
||
await expect(lc.start()).resolves.toBeUndefined(); | ||
|
||
await expect( | ||
new Promise((resolve) => { | ||
lc.emitter.on(LightclientEvent.lightClientOptimisticHeader, async (optimisticUpdate: unknown) => { | ||
resolve(optimisticUpdate); | ||
}); | ||
}) | ||
).resolves.toBeDefined(); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"exclude": ["src/index.browser.ts"], | ||
"compilerOptions": {} | ||
} |
Oops, something went wrong.