-
Notifications
You must be signed in to change notification settings - Fork 77
statement-store: Add browser sanity check zombienet test #3244
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
037cc3e
statement-store: Add browser sanity check zombienet test
AndreiEres eb65f69
statement-store: Drop unused --self-test mode from browser runner
AndreiEres 7244552
statement-store: Rename browser runner to match Rust test name
AndreiEres 2cf30da
statement-store: Verify browser-submitted stmt_A reaches alice
AndreiEres d6b0b8e
Merge branch 'main' into ae-statement-store-browser-check
AndreiEres 2538f15
statement-store: Read past replayed stmt_B on alice and drop submit r…
AndreiEres 5a1b120
statement-store: Hold browser smoldot alive until alice receives stmt_A
AndreiEres bf2749c
Merge remote-tracking branch 'origin/main' into ae-statement-store-br…
AndreiEres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,5 +1,6 @@ | ||
| /target | ||
| /e2e-tests/target | ||
| /e2e-tests/js/node_modules | ||
| /e2e-tests/browser/node_modules | ||
| /benchmarks/target | ||
| /benchmarks/js/node_modules |
This file contains hidden or 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,108 @@ | ||
| // Smoldot | ||
| // Copyright (C) 2019-2026 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| // Node-side helpers for the browser tests. | ||
|
|
||
| import http from "node:http"; | ||
| import path from "node:path"; | ||
| import fs from "node:fs/promises"; | ||
|
|
||
| export function report(name, passed, detail) { | ||
| const suffix = detail ? `: ${detail}` : ""; | ||
| if (passed) { | ||
| console.log(`PASS: ${name}${suffix}`); | ||
| } else { | ||
| console.log(`FAIL: ${name}${suffix}`); | ||
| process.exitCode = 1; | ||
| } | ||
| } | ||
|
|
||
| export function requireEnv(names) { | ||
| const missing = names.filter((n) => !process.env[n]); | ||
| if (missing.length > 0) { | ||
| console.error(`Required env vars: ${missing.join(", ")}`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| /// Polls `path` until a line equals `expected`. Pair with `SyncFile` on the Rust side. | ||
| export async function waitForSyncMessage(filePath, expected, timeoutMs = 120_000) { | ||
| const deadline = Date.now() + timeoutMs; | ||
| while (Date.now() < deadline) { | ||
| const contents = await fs.readFile(filePath, "utf8").catch(() => ""); | ||
| if (contents.split("\n").some((line) => line.trim() === expected)) { | ||
| return; | ||
| } | ||
| await new Promise((r) => setTimeout(r, 100)); | ||
| } | ||
| throw new Error( | ||
| `Timed out waiting for sync message "${expected}" at ${filePath}`, | ||
| ); | ||
| } | ||
|
|
||
| /// Starts a tiny HTTP server that serves files from `pageDir` at `/` and from | ||
| /// `smoldotPkgDir` at `/smoldot/`. Returns the server (already listening on a | ||
| /// random local port). | ||
| export function startStaticServer(pageDir, smoldotPkgDir) { | ||
| const server = http.createServer(async (req, res) => { | ||
| try { | ||
| const reqPath = decodeURIComponent(req.url.split("?")[0]); | ||
| let filePath; | ||
| if (reqPath === "/" || reqPath === "/index.html") { | ||
| filePath = path.join(pageDir, "index.html"); | ||
| } else if (reqPath.startsWith("/smoldot/")) { | ||
| filePath = path.join(smoldotPkgDir, reqPath.slice("/smoldot/".length)); | ||
| } else { | ||
| res.statusCode = 404; | ||
| res.end("not found"); | ||
| return; | ||
| } | ||
| const resolved = path.resolve(filePath); | ||
| if ( | ||
| !resolved.startsWith(path.resolve(pageDir)) && | ||
| !resolved.startsWith(path.resolve(smoldotPkgDir)) | ||
| ) { | ||
| res.statusCode = 403; | ||
| res.end("forbidden"); | ||
| return; | ||
| } | ||
| const data = await fs.readFile(resolved); | ||
| res.setHeader("Content-Type", contentTypeFor(resolved)); | ||
| res.end(data); | ||
| } catch (e) { | ||
| res.statusCode = 500; | ||
| res.end(String(e)); | ||
| } | ||
| }); | ||
| return new Promise((resolve) => { | ||
| server.listen(0, "127.0.0.1", () => resolve(server)); | ||
| }); | ||
| } | ||
|
|
||
| function contentTypeFor(filePath) { | ||
| switch (path.extname(filePath)) { | ||
| case ".html": | ||
| return "text/html; charset=utf-8"; | ||
| case ".js": | ||
| case ".mjs": | ||
| return "application/javascript; charset=utf-8"; | ||
| case ".wasm": | ||
| return "application/wasm"; | ||
| default: | ||
| return "application/octet-stream"; | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,8 @@ | ||
| { | ||
| "type": "module", | ||
| "private": true, | ||
| "dependencies": { | ||
| "playwright": "^1.49.0", | ||
| "smoldot": "file:../../wasm-node/javascript" | ||
| } | ||
| } |
This file contains hidden or 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,11 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head><meta charset="utf-8"><title>smoldot browser tests</title></head> | ||
| <body> | ||
| <script type="module"> | ||
| import * as smoldot from '/smoldot/dist/mjs/index-browser.js'; | ||
| window.__smoldot = smoldot; | ||
| window.__ready = true; | ||
| </script> | ||
| </body> | ||
| </html> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very minor, but polkadot host uses Vite as a bundler maybe it make sense to also use it to build smoldot for this test. Bundlers can introduce their own problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very don't want to add Vite here. I tried to keep the test very simple.