mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-03 14:23:12 +00:00
Compare commits
No commits in common. "master" and "utils-v0.0.26" have entirely different histories.
master
...
utils-v0.0
14
.cspell.json
14
.cspell.json
@ -24,11 +24,9 @@
|
|||||||
"cipherparams",
|
"cipherparams",
|
||||||
"ciphertext",
|
"ciphertext",
|
||||||
"circleci",
|
"circleci",
|
||||||
"circom",
|
|
||||||
"codecov",
|
"codecov",
|
||||||
"codegen",
|
"codegen",
|
||||||
"commitlint",
|
"commitlint",
|
||||||
"cooldown",
|
|
||||||
"dependabot",
|
"dependabot",
|
||||||
"dialable",
|
"dialable",
|
||||||
"dingpu",
|
"dingpu",
|
||||||
@ -43,7 +41,9 @@
|
|||||||
"Encrypters",
|
"Encrypters",
|
||||||
"enr",
|
"enr",
|
||||||
"enrs",
|
"enrs",
|
||||||
|
"unsubscription",
|
||||||
"enrtree",
|
"enrtree",
|
||||||
|
"unhandle",
|
||||||
"ephem",
|
"ephem",
|
||||||
"esnext",
|
"esnext",
|
||||||
"ethersproject",
|
"ethersproject",
|
||||||
@ -55,7 +55,6 @@
|
|||||||
"fontsource",
|
"fontsource",
|
||||||
"globby",
|
"globby",
|
||||||
"gossipsub",
|
"gossipsub",
|
||||||
"hackathons",
|
|
||||||
"huilong",
|
"huilong",
|
||||||
"iasked",
|
"iasked",
|
||||||
"ihave",
|
"ihave",
|
||||||
@ -63,7 +62,7 @@
|
|||||||
"ineed",
|
"ineed",
|
||||||
"IPAM",
|
"IPAM",
|
||||||
"ipfs",
|
"ipfs",
|
||||||
"isready",
|
"cooldown",
|
||||||
"iwant",
|
"iwant",
|
||||||
"jdev",
|
"jdev",
|
||||||
"jswaku",
|
"jswaku",
|
||||||
@ -104,7 +103,6 @@
|
|||||||
"reactjs",
|
"reactjs",
|
||||||
"recid",
|
"recid",
|
||||||
"rlnrelay",
|
"rlnrelay",
|
||||||
"rlnv",
|
|
||||||
"roadmap",
|
"roadmap",
|
||||||
"sandboxed",
|
"sandboxed",
|
||||||
"scanf",
|
"scanf",
|
||||||
@ -124,18 +122,14 @@
|
|||||||
"typedoc",
|
"typedoc",
|
||||||
"undialable",
|
"undialable",
|
||||||
"unencrypted",
|
"unencrypted",
|
||||||
"unhandle",
|
|
||||||
"unmarshal",
|
"unmarshal",
|
||||||
"unmount",
|
"unmount",
|
||||||
"unmounts",
|
"unmounts",
|
||||||
"unsubscription",
|
|
||||||
"untracked",
|
"untracked",
|
||||||
"upgrader",
|
"upgrader",
|
||||||
"vacp",
|
"vacp",
|
||||||
"varint",
|
"varint",
|
||||||
"viem",
|
|
||||||
"vkey",
|
"vkey",
|
||||||
"wagmi",
|
|
||||||
"waku",
|
"waku",
|
||||||
"wakuconnect",
|
"wakuconnect",
|
||||||
"wakunode",
|
"wakunode",
|
||||||
@ -145,7 +139,6 @@
|
|||||||
"weboko",
|
"weboko",
|
||||||
"websockets",
|
"websockets",
|
||||||
"wifi",
|
"wifi",
|
||||||
"WTNS",
|
|
||||||
"xsalsa20",
|
"xsalsa20",
|
||||||
"zerokit",
|
"zerokit",
|
||||||
"Привет",
|
"Привет",
|
||||||
@ -170,7 +163,6 @@
|
|||||||
"gen",
|
"gen",
|
||||||
"proto",
|
"proto",
|
||||||
"*.spec.ts",
|
"*.spec.ts",
|
||||||
"*.log",
|
|
||||||
"CHANGELOG.md"
|
"CHANGELOG.md"
|
||||||
],
|
],
|
||||||
"patterns": [
|
"patterns": [
|
||||||
|
|||||||
87
.github/workflows/ci.yml
vendored
87
.github/workflows/ci.yml
vendored
@ -15,7 +15,7 @@ on:
|
|||||||
type: string
|
type: string
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NODE_JS: "24"
|
NODE_JS: "22"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
@ -57,7 +57,7 @@ jobs:
|
|||||||
browser:
|
browser:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: mcr.microsoft.com/playwright:v1.56.1-jammy
|
image: mcr.microsoft.com/playwright:v1.53.1-jammy
|
||||||
env:
|
env:
|
||||||
HOME: "/root"
|
HOME: "/root"
|
||||||
steps:
|
steps:
|
||||||
@ -71,18 +71,65 @@ jobs:
|
|||||||
- run: npm run build:esm
|
- run: npm run build:esm
|
||||||
- run: npm run test:browser
|
- run: npm run test:browser
|
||||||
|
|
||||||
|
build_rln_tree:
|
||||||
|
if: false # This condition disables the job
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
repository: waku-org/js-waku
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_JS }}
|
||||||
|
- name: Check for existing RLN tree artifact
|
||||||
|
id: check-artifact
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const artifact = await github.rest.actions.listWorkflowRunArtifacts({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
run_id: context.runId
|
||||||
|
});
|
||||||
|
console.log(artifact);
|
||||||
|
const foundArtifact = artifact.data.artifacts.find(art => art.name === 'rln_tree.tar.gz');
|
||||||
|
if (foundArtifact) {
|
||||||
|
core.setOutput('artifact_id', foundArtifact.id);
|
||||||
|
core.setOutput('artifact_found', 'true');
|
||||||
|
} else {
|
||||||
|
core.setOutput('artifact_found', 'false');
|
||||||
|
}
|
||||||
|
- name: Download RLN tree artifact
|
||||||
|
if: steps.check-artifact.outputs.artifact_found == 'true'
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: rln_tree.tar.gz
|
||||||
|
path: /tmp
|
||||||
|
- uses: ./.github/actions/npm
|
||||||
|
- name: Sync rln tree and save artifact
|
||||||
|
run: |
|
||||||
|
mkdir -p /tmp/rln_tree.db
|
||||||
|
npm run build:esm
|
||||||
|
npm run sync-rln-tree
|
||||||
|
tar -czf rln_tree.tar.gz -C /tmp/rln_tree.db .
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: rln_tree.tar.gz
|
||||||
|
path: rln_tree.tar.gz
|
||||||
|
|
||||||
node:
|
node:
|
||||||
uses: ./.github/workflows/test-node.yml
|
uses: ./.github/workflows/test-node.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
with:
|
with:
|
||||||
nim_wakunode_image: ${{ inputs.nim_wakunode_image || 'wakuorg/nwaku:v0.36.0' }}
|
nim_wakunode_image: ${{ inputs.nim_wakunode_image || 'wakuorg/nwaku:v0.35.1' }}
|
||||||
test_type: node
|
test_type: node
|
||||||
allure_reports: true
|
allure_reports: true
|
||||||
|
|
||||||
node_optional:
|
node_optional:
|
||||||
uses: ./.github/workflows/test-node.yml
|
uses: ./.github/workflows/test-node.yml
|
||||||
with:
|
with:
|
||||||
nim_wakunode_image: ${{ inputs.nim_wakunode_image || 'wakuorg/nwaku:v0.36.0' }}
|
nim_wakunode_image: ${{ inputs.nim_wakunode_image || 'wakuorg/nwaku:v0.35.1' }}
|
||||||
test_type: node-optional
|
test_type: node-optional
|
||||||
|
|
||||||
node_with_nwaku_master:
|
node_with_nwaku_master:
|
||||||
@ -113,44 +160,12 @@ jobs:
|
|||||||
node-version: ${{ env.NODE_JS }}
|
node-version: ${{ env.NODE_JS }}
|
||||||
registry-url: "https://registry.npmjs.org"
|
registry-url: "https://registry.npmjs.org"
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
|
||||||
if: ${{ steps.release.outputs.releases_created }}
|
|
||||||
with:
|
|
||||||
version: 9
|
|
||||||
|
|
||||||
- run: npm install
|
- run: npm install
|
||||||
if: ${{ steps.release.outputs.releases_created }}
|
if: ${{ steps.release.outputs.releases_created }}
|
||||||
|
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
if: ${{ steps.release.outputs.releases_created }}
|
if: ${{ steps.release.outputs.releases_created }}
|
||||||
|
|
||||||
- name: Setup Foundry
|
|
||||||
if: ${{ steps.release.outputs.releases_created }}
|
|
||||||
uses: foundry-rs/foundry-toolchain@v1
|
|
||||||
with:
|
|
||||||
version: nightly
|
|
||||||
|
|
||||||
- name: Generate RLN contract ABIs
|
|
||||||
id: rln-abi
|
|
||||||
if: ${{ steps.release.outputs.releases_created }}
|
|
||||||
run: |
|
|
||||||
npm run setup:contract-abi -w @waku/rln || {
|
|
||||||
echo "::warning::Failed to generate contract ABIs, marking @waku/rln as private to skip publishing"
|
|
||||||
cd packages/rln
|
|
||||||
node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.private = true; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));"
|
|
||||||
echo "failed=true" >> $GITHUB_OUTPUT
|
|
||||||
}
|
|
||||||
|
|
||||||
- name: Rebuild with new ABIs
|
|
||||||
if: ${{ steps.release.outputs.releases_created && steps.rln-abi.outputs.failed != 'true' }}
|
|
||||||
run: |
|
|
||||||
npm install -w packages/rln
|
|
||||||
npm run build -w @waku/rln || {
|
|
||||||
echo "::warning::Failed to build @waku/rln, marking as private to skip publishing"
|
|
||||||
cd packages/rln
|
|
||||||
node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.private = true; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));"
|
|
||||||
}
|
|
||||||
|
|
||||||
- run: npm run publish
|
- run: npm run publish
|
||||||
if: ${{ steps.release.outputs.releases_created }}
|
if: ${{ steps.release.outputs.releases_created }}
|
||||||
env:
|
env:
|
||||||
|
|||||||
12
.github/workflows/playwright.yml
vendored
12
.github/workflows/playwright.yml
vendored
@ -8,6 +8,9 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
NODE_JS: "22"
|
NODE_JS: "22"
|
||||||
|
EXAMPLE_TEMPLATE: "web-chat"
|
||||||
|
EXAMPLE_NAME: "example"
|
||||||
|
EXAMPLE_PORT: "8080"
|
||||||
# Firefox in container fails due to $HOME not being owned by user running commands
|
# Firefox in container fails due to $HOME not being owned by user running commands
|
||||||
# more details https://github.com/microsoft/playwright/issues/6500
|
# more details https://github.com/microsoft/playwright/issues/6500
|
||||||
HOME: "/root"
|
HOME: "/root"
|
||||||
@ -17,7 +20,7 @@ jobs:
|
|||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
image: mcr.microsoft.com/playwright:v1.56.1-jammy
|
image: mcr.microsoft.com/playwright:v1.53.1-jammy
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
@ -26,8 +29,11 @@ jobs:
|
|||||||
|
|
||||||
- uses: ./.github/actions/npm
|
- uses: ./.github/actions/npm
|
||||||
|
|
||||||
- name: Build entire monorepo
|
- name: Build browser container
|
||||||
run: npm run build
|
run: npm run build --workspace=@waku/headless-tests
|
||||||
|
|
||||||
|
- name: Build browser test environment
|
||||||
|
run: npm run build --workspace=@waku/browser-tests
|
||||||
|
|
||||||
- name: Run Playwright tests
|
- name: Run Playwright tests
|
||||||
run: npm run test --workspace=@waku/browser-tests
|
run: npm run test --workspace=@waku/browser-tests
|
||||||
|
|||||||
50
.github/workflows/pre-release.yml
vendored
50
.github/workflows/pre-release.yml
vendored
@ -2,11 +2,7 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NODE_JS: "24"
|
NODE_JS: "22"
|
||||||
|
|
||||||
permissions:
|
|
||||||
id-token: write
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-release:
|
pre-release:
|
||||||
@ -14,49 +10,19 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'workflow_dispatch'
|
if: github.event_name == 'workflow_dispatch'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: waku-org/js-waku
|
repository: waku-org/js-waku
|
||||||
ref: ${{ github.ref }}
|
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
with:
|
||||||
node-version: ${{ env.NODE_JS }}
|
node-version: ${{ env.NODE_JS }}
|
||||||
registry-url: "https://registry.npmjs.org"
|
registry-url: "https://registry.npmjs.org"
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
|
||||||
with:
|
|
||||||
version: 9
|
|
||||||
|
|
||||||
- run: npm install
|
- run: npm install
|
||||||
|
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
|
||||||
- name: Setup Foundry
|
|
||||||
uses: foundry-rs/foundry-toolchain@v1
|
|
||||||
with:
|
|
||||||
version: nightly
|
|
||||||
|
|
||||||
- name: Generate RLN contract ABIs
|
|
||||||
id: rln-abi
|
|
||||||
run: |
|
|
||||||
npm run setup:contract-abi -w @waku/rln || {
|
|
||||||
echo "::warning::Failed to generate contract ABIs, marking @waku/rln as private to skip publishing"
|
|
||||||
cd packages/rln
|
|
||||||
node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.private = true; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));"
|
|
||||||
echo "failed=true" >> $GITHUB_OUTPUT
|
|
||||||
}
|
|
||||||
|
|
||||||
- name: Rebuild with new ABIs
|
|
||||||
if: steps.rln-abi.outputs.failed != 'true'
|
|
||||||
run: |
|
|
||||||
npm install -w packages/rln
|
|
||||||
npm run build -w @waku/rln || {
|
|
||||||
echo "::warning::Failed to build @waku/rln, marking as private to skip publishing"
|
|
||||||
cd packages/rln
|
|
||||||
node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.private = true; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));"
|
|
||||||
}
|
|
||||||
|
|
||||||
- run: npm run publish -- --tag next
|
- run: npm run publish -- --tag next
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_JS_WAKU_PUBLISH }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_JS_WAKU_PUBLISH }}
|
||||||
|
|||||||
8
.github/workflows/test-node.yml
vendored
8
.github/workflows/test-node.yml
vendored
@ -24,7 +24,7 @@ on:
|
|||||||
default: false
|
default: false
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NODE_JS: "24"
|
NODE_JS: "22"
|
||||||
# Ensure test type conditions remain consistent.
|
# Ensure test type conditions remain consistent.
|
||||||
WAKU_SERVICE_NODE_PARAMS: ${{ (inputs.test_type == 'go-waku-master') && '--min-relay-peers-to-publish=0' || '' }}
|
WAKU_SERVICE_NODE_PARAMS: ${{ (inputs.test_type == 'go-waku-master') && '--min-relay-peers-to-publish=0' || '' }}
|
||||||
DEBUG: ${{ inputs.debug }}
|
DEBUG: ${{ inputs.debug }}
|
||||||
@ -42,7 +42,7 @@ jobs:
|
|||||||
checks: write
|
checks: write
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: waku-org/js-waku
|
repository: waku-org/js-waku
|
||||||
|
|
||||||
- name: Remove unwanted software
|
- name: Remove unwanted software
|
||||||
@ -62,7 +62,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Merge allure reports
|
- name: Merge allure reports
|
||||||
if: always() && env.ALLURE_REPORTS == 'true'
|
if: always() && env.ALLURE_REPORTS == 'true'
|
||||||
run: node ci/mergeAllureResults.cjs
|
run: node ci/mergeAllureResults.cjs
|
||||||
|
|
||||||
- name: Get allure history
|
- name: Get allure history
|
||||||
if: always() && env.ALLURE_REPORTS == 'true'
|
if: always() && env.ALLURE_REPORTS == 'true'
|
||||||
@ -125,4 +125,4 @@ jobs:
|
|||||||
echo "## Run Information" >> $GITHUB_STEP_SUMMARY
|
echo "## Run Information" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "- **NWAKU**: ${{ env.WAKUNODE_IMAGE }}" >> $GITHUB_STEP_SUMMARY
|
echo "- **NWAKU**: ${{ env.WAKUNODE_IMAGE }}" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
|
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
|
||||||
echo "Allure report will be available at: https://waku-org.github.io/allure-jswaku/${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
|
echo "Allure report will be available at: https://waku-org.github.io/allure-jswaku/${{ github.run_number }}" >> $GITHUB_STEP_SUMMARY
|
||||||
6
.github/workflows/test-reliability.yml
vendored
6
.github/workflows/test-reliability.yml
vendored
@ -18,7 +18,7 @@ on:
|
|||||||
- all
|
- all
|
||||||
|
|
||||||
env:
|
env:
|
||||||
NODE_JS: "24"
|
NODE_JS: "22"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@ -34,7 +34,7 @@ jobs:
|
|||||||
if: ${{ github.event.inputs.test_type == 'all' }}
|
if: ${{ github.event.inputs.test_type == 'all' }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: waku-org/js-waku
|
repository: waku-org/js-waku
|
||||||
|
|
||||||
- name: Remove unwanted software
|
- name: Remove unwanted software
|
||||||
@ -74,7 +74,7 @@ jobs:
|
|||||||
if: ${{ github.event.inputs.test_type != 'all' }}
|
if: ${{ github.event.inputs.test_type != 'all' }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: waku-org/js-waku
|
repository: waku-org/js-waku
|
||||||
|
|
||||||
- name: Remove unwanted software
|
- name: Remove unwanted software
|
||||||
|
|||||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -17,7 +17,4 @@ packages/discovery/mock_local_storage
|
|||||||
.giga
|
.giga
|
||||||
.cursor
|
.cursor
|
||||||
.DS_Store
|
.DS_Store
|
||||||
CLAUDE.md
|
CLAUDE.md
|
||||||
.env
|
|
||||||
postgres-data/
|
|
||||||
packages/rln/waku-rlnv2-contract/
|
|
||||||
@ -1,15 +1,13 @@
|
|||||||
{
|
{
|
||||||
"packages/utils": "0.0.27",
|
"packages/utils": "0.0.26",
|
||||||
"packages/proto": "0.0.15",
|
"packages/proto": "0.0.13",
|
||||||
"packages/interfaces": "0.0.34",
|
"packages/interfaces": "0.0.33",
|
||||||
"packages/enr": "0.0.33",
|
"packages/enr": "0.0.32",
|
||||||
"packages/core": "0.0.40",
|
"packages/core": "0.0.38",
|
||||||
"packages/message-encryption": "0.0.38",
|
"packages/message-encryption": "0.0.36",
|
||||||
"packages/relay": "0.0.23",
|
"packages/relay": "0.0.21",
|
||||||
"packages/sdk": "0.0.36",
|
"packages/sdk": "0.0.34",
|
||||||
"packages/discovery": "0.0.13",
|
"packages/discovery": "0.0.11",
|
||||||
"packages/sds": "0.0.8",
|
"packages/sds": "0.0.6",
|
||||||
"packages/rln": "0.1.10",
|
"packages/rln": "0.1.8"
|
||||||
"packages/react": "0.0.8",
|
|
||||||
"packages/run": "0.0.2"
|
|
||||||
}
|
}
|
||||||
|
|||||||
45
Dockerfile
Normal file
45
Dockerfile
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
FROM node:20-slim
|
||||||
|
|
||||||
|
# Install Chrome dependencies
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
procps \
|
||||||
|
libglib2.0-0 \
|
||||||
|
libnss3 \
|
||||||
|
libnspr4 \
|
||||||
|
libatk1.0-0 \
|
||||||
|
libatk-bridge2.0-0 \
|
||||||
|
libcups2 \
|
||||||
|
libdrm2 \
|
||||||
|
libxkbcommon0 \
|
||||||
|
libxcomposite1 \
|
||||||
|
libxdamage1 \
|
||||||
|
libxfixes3 \
|
||||||
|
libxrandr2 \
|
||||||
|
libgbm1 \
|
||||||
|
libasound2 \
|
||||||
|
libpango-1.0-0 \
|
||||||
|
libcairo2 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY packages/browser-tests/package.json ./packages/browser-tests/
|
||||||
|
COPY packages/headless-tests/package.json ./packages/headless-tests/
|
||||||
|
|
||||||
|
# Install dependencies and serve
|
||||||
|
RUN npm install && npm install -g serve
|
||||||
|
|
||||||
|
# Copy source files
|
||||||
|
COPY tsconfig.json ./
|
||||||
|
COPY packages/ ./packages/
|
||||||
|
|
||||||
|
# Build packages
|
||||||
|
RUN npm run build -w packages/headless-tests && \
|
||||||
|
npm run build:server -w packages/browser-tests && \
|
||||||
|
npx playwright install chromium
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["npm", "run", "start:server", "-w", "packages/browser-tests"]
|
||||||
@ -23,15 +23,6 @@ npm install
|
|||||||
npm run doc
|
npm run doc
|
||||||
```
|
```
|
||||||
|
|
||||||
# Using Nix shell
|
|
||||||
```shell
|
|
||||||
git clone https://github.com/waku-org/js-waku.git
|
|
||||||
cd js-waku
|
|
||||||
nix develop
|
|
||||||
npm install
|
|
||||||
npm run doc
|
|
||||||
```
|
|
||||||
|
|
||||||
## Bugs, Questions & Features
|
## Bugs, Questions & Features
|
||||||
|
|
||||||
If you encounter any bug or would like to propose new features, feel free to [open an issue](https://github.com/waku-org/js-waku/issues/new/).
|
If you encounter any bug or would like to propose new features, feel free to [open an issue](https://github.com/waku-org/js-waku/issues/new/).
|
||||||
|
|||||||
29
ci/Jenkinsfile
vendored
29
ci/Jenkinsfile
vendored
@ -1,16 +1,5 @@
|
|||||||
#!/usr/bin/env groovy
|
|
||||||
library 'status-jenkins-lib@v1.9.27'
|
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent {
|
agent { label 'linux' }
|
||||||
docker {
|
|
||||||
label 'linuxcontainer'
|
|
||||||
image 'harbor.status.im/infra/ci-build-containers:linux-base-1.0.0'
|
|
||||||
args '--volume=/nix:/nix ' +
|
|
||||||
'--volume=/etc/nix:/etc/nix ' +
|
|
||||||
'--user jenkins'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
options {
|
options {
|
||||||
disableConcurrentBuilds()
|
disableConcurrentBuilds()
|
||||||
@ -32,25 +21,19 @@ pipeline {
|
|||||||
stages {
|
stages {
|
||||||
stage('Deps') {
|
stage('Deps') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
sh 'npm install'
|
||||||
nix.develop('npm install', pure: true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Packages') {
|
stage('Packages') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
sh 'npm run build'
|
||||||
nix.develop('npm run build', pure: true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
sh 'npm run doc'
|
||||||
nix.develop('npm run doc', pure: true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,9 +41,7 @@ pipeline {
|
|||||||
when { expression { GIT_BRANCH.endsWith('master') } }
|
when { expression { GIT_BRANCH.endsWith('master') } }
|
||||||
steps {
|
steps {
|
||||||
sshagent(credentials: ['status-im-auto-ssh']) {
|
sshagent(credentials: ['status-im-auto-ssh']) {
|
||||||
script {
|
sh 'npm run deploy'
|
||||||
nix.develop('npm run deploy', pure: false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
flake.lock
generated
26
flake.lock
generated
@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1761016216,
|
|
||||||
"narHash": "sha256-G/iC4t/9j/52i/nm+0/4ybBmAF4hzR8CNHC75qEhjHo=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "481cf557888e05d3128a76f14c76397b7d7cc869",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"id": "nixpkgs",
|
|
||||||
"ref": "nixos-25.05",
|
|
||||||
"type": "indirect"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
||||||
33
flake.nix
33
flake.nix
@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
description = "Nix flake development shell.";
|
|
||||||
|
|
||||||
inputs = {
|
|
||||||
nixpkgs.url = "nixpkgs/nixos-25.05";
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs =
|
|
||||||
{ self, nixpkgs }:
|
|
||||||
let
|
|
||||||
supportedSystems = [
|
|
||||||
"x86_64-linux"
|
|
||||||
"aarch64-linux"
|
|
||||||
"x86_64-darwin"
|
|
||||||
"aarch64-darwin"
|
|
||||||
];
|
|
||||||
forEachSystem = nixpkgs.lib.genAttrs supportedSystems;
|
|
||||||
pkgsFor = forEachSystem (system: import nixpkgs { inherit system; });
|
|
||||||
in
|
|
||||||
rec {
|
|
||||||
formatter = forEachSystem (system: pkgsFor.${system}.nixpkgs-fmt);
|
|
||||||
|
|
||||||
devShells = forEachSystem (system: {
|
|
||||||
default = pkgsFor.${system}.mkShellNoCC {
|
|
||||||
packages = with pkgsFor.${system}.buildPackages; [
|
|
||||||
git # 2.44.1
|
|
||||||
openssh # 9.7p1
|
|
||||||
nodejs_20 # v20.15.1
|
|
||||||
];
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
8184
package-lock.json
generated
8184
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@ -10,16 +10,15 @@
|
|||||||
"packages/core",
|
"packages/core",
|
||||||
"packages/discovery",
|
"packages/discovery",
|
||||||
"packages/message-encryption",
|
"packages/message-encryption",
|
||||||
"packages/sds",
|
|
||||||
"packages/rln",
|
|
||||||
"packages/sdk",
|
"packages/sdk",
|
||||||
"packages/relay",
|
"packages/relay",
|
||||||
"packages/run",
|
"packages/sds",
|
||||||
|
"packages/rln",
|
||||||
"packages/tests",
|
"packages/tests",
|
||||||
"packages/reliability-tests",
|
"packages/reliability-tests",
|
||||||
|
"packages/headless-tests",
|
||||||
"packages/browser-tests",
|
"packages/browser-tests",
|
||||||
"packages/build-utils",
|
"packages/build-utils"
|
||||||
"packages/react"
|
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
@ -45,7 +44,8 @@
|
|||||||
"doc": "run-s doc:*",
|
"doc": "run-s doc:*",
|
||||||
"doc:html": "typedoc --options typedoc.cjs",
|
"doc:html": "typedoc --options typedoc.cjs",
|
||||||
"doc:cname": "echo 'js.waku.org' > docs/CNAME",
|
"doc:cname": "echo 'js.waku.org' > docs/CNAME",
|
||||||
"publish": "node ./ci/publish.js"
|
"publish": "node ./ci/publish.js",
|
||||||
|
"sync-rln-tree": "node ./packages/tests/src/sync-rln-tree.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@size-limit/preset-big-lib": "^11.0.2",
|
"@size-limit/preset-big-lib": "^11.0.2",
|
||||||
@ -78,6 +78,5 @@
|
|||||||
"*.{ts,js}": [
|
"*.{ts,js}": [
|
||||||
"eslint --fix"
|
"eslint --fix"
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
"version": ""
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
dist
|
||||||
build
|
build
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.log
|
*.log
|
||||||
|
|||||||
@ -12,7 +12,7 @@ module.exports = {
|
|||||||
plugins: ["import"],
|
plugins: ["import"],
|
||||||
extends: ["eslint:recommended"],
|
extends: ["eslint:recommended"],
|
||||||
rules: {
|
rules: {
|
||||||
"no-unused-vars": ["error", { "argsIgnorePattern": "^_", "ignoreRestSiblings": true }]
|
"no-console": "off"
|
||||||
},
|
},
|
||||||
globals: {
|
globals: {
|
||||||
process: true
|
process: true
|
||||||
|
|||||||
@ -1,72 +0,0 @@
|
|||||||
# syntax=docker/dockerfile:1
|
|
||||||
|
|
||||||
# Build stage - install all dependencies and build
|
|
||||||
FROM node:22-bullseye AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy package.json and temporarily remove workspace dependencies that can't be resolved
|
|
||||||
COPY package.json package.json.orig
|
|
||||||
RUN sed '/"@waku\/tests": "\*",/d' package.json.orig > package.json
|
|
||||||
RUN npm install --no-audit --no-fund
|
|
||||||
|
|
||||||
COPY src ./src
|
|
||||||
COPY types ./types
|
|
||||||
COPY tsconfig.json ./
|
|
||||||
COPY web ./web
|
|
||||||
|
|
||||||
RUN npm run build
|
|
||||||
|
|
||||||
# Production stage - only runtime dependencies
|
|
||||||
FROM node:22-bullseye
|
|
||||||
|
|
||||||
# Install required system deps for Playwright Chromium
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
wget \
|
|
||||||
gnupg \
|
|
||||||
ca-certificates \
|
|
||||||
fonts-liberation \
|
|
||||||
libatk-bridge2.0-0 \
|
|
||||||
libatk1.0-0 \
|
|
||||||
libatspi2.0-0 \
|
|
||||||
libcups2 \
|
|
||||||
libdbus-1-3 \
|
|
||||||
libdrm2 \
|
|
||||||
libgtk-3-0 \
|
|
||||||
libnspr4 \
|
|
||||||
libnss3 \
|
|
||||||
libx11-xcb1 \
|
|
||||||
libxcomposite1 \
|
|
||||||
libxdamage1 \
|
|
||||||
libxfixes3 \
|
|
||||||
libxkbcommon0 \
|
|
||||||
libxrandr2 \
|
|
||||||
xdg-utils \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy package files and install only production dependencies
|
|
||||||
COPY package.json package.json.orig
|
|
||||||
RUN sed '/"@waku\/tests": "\*",/d' package.json.orig > package.json
|
|
||||||
RUN npm install --only=production --no-audit --no-fund
|
|
||||||
|
|
||||||
# Copy built application from builder stage
|
|
||||||
COPY --from=builder /app/dist ./dist
|
|
||||||
|
|
||||||
# Install Playwright browsers (Chromium only) at runtime layer
|
|
||||||
RUN npx playwright install --with-deps chromium
|
|
||||||
|
|
||||||
ENV PORT=8080 \
|
|
||||||
NODE_ENV=production
|
|
||||||
|
|
||||||
EXPOSE 8080
|
|
||||||
|
|
||||||
# Use a script to handle CLI arguments and environment variables
|
|
||||||
COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
|
||||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
|
||||||
CMD ["npm", "run", "start:server"]
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,174 +1,182 @@
|
|||||||
# Waku Browser Tests
|
# Waku Browser Tests
|
||||||
|
|
||||||
This package provides a containerized Waku light node simulation server for testing and development. The server runs a headless browser using Playwright and exposes a REST API similar to the nwaku REST API. A Dockerfile is provided to allow programmatic simulation and "deployment" of js-waku nodes in any Waku orchestration environment that uses Docker (e.g. [10ksim](https://github.com/vacp2p/10ksim) ).
|
This project provides a system for testing the Waku SDK in a browser environment.
|
||||||
|
|
||||||
## Quick Start
|
## Architecture
|
||||||
|
|
||||||
### Build and Run
|
The system consists of:
|
||||||
|
|
||||||
|
1. **Headless Web App**: A simple web application (in the `@waku/headless-tests` package) that loads the Waku SDK and exposes shared API functions.
|
||||||
|
2. **Express Server**: A server that communicates with the headless app using Playwright.
|
||||||
|
3. **Shared API**: TypeScript functions shared between the server and web app.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
1. Install dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install main dependencies
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# Install headless app dependencies
|
||||||
|
cd ../headless-tests
|
||||||
|
npm install
|
||||||
|
cd ../browser-tests
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Build the application:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build the application
|
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
# Start the server (port 8080)
|
|
||||||
npm run start:server
|
|
||||||
|
|
||||||
# Build and run Docker container
|
|
||||||
npm run docker:build
|
|
||||||
docker run -p 8080:8080 waku-browser-tests:local
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
This will:
|
||||||
|
- Build the headless web app using webpack
|
||||||
|
- Compile the TypeScript server code
|
||||||
|
|
||||||
Configure the Waku node using environment variables:
|
## Running
|
||||||
|
|
||||||
### Network Configuration
|
Start the server with:
|
||||||
- `WAKU_CLUSTER_ID`: Cluster ID (default: 1)
|
|
||||||
- `WAKU_SHARD`: Specific shard number - enables static sharding mode (optional)
|
|
||||||
|
|
||||||
**Sharding Behavior:**
|
|
||||||
- **Auto-sharding** (default): Uses `numShardsInCluster: 8` across cluster 1
|
|
||||||
- **Static sharding**: When `WAKU_SHARD` is set, uses only that specific shard
|
|
||||||
|
|
||||||
### Bootstrap Configuration
|
|
||||||
- `WAKU_ENR_BOOTSTRAP`: Enable ENR bootstrap mode with custom bootstrap peers (comma-separated)
|
|
||||||
- `WAKU_LIGHTPUSH_NODE`: Preferred lightpush node multiaddr (Docker only)
|
|
||||||
|
|
||||||
### ENR Bootstrap Mode
|
|
||||||
|
|
||||||
When `WAKU_ENR_BOOTSTRAP` is set:
|
|
||||||
- Disables default bootstrap (`defaultBootstrap: false`)
|
|
||||||
- Enables DNS discovery using production ENR trees
|
|
||||||
- Enables peer exchange and peer cache
|
|
||||||
- Uses the specified ENR for additional bootstrap peers
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Example: ENR bootstrap mode
|
npm run start:server
|
||||||
WAKU_ENR_BOOTSTRAP="enr:-QEnuEBEAyErHEfhiQxAVQoWowGTCuEF9fKZtXSd7H_PymHFhGJA3rGAYDVSHKCyJDGRLBGsloNbS8AZF33IVuefjOO6BIJpZIJ2NIJpcIQS39tkim11bHRpYWRkcnO4lgAvNihub2RlLTAxLmRvLWFtczMud2FrdXYyLnRlc3Quc3RhdHVzaW0ubmV0BgG73gMAODcxbm9kZS0wMS5hYy1jbi1ob25na29uZy1jLndha3V2Mi50ZXN0LnN0YXR1c2ltLm5ldAYBu94DACm9A62t7AQL4Ef5ZYZosRpQTzFVAB8jGjf1TER2wH-0zBOe1-MDBNLeA4lzZWNwMjU2azGhAzfsxbxyCkgCqq8WwYsVWH7YkpMLnU2Bw5xJSimxKav-g3VkcIIjKA" npm run start:server
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This will:
|
||||||
|
1. Serve the headless app on port 8080
|
||||||
|
2. Start a headless browser to load the app
|
||||||
|
3. Expose API endpoints to interact with Waku
|
||||||
|
|
||||||
## API Endpoints
|
## API Endpoints
|
||||||
|
|
||||||
The server exposes the following HTTP endpoints:
|
- `GET /info`: Get information about the Waku node
|
||||||
|
- `GET /debug/v1/info`: Get debug information from the Waku node
|
||||||
|
- `POST /push`: Push a message to the Waku network (legacy)
|
||||||
|
- `POST /lightpush/v1/message`: Push a message to the Waku network (Waku REST API compatible)
|
||||||
|
- `POST /admin/v1/create-node`: Create a new Waku node (requires networkConfig)
|
||||||
|
- `POST /admin/v1/start-node`: Start the Waku node
|
||||||
|
- `POST /admin/v1/stop-node`: Stop the Waku node
|
||||||
|
- `POST /admin/v1/peers`: Dial to specified peers (Waku REST API compatible)
|
||||||
|
- `GET /filter/v2/messages/:contentTopic`: Subscribe to messages on a specific content topic using Server-Sent Events (Waku REST API compatible)
|
||||||
|
- `GET /filter/v1/messages/:contentTopic`: Retrieve stored messages from a content topic (Waku REST API compatible)
|
||||||
|
|
||||||
### Node Management
|
### Example: Pushing a message with the legacy endpoint
|
||||||
- `GET /`: Health check - returns server status
|
|
||||||
- `GET /waku/v1/peer-info`: Get node peer information
|
|
||||||
- `POST /waku/v1/wait-for-peers`: Wait for peers with specific protocols
|
|
||||||
|
|
||||||
### Messaging
|
|
||||||
- `POST /lightpush/v3/message`: Send message via lightpush
|
|
||||||
|
|
||||||
### Static Files
|
|
||||||
- `GET /app/index.html`: Web application entry point
|
|
||||||
- `GET /app/*`: Static web application files
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
#### Send a Message (Auto-sharding)
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:8080/lightpush/v3/message \
|
curl -X POST http://localhost:3000/push \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"contentTopic": "/toy-chat/2/huilong/proto", "payload": [1, 2, 3]}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example: Pushing a message with the Waku REST API compatible endpoint
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/lightpush/v1/message \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"pubsubTopic": "",
|
"pubsubTopic": "/waku/2/rs/0/0",
|
||||||
"message": {
|
"message": {
|
||||||
"contentTopic": "/test/1/example/proto",
|
"payload": "SGVsbG8sIFdha3Uh",
|
||||||
"payload": "SGVsbG8gV2FrdQ==",
|
"contentTopic": "/toy-chat/2/huilong/proto",
|
||||||
"version": 1
|
"timestamp": 1712135330213797632
|
||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Send a Message (Explicit pubsub topic)
|
### Example: Executing a function
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:8080/lightpush/v3/message \
|
curl -X POST http://localhost:3000/execute \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"functionName": "getPeerInfo", "params": []}'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example: Creating a Waku node
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/admin/v1/create-node \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"pubsubTopic": "/waku/2/rs/1/4",
|
"defaultBootstrap": true,
|
||||||
"message": {
|
"networkConfig": {
|
||||||
"contentTopic": "/test/1/example/proto",
|
"clusterId": 1,
|
||||||
"payload": "SGVsbG8gV2FrdQ==",
|
"shards": [0, 1]
|
||||||
"version": 1
|
|
||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Wait for Peers
|
### Example: Starting and stopping a Waku node
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:8080/waku/v1/wait-for-peers \
|
# Start the node
|
||||||
|
curl -X POST http://localhost:3000/admin/v1/start-node
|
||||||
|
|
||||||
|
# Stop the node
|
||||||
|
curl -X POST http://localhost:3000/admin/v1/stop-node
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example: Dialing to specific peers with the Waku REST API compatible endpoint
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/admin/v1/peers \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"timeoutMs": 30000,
|
"peerMultiaddrs": [
|
||||||
"protocols": ["lightpush", "filter"]
|
"/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm4v8KuHUH6Cwz3upPeQbkyxQJsFGPdt7kHtkN8F79QiE6"]
|
||||||
|
]
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Get Peer Info
|
### Example: Dialing to specific peers with the execute endpoint
|
||||||
```bash
|
|
||||||
curl -X GET http://localhost:8080/waku/v1/peer-info
|
|
||||||
```
|
|
||||||
|
|
||||||
## CLI Usage
|
|
||||||
|
|
||||||
Run with CLI arguments:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Custom cluster and shard
|
curl -X POST http://localhost:3000/execute \
|
||||||
node dist/src/server.js --cluster-id=2 --shard=0
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"functionName": "dialPeers",
|
||||||
|
"params": [
|
||||||
|
["/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm4v8KuHUH6Cwz3upPeQbkyxQJsFGPdt7kHtkN8F79QiE6"]
|
||||||
|
]
|
||||||
|
}'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Testing
|
### Example: Subscribing to a content topic with the filter endpoint
|
||||||
|
|
||||||
The package includes several test suites:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Basic server functionality tests (default)
|
# Open a persistent connection to receive messages as Server-Sent Events
|
||||||
npm test
|
curl -N http://localhost:3000/filter/v2/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto
|
||||||
|
|
||||||
# Docker testing workflow
|
# You can also specify clustering options
|
||||||
npm run docker:build
|
curl -N "http://localhost:3000/filter/v2/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto?clusterId=0&shard=0"
|
||||||
npm run test:integration
|
|
||||||
|
|
||||||
# All tests
|
|
||||||
npm run test:all
|
|
||||||
|
|
||||||
# Individual test suites:
|
|
||||||
npm run test:server # Server-only tests
|
|
||||||
npm run test:e2e # End-to-end tests
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Test Types:**
|
### Example: Retrieving stored messages from a content topic
|
||||||
- `server.spec.ts` - Tests basic server functionality and static file serving
|
|
||||||
- `integration.spec.ts` - Tests Docker container integration with external services
|
|
||||||
- `e2e.spec.ts` - Full end-to-end tests using nwaku nodes
|
|
||||||
|
|
||||||
## Docker Usage
|
|
||||||
|
|
||||||
The package includes Docker support for containerized testing:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build image
|
# Get the most recent 20 messages
|
||||||
docker build -t waku-browser-tests:local .
|
curl http://localhost:3000/filter/v1/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto
|
||||||
|
|
||||||
# Run with ENR bootstrap
|
# Get messages with pagination and time filtering
|
||||||
docker run -p 8080:8080 \
|
curl "http://localhost:3000/filter/v1/messages/%2Ftoy-chat%2F2%2Fhuilong%2Fproto?pageSize=10&startTime=1712000000000&endTime=1713000000000&ascending=true"
|
||||||
-e WAKU_ENR_BOOTSTRAP="enr:-QEnuE..." \
|
|
||||||
-e WAKU_CLUSTER_ID="1" \
|
|
||||||
waku-browser-tests:local
|
|
||||||
|
|
||||||
# Run with specific configuration
|
|
||||||
docker run -p 8080:8080 \
|
|
||||||
-e WAKU_CLUSTER_ID="2" \
|
|
||||||
-e WAKU_SHARD="0" \
|
|
||||||
waku-browser-tests:local
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Extending
|
||||||
|
|
||||||
The server automatically:
|
To add new functionality:
|
||||||
- Creates a Waku light node on startup
|
|
||||||
- Configures network settings from environment variables
|
|
||||||
- Enables appropriate protocols (lightpush, filter)
|
|
||||||
- Handles peer discovery and connection management
|
|
||||||
|
|
||||||
All endpoints are CORS-enabled for cross-origin requests.
|
1. Add your function to `src/api/shared.ts`
|
||||||
|
2. Add your function to the `API` object in `src/api/shared.ts`
|
||||||
|
3. Use it via the server endpoints
|
||||||
|
|
||||||
|
### Example: Dialing to specific peers
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3000/execute \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"functionName": "dialPeers",
|
||||||
|
"params": [
|
||||||
|
["/ip4/127.0.0.1/tcp/8000/p2p/16Uiu2HAm4v8KuHUH6Cwz3upPeQbkyxQJsFGPdt7kHtkN8F79QiE6"]
|
||||||
|
]
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|||||||
@ -5,38 +5,27 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "npm run start:server",
|
"start": "npm run start:server",
|
||||||
"start:server": "PORT=8080 node ./dist/src/server.js",
|
"start:server": "node ./dist/server.js",
|
||||||
"test": "npx playwright test tests/server.spec.ts --reporter=line",
|
"test": "npx playwright test",
|
||||||
"test:all": "npx playwright test --reporter=line",
|
|
||||||
"test:server": "npx playwright test tests/server.spec.ts --reporter=line",
|
|
||||||
"test:integration": "npx playwright test tests/integration.spec.ts --reporter=line",
|
|
||||||
"test:e2e": "npx playwright test tests/e2e.spec.ts --reporter=line",
|
|
||||||
"build:server": "tsc -p tsconfig.json",
|
"build:server": "tsc -p tsconfig.json",
|
||||||
"build:web": "esbuild web/index.ts --bundle --format=esm --platform=browser --outdir=dist/web && cp web/index.html dist/web/index.html",
|
"build": "npm run build:server"
|
||||||
"build": "npm-run-all -s build:server build:web",
|
|
||||||
"docker:build": "docker build -t waku-browser-tests:local . && docker tag waku-browser-tests:local waku-browser-tests:latest"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@playwright/test": "^1.51.1",
|
|
||||||
"@waku/discovery": "^0.0.11",
|
|
||||||
"@waku/interfaces": "^0.0.33",
|
|
||||||
"@waku/sdk": "^0.0.34",
|
|
||||||
"@waku/utils": "0.0.27",
|
|
||||||
"cors": "^2.8.5",
|
|
||||||
"dotenv-flow": "^0.4.0",
|
|
||||||
"express": "^4.21.2",
|
|
||||||
"filter-obj": "^2.0.2",
|
|
||||||
"it-first": "^3.0.9"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cors": "^2.8.15",
|
"@types/cors": "^2.8.15",
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/node": "^20.10.0",
|
"@types/node": "^20.10.0",
|
||||||
"@waku/tests": "*",
|
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
"esbuild": "^0.21.5",
|
"dotenv-flow": "^0.4.0",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"testcontainers": "^10.9.0",
|
"serve": "^14.2.3",
|
||||||
"typescript": "5.8.3"
|
"typescript": "5.8.3",
|
||||||
|
"webpack-cli": "^6.0.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@playwright/test": "^1.51.1",
|
||||||
|
"@waku/sdk": "^0.0.30",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.21.2",
|
||||||
|
"node-polyfill-webpack-plugin": "^4.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,39 +1,57 @@
|
|||||||
|
// For dynamic import of dotenv-flow
|
||||||
import { defineConfig, devices } from "@playwright/test";
|
import { defineConfig, devices } from "@playwright/test";
|
||||||
import { Logger } from "@waku/utils";
|
|
||||||
|
|
||||||
const log = new Logger("playwright-config");
|
|
||||||
|
|
||||||
|
// Only load dotenv-flow in non-CI environments
|
||||||
if (!process.env.CI) {
|
if (!process.env.CI) {
|
||||||
try {
|
// Need to use .js extension for ES modules
|
||||||
await import("dotenv-flow/config.js");
|
// eslint-disable-next-line import/extensions
|
||||||
} catch (e) {
|
await import("dotenv-flow/config.js");
|
||||||
log.warn("dotenv-flow not found; skipping env loading");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const EXAMPLE_PORT = process.env.EXAMPLE_PORT || "8080";
|
const EXAMPLE_PORT = process.env.EXAMPLE_PORT || "8080";
|
||||||
const BASE_URL = `http://127.0.0.1:${EXAMPLE_PORT}`;
|
// web-chat specific thingy
|
||||||
const TEST_IGNORE = process.env.CI ? ["tests/e2e.spec.ts"] : [];
|
const EXAMPLE_TEMPLATE = process.env.EXAMPLE_TEMPLATE || "";
|
||||||
|
const BASE_URL = `http://127.0.0.1:${EXAMPLE_PORT}/${EXAMPLE_TEMPLATE}`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://playwright.dev/docs/test-configuration.
|
||||||
|
*/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
testDir: "./tests",
|
testDir: "./tests",
|
||||||
testIgnore: TEST_IGNORE,
|
/* Run tests in files in parallel */
|
||||||
fullyParallel: true,
|
fullyParallel: true,
|
||||||
|
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||||
forbidOnly: !!process.env.CI,
|
forbidOnly: !!process.env.CI,
|
||||||
|
/* Retry on CI only */
|
||||||
retries: process.env.CI ? 2 : 0,
|
retries: process.env.CI ? 2 : 0,
|
||||||
|
/* Opt out of parallel tests on CI. */
|
||||||
workers: process.env.CI ? 2 : undefined,
|
workers: process.env.CI ? 2 : undefined,
|
||||||
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||||
reporter: "html",
|
reporter: "html",
|
||||||
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||||
use: {
|
use: {
|
||||||
|
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||||
baseURL: BASE_URL,
|
baseURL: BASE_URL,
|
||||||
|
|
||||||
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||||
trace: "on-first-retry"
|
trace: "on-first-retry"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/* Configure projects for major browsers */
|
||||||
projects: [
|
projects: [
|
||||||
{
|
{
|
||||||
name: "chromium",
|
name: "chromium",
|
||||||
use: { ...devices["Desktop Chrome"] }
|
use: { ...devices["Desktop Chrome"] }
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
|
||||||
|
/* Run your local dev server before starting the tests */
|
||||||
|
webServer: {
|
||||||
|
url: BASE_URL,
|
||||||
|
stdout: "pipe",
|
||||||
|
stderr: "pipe",
|
||||||
|
command: "npm run start:server",
|
||||||
|
reuseExistingServer: !process.env.CI,
|
||||||
|
timeout: 5 * 60 * 1000 // five minutes for bootstrapping an example
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,54 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Docker entrypoint script for waku-browser-tests
|
|
||||||
# Handles CLI arguments and converts them to environment variables
|
|
||||||
# Supports reading discovered addresses from /etc/addrs/addrs.env (10k sim pattern)
|
|
||||||
echo "docker-entrypoint.sh"
|
|
||||||
echo "Using address: $addrs1"
|
|
||||||
# Only set WAKU_LIGHTPUSH_NODE if it's not already set and addrs1 is available
|
|
||||||
if [ -z "$WAKU_LIGHTPUSH_NODE" ] && [ -n "$addrs1" ]; then
|
|
||||||
export WAKU_LIGHTPUSH_NODE="$addrs1"
|
|
||||||
fi
|
|
||||||
echo "Num Args: $#"
|
|
||||||
echo "Args: $@"
|
|
||||||
|
|
||||||
echo "WAKU_LIGHTPUSH_NODE=$WAKU_LIGHTPUSH_NODE"
|
|
||||||
|
|
||||||
# Parse command line arguments
|
|
||||||
while [[ $# -gt 0 ]]; do
|
|
||||||
case $1 in
|
|
||||||
--cluster-id=*)
|
|
||||||
export WAKU_CLUSTER_ID="${1#*=}"
|
|
||||||
echo "Setting WAKU_CLUSTER_ID=${WAKU_CLUSTER_ID}"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--shard=*)
|
|
||||||
export WAKU_SHARD="${1#*=}"
|
|
||||||
echo "Setting WAKU_SHARD=${WAKU_SHARD}"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--lightpushnode=*)
|
|
||||||
export WAKU_LIGHTPUSH_NODE="${1#*=}"
|
|
||||||
echo "Setting WAKU_LIGHTPUSH_NODE=${WAKU_LIGHTPUSH_NODE}"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--enr-bootstrap=*)
|
|
||||||
export WAKU_ENR_BOOTSTRAP="${1#*=}"
|
|
||||||
echo "Setting WAKU_ENR_BOOTSTRAP=${WAKU_ENR_BOOTSTRAP}"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# Unknown argument, notify user and keep it for the main command
|
|
||||||
echo "Warning: Unknown argument '$1' will be passed to the main command"
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# If no specific command is provided, use the default CMD
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
set -- "npm" "run" "start:server"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Execute the main command
|
|
||||||
exec "$@"
|
|
||||||
22
packages/browser-tests/src/api/common.d.ts
vendored
Normal file
22
packages/browser-tests/src/api/common.d.ts
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Shared utilities for working with Waku nodes
|
||||||
|
* This file contains functions used by both browser tests and server
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type definition for a minimal Waku node interface
|
||||||
|
* This allows us to use the same code in different contexts
|
||||||
|
*/
|
||||||
|
export interface IWakuNode {
|
||||||
|
libp2p: {
|
||||||
|
peerId: { toString(): string };
|
||||||
|
getMultiaddrs(): Array<{ toString(): string }>;
|
||||||
|
getProtocols(): any;
|
||||||
|
peerStore: {
|
||||||
|
all(): Promise<Array<{ id: { toString(): string } }>>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
lightPush: {
|
||||||
|
send: (encoder: any, message: { payload: Uint8Array }) => Promise<{ successes: any[] }>;
|
||||||
|
};
|
||||||
|
}
|
||||||
36
packages/browser-tests/src/api/debug.ts
Normal file
36
packages/browser-tests/src/api/debug.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { IWakuNode } from "./common.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets peer information from a Waku node
|
||||||
|
* Used in both server API endpoints and headless tests
|
||||||
|
*/
|
||||||
|
export async function getPeerInfo(waku: IWakuNode): Promise<{
|
||||||
|
peerId: string;
|
||||||
|
multiaddrs: string[];
|
||||||
|
peers: string[];
|
||||||
|
}> {
|
||||||
|
const multiaddrs = waku.libp2p.getMultiaddrs();
|
||||||
|
const peers = await waku.libp2p.peerStore.all();
|
||||||
|
|
||||||
|
return {
|
||||||
|
peerId: waku.libp2p.peerId.toString(),
|
||||||
|
multiaddrs: multiaddrs.map((addr) => addr.toString()),
|
||||||
|
peers: peers.map((peer) => peer.id.toString())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets debug information from a Waku node
|
||||||
|
* Used in both server API endpoints and tests
|
||||||
|
*/
|
||||||
|
export async function getDebugInfo(waku: IWakuNode): Promise<{
|
||||||
|
listenAddresses: string[];
|
||||||
|
peerId: string;
|
||||||
|
protocols: string[];
|
||||||
|
}> {
|
||||||
|
return {
|
||||||
|
listenAddresses: waku.libp2p.getMultiaddrs().map((addr) => addr.toString()),
|
||||||
|
peerId: waku.libp2p.peerId.toString(),
|
||||||
|
protocols: Array.from(waku.libp2p.getProtocols())
|
||||||
|
};
|
||||||
|
}
|
||||||
16
packages/browser-tests/src/api/push.ts
Normal file
16
packages/browser-tests/src/api/push.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { createEncoder, LightNode, SDKProtocolResult } from "@waku/sdk";
|
||||||
|
|
||||||
|
export async function pushMessage(
|
||||||
|
waku: LightNode,
|
||||||
|
contentTopic: string,
|
||||||
|
payload?: Uint8Array
|
||||||
|
): Promise<SDKProtocolResult> {
|
||||||
|
const enc = createEncoder({
|
||||||
|
contentTopic
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await waku.lightPush.send(enc, {
|
||||||
|
payload: payload ?? new Uint8Array()
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
274
packages/browser-tests/src/api/shared.ts
Normal file
274
packages/browser-tests/src/api/shared.ts
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
import {
|
||||||
|
createDecoder,
|
||||||
|
createEncoder,
|
||||||
|
createLightNode,
|
||||||
|
CreateNodeOptions,
|
||||||
|
DecodedMessage,
|
||||||
|
LightNode,
|
||||||
|
SDKProtocolResult,
|
||||||
|
SubscribeResult
|
||||||
|
} from "@waku/sdk";
|
||||||
|
|
||||||
|
import { IWakuNode } from "./common.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets peer information from a Waku node
|
||||||
|
*/
|
||||||
|
export async function getPeerInfo(waku: IWakuNode): Promise<{
|
||||||
|
peerId: string;
|
||||||
|
multiaddrs: string[];
|
||||||
|
peers: string[];
|
||||||
|
}> {
|
||||||
|
const multiaddrs = waku.libp2p.getMultiaddrs();
|
||||||
|
const peers = await waku.libp2p.peerStore.all();
|
||||||
|
|
||||||
|
return {
|
||||||
|
peerId: waku.libp2p.peerId.toString(),
|
||||||
|
multiaddrs: multiaddrs.map((addr) => addr.toString()),
|
||||||
|
peers: peers.map((peer) => peer.id.toString())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets debug information from a Waku node
|
||||||
|
*/
|
||||||
|
export async function getDebugInfo(waku: IWakuNode): Promise<{
|
||||||
|
listenAddresses: string[];
|
||||||
|
peerId: string;
|
||||||
|
protocols: string[];
|
||||||
|
}> {
|
||||||
|
return {
|
||||||
|
listenAddresses: waku.libp2p.getMultiaddrs().map((addr) => addr.toString()),
|
||||||
|
peerId: waku.libp2p.peerId.toString(),
|
||||||
|
protocols: Array.from(waku.libp2p.getProtocols())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pushes a message to the network
|
||||||
|
*/
|
||||||
|
export async function pushMessage(
|
||||||
|
waku: LightNode,
|
||||||
|
contentTopic: string,
|
||||||
|
payload?: Uint8Array,
|
||||||
|
options?: {
|
||||||
|
clusterId?: number;
|
||||||
|
shard?: number;
|
||||||
|
}
|
||||||
|
): Promise<SDKProtocolResult> {
|
||||||
|
if (!waku) {
|
||||||
|
throw new Error("Waku node not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
const encoder = createEncoder({
|
||||||
|
contentTopic,
|
||||||
|
pubsubTopicShardInfo: {
|
||||||
|
clusterId: options?.clusterId ?? 1,
|
||||||
|
shard: options?.shard ?? 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await waku.lightPush.send(encoder, {
|
||||||
|
payload: payload ?? new Uint8Array()
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and initializes a Waku node
|
||||||
|
* Checks if a node is already running in window and stops it if it exists
|
||||||
|
*/
|
||||||
|
export async function createWakuNode(
|
||||||
|
options: CreateNodeOptions
|
||||||
|
): Promise<{ success: boolean; error?: string }> {
|
||||||
|
// Check if we're in a browser environment and a node already exists
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
return { success: false, error: "No window found" };
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ((window as any).waku) {
|
||||||
|
await (window as any).waku.stop();
|
||||||
|
}
|
||||||
|
(window as any).waku = await createLightNode(options);
|
||||||
|
return { success: true };
|
||||||
|
} catch (error: any) {
|
||||||
|
return { success: false, error: error.message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function startNode(): Promise<{
|
||||||
|
success: boolean;
|
||||||
|
error?: string;
|
||||||
|
}> {
|
||||||
|
if (typeof window !== "undefined" && (window as any).waku) {
|
||||||
|
try {
|
||||||
|
await (window as any).waku.start();
|
||||||
|
return { success: true };
|
||||||
|
} catch (error: any) {
|
||||||
|
// Silently continue if there's an error starting the node
|
||||||
|
return { success: false, error: error.message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { success: false, error: "Waku node not found in window" };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function stopNode(): Promise<{
|
||||||
|
success: boolean;
|
||||||
|
error?: string;
|
||||||
|
}> {
|
||||||
|
if (typeof window !== "undefined" && (window as any).waku) {
|
||||||
|
await (window as any).waku.stop();
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
return { success: false, error: "Waku node not found in window" };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function dialPeers(
|
||||||
|
waku: LightNode,
|
||||||
|
peers: string[]
|
||||||
|
): Promise<{
|
||||||
|
total: number;
|
||||||
|
errors: string[];
|
||||||
|
}> {
|
||||||
|
const total = peers.length;
|
||||||
|
const errors: string[] = [];
|
||||||
|
|
||||||
|
await Promise.allSettled(
|
||||||
|
peers.map((peer) =>
|
||||||
|
waku.dial(peer).catch((error: any) => {
|
||||||
|
errors.push(error.message);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return { total, errors };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function subscribe(
|
||||||
|
waku: LightNode,
|
||||||
|
contentTopic: string,
|
||||||
|
options?: {
|
||||||
|
clusterId?: number;
|
||||||
|
shard?: number;
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
callback?: (message: DecodedMessage) => void
|
||||||
|
): Promise<SubscribeResult> {
|
||||||
|
const clusterId = options?.clusterId ?? 42;
|
||||||
|
const shard = options?.shard ?? 0;
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Creating decoder for content topic ${contentTopic} with clusterId=${clusterId}, shard=${shard}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const pubsubTopic = `/waku/2/rs/${clusterId}/${shard}`;
|
||||||
|
|
||||||
|
let configuredTopics: string[] = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
const protocols = waku.libp2p.getProtocols();
|
||||||
|
console.log(`Available protocols: ${Array.from(protocols).join(", ")}`);
|
||||||
|
|
||||||
|
const metadataMethod = (waku.libp2p as any)._services?.metadata?.getInfo;
|
||||||
|
if (metadataMethod) {
|
||||||
|
const metadata = metadataMethod();
|
||||||
|
console.log(`Node metadata: ${JSON.stringify(metadata)}`);
|
||||||
|
|
||||||
|
if (metadata?.pubsubTopics && Array.isArray(metadata.pubsubTopics)) {
|
||||||
|
configuredTopics = metadata.pubsubTopics;
|
||||||
|
console.log(
|
||||||
|
`Found configured pubsub topics: ${configuredTopics.join(", ")}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
configuredTopics.length > 0 &&
|
||||||
|
!configuredTopics.includes(pubsubTopic)
|
||||||
|
) {
|
||||||
|
console.warn(
|
||||||
|
`Pubsub topic ${pubsubTopic} is not configured. Configured topics: ${configuredTopics.join(", ")}`
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const topic of configuredTopics) {
|
||||||
|
const parts = topic.split("/");
|
||||||
|
if (parts.length === 6 && parts[1] === "waku" && parts[3] === "rs") {
|
||||||
|
console.log(`Found potential matching pubsub topic: ${topic}`);
|
||||||
|
|
||||||
|
// Use the first topic as a fallback if no exact match is found
|
||||||
|
// This isn't ideal but allows tests to continue
|
||||||
|
const topicClusterId = parseInt(parts[4]);
|
||||||
|
const topicShard = parseInt(parts[5]);
|
||||||
|
|
||||||
|
if (!isNaN(topicClusterId) && !isNaN(topicShard)) {
|
||||||
|
console.log(
|
||||||
|
`Using pubsub topic with clusterId=${topicClusterId}, shard=${topicShard} instead`
|
||||||
|
);
|
||||||
|
|
||||||
|
const decoder = createDecoder(contentTopic, {
|
||||||
|
clusterId: topicClusterId,
|
||||||
|
shard: topicShard
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const subscription = await waku.filter.subscribe(
|
||||||
|
decoder,
|
||||||
|
callback ??
|
||||||
|
((_message) => {
|
||||||
|
console.log(_message);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return subscription;
|
||||||
|
} catch (innerErr: any) {
|
||||||
|
console.error(
|
||||||
|
`Error with alternative pubsub topic: ${innerErr.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Error checking node protocols: ${String(err)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const decoder = createDecoder(contentTopic, {
|
||||||
|
clusterId,
|
||||||
|
shard
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const subscription = await waku.filter.subscribe(
|
||||||
|
decoder,
|
||||||
|
callback ??
|
||||||
|
((_message) => {
|
||||||
|
console.log(_message);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return subscription;
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.message && err.message.includes("Pubsub topic")) {
|
||||||
|
console.error(`Pubsub topic error: ${err.message}`);
|
||||||
|
console.log("Subscription failed, but continuing with empty result");
|
||||||
|
|
||||||
|
return {
|
||||||
|
unsubscribe: async () => {
|
||||||
|
console.log("No-op unsubscribe from failed subscription");
|
||||||
|
}
|
||||||
|
} as unknown as SubscribeResult;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const API = {
|
||||||
|
getPeerInfo,
|
||||||
|
getDebugInfo,
|
||||||
|
pushMessage,
|
||||||
|
createWakuNode,
|
||||||
|
startNode,
|
||||||
|
stopNode,
|
||||||
|
dialPeers,
|
||||||
|
subscribe
|
||||||
|
};
|
||||||
@ -1,63 +1,43 @@
|
|||||||
import { Browser, chromium, Page } from "@playwright/test";
|
import { Browser, chromium, Page } from "@playwright/test";
|
||||||
import { Logger } from "@waku/utils";
|
|
||||||
|
|
||||||
const log = new Logger("browser-test");
|
|
||||||
|
|
||||||
|
// Global variable to store the browser and page
|
||||||
let browser: Browser | undefined;
|
let browser: Browser | undefined;
|
||||||
let page: Page | undefined;
|
let page: Page | undefined;
|
||||||
|
|
||||||
export async function initBrowser(appPort: number): Promise<void> {
|
/**
|
||||||
try {
|
* Initialize browser and load headless page
|
||||||
const launchArgs = ["--no-sandbox", "--disable-setuid-sandbox"];
|
*/
|
||||||
|
export async function initBrowser(): Promise<void> {
|
||||||
|
browser = await chromium.launch({
|
||||||
|
headless: true
|
||||||
|
});
|
||||||
|
|
||||||
browser = await chromium.launch({
|
if (!browser) {
|
||||||
headless: true,
|
throw new Error("Failed to initialize browser");
|
||||||
args: launchArgs
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!browser) {
|
|
||||||
throw new Error("Failed to initialize browser");
|
|
||||||
}
|
|
||||||
|
|
||||||
page = await browser.newPage();
|
|
||||||
|
|
||||||
// Forward browser console to server logs
|
|
||||||
page.on('console', msg => {
|
|
||||||
const type = msg.type();
|
|
||||||
const text = msg.text();
|
|
||||||
log.info(`[Browser Console ${type.toUpperCase()}] ${text}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
page.on('pageerror', error => {
|
|
||||||
log.error('[Browser Page Error]', error.message);
|
|
||||||
});
|
|
||||||
|
|
||||||
await page.goto(`http://localhost:${appPort}/app/index.html`, {
|
|
||||||
waitUntil: "networkidle",
|
|
||||||
});
|
|
||||||
|
|
||||||
await page.waitForFunction(
|
|
||||||
() => {
|
|
||||||
return window.wakuApi && typeof window.wakuApi.createWakuNode === "function";
|
|
||||||
},
|
|
||||||
{ timeout: 30000 }
|
|
||||||
);
|
|
||||||
|
|
||||||
log.info("Browser initialized successfully with wakuApi");
|
|
||||||
} catch (error) {
|
|
||||||
log.error("Error initializing browser:", error);
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
page = await browser.newPage();
|
||||||
|
|
||||||
|
await page.goto("http://localhost:8080");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current page instance
|
||||||
|
*/
|
||||||
export function getPage(): Page | undefined {
|
export function getPage(): Page | undefined {
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the page instance (for use by server.ts)
|
||||||
|
*/
|
||||||
export function setPage(pageInstance: Page | undefined): void {
|
export function setPage(pageInstance: Page | undefined): void {
|
||||||
page = pageInstance;
|
page = pageInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the browser instance
|
||||||
|
*/
|
||||||
export async function closeBrowser(): Promise<void> {
|
export async function closeBrowser(): Promise<void> {
|
||||||
if (browser) {
|
if (browser) {
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|||||||
89
packages/browser-tests/src/queue/index.ts
Normal file
89
packages/browser-tests/src/queue/index.ts
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
// Message queue to store received messages by content topic
|
||||||
|
export interface QueuedMessage {
|
||||||
|
payload: number[] | undefined;
|
||||||
|
contentTopic: string;
|
||||||
|
timestamp: number;
|
||||||
|
receivedAt: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MessageQueue {
|
||||||
|
[contentTopic: string]: QueuedMessage[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Global message queue storage
|
||||||
|
const messageQueue: MessageQueue = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a message in the queue
|
||||||
|
*/
|
||||||
|
export function storeMessage(message: QueuedMessage): void {
|
||||||
|
const { contentTopic } = message;
|
||||||
|
|
||||||
|
if (!messageQueue[contentTopic]) {
|
||||||
|
messageQueue[contentTopic] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
messageQueue[contentTopic].push(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get messages for a specific content topic
|
||||||
|
*/
|
||||||
|
export function getMessages(
|
||||||
|
contentTopic: string,
|
||||||
|
options?: {
|
||||||
|
startTime?: number;
|
||||||
|
endTime?: number;
|
||||||
|
pageSize?: number;
|
||||||
|
ascending?: boolean;
|
||||||
|
}
|
||||||
|
): QueuedMessage[] {
|
||||||
|
if (!messageQueue[contentTopic]) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
let messages = [...messageQueue[contentTopic]];
|
||||||
|
|
||||||
|
// Filter by time if specified
|
||||||
|
if (options?.startTime || options?.endTime) {
|
||||||
|
messages = messages.filter((msg) => {
|
||||||
|
const afterStart = options.startTime
|
||||||
|
? msg.timestamp >= options.startTime
|
||||||
|
: true;
|
||||||
|
const beforeEnd = options.endTime
|
||||||
|
? msg.timestamp <= options.endTime
|
||||||
|
: true;
|
||||||
|
return afterStart && beforeEnd;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by timestamp
|
||||||
|
messages.sort((a, b) => {
|
||||||
|
return options?.ascending
|
||||||
|
? a.timestamp - b.timestamp
|
||||||
|
: b.timestamp - a.timestamp;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Limit result size
|
||||||
|
if (options?.pageSize && options.pageSize > 0) {
|
||||||
|
messages = messages.slice(0, options.pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all messages from the queue
|
||||||
|
*/
|
||||||
|
export function clearQueue(): void {
|
||||||
|
Object.keys(messageQueue).forEach((topic) => {
|
||||||
|
delete messageQueue[topic];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all content topics in the queue
|
||||||
|
*/
|
||||||
|
export function getContentTopics(): string[] {
|
||||||
|
return Object.keys(messageQueue);
|
||||||
|
}
|
||||||
223
packages/browser-tests/src/routes/admin.ts
Normal file
223
packages/browser-tests/src/routes/admin.ts
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
import express, { Request, Response, Router } from "express";
|
||||||
|
|
||||||
|
import { getPage } from "../browser/index.js";
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.head("/admin/v1/create-node", (_req: Request, res: Response) => {
|
||||||
|
res.status(200).end();
|
||||||
|
});
|
||||||
|
|
||||||
|
router.head("/admin/v1/start-node", (_req: Request, res: Response) => {
|
||||||
|
res.status(200).end();
|
||||||
|
});
|
||||||
|
|
||||||
|
router.head("/admin/v1/stop-node", (_req: Request, res: Response) => {
|
||||||
|
res.status(200).end();
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post("/admin/v1/create-node", (async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
defaultBootstrap = true,
|
||||||
|
networkConfig
|
||||||
|
} = req.body;
|
||||||
|
|
||||||
|
// Validate that networkConfig is provided
|
||||||
|
if (!networkConfig) {
|
||||||
|
return res.status(400).json({
|
||||||
|
code: 400,
|
||||||
|
message: "networkConfig is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate that networkConfig has required properties
|
||||||
|
if (networkConfig.clusterId === undefined) {
|
||||||
|
return res.status(400).json({
|
||||||
|
code: 400,
|
||||||
|
message: "networkConfig.clusterId is required"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = getPage();
|
||||||
|
|
||||||
|
if (!page) {
|
||||||
|
return res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Browser not initialized"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await page.evaluate(
|
||||||
|
({ defaultBootstrap, networkConfig }) => {
|
||||||
|
const nodeOptions: any = {
|
||||||
|
defaultBootstrap,
|
||||||
|
relay: {
|
||||||
|
advertise: true,
|
||||||
|
gossipsubOptions: {
|
||||||
|
allowPublishToZeroPeers: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
filter: true,
|
||||||
|
peers: [],
|
||||||
|
networkConfig: {
|
||||||
|
clusterId: networkConfig.clusterId,
|
||||||
|
shards: networkConfig.shards || [0]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return window.wakuAPI.createWakuNode(nodeOptions);
|
||||||
|
},
|
||||||
|
{ defaultBootstrap, networkConfig }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result && result.success) {
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
message: "Waku node created successfully"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: "Failed to create Waku node",
|
||||||
|
details: result?.error || "Unknown error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: `Could not create Waku node: ${error.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
// Start Waku node endpoint
|
||||||
|
router.post("/admin/v1/start-node", (async (_req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const page = getPage();
|
||||||
|
|
||||||
|
if (!page) {
|
||||||
|
return res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Browser not initialized"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await page.evaluate(() => {
|
||||||
|
return window.wakuAPI.startNode
|
||||||
|
? window.wakuAPI.startNode()
|
||||||
|
: { error: "startNode function not available" };
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result && !result.error) {
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
message: "Waku node started successfully"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: "Failed to start Waku node",
|
||||||
|
details: result?.error || "Unknown error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: `Could not start Waku node: ${error.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
// Stop Waku node endpoint
|
||||||
|
router.post("/admin/v1/stop-node", (async (_req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const page = getPage();
|
||||||
|
|
||||||
|
if (!page) {
|
||||||
|
return res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Browser not initialized"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await page.evaluate(() => {
|
||||||
|
return window.wakuAPI.stopNode
|
||||||
|
? window.wakuAPI.stopNode()
|
||||||
|
: { error: "stopNode function not available" };
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result && !result.error) {
|
||||||
|
res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
message: "Waku node stopped successfully"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: "Failed to stop Waku node",
|
||||||
|
details: result?.error || "Unknown error"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: `Could not stop Waku node: ${error.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
// Dial to peers endpoint
|
||||||
|
router.post("/admin/v1/peers", (async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const { peerMultiaddrs } = req.body;
|
||||||
|
|
||||||
|
if (!peerMultiaddrs || !Array.isArray(peerMultiaddrs)) {
|
||||||
|
return res.status(400).json({
|
||||||
|
code: 400,
|
||||||
|
message: "Invalid request. peerMultiaddrs array is required."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = getPage();
|
||||||
|
|
||||||
|
if (!page) {
|
||||||
|
return res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Browser not initialized"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await page.evaluate(
|
||||||
|
({ peerAddrs }) => {
|
||||||
|
return window.wakuAPI.dialPeers(window.waku, peerAddrs);
|
||||||
|
},
|
||||||
|
{ peerAddrs: peerMultiaddrs }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
res.status(200).json({
|
||||||
|
peersAdded: peerMultiaddrs.length - (result.errors?.length || 0),
|
||||||
|
peerErrors:
|
||||||
|
result.errors?.map((error: string, index: number) => {
|
||||||
|
return {
|
||||||
|
peerMultiaddr: peerMultiaddrs[index],
|
||||||
|
error
|
||||||
|
};
|
||||||
|
}) || []
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: "Failed to dial peers"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: `Could not dial peers: ${error.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
export default router;
|
||||||
51
packages/browser-tests/src/routes/info.ts
Normal file
51
packages/browser-tests/src/routes/info.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import express, { Request, Response, Router } from "express";
|
||||||
|
|
||||||
|
import { getPage } from "../browser/index.js";
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
// Get node info endpoint
|
||||||
|
router.get("/info", (async (_req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const page = getPage();
|
||||||
|
if (!page) {
|
||||||
|
return res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Browser not initialized"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await page.evaluate(() => {
|
||||||
|
return window.wakuAPI.getPeerInfo(window.waku);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json(result);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error getting info:", error);
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
// Get node debug info endpoint
|
||||||
|
router.get("/debug/v1/info", (async (_req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const page = getPage();
|
||||||
|
if (!page) {
|
||||||
|
return res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Browser not initialized"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await page.evaluate(() => {
|
||||||
|
return window.wakuAPI.getDebugInfo(window.waku);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json(result);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error getting debug info:", error);
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
export default router;
|
||||||
131
packages/browser-tests/src/routes/push.ts
Normal file
131
packages/browser-tests/src/routes/push.ts
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
import express, { Request, Response, Router } from "express";
|
||||||
|
|
||||||
|
import { getPage } from "../browser/index.js";
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
// Legacy push message endpoint
|
||||||
|
router.post("/push", (async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const { contentTopic, payload } = req.body;
|
||||||
|
|
||||||
|
if (!contentTopic) {
|
||||||
|
return res.status(400).json({
|
||||||
|
code: 400,
|
||||||
|
message: "Invalid request. contentTopic is required."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = getPage();
|
||||||
|
if (!page) {
|
||||||
|
return res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Browser not initialized"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await page.evaluate(
|
||||||
|
({ topic, data }) => {
|
||||||
|
return window.wakuAPI.pushMessage(window.waku, topic, data);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
topic: contentTopic,
|
||||||
|
data: payload
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
res.status(200).json({
|
||||||
|
messageId:
|
||||||
|
"0x" +
|
||||||
|
Buffer.from(contentTopic + Date.now().toString()).toString("hex")
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Could not publish message: no suitable peers"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
if (
|
||||||
|
error.message.includes("size exceeds") ||
|
||||||
|
error.message.includes("stream reset")
|
||||||
|
) {
|
||||||
|
res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message:
|
||||||
|
"Could not publish message: message size exceeds gossipsub max message size"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: `Could not publish message: ${error.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
// Waku REST API compatible push endpoint
|
||||||
|
router.post("/lightpush/v1/message", (async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const { message } = req.body;
|
||||||
|
|
||||||
|
if (!message || !message.contentTopic) {
|
||||||
|
return res.status(400).json({
|
||||||
|
code: 400,
|
||||||
|
message: "Invalid request. contentTopic is required."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = getPage();
|
||||||
|
if (!page) {
|
||||||
|
return res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Browser not initialized"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await page.evaluate(
|
||||||
|
({ contentTopic, payload }) => {
|
||||||
|
return window.wakuAPI.pushMessage(window.waku, contentTopic, payload);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
contentTopic: message.contentTopic,
|
||||||
|
payload: message.payload
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
res.status(200).json({
|
||||||
|
messageId:
|
||||||
|
"0x" +
|
||||||
|
Buffer.from(message.contentTopic + Date.now().toString()).toString(
|
||||||
|
"hex"
|
||||||
|
)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Could not publish message: no suitable peers"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
if (
|
||||||
|
error.message.includes("size exceeds") ||
|
||||||
|
error.message.includes("stream reset")
|
||||||
|
) {
|
||||||
|
res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message:
|
||||||
|
"Could not publish message: message size exceeds gossipsub max message size"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: `Could not publish message: ${error.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
export default router;
|
||||||
@ -1,87 +0,0 @@
|
|||||||
import { Router } from "express";
|
|
||||||
import { Logger } from "@waku/utils";
|
|
||||||
import {
|
|
||||||
createEndpointHandler,
|
|
||||||
validators,
|
|
||||||
errorHandlers,
|
|
||||||
} from "../utils/endpoint-handler.js";
|
|
||||||
|
|
||||||
interface LightPushResult {
|
|
||||||
successes: string[];
|
|
||||||
failures: Array<{ error: string; peerId?: string }>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const log = new Logger("routes:waku");
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
const corsEndpoints = [
|
|
||||||
"/waku/v1/wait-for-peers",
|
|
||||||
"/waku/v1/peer-info",
|
|
||||||
"/lightpush/v3/message",
|
|
||||||
];
|
|
||||||
|
|
||||||
corsEndpoints.forEach((endpoint) => {
|
|
||||||
router.head(endpoint, (_req, res) => {
|
|
||||||
res.status(200).end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post(
|
|
||||||
"/waku/v1/wait-for-peers",
|
|
||||||
createEndpointHandler({
|
|
||||||
methodName: "waitForPeers",
|
|
||||||
validateInput: (body: unknown) => {
|
|
||||||
const bodyObj = body as { timeoutMs?: number; protocols?: string[] };
|
|
||||||
return [
|
|
||||||
bodyObj.timeoutMs || 10000,
|
|
||||||
bodyObj.protocols || ["lightpush", "filter"],
|
|
||||||
];
|
|
||||||
},
|
|
||||||
transformResult: () => ({
|
|
||||||
success: true,
|
|
||||||
message: "Successfully connected to peers",
|
|
||||||
}),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
router.get(
|
|
||||||
"/waku/v1/peer-info",
|
|
||||||
createEndpointHandler({
|
|
||||||
methodName: "getPeerInfo",
|
|
||||||
validateInput: validators.noInput,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
router.post(
|
|
||||||
"/lightpush/v3/message",
|
|
||||||
createEndpointHandler({
|
|
||||||
methodName: "pushMessageV3",
|
|
||||||
validateInput: (body: unknown): [string, string, string] => {
|
|
||||||
const validatedRequest = validators.requireLightpushV3(body);
|
|
||||||
|
|
||||||
return [
|
|
||||||
validatedRequest.message.contentTopic,
|
|
||||||
validatedRequest.message.payload,
|
|
||||||
validatedRequest.pubsubTopic,
|
|
||||||
];
|
|
||||||
},
|
|
||||||
handleError: errorHandlers.lightpushError,
|
|
||||||
transformResult: (result: unknown) => {
|
|
||||||
const lightPushResult = result as LightPushResult;
|
|
||||||
if (lightPushResult && lightPushResult.successes && lightPushResult.successes.length > 0) {
|
|
||||||
log.info("[Server] Message successfully sent via v3 lightpush!");
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
result: lightPushResult,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
error: "Could not publish message: no suitable peers",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
export default router;
|
|
||||||
@ -1,244 +1,507 @@
|
|||||||
|
import { ChildProcess, exec } from "child_process";
|
||||||
|
import * as net from "net";
|
||||||
|
import { dirname, join } from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import * as path from "path";
|
|
||||||
|
|
||||||
|
import { chromium } from "@playwright/test";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import express, { Request, Response } from "express";
|
import express, { Request, Response } from "express";
|
||||||
import { Logger } from "@waku/utils";
|
|
||||||
|
|
||||||
import wakuRouter from "./routes/waku.js";
|
import adminRouter from "./routes/admin.js";
|
||||||
import { initBrowser, getPage, closeBrowser } from "./browser/index.js";
|
import { setPage, getPage, closeBrowser } from "./browser/index.js";
|
||||||
import {
|
|
||||||
DEFAULT_CLUSTER_ID,
|
|
||||||
DEFAULT_NUM_SHARDS,
|
|
||||||
Protocols,
|
|
||||||
AutoSharding,
|
|
||||||
StaticSharding,
|
|
||||||
} from "@waku/interfaces";
|
|
||||||
import { CreateNodeOptions } from "@waku/sdk";
|
|
||||||
import type { WindowNetworkConfig } from "../types/global.js";
|
|
||||||
|
|
||||||
interface NodeError extends Error {
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
code?: string;
|
const __dirname = dirname(__filename);
|
||||||
}
|
|
||||||
|
|
||||||
const log = new Logger("server");
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
app.use(adminRouter);
|
||||||
|
|
||||||
import * as fs from "fs";
|
let headlessServerProcess: ChildProcess | undefined;
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
interface MessageQueue {
|
||||||
const __dirname = path.dirname(__filename);
|
[contentTopic: string]: Array<{
|
||||||
const distRoot = path.resolve(__dirname, "..");
|
payload: number[] | undefined;
|
||||||
const webDir = path.resolve(distRoot, "web");
|
contentTopic: string;
|
||||||
|
timestamp: number;
|
||||||
|
receivedAt: number;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
app.get("/app/index.html", (_req: Request, res: Response) => {
|
const messageQueue: MessageQueue = {};
|
||||||
|
|
||||||
|
async function startHeadlessServer(): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
headlessServerProcess = exec(
|
||||||
|
`serve ${join(__dirname, "../../headless-tests")} -p 8080 -s`,
|
||||||
|
(error) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(`Error starting serve: ${error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
setTimeout(resolve, 2000);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to start headless server:", error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function initBrowser(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const htmlPath = path.join(webDir, "index.html");
|
const browser = await chromium.launch({
|
||||||
let htmlContent = fs.readFileSync(htmlPath, "utf8");
|
headless: true
|
||||||
|
});
|
||||||
|
|
||||||
const networkConfig: WindowNetworkConfig = {};
|
if (!browser) {
|
||||||
if (process.env.WAKU_CLUSTER_ID) {
|
throw new Error("Failed to initialize browser");
|
||||||
networkConfig.clusterId = parseInt(process.env.WAKU_CLUSTER_ID, 10);
|
|
||||||
}
|
|
||||||
if (process.env.WAKU_SHARD) {
|
|
||||||
networkConfig.shards = [parseInt(process.env.WAKU_SHARD, 10)];
|
|
||||||
log.info("Using static shard:", networkConfig.shards);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const lightpushNode = process.env.WAKU_LIGHTPUSH_NODE || null;
|
const page = await browser.newPage();
|
||||||
const enrBootstrap = process.env.WAKU_ENR_BOOTSTRAP || null;
|
|
||||||
|
|
||||||
log.info("Network config on server start, pre headless:", networkConfig);
|
try {
|
||||||
|
await checkServerAvailability("http://localhost:8080", 3);
|
||||||
|
await page.goto("http://localhost:8080");
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
"Error loading headless app, continuing without it:",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
await page.setContent(`
|
||||||
|
<html>
|
||||||
|
<head><title>Waku Test Environment</title></head>
|
||||||
|
<body>
|
||||||
|
<h1>Waku Test Environment (No headless app available)</h1>
|
||||||
|
<script>
|
||||||
|
window.waku = {};
|
||||||
|
window.wakuAPI = {
|
||||||
|
getPeerInfo: () => ({ peerId: "mock-peer-id", multiaddrs: [], peers: [] }),
|
||||||
|
getDebugInfo: () => ({ listenAddresses: [], peerId: "mock-peer-id", protocols: [] }),
|
||||||
|
pushMessage: () => ({ successes: [], failures: [{ error: "No headless app available" }] }),
|
||||||
|
dialPeers: () => ({ total: 0, errors: ["No headless app available"] }),
|
||||||
|
createWakuNode: () => ({ success: true, message: "Mock node created" }),
|
||||||
|
startNode: () => ({ success: true }),
|
||||||
|
stopNode: () => ({ success: true }),
|
||||||
|
subscribe: () => ({ unsubscribe: async () => {} })
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
const configScript = ` <script>
|
setPage(page);
|
||||||
window.__WAKU_NETWORK_CONFIG = ${JSON.stringify(networkConfig)};
|
|
||||||
window.__WAKU_LIGHTPUSH_NODE = ${JSON.stringify(lightpushNode)};
|
|
||||||
window.__WAKU_ENR_BOOTSTRAP = ${JSON.stringify(enrBootstrap)};
|
|
||||||
</script>`;
|
|
||||||
const originalPattern =
|
|
||||||
' <script type="module" src="./index.js"></script>';
|
|
||||||
const replacement = `${configScript}\n <script type="module" src="./index.js"></script>`;
|
|
||||||
|
|
||||||
htmlContent = htmlContent.replace(originalPattern, replacement);
|
|
||||||
|
|
||||||
res.setHeader("Content-Type", "text/html");
|
|
||||||
res.send(htmlContent);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error("Error serving dynamic index.html:", error);
|
console.error("Error initializing browser:", error);
|
||||||
res.status(500).send("Error loading page");
|
throw error;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
app.use("/app", express.static(webDir, { index: false }));
|
async function checkServerAvailability(
|
||||||
|
url: string,
|
||||||
|
retries = 3
|
||||||
|
): Promise<boolean> {
|
||||||
|
for (let i = 0; i < retries; i++) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url, { method: "HEAD" });
|
||||||
|
if (response.ok) return true;
|
||||||
|
} catch (e) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(`Server at ${url} not available after ${retries} retries`);
|
||||||
|
}
|
||||||
|
|
||||||
app.use(wakuRouter);
|
async function findAvailablePort(
|
||||||
|
startPort: number,
|
||||||
|
maxAttempts = 10
|
||||||
|
): Promise<number> {
|
||||||
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
||||||
|
const port = startPort + attempt;
|
||||||
|
try {
|
||||||
|
// Try to create a server on the port
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
const server = net
|
||||||
|
.createServer()
|
||||||
|
.once("error", (err: any) => {
|
||||||
|
reject(err);
|
||||||
|
})
|
||||||
|
.once("listening", () => {
|
||||||
|
// If we can listen, the port is available
|
||||||
|
server.close();
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.listen(port);
|
||||||
|
});
|
||||||
|
|
||||||
async function startAPI(requestedPort: number): Promise<number> {
|
// If we get here, the port is available
|
||||||
|
return port;
|
||||||
|
} catch (err) {
|
||||||
|
// Port is not available, continue to next port
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we tried all ports and none are available, throw an error
|
||||||
|
throw new Error(
|
||||||
|
`Unable to find an available port after ${maxAttempts} attempts`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startServer(port: number = 3000): Promise<void> {
|
||||||
|
try {
|
||||||
|
await startHeadlessServer();
|
||||||
|
|
||||||
|
await initBrowser();
|
||||||
|
|
||||||
|
await startAPI(port);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error starting server:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startAPI(requestedPort: number): Promise<void> {
|
||||||
try {
|
try {
|
||||||
app.get("/", (_req: Request, res: Response) => {
|
app.get("/", (_req: Request, res: Response) => {
|
||||||
res.json({ status: "Waku simulation server is running" });
|
res.json({ status: "Waku simulation server is running" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get("/info", (async (_req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const result = await getPage()?.evaluate(() => {
|
||||||
|
return window.wakuAPI.getPeerInfo(window.waku);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json(result);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error getting info:", error);
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
app.get("/debug/v1/info", (async (_req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const result = await getPage()?.evaluate(() => {
|
||||||
|
return window.wakuAPI.getDebugInfo(window.waku);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json(result);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error getting debug info:", error);
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
app.post("/lightpush/v1/message", (async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const { message } = req.body;
|
||||||
|
|
||||||
|
if (!message || !message.contentTopic) {
|
||||||
|
return res.status(400).json({
|
||||||
|
code: 400,
|
||||||
|
message: "Invalid request. contentTopic is required."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await getPage()?.evaluate(
|
||||||
|
({ contentTopic, payload }) => {
|
||||||
|
return window.wakuAPI.pushMessage(
|
||||||
|
window.waku,
|
||||||
|
contentTopic,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
contentTopic: message.contentTopic,
|
||||||
|
payload: message.payload
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
res.status(200).json({
|
||||||
|
messageId:
|
||||||
|
"0x" +
|
||||||
|
Buffer.from(
|
||||||
|
message.contentTopic + Date.now().toString()
|
||||||
|
).toString("hex")
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
message: "Could not publish message: no suitable peers"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
|
||||||
|
if (
|
||||||
|
error.message.includes("size exceeds") ||
|
||||||
|
error.message.includes("stream reset")
|
||||||
|
) {
|
||||||
|
res.status(503).json({
|
||||||
|
code: 503,
|
||||||
|
|
||||||
|
message:
|
||||||
|
"Could not publish message: message size exceeds gossipsub max message size"
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: `Could not publish message: ${error.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
app.get("/filter/v2/messages/:contentTopic", (async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const { contentTopic } = req.params;
|
||||||
|
const { clusterId, shard } = req.query;
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
clusterId: clusterId ? parseInt(clusterId as string, 10) : 42, // Default to match node creation
|
||||||
|
shard: shard ? parseInt(shard as string, 10) : 0 // Default to match node creation
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Set up SSE (Server-Sent Events)
|
||||||
|
res.setHeader("Content-Type", "text/event-stream");
|
||||||
|
res.setHeader("Cache-Control", "no-cache");
|
||||||
|
res.setHeader("Connection", "keep-alive");
|
||||||
|
|
||||||
|
// Function to send SSE
|
||||||
|
const sendSSE = (data: any): void => {
|
||||||
|
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Subscribe to messages
|
||||||
|
await getPage()?.evaluate(
|
||||||
|
({ contentTopic, options }) => {
|
||||||
|
// Message handler that will send messages back to the client
|
||||||
|
const callback = (message: any): void => {
|
||||||
|
// Post message to the browser context
|
||||||
|
window.postMessage(
|
||||||
|
{
|
||||||
|
type: "WAKU_MESSAGE",
|
||||||
|
payload: {
|
||||||
|
payload: message.payload
|
||||||
|
? Array.from(message.payload)
|
||||||
|
: undefined,
|
||||||
|
contentTopic: message.contentTopic,
|
||||||
|
timestamp: message.timestamp
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"*"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return window.wakuAPI.subscribe(
|
||||||
|
window.waku,
|
||||||
|
contentTopic,
|
||||||
|
options,
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{ contentTopic, options }
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set up event listener for messages from the page
|
||||||
|
await getPage()?.exposeFunction("sendMessageToServer", (message: any) => {
|
||||||
|
// Send the message as SSE
|
||||||
|
sendSSE(message);
|
||||||
|
|
||||||
|
const topic = message.contentTopic;
|
||||||
|
if (!messageQueue[topic]) {
|
||||||
|
messageQueue[topic] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
messageQueue[topic].push({
|
||||||
|
...message,
|
||||||
|
receivedAt: Date.now()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (messageQueue[topic].length > 1000) {
|
||||||
|
messageQueue[topic].shift();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add event listener in the browser context to forward messages to the server
|
||||||
|
await getPage()?.evaluate(() => {
|
||||||
|
window.addEventListener("message", (event) => {
|
||||||
|
if (event.data.type === "WAKU_MESSAGE") {
|
||||||
|
(window as any).sendMessageToServer(event.data.payload);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
req.on("close", () => {
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error in filter subscription:", error);
|
||||||
|
res.write(`data: ${JSON.stringify({ error: error.message })}\n\n`);
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
app.get("/filter/v1/messages/:contentTopic", (async (
|
||||||
|
req: Request,
|
||||||
|
res: Response
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const { contentTopic } = req.params;
|
||||||
|
const {
|
||||||
|
pageSize = "20",
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
ascending = "false"
|
||||||
|
} = req.query;
|
||||||
|
|
||||||
|
if (!messageQueue[contentTopic]) {
|
||||||
|
return res.status(200).json({ messages: [] });
|
||||||
|
}
|
||||||
|
|
||||||
|
const limit = parseInt(pageSize as string, 10);
|
||||||
|
const isAscending = (ascending as string).toLowerCase() === "true";
|
||||||
|
const timeStart = startTime ? parseInt(startTime as string, 10) : 0;
|
||||||
|
const timeEnd = endTime ? parseInt(endTime as string, 10) : Date.now();
|
||||||
|
|
||||||
|
const filteredMessages = messageQueue[contentTopic]
|
||||||
|
.filter((msg) => {
|
||||||
|
const msgTime = msg.timestamp || msg.receivedAt;
|
||||||
|
return msgTime >= timeStart && msgTime <= timeEnd;
|
||||||
|
})
|
||||||
|
.sort((a, b) => {
|
||||||
|
const timeA = a.timestamp || a.receivedAt;
|
||||||
|
const timeB = b.timestamp || b.receivedAt;
|
||||||
|
return isAscending ? timeA - timeB : timeB - timeA;
|
||||||
|
})
|
||||||
|
.slice(0, limit);
|
||||||
|
|
||||||
|
|
||||||
|
// Format response to match Waku REST API format
|
||||||
|
const response = {
|
||||||
|
messages: filteredMessages.map((msg) => ({
|
||||||
|
payload: msg.payload
|
||||||
|
? Buffer.from(msg.payload).toString("base64")
|
||||||
|
: "",
|
||||||
|
contentTopic: msg.contentTopic,
|
||||||
|
timestamp: msg.timestamp,
|
||||||
|
version: 0 // Default version
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
|
res.status(200).json(response);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error retrieving messages:", error);
|
||||||
|
res.status(500).json({
|
||||||
|
code: 500,
|
||||||
|
message: `Failed to retrieve messages: ${error.message}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
// Helper endpoint for executing functions (useful for testing)
|
||||||
|
app.post("/execute", (async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const { functionName, params = [] } = req.body;
|
||||||
|
|
||||||
|
if (functionName === "simulateMessages") {
|
||||||
|
const [contentTopic, messages] = params;
|
||||||
|
|
||||||
|
if (!messageQueue[contentTopic]) {
|
||||||
|
messageQueue[contentTopic] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add messages to the queue
|
||||||
|
for (const msg of messages) {
|
||||||
|
messageQueue[contentTopic].push({
|
||||||
|
...msg,
|
||||||
|
contentTopic,
|
||||||
|
receivedAt: Date.now()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
messagesAdded: messages.length
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await getPage()?.evaluate(
|
||||||
|
({ fnName, fnParams }) => {
|
||||||
|
if (!window.wakuAPI[fnName]) {
|
||||||
|
return { error: `Function ${fnName} not found` };
|
||||||
|
}
|
||||||
|
return window.wakuAPI[fnName](...fnParams);
|
||||||
|
},
|
||||||
|
{ fnName: functionName, fnParams: params }
|
||||||
|
);
|
||||||
|
|
||||||
|
res.status(200).json(result);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(
|
||||||
|
`Error executing function ${req.body.functionName}:`,
|
||||||
|
error
|
||||||
|
);
|
||||||
|
res.status(500).json({
|
||||||
|
error: error.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}) as express.RequestHandler);
|
||||||
|
|
||||||
|
|
||||||
|
let actualPort: number;
|
||||||
|
try {
|
||||||
|
actualPort = await findAvailablePort(requestedPort);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to find an available port:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
app
|
app
|
||||||
.listen(requestedPort, () => {
|
.listen(actualPort, () => {
|
||||||
log.info(`API server running on http://localhost:${requestedPort}`);
|
|
||||||
})
|
})
|
||||||
.on("error", (error: NodeError) => {
|
.on("error", (error: any) => {
|
||||||
if (error.code === "EADDRINUSE") {
|
if (error.code === "EADDRINUSE") {
|
||||||
log.error(
|
console.error(
|
||||||
`Port ${requestedPort} is already in use. Please close the application using this port and try again.`,
|
`Port ${actualPort} is already in use. Please close the application using this port and try again.`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
log.error("Error starting server:", error);
|
console.error("Error starting server:", error);
|
||||||
}
|
}
|
||||||
throw error;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return requestedPort;
|
return Promise.resolve();
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
log.error("Error starting server:", error);
|
console.error("Error starting server:", error);
|
||||||
throw error;
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startServer(port: number = 3000): Promise<void> {
|
process.on("SIGINT", (async () => {
|
||||||
try {
|
await closeBrowser();
|
||||||
const actualPort = await startAPI(port);
|
|
||||||
await initBrowser(actualPort);
|
|
||||||
|
|
||||||
|
if (headlessServerProcess && headlessServerProcess.pid) {
|
||||||
try {
|
try {
|
||||||
log.info("Auto-starting node with CLI configuration...");
|
process.kill(headlessServerProcess.pid);
|
||||||
|
|
||||||
const hasEnrBootstrap = Boolean(process.env.WAKU_ENR_BOOTSTRAP);
|
|
||||||
|
|
||||||
const networkConfig: AutoSharding | StaticSharding = process.env.WAKU_SHARD
|
|
||||||
? ({
|
|
||||||
clusterId: process.env.WAKU_CLUSTER_ID
|
|
||||||
? parseInt(process.env.WAKU_CLUSTER_ID, 10)
|
|
||||||
: DEFAULT_CLUSTER_ID,
|
|
||||||
shards: [parseInt(process.env.WAKU_SHARD, 10)],
|
|
||||||
} as StaticSharding)
|
|
||||||
: ({
|
|
||||||
clusterId: process.env.WAKU_CLUSTER_ID
|
|
||||||
? parseInt(process.env.WAKU_CLUSTER_ID, 10)
|
|
||||||
: DEFAULT_CLUSTER_ID,
|
|
||||||
numShardsInCluster: DEFAULT_NUM_SHARDS,
|
|
||||||
} as AutoSharding);
|
|
||||||
|
|
||||||
const createOptions: CreateNodeOptions = {
|
|
||||||
defaultBootstrap: false,
|
|
||||||
...(hasEnrBootstrap && {
|
|
||||||
discovery: {
|
|
||||||
dns: true,
|
|
||||||
peerExchange: true,
|
|
||||||
peerCache: true,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
networkConfig,
|
|
||||||
};
|
|
||||||
|
|
||||||
log.info(
|
|
||||||
`Bootstrap mode: ${hasEnrBootstrap ? "ENR-only (defaultBootstrap=false)" : "default bootstrap (defaultBootstrap=true)"}`,
|
|
||||||
);
|
|
||||||
if (hasEnrBootstrap) {
|
|
||||||
log.info(`ENR bootstrap peers: ${process.env.WAKU_ENR_BOOTSTRAP}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info(
|
|
||||||
`Network config: ${JSON.stringify(networkConfig)}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
await getPage()?.evaluate((config) => {
|
|
||||||
return window.wakuApi.createWakuNode(config);
|
|
||||||
}, createOptions);
|
|
||||||
await getPage()?.evaluate(() => window.wakuApi.startNode());
|
|
||||||
|
|
||||||
try {
|
|
||||||
await getPage()?.evaluate(() =>
|
|
||||||
window.wakuApi.waitForPeers?.(5000, [Protocols.LightPush]),
|
|
||||||
);
|
|
||||||
log.info("Auto-start completed with bootstrap peers");
|
|
||||||
} catch (peerError) {
|
|
||||||
log.info(
|
|
||||||
"Auto-start completed (no bootstrap peers found - may be expected with test ENRs)",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.warn("Auto-start failed:", e);
|
// Process already stopped
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
log.error("Error starting server:", error);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
process.on("uncaughtException", (error) => {
|
|
||||||
log.error("Uncaught Exception:", error);
|
|
||||||
if (process.env.NODE_ENV !== "production") {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on("unhandledRejection", (reason, promise) => {
|
|
||||||
log.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
||||||
if (process.env.NODE_ENV !== "production") {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const gracefulShutdown = async (signal: string) => {
|
|
||||||
log.info(`Received ${signal}, gracefully shutting down...`);
|
|
||||||
try {
|
|
||||||
await closeBrowser();
|
|
||||||
} catch (e) {
|
|
||||||
log.warn("Error closing browser:", e);
|
|
||||||
}
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
};
|
}) as any);
|
||||||
|
|
||||||
process.on("SIGINT", () => gracefulShutdown("SIGINT"));
|
|
||||||
process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
|
|
||||||
|
|
||||||
function parseCliArgs() {
|
|
||||||
const args = process.argv.slice(2);
|
|
||||||
let clusterId: number | undefined;
|
|
||||||
let shard: number | undefined;
|
|
||||||
|
|
||||||
for (const arg of args) {
|
|
||||||
if (arg.startsWith("--cluster-id=")) {
|
|
||||||
clusterId = parseInt(arg.split("=")[1], 10);
|
|
||||||
if (isNaN(clusterId)) {
|
|
||||||
log.error("Invalid cluster-id value. Must be a number.");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
} else if (arg.startsWith("--shard=")) {
|
|
||||||
shard = parseInt(arg.split("=")[1], 10);
|
|
||||||
if (isNaN(shard)) {
|
|
||||||
log.error("Invalid shard value. Must be a number.");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { clusterId, shard };
|
|
||||||
}
|
|
||||||
|
|
||||||
const isMainModule = process.argv[1] === fileURLToPath(import.meta.url);
|
const isMainModule = process.argv[1] === fileURLToPath(import.meta.url);
|
||||||
|
|
||||||
if (isMainModule) {
|
if (isMainModule) {
|
||||||
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
||||||
const cliArgs = parseCliArgs();
|
|
||||||
|
|
||||||
if (cliArgs.clusterId !== undefined) {
|
|
||||||
process.env.WAKU_CLUSTER_ID = cliArgs.clusterId.toString();
|
|
||||||
log.info(`Using CLI cluster ID: ${cliArgs.clusterId}`);
|
|
||||||
}
|
|
||||||
if (cliArgs.shard !== undefined) {
|
|
||||||
process.env.WAKU_SHARD = cliArgs.shard.toString();
|
|
||||||
log.info(`Using CLI shard: ${cliArgs.shard}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
void startServer(port);
|
void startServer(port);
|
||||||
}
|
}
|
||||||
|
|||||||
8
packages/browser-tests/src/utils.js
Normal file
8
packages/browser-tests/src/utils.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { readFileSync } from "fs";
|
||||||
|
import { dirname } from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
export const __dirname = dirname(__filename);
|
||||||
|
|
||||||
|
export const readJSON = (path) => JSON.parse(readFileSync(path, "utf-8"));
|
||||||
@ -1,197 +0,0 @@
|
|||||||
import { Request, Response } from "express";
|
|
||||||
import { Logger } from "@waku/utils";
|
|
||||||
import { getPage } from "../browser/index.js";
|
|
||||||
import type { ITestBrowser } from "../../types/global.js";
|
|
||||||
|
|
||||||
const log = new Logger("endpoint-handler");
|
|
||||||
|
|
||||||
export interface LightpushV3Request {
|
|
||||||
pubsubTopic: string;
|
|
||||||
message: {
|
|
||||||
payload: string;
|
|
||||||
contentTopic: string;
|
|
||||||
version: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface LightpushV3Response {
|
|
||||||
success?: boolean;
|
|
||||||
error?: string;
|
|
||||||
result?: {
|
|
||||||
successes: string[];
|
|
||||||
failures: Array<{
|
|
||||||
error: string;
|
|
||||||
peerId?: string;
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EndpointConfig<TInput = unknown, TOutput = unknown> {
|
|
||||||
methodName: string;
|
|
||||||
validateInput?: (_requestBody: unknown) => TInput;
|
|
||||||
transformResult?: (_sdkResult: unknown) => TOutput;
|
|
||||||
handleError?: (_caughtError: Error) => { code: number; message: string };
|
|
||||||
preCheck?: () => Promise<void> | void;
|
|
||||||
logResult?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createEndpointHandler<TInput = unknown, TOutput = unknown>(
|
|
||||||
config: EndpointConfig<TInput, TOutput>,
|
|
||||||
) {
|
|
||||||
return async (req: Request, res: Response) => {
|
|
||||||
try {
|
|
||||||
let input: TInput;
|
|
||||||
try {
|
|
||||||
input = config.validateInput
|
|
||||||
? config.validateInput(req.body)
|
|
||||||
: req.body;
|
|
||||||
} catch (validationError) {
|
|
||||||
return res.status(400).json({
|
|
||||||
code: 400,
|
|
||||||
message: `Invalid input: ${validationError instanceof Error ? validationError.message : String(validationError)}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.preCheck) {
|
|
||||||
try {
|
|
||||||
await config.preCheck();
|
|
||||||
} catch (checkError) {
|
|
||||||
return res.status(503).json({
|
|
||||||
code: 503,
|
|
||||||
message: checkError instanceof Error ? checkError.message : String(checkError),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const page = getPage();
|
|
||||||
if (!page) {
|
|
||||||
return res.status(503).json({
|
|
||||||
code: 503,
|
|
||||||
message: "Browser not initialized",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await page.evaluate(
|
|
||||||
({ methodName, params }) => {
|
|
||||||
const testWindow = window as ITestBrowser;
|
|
||||||
if (!testWindow.wakuApi) {
|
|
||||||
throw new Error("window.wakuApi is not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
const wakuApi = testWindow.wakuApi as unknown as Record<string, unknown>;
|
|
||||||
const method = wakuApi[methodName];
|
|
||||||
if (typeof method !== "function") {
|
|
||||||
throw new Error(`window.wakuApi.${methodName} is not a function`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params === null || params === undefined) {
|
|
||||||
return method.call(testWindow.wakuApi);
|
|
||||||
} else if (Array.isArray(params)) {
|
|
||||||
return method.apply(testWindow.wakuApi, params);
|
|
||||||
} else {
|
|
||||||
return method.call(testWindow.wakuApi, params);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ methodName: config.methodName, params: input },
|
|
||||||
);
|
|
||||||
|
|
||||||
if (config.logResult !== false) {
|
|
||||||
log.info(
|
|
||||||
`[${config.methodName}] Result:`,
|
|
||||||
JSON.stringify(result, null, 2),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const finalResult = config.transformResult
|
|
||||||
? config.transformResult(result)
|
|
||||||
: result;
|
|
||||||
|
|
||||||
res.status(200).json(finalResult);
|
|
||||||
} catch (error) {
|
|
||||||
if (config.handleError) {
|
|
||||||
const errorResponse = config.handleError(error as Error);
|
|
||||||
return res.status(errorResponse.code).json({
|
|
||||||
code: errorResponse.code,
|
|
||||||
message: errorResponse.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
log.error(`[${config.methodName}] Error:`, error);
|
|
||||||
res.status(500).json({
|
|
||||||
code: 500,
|
|
||||||
message: `Could not execute ${config.methodName}: ${error instanceof Error ? error.message : String(error)}`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const validators = {
|
|
||||||
requireLightpushV3: (body: unknown): LightpushV3Request => {
|
|
||||||
// Type guard to check if body is an object
|
|
||||||
if (!body || typeof body !== "object") {
|
|
||||||
throw new Error("Request body must be an object");
|
|
||||||
}
|
|
||||||
|
|
||||||
const bodyObj = body as Record<string, unknown>;
|
|
||||||
|
|
||||||
if (
|
|
||||||
bodyObj.pubsubTopic !== undefined &&
|
|
||||||
typeof bodyObj.pubsubTopic !== "string"
|
|
||||||
) {
|
|
||||||
throw new Error("pubsubTopic must be a string if provided");
|
|
||||||
}
|
|
||||||
if (!bodyObj.message || typeof bodyObj.message !== "object") {
|
|
||||||
throw new Error("message is required and must be an object");
|
|
||||||
}
|
|
||||||
|
|
||||||
const message = bodyObj.message as Record<string, unknown>;
|
|
||||||
|
|
||||||
if (
|
|
||||||
!message.contentTopic ||
|
|
||||||
typeof message.contentTopic !== "string"
|
|
||||||
) {
|
|
||||||
throw new Error("message.contentTopic is required and must be a string");
|
|
||||||
}
|
|
||||||
if (!message.payload || typeof message.payload !== "string") {
|
|
||||||
throw new Error(
|
|
||||||
"message.payload is required and must be a string (base64 encoded)",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
message.version !== undefined &&
|
|
||||||
typeof message.version !== "number"
|
|
||||||
) {
|
|
||||||
throw new Error("message.version must be a number if provided");
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
pubsubTopic: (bodyObj.pubsubTopic as string) || "",
|
|
||||||
message: {
|
|
||||||
payload: message.payload as string,
|
|
||||||
contentTopic: message.contentTopic as string,
|
|
||||||
version: (message.version as number) || 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
noInput: () => null,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const errorHandlers = {
|
|
||||||
lightpushError: (error: Error) => {
|
|
||||||
if (
|
|
||||||
error.message.includes("size exceeds") ||
|
|
||||||
error.message.includes("stream reset")
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
code: 503,
|
|
||||||
message:
|
|
||||||
"Could not publish message: message size exceeds gossipsub max message size",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
code: 500,
|
|
||||||
message: `Could not publish message: ${error.message}`,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,117 +0,0 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
|
||||||
import axios from "axios";
|
|
||||||
import { StartedTestContainer } from "testcontainers";
|
|
||||||
import { DefaultTestRoutingInfo } from "@waku/tests";
|
|
||||||
import {
|
|
||||||
startBrowserTestsContainer,
|
|
||||||
stopContainer
|
|
||||||
} from "./utils/container-helpers.js";
|
|
||||||
import {
|
|
||||||
createTwoNodeNetwork,
|
|
||||||
getDockerAccessibleMultiaddr,
|
|
||||||
stopNwakuNodes,
|
|
||||||
TwoNodeNetwork
|
|
||||||
} from "./utils/nwaku-helpers.js";
|
|
||||||
import {
|
|
||||||
ENV_BUILDERS,
|
|
||||||
TEST_CONFIG,
|
|
||||||
ASSERTIONS
|
|
||||||
} from "./utils/test-config.js";
|
|
||||||
|
|
||||||
test.describe.configure({ mode: "serial" });
|
|
||||||
|
|
||||||
let container: StartedTestContainer;
|
|
||||||
let nwakuNodes: TwoNodeNetwork;
|
|
||||||
let baseUrl: string;
|
|
||||||
|
|
||||||
test.beforeAll(async () => {
|
|
||||||
nwakuNodes = await createTwoNodeNetwork();
|
|
||||||
|
|
||||||
const lightPushPeerAddr = await getDockerAccessibleMultiaddr(nwakuNodes.nodes[0]);
|
|
||||||
|
|
||||||
const result = await startBrowserTestsContainer({
|
|
||||||
environment: {
|
|
||||||
...ENV_BUILDERS.withLocalLightPush(lightPushPeerAddr),
|
|
||||||
DEBUG: "waku:*",
|
|
||||||
WAKU_LIGHTPUSH_NODE: lightPushPeerAddr,
|
|
||||||
},
|
|
||||||
networkMode: "waku",
|
|
||||||
});
|
|
||||||
|
|
||||||
container = result.container;
|
|
||||||
baseUrl = result.baseUrl;
|
|
||||||
});
|
|
||||||
|
|
||||||
test.afterAll(async () => {
|
|
||||||
await Promise.all([
|
|
||||||
stopContainer(container),
|
|
||||||
stopNwakuNodes(nwakuNodes?.nodes || []),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("WakuHeadless can discover nwaku peer and use it for light push", async () => {
|
|
||||||
test.setTimeout(TEST_CONFIG.DEFAULT_TEST_TIMEOUT);
|
|
||||||
|
|
||||||
const contentTopic = TEST_CONFIG.DEFAULT_CONTENT_TOPIC;
|
|
||||||
const testMessage = TEST_CONFIG.DEFAULT_TEST_MESSAGE;
|
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, TEST_CONFIG.WAKU_INIT_DELAY));
|
|
||||||
|
|
||||||
const healthResponse = await axios.get(`${baseUrl}/`, { timeout: 5000 });
|
|
||||||
ASSERTIONS.serverHealth(healthResponse);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await axios.post(`${baseUrl}/waku/v1/wait-for-peers`, {
|
|
||||||
timeoutMs: 10000,
|
|
||||||
protocols: ["lightpush"],
|
|
||||||
}, { timeout: 15000 });
|
|
||||||
} catch {
|
|
||||||
// Ignore errors
|
|
||||||
}
|
|
||||||
|
|
||||||
const peerInfoResponse = await axios.get(`${baseUrl}/waku/v1/peer-info`);
|
|
||||||
ASSERTIONS.peerInfo(peerInfoResponse);
|
|
||||||
|
|
||||||
const routingInfo = DefaultTestRoutingInfo;
|
|
||||||
|
|
||||||
const subscriptionResults = await Promise.all([
|
|
||||||
nwakuNodes.nodes[0].ensureSubscriptions([routingInfo.pubsubTopic]),
|
|
||||||
nwakuNodes.nodes[1].ensureSubscriptions([routingInfo.pubsubTopic])
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(subscriptionResults[0]).toBe(true);
|
|
||||||
expect(subscriptionResults[1]).toBe(true);
|
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, TEST_CONFIG.SUBSCRIPTION_DELAY));
|
|
||||||
|
|
||||||
const base64Payload = btoa(testMessage);
|
|
||||||
|
|
||||||
const pushResponse = await axios.post(`${baseUrl}/lightpush/v3/message`, {
|
|
||||||
pubsubTopic: routingInfo.pubsubTopic,
|
|
||||||
message: {
|
|
||||||
contentTopic,
|
|
||||||
payload: base64Payload,
|
|
||||||
version: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
ASSERTIONS.lightPushV3Success(pushResponse);
|
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, TEST_CONFIG.MESSAGE_PROPAGATION_DELAY));
|
|
||||||
|
|
||||||
const [node1Messages, node2Messages] = await Promise.all([
|
|
||||||
nwakuNodes.nodes[0].messages(contentTopic),
|
|
||||||
nwakuNodes.nodes[1].messages(contentTopic)
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
|
||||||
const totalMessages = node1Messages.length + node2Messages.length;
|
|
||||||
expect(totalMessages).toBeGreaterThanOrEqual(1);
|
|
||||||
|
|
||||||
const receivedMessages = [...node1Messages, ...node2Messages];
|
|
||||||
expect(receivedMessages.length).toBeGreaterThan(0);
|
|
||||||
|
|
||||||
const receivedMessage = receivedMessages[0];
|
|
||||||
ASSERTIONS.messageContent(receivedMessage, testMessage, contentTopic);
|
|
||||||
|
|
||||||
});
|
|
||||||
136
packages/browser-tests/tests/headless.spec.ts
Normal file
136
packages/browser-tests/tests/headless.spec.ts
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { expect, test } from "@playwright/test";
|
||||||
|
import { LightNode } from "@waku/sdk";
|
||||||
|
|
||||||
|
import { API } from "../src/api/shared.js";
|
||||||
|
import { NETWORK_CONFIG, ACTIVE_PEERS } from "./test-config.js";
|
||||||
|
|
||||||
|
// Define the window interface for TypeScript
|
||||||
|
declare global {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
interface Window {
|
||||||
|
waku: LightNode;
|
||||||
|
wakuAPI: typeof API;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test.describe("waku", () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await page.goto("");
|
||||||
|
await page.waitForTimeout(5000);
|
||||||
|
|
||||||
|
// Create and initialize a fresh Waku node for each test
|
||||||
|
const setupResult = await page.evaluate(async (config) => {
|
||||||
|
try {
|
||||||
|
await window.wakuAPI.createWakuNode({
|
||||||
|
...config.defaultNodeConfig,
|
||||||
|
networkConfig: config.networkConfig
|
||||||
|
});
|
||||||
|
await window.wakuAPI.startNode();
|
||||||
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to initialize Waku node:", error);
|
||||||
|
return { success: false, error: String(error) };
|
||||||
|
}
|
||||||
|
}, NETWORK_CONFIG);
|
||||||
|
|
||||||
|
expect(setupResult.success).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can get peer id", async ({ page }) => {
|
||||||
|
const peerId = await page.evaluate(() => {
|
||||||
|
return window.waku.libp2p.peerId.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(peerId).toBeDefined();
|
||||||
|
console.log("Peer ID:", peerId);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can get info", async ({ page }) => {
|
||||||
|
const info = await page.evaluate(() => {
|
||||||
|
return window.wakuAPI.getPeerInfo(window.waku);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(info).toBeDefined();
|
||||||
|
expect(info.peerId).toBeDefined();
|
||||||
|
expect(info.multiaddrs).toBeDefined();
|
||||||
|
expect(info.peers).toBeDefined();
|
||||||
|
console.log("Info:", info);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can get debug info", async ({ page }) => {
|
||||||
|
const debug = await page.evaluate(() => {
|
||||||
|
return window.wakuAPI.getDebugInfo(window.waku);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(debug).toBeDefined();
|
||||||
|
expect(debug.listenAddresses).toBeDefined();
|
||||||
|
expect(debug.peerId).toBeDefined();
|
||||||
|
expect(debug.protocols).toBeDefined();
|
||||||
|
console.log("Debug:", debug);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can dial peers", async ({ page }) => {
|
||||||
|
const result = await page.evaluate((peerAddrs) => {
|
||||||
|
return window.wakuAPI.dialPeers(window.waku, peerAddrs);
|
||||||
|
}, ACTIVE_PEERS);
|
||||||
|
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
expect(result.total).toBe(ACTIVE_PEERS.length);
|
||||||
|
expect(result.errors.length >= result.total).toBe(false);
|
||||||
|
console.log("Dial result:", result);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can push a message", async ({ page }) => {
|
||||||
|
// First dial to peers
|
||||||
|
await page.evaluate((peersToDial) => {
|
||||||
|
return window.wakuAPI.dialPeers(window.waku, peersToDial);
|
||||||
|
}, ACTIVE_PEERS);
|
||||||
|
|
||||||
|
// Create a test message
|
||||||
|
const contentTopic = NETWORK_CONFIG.testMessage.contentTopic;
|
||||||
|
const payload = new TextEncoder().encode(NETWORK_CONFIG.testMessage.payload);
|
||||||
|
const arrayPayload = Array.from(payload);
|
||||||
|
|
||||||
|
// Push the message
|
||||||
|
const result = await page.evaluate(
|
||||||
|
({ topic, data }) => {
|
||||||
|
return window.wakuAPI.pushMessage(
|
||||||
|
window.waku,
|
||||||
|
topic,
|
||||||
|
new Uint8Array(data)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{ topic: contentTopic, data: arrayPayload }
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
console.log("Push result:", result);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can recreate Waku node", async ({ page }) => {
|
||||||
|
// Get the current node's peer ID
|
||||||
|
const initialPeerId = await page.evaluate(() => {
|
||||||
|
return window.waku.libp2p.peerId.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a new node with different parameters
|
||||||
|
const result = await page.evaluate(() => {
|
||||||
|
return window.wakuAPI.createWakuNode({
|
||||||
|
defaultBootstrap: true // Different from beforeEach
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
|
||||||
|
// Start the new node
|
||||||
|
await page.evaluate(() => window.wakuAPI.startNode());
|
||||||
|
|
||||||
|
// Get the new peer ID
|
||||||
|
const newPeerId = await page.evaluate(() => {
|
||||||
|
return window.waku.libp2p.peerId.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(newPeerId).not.toBe(initialPeerId);
|
||||||
|
console.log("Initial:", initialPeerId, "New:", newPeerId);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,134 +0,0 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
|
||||||
import axios from "axios";
|
|
||||||
import { StartedTestContainer } from "testcontainers";
|
|
||||||
import {
|
|
||||||
createLightNode,
|
|
||||||
LightNode,
|
|
||||||
Protocols,
|
|
||||||
IDecodedMessage,
|
|
||||||
} from "@waku/sdk";
|
|
||||||
import { DEFAULT_CLUSTER_ID, DEFAULT_NUM_SHARDS } from "@waku/interfaces";
|
|
||||||
import { startBrowserTestsContainer, stopContainer } from "./utils/container-helpers.js";
|
|
||||||
import { ENV_BUILDERS, TEST_CONFIG } from "./utils/test-config.js";
|
|
||||||
|
|
||||||
test.describe.configure({ mode: "serial" });
|
|
||||||
|
|
||||||
let container: StartedTestContainer;
|
|
||||||
let baseUrl: string;
|
|
||||||
let wakuNode: LightNode;
|
|
||||||
|
|
||||||
test.beforeAll(async () => {
|
|
||||||
const result = await startBrowserTestsContainer({
|
|
||||||
environment: {
|
|
||||||
...ENV_BUILDERS.withProductionEnr(),
|
|
||||||
DEBUG: "waku:*",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
container = result.container;
|
|
||||||
baseUrl = result.baseUrl;
|
|
||||||
});
|
|
||||||
|
|
||||||
test.afterAll(async () => {
|
|
||||||
if (wakuNode) {
|
|
||||||
try {
|
|
||||||
await wakuNode.stop();
|
|
||||||
} catch {
|
|
||||||
// Ignore errors
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await stopContainer(container);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("cross-network message delivery: SDK light node receives server lightpush", async () => {
|
|
||||||
test.setTimeout(TEST_CONFIG.DEFAULT_TEST_TIMEOUT);
|
|
||||||
|
|
||||||
const contentTopic = TEST_CONFIG.DEFAULT_CONTENT_TOPIC;
|
|
||||||
const testMessage = TEST_CONFIG.DEFAULT_TEST_MESSAGE;
|
|
||||||
|
|
||||||
wakuNode = await createLightNode({
|
|
||||||
defaultBootstrap: true,
|
|
||||||
discovery: {
|
|
||||||
dns: true,
|
|
||||||
peerExchange: true,
|
|
||||||
peerCache: true,
|
|
||||||
},
|
|
||||||
networkConfig: {
|
|
||||||
clusterId: DEFAULT_CLUSTER_ID,
|
|
||||||
numShardsInCluster: DEFAULT_NUM_SHARDS,
|
|
||||||
},
|
|
||||||
libp2p: {
|
|
||||||
filterMultiaddrs: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await wakuNode.start();
|
|
||||||
|
|
||||||
await wakuNode.waitForPeers(
|
|
||||||
[Protocols.Filter, Protocols.LightPush],
|
|
||||||
30000,
|
|
||||||
);
|
|
||||||
|
|
||||||
const messages: IDecodedMessage[] = [];
|
|
||||||
const decoder = wakuNode.createDecoder({ contentTopic });
|
|
||||||
|
|
||||||
if (
|
|
||||||
!(await wakuNode.filter.subscribe([decoder], (message) => {
|
|
||||||
messages.push(message);
|
|
||||||
}))
|
|
||||||
) {
|
|
||||||
throw new Error("Failed to subscribe to Filter");
|
|
||||||
}
|
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 2000));
|
|
||||||
|
|
||||||
const messagePromise = new Promise<void>((resolve) => {
|
|
||||||
const originalLength = messages.length;
|
|
||||||
const checkForMessage = () => {
|
|
||||||
if (messages.length > originalLength) {
|
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
setTimeout(checkForMessage, 100);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
checkForMessage();
|
|
||||||
});
|
|
||||||
|
|
||||||
await axios.post(`${baseUrl}/waku/v1/wait-for-peers`, {
|
|
||||||
timeoutMs: 30000, // Increased timeout
|
|
||||||
protocols: ["lightpush", "filter"],
|
|
||||||
});
|
|
||||||
|
|
||||||
await new Promise((r) => setTimeout(r, 10000));
|
|
||||||
|
|
||||||
const base64Payload = btoa(testMessage);
|
|
||||||
|
|
||||||
const pushResponse = await axios.post(`${baseUrl}/lightpush/v3/message`, {
|
|
||||||
pubsubTopic: decoder.pubsubTopic,
|
|
||||||
message: {
|
|
||||||
contentTopic,
|
|
||||||
payload: base64Payload,
|
|
||||||
version: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(pushResponse.status).toBe(200);
|
|
||||||
expect(pushResponse.data.success).toBe(true);
|
|
||||||
|
|
||||||
await Promise.race([
|
|
||||||
messagePromise,
|
|
||||||
new Promise((_, reject) =>
|
|
||||||
setTimeout(() => {
|
|
||||||
reject(new Error("Timeout waiting for message"));
|
|
||||||
}, 45000),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(messages).toHaveLength(1);
|
|
||||||
const receivedMessage = messages[0];
|
|
||||||
expect(receivedMessage.contentTopic).toBe(contentTopic);
|
|
||||||
|
|
||||||
const receivedPayload = new TextDecoder().decode(receivedMessage.payload);
|
|
||||||
expect(receivedPayload).toBe(testMessage);
|
|
||||||
});
|
|
||||||
@ -1,82 +1,722 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
import { ChildProcess, exec, spawn } from "child_process";
|
||||||
|
import * as http from "http";
|
||||||
|
import * as net from "net";
|
||||||
|
import { join } from "path";
|
||||||
|
|
||||||
|
import { expect, test } from "@playwright/test";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { spawn, ChildProcess } from "child_process";
|
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
import { dirname, join } from "path";
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
// The default URL, but we'll update this if we detect a different port
|
||||||
const __dirname = dirname(__filename);
|
let API_URL = "http://localhost:3000";
|
||||||
|
// Need this for basic node initialization that doesn't rely on /execute
|
||||||
|
const PEERS = [
|
||||||
|
"/dns4/waku-test.bloxy.one/tcp/8095/wss/p2p/16Uiu2HAmSZbDB7CusdRhgkD81VssRjQV5ZH13FbzCGcdnbbh6VwZ",
|
||||||
|
"/dns4/waku.fryorcraken.xyz/tcp/8000/wss/p2p/16Uiu2HAmMRvhDHrtiHft1FTUYnn6cVA8AWVrTyLUayJJ3MWpUZDB"
|
||||||
|
];
|
||||||
|
|
||||||
|
let serverProcess: ChildProcess;
|
||||||
|
|
||||||
|
// Force tests to run sequentially to avoid port conflicts
|
||||||
test.describe.configure({ mode: "serial" });
|
test.describe.configure({ mode: "serial" });
|
||||||
|
|
||||||
test.describe("Server Tests", () => {
|
// Helper function to check if a port is in use
|
||||||
let serverProcess: ChildProcess;
|
async function isPortInUse(port: number): Promise<boolean> {
|
||||||
let baseUrl = "http://localhost:3000";
|
return new Promise((resolve) => {
|
||||||
|
const server = net
|
||||||
|
.createServer()
|
||||||
|
.once("error", () => {
|
||||||
|
// Port is in use
|
||||||
|
resolve(true);
|
||||||
|
})
|
||||||
|
.once("listening", () => {
|
||||||
|
// Port is free, close server
|
||||||
|
server.close();
|
||||||
|
resolve(false);
|
||||||
|
})
|
||||||
|
.listen(port);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test.beforeAll(async () => {
|
// Helper function to kill processes on port 3000
|
||||||
const serverPath = join(__dirname, "..", "dist", "src", "server.js");
|
async function killProcessOnPort(): Promise<void> {
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
// Different commands for different platforms
|
||||||
|
const cmd =
|
||||||
|
process.platform === "win32"
|
||||||
|
? `netstat -ano | findstr :3000 | findstr LISTENING`
|
||||||
|
: `lsof -i:3000 -t`;
|
||||||
|
|
||||||
serverProcess = spawn("node", [serverPath], {
|
exec(cmd, (err, stdout) => {
|
||||||
stdio: "pipe",
|
if (err || !stdout.trim()) {
|
||||||
env: { ...process.env, PORT: "3000" }
|
console.log("No process running on port 3000");
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Found processes on port 3000: ${stdout.trim()}`);
|
||||||
|
|
||||||
|
// Kill the process
|
||||||
|
const killCmd =
|
||||||
|
process.platform === "win32"
|
||||||
|
? `FOR /F "tokens=5" %P IN ('netstat -ano ^| findstr :3000 ^| findstr LISTENING') DO taskkill /F /PID %P`
|
||||||
|
: `kill -9 ${stdout.trim()}`;
|
||||||
|
|
||||||
|
exec(killCmd, (killErr) => {
|
||||||
|
if (killErr) {
|
||||||
|
console.error(`Error killing process: ${killErr.message}`);
|
||||||
|
} else {
|
||||||
|
console.log("Killed process on port 3000");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait a moment for OS to release the port
|
||||||
|
setTimeout(resolve, 500);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
serverProcess.stdout?.on("data", (_data: Buffer) => {
|
// Helper function to wait for the API server to be available
|
||||||
});
|
async function waitForApiServer(
|
||||||
|
maxRetries = 10,
|
||||||
|
interval = 1000
|
||||||
|
): Promise<boolean> {
|
||||||
|
for (let i = 0; i < maxRetries; i++) {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(API_URL, { timeout: 2000 });
|
||||||
|
if (response.status === 200) {
|
||||||
|
console.log(`API server is available at ${API_URL}`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(
|
||||||
|
`API server not available at ${API_URL}, retrying (${i + 1}/${maxRetries})...`
|
||||||
|
);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, interval));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.warn(
|
||||||
|
`API server at ${API_URL} not available after ${maxRetries} attempts`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
serverProcess.stderr?.on("data", (_data: Buffer) => {
|
// Setup and teardown for the whole test suite
|
||||||
});
|
test.beforeAll(async () => {
|
||||||
|
// First check if port 3000 is already in use - if so, try to kill it
|
||||||
|
const portInUse = await isPortInUse(3000);
|
||||||
|
if (portInUse) {
|
||||||
|
console.log(
|
||||||
|
"Port 3000 is already in use. Attempting to kill the process..."
|
||||||
|
);
|
||||||
|
await killProcessOnPort();
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
// Check again
|
||||||
|
const stillInUse = await isPortInUse(3000);
|
||||||
|
if (stillInUse) {
|
||||||
|
console.log("Failed to free port 3000. Waiting for it to be released...");
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let serverReady = false;
|
// Start the server
|
||||||
for (let i = 0; i < 30; i++) {
|
console.log("Starting server for tests...");
|
||||||
|
serverProcess = spawn("node", [join(process.cwd(), "dist/server.js")], {
|
||||||
|
stdio: "pipe",
|
||||||
|
detached: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Log server output for debugging and capture the actual port
|
||||||
|
serverProcess.stdout?.on("data", (data) => {
|
||||||
|
const output = data.toString();
|
||||||
|
console.log(`Server: ${output}`);
|
||||||
|
|
||||||
|
// Check if the output contains the port information
|
||||||
|
const portMatch = output.match(
|
||||||
|
/API server running on http:\/\/localhost:(\d+)/
|
||||||
|
);
|
||||||
|
if (portMatch && portMatch[1]) {
|
||||||
|
const detectedPort = parseInt(portMatch[1], 10);
|
||||||
|
if (detectedPort !== 3000) {
|
||||||
|
console.log(
|
||||||
|
`Server is running on port ${detectedPort} instead of 3000`
|
||||||
|
);
|
||||||
|
API_URL = `http://localhost:${detectedPort}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
serverProcess.stderr?.on("data", (data) => {
|
||||||
|
console.error(`Server Error: ${data}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wait for server to start and API to be available
|
||||||
|
console.log("Waiting for server to start...");
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
||||||
|
|
||||||
|
const apiAvailable = await waitForApiServer();
|
||||||
|
if (!apiAvailable) {
|
||||||
|
console.warn("API server is not available, tests may fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiAvailable) {
|
||||||
|
// Create a node for the tests
|
||||||
|
try {
|
||||||
|
console.log("Creating node for tests...");
|
||||||
|
const createNodeResponse = await axios.post(
|
||||||
|
`${API_URL}/admin/v1/create-node`,
|
||||||
|
{
|
||||||
|
defaultBootstrap: false,
|
||||||
|
networkConfig: {
|
||||||
|
clusterId: 42,
|
||||||
|
shards: [0]
|
||||||
|
},
|
||||||
|
pubsubTopics: ["/waku/2/rs/42/0"] // Explicitly configure the pubsub topic
|
||||||
|
},
|
||||||
|
{ timeout: 10000 }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (createNodeResponse.status === 200) {
|
||||||
|
console.log("Node creation response:", createNodeResponse.data);
|
||||||
|
|
||||||
|
// Start the node
|
||||||
|
const startNodeResponse = await axios.post(
|
||||||
|
`${API_URL}/admin/v1/start-node`,
|
||||||
|
{},
|
||||||
|
{ timeout: 5000 }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (startNodeResponse.status === 200) {
|
||||||
|
console.log("Node started successfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(
|
||||||
|
"Failed to create/start node through API, some tests may fail:",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
"Skipping node creation as server doesn't appear to be running"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterAll(async () => {
|
||||||
|
// Stop the server
|
||||||
|
console.log("Stopping server...");
|
||||||
|
if (serverProcess && serverProcess.pid) {
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
spawn("taskkill", ["/pid", serverProcess.pid.toString(), "/f", "/t"]);
|
||||||
|
} else {
|
||||||
|
// Ensure the process and all its children are terminated
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(`${baseUrl}/`, { timeout: 2000 });
|
process.kill(-serverProcess.pid, "SIGINT");
|
||||||
if (res.status === 200) {
|
} catch (e) {
|
||||||
serverReady = true;
|
console.log("Server process already terminated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify no processes running on port 3000
|
||||||
|
await killProcessOnPort();
|
||||||
|
|
||||||
|
// Give time for all processes to terminate
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe("Waku Server API", () => {
|
||||||
|
// Direct test of filter endpoint - this runs first
|
||||||
|
test("can directly access filter/v1/messages endpoint", async () => {
|
||||||
|
// Try with different content topic formats
|
||||||
|
const testTopics = [
|
||||||
|
"test-topic",
|
||||||
|
"/test/topic",
|
||||||
|
"%2Ftest%2Ftopic", // Pre-encoded
|
||||||
|
"%2Ftest%2Ftopic" // Pre-encoded
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const topic of testTopics) {
|
||||||
|
console.log(`Testing direct access with topic: ${topic}`);
|
||||||
|
try {
|
||||||
|
const response = await axios.get(
|
||||||
|
`${API_URL}/filter/v1/messages/${topic}`,
|
||||||
|
{
|
||||||
|
timeout: 5000,
|
||||||
|
validateStatus: () => true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(` Status: ${response.status}`);
|
||||||
|
console.log(` Content-Type: ${response.headers["content-type"]}`);
|
||||||
|
console.log(` Data: ${JSON.stringify(response.data)}`);
|
||||||
|
|
||||||
|
// If this succeeds, we'll use this topic format for our tests
|
||||||
|
if (response.status === 200) {
|
||||||
|
console.log(` Found working topic format: ${topic}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (error: any) {
|
||||||
// Ignore errors
|
console.error(` Error with topic ${topic}:`, error.message);
|
||||||
|
if (error.response) {
|
||||||
|
console.error(` Response status: ${error.response.status}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await new Promise((r) => setTimeout(r, 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(serverReady).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test.afterAll(async () => {
|
|
||||||
if (serverProcess) {
|
|
||||||
serverProcess.kill("SIGTERM");
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test("server health endpoint", async () => {
|
// This test checks if the server is running and can serve the basic endpoints
|
||||||
const res = await axios.get(`${baseUrl}/`);
|
test("can get server status and verify endpoints", async () => {
|
||||||
expect(res.status).toBe(200);
|
// Get initial server status with retry mechanism
|
||||||
expect(res.data.status).toBe("Waku simulation server is running");
|
let initialResponse;
|
||||||
});
|
for (let attempt = 0; attempt < 5; attempt++) {
|
||||||
|
try {
|
||||||
|
initialResponse = await axios.get(`${API_URL}/`, {
|
||||||
|
timeout: 5000,
|
||||||
|
validateStatus: () => true // Accept any status code
|
||||||
|
});
|
||||||
|
if (initialResponse.status === 200) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(
|
||||||
|
`Server not responding on attempt ${attempt + 1}/5, retrying...`
|
||||||
|
);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test("static files are served", async () => {
|
// If we still couldn't connect, skip this test
|
||||||
const htmlRes = await axios.get(`${baseUrl}/app/index.html`);
|
if (!initialResponse || initialResponse.status !== 200) {
|
||||||
expect(htmlRes.status).toBe(200);
|
console.warn("Server is not responding, skipping endpoint checks");
|
||||||
expect(htmlRes.data).toContain("Waku Test Environment");
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const jsRes = await axios.get(`${baseUrl}/app/index.js`);
|
expect(initialResponse.status).toBe(200);
|
||||||
expect(jsRes.status).toBe(200);
|
expect(initialResponse.data.status).toBe(
|
||||||
expect(jsRes.data).toContain("WakuHeadless");
|
"Waku simulation server is running"
|
||||||
});
|
);
|
||||||
|
|
||||||
|
// Check if key endpoints are available
|
||||||
|
console.log("Checking if server endpoints are properly registered...");
|
||||||
|
|
||||||
test("Waku node auto-started", async () => {
|
|
||||||
try {
|
try {
|
||||||
const infoRes = await axios.get(`${baseUrl}/waku/v1/peer-info`);
|
// Try to access the various endpoints with simple HEAD requests
|
||||||
expect(infoRes.status).toBe(200);
|
const endpoints = [
|
||||||
expect(infoRes.data.peerId).toBeDefined();
|
"/info",
|
||||||
expect(infoRes.data.multiaddrs).toBeDefined();
|
"/debug/v1/info",
|
||||||
|
"/admin/v1/create-node",
|
||||||
|
"/admin/v1/start-node",
|
||||||
|
"/admin/v1/stop-node",
|
||||||
|
"/filter/v1/messages/test-topic",
|
||||||
|
"/filter/v2/messages/test-topic"
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const endpoint of endpoints) {
|
||||||
|
try {
|
||||||
|
const response = await axios.head(`${API_URL}${endpoint}`, {
|
||||||
|
validateStatus: () => true, // Accept any status code
|
||||||
|
timeout: 3000 // Short timeout to avoid hanging
|
||||||
|
});
|
||||||
|
|
||||||
|
// Some endpoints may return 404 or 405 if they only support specific methods,
|
||||||
|
// but at least we should get a response if the route is registered
|
||||||
|
console.log(`Endpoint ${endpoint}: Status ${response.status}`);
|
||||||
|
|
||||||
|
// If we get a 404, the route is not registered
|
||||||
|
expect(response.status).not.toBe(404);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`Error checking endpoint ${endpoint}:`, error.message);
|
||||||
|
// Continue checking other endpoints even if one fails
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error checking endpoints:", error.message);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test node lifecycle operations using the dedicated endpoints
|
||||||
|
test("can create, start, and stop a node", async () => {
|
||||||
|
// 1. Create a new node
|
||||||
|
const createResponse = await axios.post(`${API_URL}/admin/v1/create-node`, {
|
||||||
|
defaultBootstrap: true,
|
||||||
|
networkConfig: {
|
||||||
|
clusterId: 42,
|
||||||
|
shards: [0]
|
||||||
|
},
|
||||||
|
pubsubTopics: ["/waku/2/rs/42/0"] // Explicitly configure the pubsub topic
|
||||||
|
});
|
||||||
|
expect(createResponse.status).toBe(200);
|
||||||
|
expect(createResponse.data.success).toBe(true);
|
||||||
|
|
||||||
|
// 2. Start the node
|
||||||
|
const startResponse = await axios.post(`${API_URL}/admin/v1/start-node`);
|
||||||
|
expect(startResponse.status).toBe(200);
|
||||||
|
expect(startResponse.data.success).toBe(true);
|
||||||
|
|
||||||
|
// 3. Get info to verify it's running
|
||||||
|
const infoResponse = await axios.get(`${API_URL}/info`);
|
||||||
|
expect(infoResponse.status).toBe(200);
|
||||||
|
expect(infoResponse.data.peerId).toBeDefined();
|
||||||
|
console.log("Node peer ID:", infoResponse.data.peerId);
|
||||||
|
|
||||||
|
// 4. Stop the node
|
||||||
|
const stopResponse = await axios.post(`${API_URL}/admin/v1/stop-node`);
|
||||||
|
expect(stopResponse.status).toBe(200);
|
||||||
|
expect(stopResponse.data.success).toBe(true);
|
||||||
|
|
||||||
|
// 5. Start it again
|
||||||
|
const restartResponse = await axios.post(`${API_URL}/admin/v1/start-node`);
|
||||||
|
expect(restartResponse.status).toBe(200);
|
||||||
|
expect(restartResponse.data.success).toBe(true);
|
||||||
|
|
||||||
|
// 6. Verify it's running again
|
||||||
|
const finalInfoResponse = await axios.get(`${API_URL}/info`);
|
||||||
|
expect(finalInfoResponse.status).toBe(200);
|
||||||
|
expect(finalInfoResponse.data.peerId).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
// This test requires a running node, which we now can properly initialize with our new endpoints
|
||||||
|
test("can connect to peers and get node info", async () => {
|
||||||
|
// Create and start a fresh node
|
||||||
|
await axios.post(`${API_URL}/admin/v1/create-node`, {
|
||||||
|
defaultBootstrap: false,
|
||||||
|
networkConfig: {
|
||||||
|
clusterId: 42,
|
||||||
|
shards: [0]
|
||||||
|
},
|
||||||
|
pubsubTopics: ["/waku/2/rs/42/0"] // Explicitly configure the pubsub topic
|
||||||
|
});
|
||||||
|
await axios.post(`${API_URL}/admin/v1/start-node`);
|
||||||
|
|
||||||
|
// Connect to peers
|
||||||
|
const dialResponse = await axios.post(`${API_URL}/admin/v1/peers`, {
|
||||||
|
peerMultiaddrs: PEERS
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(dialResponse.status).toBe(200);
|
||||||
|
console.log("Peer connection response:", dialResponse.data);
|
||||||
|
|
||||||
|
// Get debug info now that we have a properly initialized node
|
||||||
|
const debugResponse = await axios.get(`${API_URL}/debug/v1/info`);
|
||||||
|
expect(debugResponse.status).toBe(200);
|
||||||
|
expect(debugResponse.data).toBeDefined();
|
||||||
|
|
||||||
|
// Log protocols available
|
||||||
|
if (debugResponse.data.protocols) {
|
||||||
|
const wakuProtocols = debugResponse.data.protocols.filter((p: string) =>
|
||||||
|
p.includes("/waku/")
|
||||||
|
);
|
||||||
|
console.log("Waku protocols:", wakuProtocols);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can push messages", async () => {
|
||||||
|
// Create and start a fresh node
|
||||||
|
await axios.post(`${API_URL}/admin/v1/create-node`, {
|
||||||
|
defaultBootstrap: true,
|
||||||
|
networkConfig: {
|
||||||
|
clusterId: 42,
|
||||||
|
shards: [0]
|
||||||
|
},
|
||||||
|
pubsubTopics: ["/waku/2/rs/42/0"] // Explicitly configure the pubsub topic
|
||||||
|
});
|
||||||
|
await axios.post(`${API_URL}/admin/v1/start-node`);
|
||||||
|
|
||||||
|
// Connect to peers
|
||||||
|
await axios.post(`${API_URL}/admin/v1/peers`, {
|
||||||
|
peerMultiaddrs: PEERS
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test the REST API format push endpoint
|
||||||
|
try {
|
||||||
|
const restPushResponse = await axios.post(
|
||||||
|
`${API_URL}/lightpush/v1/message`,
|
||||||
|
{
|
||||||
|
pubsubTopic: "/waku/2/default-waku/proto",
|
||||||
|
message: {
|
||||||
|
contentTopic: "/test/1/message/proto",
|
||||||
|
payload: Array.from(
|
||||||
|
new TextEncoder().encode("Test message via REST endpoint")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(restPushResponse.status).toBe(200);
|
||||||
|
expect(restPushResponse.data.messageId).toBeDefined();
|
||||||
|
console.log("Message ID:", restPushResponse.data.messageId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(error.response?.status).toBe(400);
|
console.log("REST push might fail if no peers connected:", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can retrieve messages from the queue", async () => {
|
||||||
|
// Create and start a fresh node
|
||||||
|
await axios.post(`${API_URL}/admin/v1/create-node`, {
|
||||||
|
defaultBootstrap: true,
|
||||||
|
networkConfig: {
|
||||||
|
clusterId: 42,
|
||||||
|
shards: [0]
|
||||||
|
},
|
||||||
|
pubsubTopics: ["/waku/2/rs/42/0"] // Explicitly configure the pubsub topic
|
||||||
|
});
|
||||||
|
await axios.post(`${API_URL}/admin/v1/start-node`);
|
||||||
|
|
||||||
|
// Connect to peers
|
||||||
|
await axios.post(`${API_URL}/admin/v1/peers`, {
|
||||||
|
peerMultiaddrs: PEERS
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use a simple content topic to avoid encoding issues
|
||||||
|
const contentTopic = "test-queue";
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check endpoint existence by checking available routes
|
||||||
|
console.log("Checking server routes and status...");
|
||||||
|
const rootResponse = await axios.get(`${API_URL}/`);
|
||||||
|
console.log(
|
||||||
|
"Server root response:",
|
||||||
|
rootResponse.status,
|
||||||
|
rootResponse.data
|
||||||
|
);
|
||||||
|
|
||||||
|
// First ensure the queue is empty
|
||||||
|
console.log(`Attempting to get messages from ${contentTopic}...`);
|
||||||
|
const emptyQueueResponse = await axios.get(
|
||||||
|
`${API_URL}/filter/v1/messages/${contentTopic}`
|
||||||
|
);
|
||||||
|
expect(emptyQueueResponse.status).toBe(200);
|
||||||
|
expect(emptyQueueResponse.data.messages).toEqual([]);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error accessing filter endpoint:", error.message);
|
||||||
|
if (error.response) {
|
||||||
|
console.error("Response status:", error.response.status);
|
||||||
|
console.error("Response data:", error.response.data);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simulate adding messages to the queue
|
||||||
|
const messages = [
|
||||||
|
{
|
||||||
|
payload: Array.from(new TextEncoder().encode("Message 1")),
|
||||||
|
timestamp: Date.now() - 2000,
|
||||||
|
contentTopic
|
||||||
|
},
|
||||||
|
{
|
||||||
|
payload: Array.from(new TextEncoder().encode("Message 2")),
|
||||||
|
timestamp: Date.now() - 1000,
|
||||||
|
contentTopic
|
||||||
|
},
|
||||||
|
{
|
||||||
|
payload: Array.from(new TextEncoder().encode("Message 3")),
|
||||||
|
timestamp: Date.now(),
|
||||||
|
contentTopic
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const testMessages = await axios.post(`${API_URL}/execute`, {
|
||||||
|
functionName: "simulateMessages",
|
||||||
|
params: [contentTopic, messages]
|
||||||
|
});
|
||||||
|
expect(testMessages.status).toBe(200);
|
||||||
|
|
||||||
|
// Now check if we can retrieve messages
|
||||||
|
const messagesResponse = await axios.get(
|
||||||
|
`${API_URL}/filter/v1/messages/${contentTopic}`
|
||||||
|
);
|
||||||
|
expect(messagesResponse.status).toBe(200);
|
||||||
|
expect(messagesResponse.data.messages.length).toBe(3);
|
||||||
|
|
||||||
|
// Verify message format
|
||||||
|
const message = messagesResponse.data.messages[0];
|
||||||
|
expect(message).toHaveProperty("payload");
|
||||||
|
expect(message).toHaveProperty("contentTopic");
|
||||||
|
expect(message).toHaveProperty("timestamp");
|
||||||
|
expect(message).toHaveProperty("version");
|
||||||
|
|
||||||
|
// Test pagination
|
||||||
|
const paginatedResponse = await axios.get(
|
||||||
|
`${API_URL}/filter/v1/messages/${contentTopic}?pageSize=2`
|
||||||
|
);
|
||||||
|
expect(paginatedResponse.status).toBe(200);
|
||||||
|
expect(paginatedResponse.data.messages.length).toBe(2);
|
||||||
|
|
||||||
|
// Test sorting order
|
||||||
|
const ascendingResponse = await axios.get(
|
||||||
|
`${API_URL}/filter/v1/messages/${contentTopic}?ascending=true`
|
||||||
|
);
|
||||||
|
expect(ascendingResponse.status).toBe(200);
|
||||||
|
expect(ascendingResponse.data.messages.length).toBe(3);
|
||||||
|
const timestamps = ascendingResponse.data.messages.map(
|
||||||
|
(msg: any) => msg.timestamp
|
||||||
|
);
|
||||||
|
expect(timestamps[0]).toBeLessThan(timestamps[1]);
|
||||||
|
expect(timestamps[1]).toBeLessThan(timestamps[2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can access filter endpoint for SSE", async () => {
|
||||||
|
// Create and start a fresh node - only if API is accessible
|
||||||
|
try {
|
||||||
|
// Quick check if server is running
|
||||||
|
await axios.get(API_URL, { timeout: 2000 });
|
||||||
|
|
||||||
|
// Create node
|
||||||
|
await axios.post(`${API_URL}/admin/v1/create-node`, {
|
||||||
|
defaultBootstrap: true,
|
||||||
|
networkConfig: {
|
||||||
|
clusterId: 42,
|
||||||
|
shards: [0]
|
||||||
|
},
|
||||||
|
pubsubTopics: ["/waku/2/rs/42/0"] // Explicitly configure the pubsub topic
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start node
|
||||||
|
await axios.post(`${API_URL}/admin/v1/start-node`);
|
||||||
|
|
||||||
|
// Connect to peers
|
||||||
|
await axios.post(`${API_URL}/admin/v1/peers`, {
|
||||||
|
peerMultiaddrs: PEERS
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("Server appears to be unreachable, skipping test");
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contentTopic = "test-sse";
|
||||||
|
|
||||||
|
// Verify filter endpoint is accessible
|
||||||
|
// Instead of implementing a full SSE client, we'll make sure the endpoint
|
||||||
|
// returns the correct headers and status code which indicates SSE readiness
|
||||||
|
try {
|
||||||
|
const sseResponse = await axios
|
||||||
|
.get(
|
||||||
|
`${API_URL}/filter/v2/messages/${contentTopic}?clusterId=42&shard=0`,
|
||||||
|
{
|
||||||
|
// Set a timeout to avoid hanging the test
|
||||||
|
timeout: 2000,
|
||||||
|
// Expecting the request to timeout as SSE keeps connection open
|
||||||
|
validateStatus: () => true,
|
||||||
|
// We can't use responseType: 'stream' directly with axios,
|
||||||
|
// but we can check the response headers
|
||||||
|
headers: {
|
||||||
|
Accept: "text/event-stream"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((e) => {
|
||||||
|
// We expect a timeout error since SSE keeps connection open
|
||||||
|
if (e.code === "ECONNABORTED") {
|
||||||
|
return e.response;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
|
||||||
|
// If response exists and has expected SSE headers, the test passes
|
||||||
|
if (sseResponse) {
|
||||||
|
expect(sseResponse.headers["content-type"]).toBe("text/event-stream");
|
||||||
|
expect(sseResponse.headers["cache-control"]).toBe("no-cache");
|
||||||
|
expect(sseResponse.headers["connection"]).toBe("keep-alive");
|
||||||
|
} else {
|
||||||
|
// If no response, we manually make an HTTP request to check the headers
|
||||||
|
const headers = await new Promise<Record<string, string>>((resolve) => {
|
||||||
|
const requestUrl = new URL(
|
||||||
|
`${API_URL}/filter/v2/messages/${contentTopic}?clusterId=42&shard=0`
|
||||||
|
);
|
||||||
|
const req = http.get(requestUrl, (res) => {
|
||||||
|
// Only interested in headers
|
||||||
|
req.destroy();
|
||||||
|
if (res.headers) {
|
||||||
|
resolve(res.headers as Record<string, string>);
|
||||||
|
} else {
|
||||||
|
resolve({});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
req.on("error", () => resolve({}));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Object.keys(headers).length === 0) {
|
||||||
|
console.warn(
|
||||||
|
"No headers received, SSE endpoint may not be accessible"
|
||||||
|
);
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(headers["content-type"]).toBe("text/event-stream");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error during SSE endpoint test:", error);
|
||||||
|
test.fail();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("SSE endpoint is accessible with correct headers");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add a specific test just for the filter/v1/messages endpoint
|
||||||
|
test("can access filter/v1/messages endpoint directly", async () => {
|
||||||
|
// Check if server is available first
|
||||||
|
try {
|
||||||
|
await axios.get(API_URL, { timeout: 2000 });
|
||||||
|
} catch (error) {
|
||||||
|
console.warn("Server appears to be unreachable, skipping test");
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a random content topic just for this test
|
||||||
|
const contentTopic = `direct-filter-${Date.now()}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try different approaches to access the endpoint
|
||||||
|
console.log(
|
||||||
|
`Testing direct access to filter/v1/messages/${contentTopic}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Method 1: GET request with encoded content topic
|
||||||
|
const getResponse = await axios({
|
||||||
|
method: "get",
|
||||||
|
url: `${API_URL}/filter/v1/messages/${contentTopic}`,
|
||||||
|
validateStatus: function () {
|
||||||
|
// Allow any status code to check what's coming back
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Response status:", getResponse.status);
|
||||||
|
console.log("Response headers:", getResponse.headers);
|
||||||
|
|
||||||
|
if (getResponse.status === 404) {
|
||||||
|
throw new Error(
|
||||||
|
`Endpoint not found (404): /filter/v1/messages/${contentTopic}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we got here, the endpoint exists even if it returns empty results
|
||||||
|
expect(getResponse.status).toBe(200);
|
||||||
|
expect(getResponse.data).toHaveProperty("messages");
|
||||||
|
expect(Array.isArray(getResponse.data.messages)).toBe(true);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error during filter/v1 endpoint test:", error.message);
|
||||||
|
|
||||||
|
if (error.response) {
|
||||||
|
console.error("Response status:", error.response.status);
|
||||||
|
console.error("Response headers:", error.response.headers);
|
||||||
|
console.error("Response data:", error.response.data);
|
||||||
|
} else if (error.request) {
|
||||||
|
console.error("No response received:", error.request);
|
||||||
|
// If no response, we'll skip the test rather than fail it
|
||||||
|
test.skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
35
packages/browser-tests/tests/test-config.ts
Normal file
35
packages/browser-tests/tests/test-config.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
export const NETWORK_CONFIG = {
|
||||||
|
"waku.sandbox": {
|
||||||
|
peers: [
|
||||||
|
"/dns4/node-01.do-ams3.waku.sandbox.status.im/tcp/30303/p2p/16Uiu2HAmNaeL4p3WEYzC9mgXBmBWSgWjPHRvatZTXnp8Jgv3iKsb",
|
||||||
|
"/dns4/node-01.gc-us-central1-a.waku.sandbox.status.im/tcp/30303/p2p/16Uiu2HAmRv1iQ3NoMMcjbtRmKxPuYBbF9nLYz2SDv9MTN8WhGuUU",
|
||||||
|
"/dns4/node-01.ac-cn-hongkong-c.waku.sandbox.status.im/tcp/30303/p2p/16Uiu2HAmQYiojgZ8APsh9wqbWNyCstVhnp9gbeNrxSEQnLJchC92"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
"waku.test": {
|
||||||
|
peers: [
|
||||||
|
"/dns4/node-01.do-ams3.waku.test.status.im/tcp/8000/wss/p2p/16Uiu2HAkykgaECHswi3YKJ5dMLbq2kPVCo89fcyTd38UcQD6ej5W",
|
||||||
|
"/dns4/node-01.gc-us-central1-a.waku.test.status.im/tcp/8000/wss/p2p/16Uiu2HAmDCp8XJ9z1ev18zuv8NHekAsjNyezAvmMfFEJkiharitG",
|
||||||
|
"/dns4/node-01.ac-cn-hongkong-c.waku.test.status.im/tcp/8000/wss/p2p/16Uiu2HAkzHaTP5JsUwfR9NR8Rj9HC24puS6ocaU8wze4QrXr9iXp"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
networkConfig: {
|
||||||
|
clusterId: 1,
|
||||||
|
shards: [0]
|
||||||
|
},
|
||||||
|
|
||||||
|
// Default node configuration
|
||||||
|
defaultNodeConfig: {
|
||||||
|
defaultBootstrap: false
|
||||||
|
},
|
||||||
|
|
||||||
|
// Test message configuration
|
||||||
|
testMessage: {
|
||||||
|
contentTopic: "/test/1/message/proto",
|
||||||
|
payload: "Hello, Waku!"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ACTIVE_PEERS = NETWORK_CONFIG["waku.test"].peers;
|
||||||
@ -1,128 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
import { GenericContainer, StartedTestContainer } from "testcontainers";
|
|
||||||
import { Logger } from "@waku/utils";
|
|
||||||
|
|
||||||
const log = new Logger("container-helpers");
|
|
||||||
|
|
||||||
export interface ContainerSetupOptions {
|
|
||||||
environment?: Record<string, string>;
|
|
||||||
networkMode?: string;
|
|
||||||
timeout?: number;
|
|
||||||
maxAttempts?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ContainerSetupResult {
|
|
||||||
container: StartedTestContainer;
|
|
||||||
baseUrl: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts a waku-browser-tests Docker container with proper health checking.
|
|
||||||
* Follows patterns from @waku/tests package for retry logic and cleanup.
|
|
||||||
*/
|
|
||||||
export async function startBrowserTestsContainer(
|
|
||||||
options: ContainerSetupOptions = {}
|
|
||||||
): Promise<ContainerSetupResult> {
|
|
||||||
const {
|
|
||||||
environment = {},
|
|
||||||
networkMode = "bridge",
|
|
||||||
timeout = 2000,
|
|
||||||
maxAttempts = 60
|
|
||||||
} = options;
|
|
||||||
|
|
||||||
log.info("Starting waku-browser-tests container...");
|
|
||||||
|
|
||||||
let generic = new GenericContainer("waku-browser-tests:local")
|
|
||||||
.withExposedPorts(8080)
|
|
||||||
.withNetworkMode(networkMode);
|
|
||||||
|
|
||||||
// Apply environment variables
|
|
||||||
for (const [key, value] of Object.entries(environment)) {
|
|
||||||
generic = generic.withEnvironment({ [key]: value });
|
|
||||||
}
|
|
||||||
|
|
||||||
const container = await generic.start();
|
|
||||||
|
|
||||||
// Set up container logging - stream all output from the start
|
|
||||||
const logs = await container.logs();
|
|
||||||
logs.on("data", (b) => process.stdout.write("[container] " + b.toString()));
|
|
||||||
logs.on("error", (err) => log.error("[container log error]", err));
|
|
||||||
|
|
||||||
// Give container time to initialize
|
|
||||||
await new Promise((r) => setTimeout(r, 5000));
|
|
||||||
|
|
||||||
const mappedPort = container.getMappedPort(8080);
|
|
||||||
const baseUrl = `http://127.0.0.1:${mappedPort}`;
|
|
||||||
|
|
||||||
// Wait for server readiness with retry logic (following waku/tests patterns)
|
|
||||||
const serverReady = await waitForServerReady(baseUrl, maxAttempts, timeout);
|
|
||||||
|
|
||||||
if (!serverReady) {
|
|
||||||
await logFinalContainerState(container);
|
|
||||||
throw new Error("Container failed to become ready");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("✅ Browser tests container ready");
|
|
||||||
await new Promise((r) => setTimeout(r, 500)); // Final settling time
|
|
||||||
|
|
||||||
return { container, baseUrl };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Waits for server to become ready with exponential backoff and detailed logging.
|
|
||||||
* Follows retry patterns from @waku/tests ServiceNode.
|
|
||||||
*/
|
|
||||||
async function waitForServerReady(
|
|
||||||
baseUrl: string,
|
|
||||||
maxAttempts: number,
|
|
||||||
timeout: number
|
|
||||||
): Promise<boolean> {
|
|
||||||
for (let i = 0; i < maxAttempts; i++) {
|
|
||||||
try {
|
|
||||||
const res = await axios.get(`${baseUrl}/`, { timeout });
|
|
||||||
if (res.status === 200) {
|
|
||||||
log.info(`Server is ready after ${i + 1} attempts`);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
if (i % 10 === 0) {
|
|
||||||
log.info(`Attempt ${i + 1}/${maxAttempts} failed:`, error.code || error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await new Promise((r) => setTimeout(r, 1000));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs final container state for debugging, following waku/tests error handling patterns.
|
|
||||||
*/
|
|
||||||
async function logFinalContainerState(container: StartedTestContainer): Promise<void> {
|
|
||||||
try {
|
|
||||||
const finalLogs = await container.logs({ tail: 50 });
|
|
||||||
log.info("=== Final Container Logs ===");
|
|
||||||
finalLogs.on("data", (b) => log.info(b.toString()));
|
|
||||||
await new Promise((r) => setTimeout(r, 1000));
|
|
||||||
} catch (logError) {
|
|
||||||
log.error("Failed to get container logs:", logError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gracefully stops containers with retry logic, following teardown patterns from waku/tests.
|
|
||||||
*/
|
|
||||||
export async function stopContainer(container: StartedTestContainer): Promise<void> {
|
|
||||||
if (!container) return;
|
|
||||||
|
|
||||||
log.info("Stopping container gracefully...");
|
|
||||||
try {
|
|
||||||
await container.stop({ timeout: 10000 });
|
|
||||||
log.info("Container stopped successfully");
|
|
||||||
} catch (error) {
|
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
|
||||||
log.warn(
|
|
||||||
"Container stop had issues (expected):",
|
|
||||||
message
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
/**
|
|
||||||
* Shared test utilities for browser-tests package.
|
|
||||||
* Follows patterns established in @waku/tests package.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export * from "./container-helpers.js";
|
|
||||||
export * from "./nwaku-helpers.js";
|
|
||||||
export * from "./test-config.js";
|
|
||||||
@ -1,141 +0,0 @@
|
|||||||
import { ServiceNode } from "@waku/tests";
|
|
||||||
import { DefaultTestRoutingInfo } from "@waku/tests";
|
|
||||||
import { Logger } from "@waku/utils";
|
|
||||||
|
|
||||||
const log = new Logger("nwaku-helpers");
|
|
||||||
|
|
||||||
export interface TwoNodeNetwork {
|
|
||||||
nodes: ServiceNode[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a two-node nwaku network following waku/tests patterns.
|
|
||||||
* Node 1: Relay + Light Push (service provider)
|
|
||||||
* Node 2: Relay only (network peer)
|
|
||||||
*/
|
|
||||||
export async function createTwoNodeNetwork(): Promise<TwoNodeNetwork> {
|
|
||||||
log.info("Creating nwaku node 1 (Relay + Light Push)...");
|
|
||||||
const lightPushNode = new ServiceNode(
|
|
||||||
"lightpush-node-" + Math.random().toString(36).substring(7),
|
|
||||||
);
|
|
||||||
|
|
||||||
const lightPushArgs = {
|
|
||||||
relay: true,
|
|
||||||
lightpush: true,
|
|
||||||
filter: false,
|
|
||||||
store: false,
|
|
||||||
clusterId: DefaultTestRoutingInfo.clusterId,
|
|
||||||
numShardsInNetwork: DefaultTestRoutingInfo.networkConfig.numShardsInCluster,
|
|
||||||
contentTopic: [DefaultTestRoutingInfo.contentTopic],
|
|
||||||
};
|
|
||||||
|
|
||||||
await lightPushNode.start(lightPushArgs, { retries: 3 });
|
|
||||||
|
|
||||||
log.info("Creating nwaku node 2 (Relay only)...");
|
|
||||||
const relayNode = new ServiceNode(
|
|
||||||
"relay-node-" + Math.random().toString(36).substring(7),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Connect second node to first node (following ServiceNodesFleet pattern)
|
|
||||||
const firstNodeAddr = await lightPushNode.getExternalMultiaddr();
|
|
||||||
const relayArgs = {
|
|
||||||
relay: true,
|
|
||||||
lightpush: false,
|
|
||||||
filter: false,
|
|
||||||
store: false,
|
|
||||||
staticnode: firstNodeAddr,
|
|
||||||
clusterId: DefaultTestRoutingInfo.clusterId,
|
|
||||||
numShardsInNetwork: DefaultTestRoutingInfo.networkConfig.numShardsInCluster,
|
|
||||||
contentTopic: [DefaultTestRoutingInfo.contentTopic],
|
|
||||||
};
|
|
||||||
|
|
||||||
await relayNode.start(relayArgs, { retries: 3 });
|
|
||||||
|
|
||||||
// Wait for network formation (following waku/tests timing patterns)
|
|
||||||
log.info("Waiting for nwaku network formation...");
|
|
||||||
await new Promise((r) => setTimeout(r, 5000));
|
|
||||||
|
|
||||||
// Verify connectivity (optional, for debugging)
|
|
||||||
await verifyNetworkFormation([lightPushNode, relayNode]);
|
|
||||||
|
|
||||||
return {
|
|
||||||
nodes: [lightPushNode, relayNode],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that nwaku nodes have formed connections.
|
|
||||||
* Follows error handling patterns from waku/tests.
|
|
||||||
*/
|
|
||||||
async function verifyNetworkFormation(nodes: ServiceNode[]): Promise<void> {
|
|
||||||
try {
|
|
||||||
const peerCounts = await Promise.all(
|
|
||||||
nodes.map(async (node, index) => {
|
|
||||||
const peers = await node.peers();
|
|
||||||
log.info(`Node ${index + 1} has ${peers.length} peer(s)`);
|
|
||||||
return peers.length;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (peerCounts.every((count) => count === 0)) {
|
|
||||||
log.warn("⚠️ Nodes may not be properly connected yet");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
log.warn("Could not verify peer connections:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts Docker-accessible multiaddr from nwaku node.
|
|
||||||
* Returns multiaddr using container's internal IP for Docker network communication.
|
|
||||||
*/
|
|
||||||
export async function getDockerAccessibleMultiaddr(
|
|
||||||
node: ServiceNode,
|
|
||||||
): Promise<string> {
|
|
||||||
// Get multiaddr with localhost and extract components
|
|
||||||
const localhostMultiaddr = await node.getMultiaddrWithId();
|
|
||||||
const peerId = await node.getPeerId();
|
|
||||||
|
|
||||||
// Extract port from multiaddr string
|
|
||||||
const multiaddrStr = localhostMultiaddr.toString();
|
|
||||||
const portMatch = multiaddrStr.match(/\/tcp\/(\d+)/);
|
|
||||||
const port = portMatch ? portMatch[1] : null;
|
|
||||||
|
|
||||||
if (!port) {
|
|
||||||
throw new Error("Could not extract port from multiaddr: " + multiaddrStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Docker container IP (accessing internal field)
|
|
||||||
// Note: This accesses an internal implementation detail of ServiceNode
|
|
||||||
const nodeWithDocker = node as ServiceNode & {
|
|
||||||
docker?: { containerIp?: string };
|
|
||||||
};
|
|
||||||
const containerIp = nodeWithDocker.docker?.containerIp;
|
|
||||||
if (!containerIp) {
|
|
||||||
throw new Error("Could not get container IP from node");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build Docker network accessible multiaddr
|
|
||||||
const dockerMultiaddr = `/ip4/${containerIp}/tcp/${port}/ws/p2p/${peerId}`;
|
|
||||||
|
|
||||||
log.info("Original multiaddr:", multiaddrStr);
|
|
||||||
log.info("Docker accessible multiaddr:", dockerMultiaddr);
|
|
||||||
|
|
||||||
return dockerMultiaddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops nwaku nodes with retry logic, following teardown patterns from waku/tests.
|
|
||||||
*/
|
|
||||||
export async function stopNwakuNodes(nodes: ServiceNode[]): Promise<void> {
|
|
||||||
if (!nodes || nodes.length === 0) return;
|
|
||||||
|
|
||||||
log.info("Stopping nwaku nodes...");
|
|
||||||
try {
|
|
||||||
await Promise.all(nodes.map((node) => node.stop()));
|
|
||||||
log.info("Nwaku nodes stopped successfully");
|
|
||||||
} catch (error) {
|
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
|
||||||
log.warn("Nwaku nodes stop had issues:", message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,127 +0,0 @@
|
|||||||
import { expect } from "@playwright/test";
|
|
||||||
import { DefaultTestRoutingInfo } from "@waku/tests";
|
|
||||||
import { AxiosResponse } from "axios";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Response type definitions for API endpoints
|
|
||||||
*/
|
|
||||||
interface ServerHealthResponse {
|
|
||||||
status: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PeerInfoResponse {
|
|
||||||
peerId: string;
|
|
||||||
multiaddrs: string[];
|
|
||||||
peers: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LightPushV3Result {
|
|
||||||
successes: string[];
|
|
||||||
failures: Array<{ error: string; peerId?: string }>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LightPushV3Response {
|
|
||||||
success: boolean;
|
|
||||||
result: LightPushV3Result;
|
|
||||||
error?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MessageResponse {
|
|
||||||
contentTopic: string;
|
|
||||||
payload: string;
|
|
||||||
version: number;
|
|
||||||
timestamp?: bigint | number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common test configuration constants following waku/tests patterns.
|
|
||||||
*/
|
|
||||||
export const TEST_CONFIG = {
|
|
||||||
// Test timeouts (following waku/tests timeout patterns)
|
|
||||||
DEFAULT_TEST_TIMEOUT: 120000, // 2 minutes
|
|
||||||
CONTAINER_READY_TIMEOUT: 60000, // 1 minute
|
|
||||||
NETWORK_FORMATION_DELAY: 5000, // 5 seconds
|
|
||||||
SUBSCRIPTION_DELAY: 3000, // 3 seconds
|
|
||||||
MESSAGE_PROPAGATION_DELAY: 5000, // 5 seconds
|
|
||||||
WAKU_INIT_DELAY: 8000, // 8 seconds
|
|
||||||
|
|
||||||
// Network configuration
|
|
||||||
DEFAULT_CLUSTER_ID: DefaultTestRoutingInfo.clusterId.toString(),
|
|
||||||
DEFAULT_CONTENT_TOPIC: "/test/1/browser-tests/proto",
|
|
||||||
|
|
||||||
// Test messages
|
|
||||||
DEFAULT_TEST_MESSAGE: "Hello from browser tests",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Environment variable builders for different test scenarios.
|
|
||||||
*/
|
|
||||||
export const ENV_BUILDERS = {
|
|
||||||
/**
|
|
||||||
* Environment for production ENR bootstrap (integration test pattern).
|
|
||||||
*/
|
|
||||||
withProductionEnr: () => ({
|
|
||||||
WAKU_ENR_BOOTSTRAP: "enr:-QEnuEBEAyErHEfhiQxAVQoWowGTCuEF9fKZtXSd7H_PymHFhGJA3rGAYDVSHKCyJDGRLBGsloNbS8AZF33IVuefjOO6BIJpZIJ2NIJpcIQS39tkim11bHRpYWRkcnO4lgAvNihub2RlLTAxLmRvLWFtczMud2FrdXYyLnRlc3Quc3RhdHVzaW0ubmV0BgG73gMAODcxbm9kZS0wMS5hYy1jbi1ob25na29uZy1jLndha3V2Mi50ZXN0LnN0YXR1c2ltLm5ldAYBu94DACm9A62t7AQL4Ef5ZYZosRpQTzFVAB8jGjf1TER2wH-0zBOe1-MDBNLeA4lzZWNwMjU2azGhAzfsxbxyCkgCqq8WwYsVWH7YkpMLnU2Bw5xJSimxKav-g3VkcIIjKA",
|
|
||||||
WAKU_CLUSTER_ID: "1",
|
|
||||||
}),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Environment for local nwaku node connection (e2e test pattern).
|
|
||||||
*/
|
|
||||||
withLocalLightPush: (lightpushMultiaddr: string) => ({
|
|
||||||
WAKU_LIGHTPUSH_NODE: lightpushMultiaddr,
|
|
||||||
WAKU_CLUSTER_ID: TEST_CONFIG.DEFAULT_CLUSTER_ID,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test assertion helpers following waku/tests verification patterns.
|
|
||||||
*/
|
|
||||||
export const ASSERTIONS = {
|
|
||||||
/**
|
|
||||||
* Verifies server health response structure.
|
|
||||||
*/
|
|
||||||
serverHealth: (response: AxiosResponse<ServerHealthResponse>) => {
|
|
||||||
expect(response.status).toBe(200);
|
|
||||||
expect(response.data.status).toBe("Waku simulation server is running");
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies peer info response structure.
|
|
||||||
*/
|
|
||||||
peerInfo: (response: AxiosResponse<PeerInfoResponse>) => {
|
|
||||||
expect(response.status).toBe(200);
|
|
||||||
expect(response.data.peerId).toBeDefined();
|
|
||||||
expect(typeof response.data.peerId).toBe("string");
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies lightpush response structure (v3 format).
|
|
||||||
*/
|
|
||||||
lightPushV3Success: (response: AxiosResponse<LightPushV3Response>) => {
|
|
||||||
expect(response.status).toBe(200);
|
|
||||||
expect(response.data).toHaveProperty('success', true);
|
|
||||||
expect(response.data).toHaveProperty('result');
|
|
||||||
expect(response.data.result).toHaveProperty('successes');
|
|
||||||
expect(Array.isArray(response.data.result.successes)).toBe(true);
|
|
||||||
expect(response.data.result.successes.length).toBeGreaterThan(0);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies message content and structure.
|
|
||||||
*/
|
|
||||||
messageContent: (message: MessageResponse, expectedContent: string, expectedTopic: string) => {
|
|
||||||
expect(message).toHaveProperty('contentTopic', expectedTopic);
|
|
||||||
expect(message).toHaveProperty('payload');
|
|
||||||
expect(typeof message.payload).toBe('string');
|
|
||||||
|
|
||||||
const receivedPayload = Buffer.from(message.payload, 'base64').toString();
|
|
||||||
expect(receivedPayload).toBe(expectedContent);
|
|
||||||
|
|
||||||
// Optional fields
|
|
||||||
expect(message).toHaveProperty('version');
|
|
||||||
if (message.timestamp) {
|
|
||||||
expect(['bigint', 'number']).toContain(typeof message.timestamp);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -15,5 +15,5 @@
|
|||||||
"typeRoots": ["./node_modules/@types", "./types"]
|
"typeRoots": ["./node_modules/@types", "./types"]
|
||||||
},
|
},
|
||||||
"include": ["src/server.ts", "types/**/*.d.ts"],
|
"include": ["src/server.ts", "types/**/*.d.ts"],
|
||||||
"exclude": ["node_modules", "dist", "web"]
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
|||||||
36
packages/browser-tests/types/global.d.ts
vendored
36
packages/browser-tests/types/global.d.ts
vendored
@ -1,19 +1,27 @@
|
|||||||
import type { WakuHeadless } from "../web/index.js";
|
import { LightNode } from "@waku/sdk";
|
||||||
|
import { IWakuNode } from "../src/api/common.js";
|
||||||
export interface WindowNetworkConfig {
|
import {
|
||||||
clusterId?: number;
|
createWakuNode,
|
||||||
shards?: number[];
|
dialPeers,
|
||||||
}
|
getDebugInfo,
|
||||||
|
getPeerInfo,
|
||||||
export interface ITestBrowser extends Window {
|
pushMessage,
|
||||||
wakuApi: WakuHeadless;
|
subscribe
|
||||||
__WAKU_NETWORK_CONFIG?: WindowNetworkConfig;
|
} from "../src/api/shared.js";
|
||||||
__WAKU_LIGHTPUSH_NODE?: string | null;
|
|
||||||
__WAKU_ENR_BOOTSTRAP?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Define types for the Waku node and window
|
||||||
declare global {
|
declare global {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
interface Window {
|
interface Window {
|
||||||
wakuApi: WakuHeadless;
|
waku: IWakuNode & LightNode;
|
||||||
|
wakuAPI: {
|
||||||
|
getPeerInfo: typeof getPeerInfo;
|
||||||
|
getDebugInfo: typeof getDebugInfo;
|
||||||
|
pushMessage: typeof pushMessage;
|
||||||
|
dialPeers: typeof dialPeers;
|
||||||
|
createWakuNode: typeof createWakuNode;
|
||||||
|
subscribe: typeof subscribe;
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
packages/browser-tests/types/serve.d.ts
vendored
6
packages/browser-tests/types/serve.d.ts
vendored
@ -1,9 +1,7 @@
|
|||||||
declare module "serve" {
|
declare module "serve" {
|
||||||
import type { Server } from "http";
|
|
||||||
|
|
||||||
function serve(
|
function serve(
|
||||||
folder: string,
|
folder: string,
|
||||||
options: { port: number; single: boolean; listen: boolean },
|
options: { port: number; single: boolean; listen: boolean }
|
||||||
): Promise<Server>;
|
): any;
|
||||||
export default serve;
|
export default serve;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>Waku Test Environment</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Waku Test Environment</h1>
|
|
||||||
<script type="module" src="./index.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,431 +0,0 @@
|
|||||||
import {
|
|
||||||
createLightNode,
|
|
||||||
LightNode,
|
|
||||||
Protocols,
|
|
||||||
NetworkConfig,
|
|
||||||
CreateNodeOptions,
|
|
||||||
} from "@waku/sdk";
|
|
||||||
import {
|
|
||||||
AutoSharding,
|
|
||||||
DEFAULT_CLUSTER_ID,
|
|
||||||
DEFAULT_NUM_SHARDS,
|
|
||||||
ShardId,
|
|
||||||
StaticSharding,
|
|
||||||
ShardInfo,
|
|
||||||
CreateLibp2pOptions,
|
|
||||||
IEncoder,
|
|
||||||
ILightPush,
|
|
||||||
SDKProtocolResult,
|
|
||||||
Failure,
|
|
||||||
} from "@waku/interfaces";
|
|
||||||
import { bootstrap } from "@libp2p/bootstrap";
|
|
||||||
import { EnrDecoder, TransportProtocol } from "@waku/enr";
|
|
||||||
import type { Multiaddr } from "@multiformats/multiaddr";
|
|
||||||
import type { ITestBrowser } from "../types/global.js";
|
|
||||||
import { Logger, StaticShardingRoutingInfo } from "@waku/utils";
|
|
||||||
import type { PeerId } from "@libp2p/interface";
|
|
||||||
|
|
||||||
const log = new Logger("waku-headless");
|
|
||||||
|
|
||||||
export interface SerializableSDKProtocolResult {
|
|
||||||
successes: string[];
|
|
||||||
failures: Array<{
|
|
||||||
error: string;
|
|
||||||
peerId?: string;
|
|
||||||
}>;
|
|
||||||
myPeerId?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeSerializable(result: SDKProtocolResult): SerializableSDKProtocolResult {
|
|
||||||
return {
|
|
||||||
...result,
|
|
||||||
successes: result.successes.map((peerId: PeerId) => peerId.toString()),
|
|
||||||
failures: result.failures.map((failure: Failure) => ({
|
|
||||||
error: failure.error || failure.toString(),
|
|
||||||
peerId: failure.peerId ? failure.peerId.toString() : undefined,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function convertEnrToMultiaddrs(enrString: string): Promise<string[]> {
|
|
||||||
try {
|
|
||||||
const enr = await EnrDecoder.fromString(enrString);
|
|
||||||
const allMultiaddrs = enr.getAllLocationMultiaddrs();
|
|
||||||
const multiaddrs: string[] = [];
|
|
||||||
|
|
||||||
for (const multiaddr of allMultiaddrs) {
|
|
||||||
const maStr = multiaddr.toString();
|
|
||||||
multiaddrs.push(maStr);
|
|
||||||
}
|
|
||||||
if (multiaddrs.length === 0) {
|
|
||||||
const tcpMultiaddr = enr.getFullMultiaddr(TransportProtocol.TCP);
|
|
||||||
if (tcpMultiaddr) {
|
|
||||||
const tcpStr = tcpMultiaddr.toString();
|
|
||||||
multiaddrs.push(tcpStr);
|
|
||||||
}
|
|
||||||
const udpMultiaddr = enr.getFullMultiaddr(TransportProtocol.UDP);
|
|
||||||
if (udpMultiaddr) {
|
|
||||||
const udpStr = udpMultiaddr.toString();
|
|
||||||
multiaddrs.push(udpStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return multiaddrs;
|
|
||||||
} catch (error) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class WakuHeadless {
|
|
||||||
waku: LightNode | null;
|
|
||||||
networkConfig: NetworkConfig;
|
|
||||||
lightpushNode: string | null;
|
|
||||||
enrBootstrap: string | null;
|
|
||||||
constructor(
|
|
||||||
networkConfig?: Partial<NetworkConfig>,
|
|
||||||
lightpushNode?: string | null,
|
|
||||||
enrBootstrap?: string | null,
|
|
||||||
) {
|
|
||||||
this.waku = null;
|
|
||||||
this.networkConfig = this.buildNetworkConfig(networkConfig);
|
|
||||||
log.info("Network config on construction:", this.networkConfig);
|
|
||||||
this.lightpushNode = lightpushNode || null;
|
|
||||||
this.enrBootstrap = enrBootstrap || null;
|
|
||||||
|
|
||||||
if (this.lightpushNode) {
|
|
||||||
log.info(`Configured preferred lightpush node: ${this.lightpushNode}`);
|
|
||||||
}
|
|
||||||
if (this.enrBootstrap) {
|
|
||||||
log.info(`Configured ENR bootstrap: ${this.enrBootstrap}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private shouldUseCustomBootstrap(options: CreateNodeOptions): boolean {
|
|
||||||
const hasEnr = Boolean(this.enrBootstrap);
|
|
||||||
const isDefaultBootstrap = Boolean(options.defaultBootstrap);
|
|
||||||
|
|
||||||
return hasEnr && !isDefaultBootstrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getBootstrapMultiaddrs(): Promise<string[]> {
|
|
||||||
if (!this.enrBootstrap) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const enrList = this.enrBootstrap.split(",").map((enr) => enr.trim());
|
|
||||||
const allMultiaddrs: string[] = [];
|
|
||||||
|
|
||||||
for (const enr of enrList) {
|
|
||||||
const multiaddrs = await convertEnrToMultiaddrs(enr);
|
|
||||||
if (multiaddrs.length > 0) {
|
|
||||||
allMultiaddrs.push(...multiaddrs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return allMultiaddrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildNetworkConfig(
|
|
||||||
providedConfig?: Partial<NetworkConfig> | Partial<ShardInfo>,
|
|
||||||
): NetworkConfig {
|
|
||||||
const clusterId = providedConfig?.clusterId ?? DEFAULT_CLUSTER_ID;
|
|
||||||
|
|
||||||
const staticShards = (providedConfig as Partial<ShardInfo>)?.shards;
|
|
||||||
if (
|
|
||||||
staticShards &&
|
|
||||||
Array.isArray(staticShards) &&
|
|
||||||
staticShards.length > 0
|
|
||||||
) {
|
|
||||||
log.info("Using static sharding with shards:", staticShards);
|
|
||||||
return {
|
|
||||||
clusterId,
|
|
||||||
} as StaticSharding;
|
|
||||||
}
|
|
||||||
|
|
||||||
const numShardsInCluster =
|
|
||||||
(providedConfig as Partial<AutoSharding>)?.numShardsInCluster ?? DEFAULT_NUM_SHARDS;
|
|
||||||
log.info(
|
|
||||||
"Using auto sharding with num shards in cluster:",
|
|
||||||
numShardsInCluster,
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
clusterId,
|
|
||||||
numShardsInCluster,
|
|
||||||
} as AutoSharding;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async send(
|
|
||||||
lightPush: ILightPush,
|
|
||||||
encoder: IEncoder,
|
|
||||||
payload: Uint8Array,
|
|
||||||
): Promise<SDKProtocolResult> {
|
|
||||||
return lightPush.send(encoder, {
|
|
||||||
payload,
|
|
||||||
timestamp: new Date(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async pushMessageV3(
|
|
||||||
contentTopic: string,
|
|
||||||
payload: string,
|
|
||||||
pubsubTopic: string,
|
|
||||||
): Promise<SerializableSDKProtocolResult> {
|
|
||||||
if (!this.waku) {
|
|
||||||
throw new Error("Waku node not started");
|
|
||||||
}
|
|
||||||
log.info(
|
|
||||||
"Pushing message via v3 lightpush:",
|
|
||||||
contentTopic,
|
|
||||||
payload,
|
|
||||||
pubsubTopic,
|
|
||||||
);
|
|
||||||
log.info("Waku node:", this.waku);
|
|
||||||
log.info("Network config:", this.networkConfig);
|
|
||||||
|
|
||||||
let processedPayload: Uint8Array;
|
|
||||||
try {
|
|
||||||
const binaryString = atob(payload);
|
|
||||||
const bytes = new Uint8Array(binaryString.length);
|
|
||||||
for (let i = 0; i < binaryString.length; i++) {
|
|
||||||
bytes[i] = binaryString.charCodeAt(i);
|
|
||||||
}
|
|
||||||
processedPayload = bytes;
|
|
||||||
} catch (e) {
|
|
||||||
processedPayload = new TextEncoder().encode(payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const lightPush = this.waku.lightPush;
|
|
||||||
if (!lightPush) {
|
|
||||||
throw new Error("Lightpush service not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
let shardId: ShardId | undefined;
|
|
||||||
if (pubsubTopic) {
|
|
||||||
const staticShardingRoutingInfo =
|
|
||||||
StaticShardingRoutingInfo.fromPubsubTopic(
|
|
||||||
pubsubTopic,
|
|
||||||
this.networkConfig as StaticSharding,
|
|
||||||
);
|
|
||||||
shardId = staticShardingRoutingInfo?.shardId;
|
|
||||||
}
|
|
||||||
|
|
||||||
const encoder = this.waku.createEncoder({
|
|
||||||
contentTopic,
|
|
||||||
shardId,
|
|
||||||
});
|
|
||||||
log.info("Encoder:", encoder);
|
|
||||||
log.info("Pubsub topic:", pubsubTopic);
|
|
||||||
log.info("Encoder pubsub topic:", encoder.pubsubTopic);
|
|
||||||
|
|
||||||
if (pubsubTopic && pubsubTopic !== encoder.pubsubTopic) {
|
|
||||||
log.warn(
|
|
||||||
`Explicit pubsubTopic ${pubsubTopic} provided, but auto-sharding determined ${encoder.pubsubTopic}. Using auto-sharding.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let result;
|
|
||||||
if (this.lightpushNode) {
|
|
||||||
try {
|
|
||||||
const preferredPeerId = this.getPeerIdFromMultiaddr(
|
|
||||||
this.lightpushNode,
|
|
||||||
);
|
|
||||||
if (preferredPeerId) {
|
|
||||||
result = await this.send(lightPush, encoder, processedPayload);
|
|
||||||
log.info("✅ Message sent via preferred lightpush node");
|
|
||||||
} else {
|
|
||||||
throw new Error(
|
|
||||||
"Could not extract peer ID from preferred node address",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
log.error(
|
|
||||||
"Couldn't send message via preferred lightpush node:",
|
|
||||||
error,
|
|
||||||
);
|
|
||||||
result = await this.send(lightPush, encoder, processedPayload);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result = await this.send(lightPush, encoder, processedPayload);
|
|
||||||
}
|
|
||||||
|
|
||||||
const serializableResult = makeSerializable(result);
|
|
||||||
|
|
||||||
return serializableResult;
|
|
||||||
} catch (error) {
|
|
||||||
log.error("Error sending message via v3 lightpush:", error);
|
|
||||||
throw new Error(
|
|
||||||
`Failed to send v3 message: ${error instanceof Error ? error.message : String(error)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async waitForPeers(
|
|
||||||
timeoutMs: number = 10000,
|
|
||||||
protocols: Protocols[] = [Protocols.LightPush, Protocols.Filter],
|
|
||||||
) {
|
|
||||||
if (!this.waku) {
|
|
||||||
throw new Error("Waku node not started");
|
|
||||||
}
|
|
||||||
|
|
||||||
const startTime = Date.now();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.waku.waitForPeers(protocols, timeoutMs);
|
|
||||||
const elapsed = Date.now() - startTime;
|
|
||||||
|
|
||||||
const peers = this.waku.libp2p.getPeers();
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: true,
|
|
||||||
peersFound: peers.length,
|
|
||||||
protocolsRequested: protocols,
|
|
||||||
timeElapsed: elapsed,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
const elapsed = Date.now() - startTime;
|
|
||||||
log.error(`Failed to find peers after ${elapsed}ms:`, error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async createWakuNode(options: CreateNodeOptions) {
|
|
||||||
try {
|
|
||||||
if (this.waku) {
|
|
||||||
await this.waku.stop();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
log.warn("ignore previous waku stop error");
|
|
||||||
}
|
|
||||||
|
|
||||||
let libp2pConfig: CreateLibp2pOptions = {
|
|
||||||
...options.libp2p,
|
|
||||||
filterMultiaddrs: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.enrBootstrap) {
|
|
||||||
const multiaddrs = await this.getBootstrapMultiaddrs();
|
|
||||||
|
|
||||||
if (multiaddrs.length > 0) {
|
|
||||||
libp2pConfig.peerDiscovery = [
|
|
||||||
bootstrap({ list: multiaddrs }),
|
|
||||||
...(options.libp2p?.peerDiscovery || []),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const createOptions = {
|
|
||||||
...options,
|
|
||||||
networkConfig: this.networkConfig,
|
|
||||||
libp2p: libp2pConfig,
|
|
||||||
};
|
|
||||||
|
|
||||||
this.waku = await createLightNode(createOptions);
|
|
||||||
return { success: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
async startNode() {
|
|
||||||
if (!this.waku) {
|
|
||||||
throw new Error("Waku node not created");
|
|
||||||
}
|
|
||||||
await this.waku.start();
|
|
||||||
|
|
||||||
if (this.lightpushNode) {
|
|
||||||
await this.dialPreferredLightpushNode();
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
private async dialPreferredLightpushNode() {
|
|
||||||
if (!this.waku || !this.lightpushNode) {
|
|
||||||
log.info("Skipping dial: waku or lightpushNode not set");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
log.info("Attempting to dial preferred lightpush node:", this.lightpushNode);
|
|
||||||
await this.waku.dial(this.lightpushNode);
|
|
||||||
log.info("Successfully dialed preferred lightpush node:", this.lightpushNode);
|
|
||||||
} catch (error) {
|
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
|
||||||
log.error(
|
|
||||||
"Failed to dial preferred lightpush node:",
|
|
||||||
this.lightpushNode,
|
|
||||||
message
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getPeerIdFromMultiaddr(multiaddr: string): string | null {
|
|
||||||
const parts = multiaddr.split("/");
|
|
||||||
const p2pIndex = parts.indexOf("p2p");
|
|
||||||
return p2pIndex !== -1 && p2pIndex + 1 < parts.length
|
|
||||||
? parts[p2pIndex + 1]
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async stopNode() {
|
|
||||||
if (!this.waku) {
|
|
||||||
throw new Error("Waku node not created");
|
|
||||||
}
|
|
||||||
await this.waku.stop();
|
|
||||||
return { success: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
getPeerInfo() {
|
|
||||||
if (!this.waku) {
|
|
||||||
throw new Error("Waku node not started");
|
|
||||||
}
|
|
||||||
|
|
||||||
const addrs = this.waku.libp2p.getMultiaddrs();
|
|
||||||
return {
|
|
||||||
peerId: this.waku.libp2p.peerId.toString(),
|
|
||||||
multiaddrs: addrs.map((a: Multiaddr) => a.toString()),
|
|
||||||
peers: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(() => {
|
|
||||||
try {
|
|
||||||
log.info("Initializing WakuHeadless...");
|
|
||||||
|
|
||||||
const testWindow = window as ITestBrowser;
|
|
||||||
const globalNetworkConfig = testWindow.__WAKU_NETWORK_CONFIG;
|
|
||||||
const globalLightpushNode = testWindow.__WAKU_LIGHTPUSH_NODE;
|
|
||||||
const globalEnrBootstrap = testWindow.__WAKU_ENR_BOOTSTRAP;
|
|
||||||
|
|
||||||
log.info("Global config from window:", {
|
|
||||||
networkConfig: globalNetworkConfig,
|
|
||||||
lightpushNode: globalLightpushNode,
|
|
||||||
enrBootstrap: globalEnrBootstrap
|
|
||||||
});
|
|
||||||
|
|
||||||
const instance = new WakuHeadless(
|
|
||||||
globalNetworkConfig,
|
|
||||||
globalLightpushNode,
|
|
||||||
globalEnrBootstrap,
|
|
||||||
);
|
|
||||||
|
|
||||||
testWindow.wakuApi = instance;
|
|
||||||
log.info("WakuHeadless initialized successfully:", !!testWindow.wakuApi);
|
|
||||||
} catch (error) {
|
|
||||||
log.error("Error initializing WakuHeadless:", error);
|
|
||||||
const testWindow = window as ITestBrowser;
|
|
||||||
// Create a stub wakuApi that will reject all method calls
|
|
||||||
testWindow.wakuApi = {
|
|
||||||
waku: null,
|
|
||||||
networkConfig: { clusterId: 0, numShardsInCluster: 0 },
|
|
||||||
lightpushNode: null,
|
|
||||||
enrBootstrap: null,
|
|
||||||
error,
|
|
||||||
createWakuNode: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
|
|
||||||
startNode: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
|
|
||||||
stopNode: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
|
|
||||||
pushMessageV3: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
|
|
||||||
waitForPeers: () => Promise.reject(new Error("WakuHeadless failed to initialize")),
|
|
||||||
getPeerInfo: () => { throw new Error("WakuHeadless failed to initialize"); },
|
|
||||||
} as unknown as WakuHeadless;
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
@ -5,36 +5,6 @@ All notable changes to this project will be documented in this file.
|
|||||||
The file is maintained by [Release Please](https://github.com/googleapis/release-please) based on [Conventional Commits](https://www.conventionalcommits.org) specification,
|
The file is maintained by [Release Please](https://github.com/googleapis/release-please) based on [Conventional Commits](https://www.conventionalcommits.org) specification,
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [0.0.40](https://github.com/waku-org/js-waku/compare/core-v0.0.39...core-v0.0.40) (2025-10-31)
|
|
||||||
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
* The following workspace dependencies were updated
|
|
||||||
* dependencies
|
|
||||||
* @waku/proto bumped from 0.0.14 to 0.0.15
|
|
||||||
|
|
||||||
## [0.0.39](https://github.com/waku-org/js-waku/compare/core-v0.0.38...core-v0.0.39) (2025-09-20)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* Add start/stop to filter ([#2592](https://github.com/waku-org/js-waku/issues/2592)) ([2fba052](https://github.com/waku-org/js-waku/commit/2fba052b8b98cb64f6383de95d01b33beb771448))
|
|
||||||
* Expose message hash from IDecodedMessage ([#2578](https://github.com/waku-org/js-waku/issues/2578)) ([836d6b8](https://github.com/waku-org/js-waku/commit/836d6b8793a5124747684f6ea76b6dd47c73048b))
|
|
||||||
* Implement lp-v3 error codes with backwards compatibility ([#2501](https://github.com/waku-org/js-waku/issues/2501)) ([1625302](https://github.com/waku-org/js-waku/commit/16253026c6e30052d87d9975b58480951de469d8))
|
|
||||||
* Implement peer-store re-bootstrapping ([#2641](https://github.com/waku-org/js-waku/issues/2641)) ([11d84ad](https://github.com/waku-org/js-waku/commit/11d84ad342fe45158ef0734f9ca070f14704503f))
|
|
||||||
* StoreConnect events ([#2601](https://github.com/waku-org/js-waku/issues/2601)) ([0dfbcf6](https://github.com/waku-org/js-waku/commit/0dfbcf6b6bd9225dcb0dec540aeb1eb2703c8397))
|
|
||||||
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
* The following workspace dependencies were updated
|
|
||||||
* dependencies
|
|
||||||
* @waku/enr bumped from ^0.0.32 to ^0.0.33
|
|
||||||
* @waku/interfaces bumped from 0.0.33 to 0.0.34
|
|
||||||
* @waku/proto bumped from 0.0.13 to 0.0.14
|
|
||||||
* @waku/utils bumped from 0.0.26 to 0.0.27
|
|
||||||
|
|
||||||
## [0.0.38](https://github.com/waku-org/js-waku/compare/core-v0.0.37...core-v0.0.38) (2025-08-14)
|
## [0.0.38](https://github.com/waku-org/js-waku/compare/core-v0.0.37...core-v0.0.38) (2025-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@waku/core",
|
"name": "@waku/core",
|
||||||
"version": "0.0.40",
|
"version": "0.0.38",
|
||||||
"description": "TypeScript implementation of the Waku v2 protocol",
|
"description": "TypeScript implementation of the Waku v2 protocol",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@ -28,7 +28,7 @@
|
|||||||
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/core#readme",
|
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/core#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/waku-org/js-waku.git"
|
"url": "https://github.com/waku-org/js-waku.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/waku-org/js-waku/issues"
|
"url": "https://github.com/waku-org/js-waku/issues"
|
||||||
@ -64,11 +64,11 @@
|
|||||||
"node": ">=22"
|
"node": ">=22"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waku/enr": "^0.0.33",
|
"@waku/enr": "^0.0.32",
|
||||||
"@waku/interfaces": "0.0.34",
|
"@waku/interfaces": "0.0.33",
|
||||||
"@libp2p/ping": "2.0.35",
|
"@libp2p/ping": "2.0.35",
|
||||||
"@waku/proto": "0.0.15",
|
"@waku/proto": "0.0.13",
|
||||||
"@waku/utils": "0.0.27",
|
"@waku/utils": "0.0.26",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"@noble/hashes": "^1.3.2",
|
"@noble/hashes": "^1.3.2",
|
||||||
"it-all": "^3.0.4",
|
"it-all": "^3.0.4",
|
||||||
|
|||||||
@ -10,11 +10,7 @@ export * as waku_filter from "./lib/filter/index.js";
|
|||||||
export { FilterCore, FilterCodecs } from "./lib/filter/index.js";
|
export { FilterCore, FilterCodecs } from "./lib/filter/index.js";
|
||||||
|
|
||||||
export * as waku_light_push from "./lib/light_push/index.js";
|
export * as waku_light_push from "./lib/light_push/index.js";
|
||||||
export {
|
export { LightPushCodec, LightPushCore } from "./lib/light_push/index.js";
|
||||||
LightPushCore,
|
|
||||||
LightPushCodec,
|
|
||||||
LightPushCodecV2
|
|
||||||
} from "./lib/light_push/index.js";
|
|
||||||
|
|
||||||
export * as waku_store from "./lib/store/index.js";
|
export * as waku_store from "./lib/store/index.js";
|
||||||
export { StoreCore, StoreCodec } from "./lib/store/index.js";
|
export { StoreCore, StoreCodec } from "./lib/store/index.js";
|
||||||
|
|||||||
@ -3,8 +3,7 @@ import { multiaddr } from "@multiformats/multiaddr";
|
|||||||
import {
|
import {
|
||||||
CONNECTION_LOCKED_TAG,
|
CONNECTION_LOCKED_TAG,
|
||||||
IWakuEventEmitter,
|
IWakuEventEmitter,
|
||||||
Tags,
|
Tags
|
||||||
WakuEvent
|
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
@ -87,12 +86,6 @@ describe("ConnectionLimiter", () => {
|
|||||||
mockPeer2 = createMockPeer("12D3KooWTest2", [Tags.BOOTSTRAP]); // Ensure mockPeer2 is prioritized and dialed
|
mockPeer2 = createMockPeer("12D3KooWTest2", [Tags.BOOTSTRAP]); // Ensure mockPeer2 is prioritized and dialed
|
||||||
mockConnection = createMockConnection(mockPeerId, [Tags.BOOTSTRAP]);
|
mockConnection = createMockConnection(mockPeerId, [Tags.BOOTSTRAP]);
|
||||||
|
|
||||||
dialer = {
|
|
||||||
start: sinon.stub(),
|
|
||||||
stop: sinon.stub(),
|
|
||||||
dial: sinon.stub().resolves()
|
|
||||||
} as unknown as sinon.SinonStubbedInstance<Dialer>;
|
|
||||||
|
|
||||||
libp2p = {
|
libp2p = {
|
||||||
addEventListener: sinon.stub(),
|
addEventListener: sinon.stub(),
|
||||||
removeEventListener: sinon.stub(),
|
removeEventListener: sinon.stub(),
|
||||||
@ -101,11 +94,7 @@ describe("ConnectionLimiter", () => {
|
|||||||
getConnections: sinon.stub().returns([]),
|
getConnections: sinon.stub().returns([]),
|
||||||
peerStore: {
|
peerStore: {
|
||||||
all: sinon.stub().resolves([]),
|
all: sinon.stub().resolves([]),
|
||||||
get: sinon.stub().resolves(mockPeer),
|
get: sinon.stub().resolves(mockPeer)
|
||||||
merge: sinon.stub().resolves()
|
|
||||||
},
|
|
||||||
components: {
|
|
||||||
components: {}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -122,20 +111,6 @@ describe("ConnectionLimiter", () => {
|
|||||||
isConnected: sinon.stub().returns(true),
|
isConnected: sinon.stub().returns(true),
|
||||||
isP2PConnected: sinon.stub().returns(true)
|
isP2PConnected: sinon.stub().returns(true)
|
||||||
} as unknown as sinon.SinonStubbedInstance<NetworkMonitor>;
|
} as unknown as sinon.SinonStubbedInstance<NetworkMonitor>;
|
||||||
|
|
||||||
// Mock the libp2p components needed by isAddressesSupported
|
|
||||||
libp2p.components = {
|
|
||||||
components: {},
|
|
||||||
transportManager: {
|
|
||||||
getTransports: sinon.stub().returns([
|
|
||||||
{
|
|
||||||
dialFilter: sinon
|
|
||||||
.stub()
|
|
||||||
.returns([multiaddr("/dns4/test/tcp/443/wss")])
|
|
||||||
}
|
|
||||||
])
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -168,7 +143,7 @@ describe("ConnectionLimiter", () => {
|
|||||||
.true;
|
.true;
|
||||||
expect(
|
expect(
|
||||||
(events.addEventListener as sinon.SinonStub).calledWith(
|
(events.addEventListener as sinon.SinonStub).calledWith(
|
||||||
WakuEvent.Connection,
|
"waku:connection",
|
||||||
sinon.match.func
|
sinon.match.func
|
||||||
)
|
)
|
||||||
).to.be.true;
|
).to.be.true;
|
||||||
@ -203,7 +178,7 @@ describe("ConnectionLimiter", () => {
|
|||||||
.true;
|
.true;
|
||||||
expect(
|
expect(
|
||||||
(events.removeEventListener as sinon.SinonStub).calledWith(
|
(events.removeEventListener as sinon.SinonStub).calledWith(
|
||||||
WakuEvent.Connection,
|
"waku:connection",
|
||||||
sinon.match.func
|
sinon.match.func
|
||||||
)
|
)
|
||||||
).to.be.true;
|
).to.be.true;
|
||||||
@ -298,6 +273,11 @@ describe("ConnectionLimiter", () => {
|
|||||||
|
|
||||||
describe("dialPeersFromStore", () => {
|
describe("dialPeersFromStore", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
dialer = {
|
||||||
|
start: sinon.stub(),
|
||||||
|
stop: sinon.stub(),
|
||||||
|
dial: sinon.stub().resolves()
|
||||||
|
} as unknown as sinon.SinonStubbedInstance<Dialer>;
|
||||||
libp2p.hangUp = sinon.stub().resolves();
|
libp2p.hangUp = sinon.stub().resolves();
|
||||||
connectionLimiter = createLimiter();
|
connectionLimiter = createLimiter();
|
||||||
mockPeer.addresses = [
|
mockPeer.addresses = [
|
||||||
@ -423,6 +403,11 @@ describe("ConnectionLimiter", () => {
|
|||||||
|
|
||||||
describe("maintainConnectionsCount", () => {
|
describe("maintainConnectionsCount", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
dialer = {
|
||||||
|
start: sinon.stub(),
|
||||||
|
stop: sinon.stub(),
|
||||||
|
dial: sinon.stub().resolves()
|
||||||
|
} as unknown as sinon.SinonStubbedInstance<Dialer>;
|
||||||
libp2p.hangUp = sinon.stub().resolves();
|
libp2p.hangUp = sinon.stub().resolves();
|
||||||
connectionLimiter = createLimiter({ maxConnections: 2 });
|
connectionLimiter = createLimiter({ maxConnections: 2 });
|
||||||
mockPeer.addresses = [
|
mockPeer.addresses = [
|
||||||
@ -529,7 +514,6 @@ describe("ConnectionLimiter", () => {
|
|||||||
];
|
];
|
||||||
libp2p.peerStore.all.resolves([bootstrapPeer, pxPeer, localPeer]);
|
libp2p.peerStore.all.resolves([bootstrapPeer, pxPeer, localPeer]);
|
||||||
libp2p.getConnections.returns([]);
|
libp2p.getConnections.returns([]);
|
||||||
connectionLimiter = createLimiter();
|
|
||||||
const peers = await (connectionLimiter as any).getPrioritizedPeers();
|
const peers = await (connectionLimiter as any).getPrioritizedPeers();
|
||||||
expect(peers[0].id.toString()).to.equal("b");
|
expect(peers[0].id.toString()).to.equal("b");
|
||||||
expect(peers[1].id.toString()).to.equal("px");
|
expect(peers[1].id.toString()).to.equal("px");
|
||||||
|
|||||||
@ -5,14 +5,12 @@ import {
|
|||||||
IWakuEventEmitter,
|
IWakuEventEmitter,
|
||||||
Libp2p,
|
Libp2p,
|
||||||
Libp2pEventHandler,
|
Libp2pEventHandler,
|
||||||
Tags,
|
Tags
|
||||||
WakuEvent
|
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { Logger } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
|
|
||||||
import { Dialer } from "./dialer.js";
|
import { Dialer } from "./dialer.js";
|
||||||
import { NetworkMonitor } from "./network_monitor.js";
|
import { NetworkMonitor } from "./network_monitor.js";
|
||||||
import { isAddressesSupported } from "./utils.js";
|
|
||||||
|
|
||||||
const log = new Logger("connection-limiter");
|
const log = new Logger("connection-limiter");
|
||||||
|
|
||||||
@ -71,10 +69,7 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.events.addEventListener(
|
this.events.addEventListener("waku:connection", this.onWakuConnectionEvent);
|
||||||
WakuEvent.Connection,
|
|
||||||
this.onWakuConnectionEvent
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NOTE: Event is not being emitted on closing nor losing a connection.
|
* NOTE: Event is not being emitted on closing nor losing a connection.
|
||||||
@ -95,7 +90,7 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
|
|
||||||
public stop(): void {
|
public stop(): void {
|
||||||
this.events.removeEventListener(
|
this.events.removeEventListener(
|
||||||
WakuEvent.Connection,
|
"waku:connection",
|
||||||
this.onWakuConnectionEvent
|
this.onWakuConnectionEvent
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -146,15 +141,13 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
const peers = await this.getPrioritizedPeers();
|
const peers = await this.getPrioritizedPeers();
|
||||||
|
|
||||||
if (peers.length === 0) {
|
if (peers.length === 0) {
|
||||||
log.info(`No peers to dial, skipping`);
|
log.info(`No peers to dial, node is utilizing all known peers`);
|
||||||
await this.triggerBootstrap();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = peers
|
const promises = peers
|
||||||
.slice(0, this.options.maxConnections - connections.length)
|
.slice(0, this.options.maxConnections - connections.length)
|
||||||
.map((p) => this.dialer.dial(p.id));
|
.map((p) => this.dialer.dial(p.id));
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -221,7 +214,6 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
|
|
||||||
if (peers.length === 0) {
|
if (peers.length === 0) {
|
||||||
log.info(`No peers to dial, skipping`);
|
log.info(`No peers to dial, skipping`);
|
||||||
await this.triggerBootstrap();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,9 +236,6 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
private async getPrioritizedPeers(): Promise<Peer[]> {
|
private async getPrioritizedPeers(): Promise<Peer[]> {
|
||||||
const allPeers = await this.libp2p.peerStore.all();
|
const allPeers = await this.libp2p.peerStore.all();
|
||||||
const allConnections = this.libp2p.getConnections();
|
const allConnections = this.libp2p.getConnections();
|
||||||
const allConnectionsSet = new Set(
|
|
||||||
allConnections.map((c) => c.remotePeer.toString())
|
|
||||||
);
|
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
`Found ${allPeers.length} peers in store, and found ${allConnections.length} connections`
|
`Found ${allPeers.length} peers in store, and found ${allConnections.length} connections`
|
||||||
@ -254,10 +243,11 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
|
|
||||||
const notConnectedPeers = allPeers.filter(
|
const notConnectedPeers = allPeers.filter(
|
||||||
(p) =>
|
(p) =>
|
||||||
!allConnectionsSet.has(p.id.toString()) &&
|
!allConnections.some((c) => c.remotePeer.equals(p.id)) &&
|
||||||
isAddressesSupported(
|
p.addresses.some(
|
||||||
this.libp2p,
|
(a) =>
|
||||||
p.addresses.map((a) => a.multiaddr)
|
a.multiaddr.toString().includes("wss") ||
|
||||||
|
a.multiaddr.toString().includes("ws")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -273,19 +263,7 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
p.tags.has(Tags.PEER_CACHE)
|
p.tags.has(Tags.PEER_CACHE)
|
||||||
);
|
);
|
||||||
|
|
||||||
const restPeers = notConnectedPeers.filter(
|
return [...bootstrapPeers, ...peerExchangePeers, ...localStorePeers];
|
||||||
(p) =>
|
|
||||||
!p.tags.has(Tags.BOOTSTRAP) &&
|
|
||||||
!p.tags.has(Tags.PEER_EXCHANGE) &&
|
|
||||||
!p.tags.has(Tags.PEER_CACHE)
|
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
|
||||||
...bootstrapPeers,
|
|
||||||
...peerExchangePeers,
|
|
||||||
...localStorePeers,
|
|
||||||
...restPeers
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getBootstrapPeers(): Promise<Peer[]> {
|
private async getBootstrapPeers(): Promise<Peer[]> {
|
||||||
@ -296,9 +274,11 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
.map((id) => this.getPeer(id))
|
.map((id) => this.getPeer(id))
|
||||||
);
|
);
|
||||||
|
|
||||||
return peers.filter(
|
const bootstrapPeers = peers.filter(
|
||||||
(peer) => peer && peer.tags.has(Tags.BOOTSTRAP)
|
(peer) => peer && peer.tags.has(Tags.BOOTSTRAP)
|
||||||
) as Peer[];
|
) as Peer[];
|
||||||
|
|
||||||
|
return bootstrapPeers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getPeer(peerId: PeerId): Promise<Peer | null> {
|
private async getPeer(peerId: PeerId): Promise<Peer | null> {
|
||||||
@ -309,41 +289,4 @@ export class ConnectionLimiter implements IConnectionLimiter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers the bootstrap or peer cache discovery if they are mounted.
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
private async triggerBootstrap(): Promise<void> {
|
|
||||||
log.info("Triggering bootstrap discovery");
|
|
||||||
|
|
||||||
const bootstrapComponents = Object.values(this.libp2p.components.components)
|
|
||||||
.filter((c) => !!c)
|
|
||||||
.filter((c: unknown) =>
|
|
||||||
[`@waku/${Tags.BOOTSTRAP}`, `@waku/${Tags.PEER_CACHE}`].includes(
|
|
||||||
(c as { [Symbol.toStringTag]: string })?.[Symbol.toStringTag]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (bootstrapComponents.length === 0) {
|
|
||||||
log.warn("No bootstrap components found to trigger");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info(
|
|
||||||
`Found ${bootstrapComponents.length} bootstrap components, starting them`
|
|
||||||
);
|
|
||||||
|
|
||||||
const promises = bootstrapComponents.map(async (component) => {
|
|
||||||
try {
|
|
||||||
await (component as { stop: () => Promise<void> })?.stop?.();
|
|
||||||
await (component as { start: () => Promise<void> })?.start?.();
|
|
||||||
log.info("Successfully started bootstrap component");
|
|
||||||
} catch (error) {
|
|
||||||
log.error("Failed to start bootstrap component", error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,12 +52,6 @@ describe("ConnectionManager", () => {
|
|||||||
dialProtocol: sinon.stub().resolves({} as Stream),
|
dialProtocol: sinon.stub().resolves({} as Stream),
|
||||||
hangUp: sinon.stub().resolves(),
|
hangUp: sinon.stub().resolves(),
|
||||||
getPeers: sinon.stub().returns([]),
|
getPeers: sinon.stub().returns([]),
|
||||||
getConnections: sinon.stub().returns([]),
|
|
||||||
addEventListener: sinon.stub(),
|
|
||||||
removeEventListener: sinon.stub(),
|
|
||||||
components: {
|
|
||||||
components: {}
|
|
||||||
},
|
|
||||||
peerStore: {
|
peerStore: {
|
||||||
get: sinon.stub().resolves(null),
|
get: sinon.stub().resolves(null),
|
||||||
merge: sinon.stub().resolves()
|
merge: sinon.stub().resolves()
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { IWakuEventEmitter, Libp2p, WakuEvent } from "@waku/interfaces";
|
import { IWakuEventEmitter, Libp2p } from "@waku/interfaces";
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ describe("NetworkMonitor", () => {
|
|||||||
const dispatchedEvent = dispatchEventStub.getCall(0)
|
const dispatchedEvent = dispatchEventStub.getCall(0)
|
||||||
.args[0] as CustomEvent<boolean>;
|
.args[0] as CustomEvent<boolean>;
|
||||||
expect(dispatchedEvent).to.be.instanceOf(CustomEvent);
|
expect(dispatchedEvent).to.be.instanceOf(CustomEvent);
|
||||||
expect(dispatchedEvent.type).to.equal(WakuEvent.Connection);
|
expect(dispatchedEvent.type).to.equal("waku:connection");
|
||||||
expect(dispatchedEvent.detail).to.be.true;
|
expect(dispatchedEvent.detail).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { IWakuEventEmitter, Libp2p, WakuEvent } from "@waku/interfaces";
|
import { IWakuEventEmitter, Libp2p } from "@waku/interfaces";
|
||||||
|
|
||||||
type NetworkMonitorConstructorOptions = {
|
type NetworkMonitorConstructorOptions = {
|
||||||
libp2p: Libp2p;
|
libp2p: Libp2p;
|
||||||
@ -104,7 +104,7 @@ export class NetworkMonitor implements INetworkMonitor {
|
|||||||
|
|
||||||
private dispatchNetworkEvent(): void {
|
private dispatchNetworkEvent(): void {
|
||||||
this.events.dispatchEvent(
|
this.events.dispatchEvent(
|
||||||
new CustomEvent<boolean>(WakuEvent.Connection, {
|
new CustomEvent<boolean>("waku:connection", {
|
||||||
detail: this.isConnected()
|
detail: this.isConnected()
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { isPeerId, type Peer, type PeerId } from "@libp2p/interface";
|
import { isPeerId, type Peer, type PeerId } from "@libp2p/interface";
|
||||||
import { peerIdFromString } from "@libp2p/peer-id";
|
import { peerIdFromString } from "@libp2p/peer-id";
|
||||||
import { Multiaddr, multiaddr, MultiaddrInput } from "@multiformats/multiaddr";
|
import { Multiaddr, multiaddr, MultiaddrInput } from "@multiformats/multiaddr";
|
||||||
import { Libp2p } from "@waku/interfaces";
|
|
||||||
import { bytesToUtf8 } from "@waku/utils/bytes";
|
import { bytesToUtf8 } from "@waku/utils/bytes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,25 +49,3 @@ export const mapToPeerId = (input: PeerId | MultiaddrInput): PeerId => {
|
|||||||
? input
|
? input
|
||||||
: peerIdFromString(multiaddr(input).getPeerId()!);
|
: peerIdFromString(multiaddr(input).getPeerId()!);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the address is supported by the libp2p instance.
|
|
||||||
* @param libp2p - The libp2p instance.
|
|
||||||
* @param addresses - The addresses to check.
|
|
||||||
* @returns True if the addresses are supported, false otherwise.
|
|
||||||
*/
|
|
||||||
export const isAddressesSupported = (
|
|
||||||
libp2p: Libp2p,
|
|
||||||
addresses: Multiaddr[]
|
|
||||||
): boolean => {
|
|
||||||
const transports =
|
|
||||||
libp2p?.components?.transportManager?.getTransports() || [];
|
|
||||||
|
|
||||||
if (transports.length === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return transports
|
|
||||||
.map((transport) => transport.dialFilter(addresses))
|
|
||||||
.some((supportedAddresses) => supportedAddresses.length > 0);
|
|
||||||
};
|
|
||||||
|
|||||||
@ -2,9 +2,9 @@ import type { PeerId } from "@libp2p/interface";
|
|||||||
import type { IncomingStreamData } from "@libp2p/interface-internal";
|
import type { IncomingStreamData } from "@libp2p/interface-internal";
|
||||||
import {
|
import {
|
||||||
type ContentTopic,
|
type ContentTopic,
|
||||||
type FilterCoreResult,
|
type CoreProtocolResult,
|
||||||
FilterError,
|
|
||||||
type Libp2p,
|
type Libp2p,
|
||||||
|
ProtocolError,
|
||||||
type PubsubTopic
|
type PubsubTopic
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { WakuMessage } from "@waku/proto";
|
import { WakuMessage } from "@waku/proto";
|
||||||
@ -42,45 +42,34 @@ export class FilterCore {
|
|||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private handleIncomingMessage: IncomingMessageHandler,
|
private handleIncomingMessage: IncomingMessageHandler,
|
||||||
private libp2p: Libp2p
|
libp2p: Libp2p
|
||||||
) {
|
) {
|
||||||
this.streamManager = new StreamManager(
|
this.streamManager = new StreamManager(
|
||||||
FilterCodecs.SUBSCRIBE,
|
FilterCodecs.SUBSCRIBE,
|
||||||
libp2p.components
|
libp2p.components
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
public async start(): Promise<void> {
|
libp2p
|
||||||
try {
|
.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
|
||||||
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
|
|
||||||
maxInboundStreams: 100
|
maxInboundStreams: 100
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
log.error("Failed to register ", FilterCodecs.PUSH, e);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
|
||||||
log.error("Failed to register ", FilterCodecs.PUSH, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async stop(): Promise<void> {
|
|
||||||
this.streamManager.stop();
|
|
||||||
try {
|
|
||||||
await this.libp2p.unhandle(FilterCodecs.PUSH);
|
|
||||||
} catch (e) {
|
|
||||||
log.error("Failed to unregister ", FilterCodecs.PUSH, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async subscribe(
|
public async subscribe(
|
||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
contentTopics: ContentTopic[]
|
contentTopics: ContentTopic[]
|
||||||
): Promise<FilterCoreResult> {
|
): Promise<CoreProtocolResult> {
|
||||||
const stream = await this.streamManager.getStream(peerId);
|
const stream = await this.streamManager.getStream(peerId);
|
||||||
|
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.NO_STREAM_AVAILABLE,
|
error: ProtocolError.NO_STREAM_AVAILABLE,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -109,7 +98,7 @@ export class FilterCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.GENERIC_FAIL,
|
error: ProtocolError.GENERIC_FAIL,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -124,7 +113,7 @@ export class FilterCore {
|
|||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.REMOTE_PEER_REJECTED,
|
error: ProtocolError.REMOTE_PEER_REJECTED,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
},
|
},
|
||||||
success: null
|
success: null
|
||||||
@ -141,7 +130,7 @@ export class FilterCore {
|
|||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
peerId: PeerId,
|
peerId: PeerId,
|
||||||
contentTopics: ContentTopic[]
|
contentTopics: ContentTopic[]
|
||||||
): Promise<FilterCoreResult> {
|
): Promise<CoreProtocolResult> {
|
||||||
const stream = await this.streamManager.getStream(peerId);
|
const stream = await this.streamManager.getStream(peerId);
|
||||||
|
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
@ -149,7 +138,7 @@ export class FilterCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.NO_STREAM_AVAILABLE,
|
error: ProtocolError.NO_STREAM_AVAILABLE,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -167,7 +156,7 @@ export class FilterCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.GENERIC_FAIL,
|
error: ProtocolError.GENERIC_FAIL,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -182,7 +171,7 @@ export class FilterCore {
|
|||||||
public async unsubscribeAll(
|
public async unsubscribeAll(
|
||||||
pubsubTopic: PubsubTopic,
|
pubsubTopic: PubsubTopic,
|
||||||
peerId: PeerId
|
peerId: PeerId
|
||||||
): Promise<FilterCoreResult> {
|
): Promise<CoreProtocolResult> {
|
||||||
const stream = await this.streamManager.getStream(peerId);
|
const stream = await this.streamManager.getStream(peerId);
|
||||||
|
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
@ -190,7 +179,7 @@ export class FilterCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.NO_STREAM_AVAILABLE,
|
error: ProtocolError.NO_STREAM_AVAILABLE,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -209,7 +198,7 @@ export class FilterCore {
|
|||||||
if (!res || !res.length) {
|
if (!res || !res.length) {
|
||||||
return {
|
return {
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.NO_RESPONSE,
|
error: ProtocolError.NO_RESPONSE,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
},
|
},
|
||||||
success: null
|
success: null
|
||||||
@ -225,7 +214,7 @@ export class FilterCore {
|
|||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.REMOTE_PEER_REJECTED,
|
error: ProtocolError.REMOTE_PEER_REJECTED,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
},
|
},
|
||||||
success: null
|
success: null
|
||||||
@ -238,7 +227,7 @@ export class FilterCore {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ping(peerId: PeerId): Promise<FilterCoreResult> {
|
public async ping(peerId: PeerId): Promise<CoreProtocolResult> {
|
||||||
const stream = await this.streamManager.getStream(peerId);
|
const stream = await this.streamManager.getStream(peerId);
|
||||||
|
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
@ -246,7 +235,7 @@ export class FilterCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.NO_STREAM_AVAILABLE,
|
error: ProtocolError.NO_STREAM_AVAILABLE,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -268,7 +257,7 @@ export class FilterCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.GENERIC_FAIL,
|
error: ProtocolError.GENERIC_FAIL,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -278,7 +267,7 @@ export class FilterCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.NO_RESPONSE,
|
error: ProtocolError.NO_RESPONSE,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -294,7 +283,7 @@ export class FilterCore {
|
|||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: FilterError.REMOTE_PEER_REJECTED,
|
error: ProtocolError.REMOTE_PEER_REJECTED,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
export const CODECS = {
|
|
||||||
v2: "/vac/waku/lightpush/2.0.0-beta1",
|
|
||||||
v3: "/vac/waku/lightpush/3.0.0"
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const LightPushCodecV2 = CODECS.v2;
|
|
||||||
export const LightPushCodec = CODECS.v3;
|
|
||||||
@ -1,2 +1 @@
|
|||||||
export { LightPushCore } from "./light_push.js";
|
export { LightPushCore, LightPushCodec, PushResponse } from "./light_push.js";
|
||||||
export { LightPushCodec, LightPushCodecV2 } from "./constants.js";
|
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
import type { PeerId, Stream } from "@libp2p/interface";
|
import type { PeerId } from "@libp2p/interface";
|
||||||
import {
|
import {
|
||||||
|
type CoreProtocolResult,
|
||||||
type IEncoder,
|
type IEncoder,
|
||||||
type IMessage,
|
type IMessage,
|
||||||
type Libp2p,
|
type Libp2p,
|
||||||
type LightPushCoreResult,
|
ProtocolError,
|
||||||
LightPushError
|
type ThisOrThat
|
||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
|
import { PushResponse } from "@waku/proto";
|
||||||
|
import { isMessageSizeUnderCap } from "@waku/utils";
|
||||||
import { Logger } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
import all from "it-all";
|
import all from "it-all";
|
||||||
import * as lp from "it-length-prefixed";
|
import * as lp from "it-length-prefixed";
|
||||||
@ -14,76 +17,92 @@ import { Uint8ArrayList } from "uint8arraylist";
|
|||||||
|
|
||||||
import { StreamManager } from "../stream_manager/index.js";
|
import { StreamManager } from "../stream_manager/index.js";
|
||||||
|
|
||||||
import { CODECS } from "./constants.js";
|
import { PushRpc } from "./push_rpc.js";
|
||||||
import { ProtocolHandler } from "./protocol_handler.js";
|
import { isRLNResponseError } from "./utils.js";
|
||||||
|
|
||||||
const log = new Logger("light-push");
|
const log = new Logger("light-push");
|
||||||
|
|
||||||
|
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
|
||||||
|
export { PushResponse };
|
||||||
|
|
||||||
|
type PreparePushMessageResult = ThisOrThat<"query", PushRpc>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
|
||||||
*/
|
*/
|
||||||
export class LightPushCore {
|
export class LightPushCore {
|
||||||
private readonly streamManager: StreamManager;
|
private readonly streamManager: StreamManager;
|
||||||
private readonly streamManagerV2: StreamManager;
|
|
||||||
|
|
||||||
public readonly multicodec = [CODECS.v3, CODECS.v2];
|
public readonly multicodec = LightPushCodec;
|
||||||
|
|
||||||
public constructor(private libp2p: Libp2p) {
|
public constructor(libp2p: Libp2p) {
|
||||||
this.streamManagerV2 = new StreamManager(CODECS.v2, libp2p.components);
|
this.streamManager = new StreamManager(LightPushCodec, libp2p.components);
|
||||||
this.streamManager = new StreamManager(CODECS.v3, libp2p.components);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop(): void {
|
private async preparePushMessage(
|
||||||
this.streamManager.stop();
|
encoder: IEncoder,
|
||||||
this.streamManagerV2.stop();
|
message: IMessage
|
||||||
|
): Promise<PreparePushMessageResult> {
|
||||||
|
try {
|
||||||
|
if (!message.payload || message.payload.length === 0) {
|
||||||
|
log.error("Failed to send waku light push: payload is empty");
|
||||||
|
return { query: null, error: ProtocolError.EMPTY_PAYLOAD };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
||||||
|
log.error("Failed to send waku light push: message is bigger than 1MB");
|
||||||
|
return { query: null, error: ProtocolError.SIZE_TOO_BIG };
|
||||||
|
}
|
||||||
|
|
||||||
|
const protoMessage = await encoder.toProtoObj(message);
|
||||||
|
if (!protoMessage) {
|
||||||
|
log.error("Failed to encode to protoMessage, aborting push");
|
||||||
|
return {
|
||||||
|
query: null,
|
||||||
|
error: ProtocolError.ENCODE_FAILED
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = PushRpc.createRequest(protoMessage, encoder.pubsubTopic);
|
||||||
|
return { query, error: null };
|
||||||
|
} catch (error) {
|
||||||
|
log.error("Failed to prepare push message", error);
|
||||||
|
|
||||||
|
return {
|
||||||
|
query: null,
|
||||||
|
error: ProtocolError.GENERIC_FAIL
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async send(
|
public async send(
|
||||||
encoder: IEncoder,
|
encoder: IEncoder,
|
||||||
message: IMessage,
|
message: IMessage,
|
||||||
peerId: PeerId,
|
peerId: PeerId
|
||||||
useLegacy: boolean = false
|
): Promise<CoreProtocolResult> {
|
||||||
): Promise<LightPushCoreResult> {
|
const { query, error: preparationError } = await this.preparePushMessage(
|
||||||
const protocol = await this.getProtocol(peerId, useLegacy);
|
|
||||||
|
|
||||||
log.info(
|
|
||||||
`Sending light push request to peer:${peerId.toString()}, protocol:${protocol}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!protocol) {
|
|
||||||
return {
|
|
||||||
success: null,
|
|
||||||
failure: {
|
|
||||||
error: LightPushError.GENERIC_FAIL,
|
|
||||||
peerId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const { rpc, error: prepError } = await ProtocolHandler.preparePushMessage(
|
|
||||||
encoder,
|
encoder,
|
||||||
message,
|
message
|
||||||
protocol
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (prepError) {
|
if (preparationError || !query) {
|
||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: prepError,
|
error: preparationError,
|
||||||
peerId
|
peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = await this.getStream(peerId, protocol);
|
const stream = await this.streamManager.getStream(peerId);
|
||||||
|
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
log.error(`Failed to get a stream for remote peer:${peerId.toString()}`);
|
log.error(`Failed to get a stream for remote peer:${peerId.toString()}`);
|
||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: LightPushError.NO_STREAM_AVAILABLE,
|
error: ProtocolError.NO_STREAM_AVAILABLE,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -92,74 +111,76 @@ export class LightPushCore {
|
|||||||
let res: Uint8ArrayList[] | undefined;
|
let res: Uint8ArrayList[] | undefined;
|
||||||
try {
|
try {
|
||||||
res = await pipe(
|
res = await pipe(
|
||||||
[rpc.encode()],
|
[query.encode()],
|
||||||
lp.encode,
|
lp.encode,
|
||||||
stream,
|
stream,
|
||||||
lp.decode,
|
lp.decode,
|
||||||
async (source) => await all(source)
|
async (source) => await all(source)
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// can fail only because of `stream` abortion
|
||||||
log.error("Failed to send waku light push request", err);
|
log.error("Failed to send waku light push request", err);
|
||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: LightPushError.STREAM_ABORTED,
|
error: ProtocolError.STREAM_ABORTED,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const bytes = new Uint8ArrayList();
|
const bytes = new Uint8ArrayList();
|
||||||
res.forEach((chunk) => bytes.append(chunk));
|
res.forEach((chunk) => {
|
||||||
|
bytes.append(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
if (bytes.length === 0) {
|
let response: PushResponse | undefined;
|
||||||
|
try {
|
||||||
|
response = PushRpc.decode(bytes).response;
|
||||||
|
} catch (err) {
|
||||||
|
log.error("Failed to decode push reply", err);
|
||||||
return {
|
return {
|
||||||
success: null,
|
success: null,
|
||||||
failure: {
|
failure: {
|
||||||
error: LightPushError.NO_RESPONSE,
|
error: ProtocolError.DECODE_FAILED,
|
||||||
peerId: peerId
|
peerId: peerId
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProtocolHandler.handleResponse(bytes, protocol, peerId);
|
if (!response) {
|
||||||
}
|
log.error("Remote peer fault: No response in PushRPC");
|
||||||
|
return {
|
||||||
private async getProtocol(
|
success: null,
|
||||||
peerId: PeerId,
|
failure: {
|
||||||
useLegacy: boolean
|
error: ProtocolError.NO_RESPONSE,
|
||||||
): Promise<string | undefined> {
|
peerId: peerId
|
||||||
try {
|
}
|
||||||
const peer = await this.libp2p.peerStore.get(peerId);
|
};
|
||||||
|
|
||||||
if (
|
|
||||||
useLegacy ||
|
|
||||||
(!peer.protocols.includes(CODECS.v3) &&
|
|
||||||
peer.protocols.includes(CODECS.v2))
|
|
||||||
) {
|
|
||||||
return CODECS.v2;
|
|
||||||
} else if (peer.protocols.includes(CODECS.v3)) {
|
|
||||||
return CODECS.v3;
|
|
||||||
} else {
|
|
||||||
throw new Error("No supported protocol found");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
log.error("Failed to get protocol", error);
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private async getStream(
|
if (isRLNResponseError(response.info)) {
|
||||||
peerId: PeerId,
|
log.error("Remote peer fault: RLN generation");
|
||||||
protocol: string
|
return {
|
||||||
): Promise<Stream | undefined> {
|
success: null,
|
||||||
switch (protocol) {
|
failure: {
|
||||||
case CODECS.v2:
|
error: ProtocolError.RLN_PROOF_GENERATION,
|
||||||
return this.streamManagerV2.getStream(peerId);
|
peerId: peerId
|
||||||
case CODECS.v3:
|
}
|
||||||
return this.streamManager.getStream(peerId);
|
};
|
||||||
default:
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!response.isSuccess) {
|
||||||
|
log.error("Remote peer rejected the message: ", response.info);
|
||||||
|
return {
|
||||||
|
success: null,
|
||||||
|
failure: {
|
||||||
|
error: ProtocolError.REMOTE_PEER_REJECTED,
|
||||||
|
peerId: peerId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: peerId, failure: null };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,191 +0,0 @@
|
|||||||
import type { PeerId } from "@libp2p/interface";
|
|
||||||
import type { IEncoder, IMessage, LightPushCoreResult } from "@waku/interfaces";
|
|
||||||
import { LightPushError, LightPushStatusCode } from "@waku/interfaces";
|
|
||||||
import { PushResponse, WakuMessage } from "@waku/proto";
|
|
||||||
import { isMessageSizeUnderCap, Logger } from "@waku/utils";
|
|
||||||
import { Uint8ArrayList } from "uint8arraylist";
|
|
||||||
|
|
||||||
import { CODECS } from "./constants.js";
|
|
||||||
import { PushRpcV2 } from "./push_rpc.js";
|
|
||||||
import { PushRpc } from "./push_rpc_v3.js";
|
|
||||||
import { isRLNResponseError } from "./utils.js";
|
|
||||||
|
|
||||||
type VersionedPushRpc =
|
|
||||||
| ({ version: "v2" } & PushRpcV2)
|
|
||||||
| ({ version: "v3" } & PushRpc);
|
|
||||||
|
|
||||||
type PreparePushMessageResult =
|
|
||||||
| { rpc: VersionedPushRpc; error: null }
|
|
||||||
| { rpc: null; error: LightPushError };
|
|
||||||
|
|
||||||
const log = new Logger("light-push:protocol-handler");
|
|
||||||
|
|
||||||
export class ProtocolHandler {
|
|
||||||
public static async preparePushMessage(
|
|
||||||
encoder: IEncoder,
|
|
||||||
message: IMessage,
|
|
||||||
protocol: string
|
|
||||||
): Promise<PreparePushMessageResult> {
|
|
||||||
try {
|
|
||||||
if (!message.payload || message.payload.length === 0) {
|
|
||||||
log.error("Failed to send waku light push: payload is empty");
|
|
||||||
return { rpc: null, error: LightPushError.EMPTY_PAYLOAD };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(await isMessageSizeUnderCap(encoder, message))) {
|
|
||||||
log.error("Failed to send waku light push: message is bigger than 1MB");
|
|
||||||
return { rpc: null, error: LightPushError.SIZE_TOO_BIG };
|
|
||||||
}
|
|
||||||
|
|
||||||
const protoMessage = await encoder.toProtoObj(message);
|
|
||||||
if (!protoMessage) {
|
|
||||||
log.error("Failed to encode to protoMessage, aborting push");
|
|
||||||
return { rpc: null, error: LightPushError.ENCODE_FAILED };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (protocol === CODECS.v3) {
|
|
||||||
log.info("Creating v3 RPC message");
|
|
||||||
return {
|
|
||||||
rpc: ProtocolHandler.createV3Rpc(protoMessage, encoder.pubsubTopic),
|
|
||||||
error: null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("Creating v2 RPC message");
|
|
||||||
return {
|
|
||||||
rpc: ProtocolHandler.createV2Rpc(protoMessage, encoder.pubsubTopic),
|
|
||||||
error: null
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
log.error("Failed to prepare push message", err);
|
|
||||||
return { rpc: null, error: LightPushError.GENERIC_FAIL };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decode and evaluate a LightPush response according to the protocol version
|
|
||||||
*/
|
|
||||||
public static handleResponse(
|
|
||||||
bytes: Uint8ArrayList,
|
|
||||||
protocol: string,
|
|
||||||
peerId: PeerId
|
|
||||||
): LightPushCoreResult {
|
|
||||||
if (protocol === CODECS.v3) {
|
|
||||||
return ProtocolHandler.handleV3Response(bytes, peerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ProtocolHandler.handleV2Response(bytes, peerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static handleV3Response(
|
|
||||||
bytes: Uint8ArrayList,
|
|
||||||
peerId: PeerId
|
|
||||||
): LightPushCoreResult {
|
|
||||||
try {
|
|
||||||
const decodedRpcV3 = PushRpc.decodeResponse(bytes);
|
|
||||||
const statusCode = decodedRpcV3.statusCode;
|
|
||||||
const statusDesc = decodedRpcV3.statusDesc;
|
|
||||||
|
|
||||||
if (statusCode !== LightPushStatusCode.SUCCESS) {
|
|
||||||
const error = LightPushError.REMOTE_PEER_REJECTED;
|
|
||||||
log.error(
|
|
||||||
`Remote peer rejected with v3 status code ${statusCode}: ${statusDesc}`
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
success: null,
|
|
||||||
failure: {
|
|
||||||
error,
|
|
||||||
peerId: peerId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (decodedRpcV3.relayPeerCount !== undefined) {
|
|
||||||
log.info(`Message relayed to ${decodedRpcV3.relayPeerCount} peers`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: peerId, failure: null };
|
|
||||||
} catch (err) {
|
|
||||||
return {
|
|
||||||
success: null,
|
|
||||||
failure: {
|
|
||||||
error: LightPushError.DECODE_FAILED,
|
|
||||||
peerId: peerId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static handleV2Response(
|
|
||||||
bytes: Uint8ArrayList,
|
|
||||||
peerId: PeerId
|
|
||||||
): LightPushCoreResult {
|
|
||||||
let response: PushResponse | undefined;
|
|
||||||
try {
|
|
||||||
const decodedRpc = PushRpcV2.decode(bytes);
|
|
||||||
response = decodedRpc.response;
|
|
||||||
} catch (err) {
|
|
||||||
return {
|
|
||||||
success: null,
|
|
||||||
failure: {
|
|
||||||
error: LightPushError.DECODE_FAILED,
|
|
||||||
peerId: peerId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
return {
|
|
||||||
success: null,
|
|
||||||
failure: {
|
|
||||||
error: LightPushError.NO_RESPONSE,
|
|
||||||
peerId: peerId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isRLNResponseError(response.info)) {
|
|
||||||
log.error("Remote peer fault: RLN generation");
|
|
||||||
return {
|
|
||||||
success: null,
|
|
||||||
failure: {
|
|
||||||
error: LightPushError.RLN_PROOF_GENERATION,
|
|
||||||
peerId: peerId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.isSuccess) {
|
|
||||||
log.error("Remote peer rejected the message: ", response.info);
|
|
||||||
return {
|
|
||||||
success: null,
|
|
||||||
failure: {
|
|
||||||
error: LightPushError.REMOTE_PEER_REJECTED,
|
|
||||||
peerId: peerId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: peerId, failure: null };
|
|
||||||
}
|
|
||||||
|
|
||||||
private static createV2Rpc(
|
|
||||||
message: WakuMessage,
|
|
||||||
pubsubTopic: string
|
|
||||||
): VersionedPushRpc {
|
|
||||||
const v2Rpc = PushRpcV2.createRequest(message, pubsubTopic);
|
|
||||||
return Object.assign(v2Rpc, { version: "v2" as const });
|
|
||||||
}
|
|
||||||
|
|
||||||
private static createV3Rpc(
|
|
||||||
message: WakuMessage,
|
|
||||||
pubsubTopic: string
|
|
||||||
): VersionedPushRpc {
|
|
||||||
if (!message.timestamp) {
|
|
||||||
message.timestamp = BigInt(Date.now()) * BigInt(1_000_000);
|
|
||||||
}
|
|
||||||
|
|
||||||
const v3Rpc = PushRpc.createRequest(message, pubsubTopic);
|
|
||||||
return Object.assign(v3Rpc, { version: "v3" as const });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,14 +2,14 @@ import { proto_lightpush as proto } from "@waku/proto";
|
|||||||
import type { Uint8ArrayList } from "uint8arraylist";
|
import type { Uint8ArrayList } from "uint8arraylist";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
|
|
||||||
export class PushRpcV2 {
|
export class PushRpc {
|
||||||
public constructor(public proto: proto.PushRpc) {}
|
public constructor(public proto: proto.PushRpc) {}
|
||||||
|
|
||||||
public static createRequest(
|
public static createRequest(
|
||||||
message: proto.WakuMessage,
|
message: proto.WakuMessage,
|
||||||
pubsubTopic: string
|
pubsubTopic: string
|
||||||
): PushRpcV2 {
|
): PushRpc {
|
||||||
return new PushRpcV2({
|
return new PushRpc({
|
||||||
requestId: uuid(),
|
requestId: uuid(),
|
||||||
request: {
|
request: {
|
||||||
message: message,
|
message: message,
|
||||||
@ -19,9 +19,9 @@ export class PushRpcV2 {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static decode(bytes: Uint8ArrayList): PushRpcV2 {
|
public static decode(bytes: Uint8ArrayList): PushRpc {
|
||||||
const res = proto.PushRpc.decode(bytes);
|
const res = proto.PushRpc.decode(bytes);
|
||||||
return new PushRpcV2(res);
|
return new PushRpc(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
public encode(): Uint8Array {
|
public encode(): Uint8Array {
|
||||||
|
|||||||
@ -1,162 +0,0 @@
|
|||||||
import { proto_lightpush as proto } from "@waku/proto";
|
|
||||||
import type { Uint8ArrayList } from "uint8arraylist";
|
|
||||||
import { v4 as uuid } from "uuid";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LightPush v3 protocol RPC handler.
|
|
||||||
* Implements the v3 message format with correct field numbers:
|
|
||||||
* - requestId: 1
|
|
||||||
* - pubsubTopic: 20
|
|
||||||
* - message: 21
|
|
||||||
*/
|
|
||||||
export class PushRpc {
|
|
||||||
public constructor(
|
|
||||||
public proto: proto.LightPushRequestV3 | proto.LightPushResponseV3
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a v3 request message with proper field numbering
|
|
||||||
*/
|
|
||||||
public static createRequest(
|
|
||||||
message: proto.WakuMessage,
|
|
||||||
pubsubTopic: string
|
|
||||||
): PushRpc {
|
|
||||||
return new PushRpc({
|
|
||||||
requestId: uuid(),
|
|
||||||
pubsubTopic: pubsubTopic,
|
|
||||||
message: message
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a v3 response message with status code handling
|
|
||||||
*/
|
|
||||||
public static createResponse(
|
|
||||||
requestId: string,
|
|
||||||
statusCode: number,
|
|
||||||
statusDesc?: string,
|
|
||||||
relayPeerCount?: number
|
|
||||||
): PushRpc {
|
|
||||||
return new PushRpc({
|
|
||||||
requestId,
|
|
||||||
statusCode,
|
|
||||||
statusDesc,
|
|
||||||
relayPeerCount
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decode v3 request message
|
|
||||||
*/
|
|
||||||
public static decodeRequest(bytes: Uint8ArrayList): PushRpc {
|
|
||||||
const res = proto.LightPushRequestV3.decode(bytes);
|
|
||||||
return new PushRpc(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decode v3 response message
|
|
||||||
*/
|
|
||||||
public static decodeResponse(bytes: Uint8ArrayList): PushRpc {
|
|
||||||
const res = proto.LightPushResponseV3.decode(bytes);
|
|
||||||
return new PushRpc(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encode message to bytes
|
|
||||||
*/
|
|
||||||
public encode(): Uint8Array {
|
|
||||||
if (this.isRequest()) {
|
|
||||||
return proto.LightPushRequestV3.encode(
|
|
||||||
this.proto as proto.LightPushRequestV3
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return proto.LightPushResponseV3.encode(
|
|
||||||
this.proto as proto.LightPushResponseV3
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get request data (if this is a request message)
|
|
||||||
*/
|
|
||||||
public get request(): proto.LightPushRequestV3 | undefined {
|
|
||||||
return this.isRequest()
|
|
||||||
? (this.proto as proto.LightPushRequestV3)
|
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get response data (if this is a response message)
|
|
||||||
*/
|
|
||||||
public get response(): proto.LightPushResponseV3 | undefined {
|
|
||||||
return this.isResponse()
|
|
||||||
? (this.proto as proto.LightPushResponseV3)
|
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the request ID
|
|
||||||
*/
|
|
||||||
public get requestId(): string {
|
|
||||||
return this.proto.requestId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the pubsub topic (only available in requests)
|
|
||||||
*/
|
|
||||||
public get pubsubTopic(): string | undefined {
|
|
||||||
return this.isRequest()
|
|
||||||
? (this.proto as proto.LightPushRequestV3).pubsubTopic
|
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the message (only available in requests)
|
|
||||||
*/
|
|
||||||
public get message(): proto.WakuMessage | undefined {
|
|
||||||
return this.isRequest()
|
|
||||||
? (this.proto as proto.LightPushRequestV3).message
|
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the status code (only available in responses)
|
|
||||||
*/
|
|
||||||
public get statusCode(): number | undefined {
|
|
||||||
return this.isResponse()
|
|
||||||
? (this.proto as proto.LightPushResponseV3).statusCode
|
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the status description (only available in responses)
|
|
||||||
*/
|
|
||||||
public get statusDesc(): string | undefined {
|
|
||||||
return this.isResponse()
|
|
||||||
? (this.proto as proto.LightPushResponseV3).statusDesc
|
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the relay peer count (only available in responses)
|
|
||||||
*/
|
|
||||||
public get relayPeerCount(): number | undefined {
|
|
||||||
return this.isResponse()
|
|
||||||
? (this.proto as proto.LightPushResponseV3).relayPeerCount
|
|
||||||
: undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if this is a request message
|
|
||||||
*/
|
|
||||||
private isRequest(): boolean {
|
|
||||||
return "pubsubTopic" in this.proto && "message" in this.proto;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if this is a response message
|
|
||||||
*/
|
|
||||||
private isResponse(): boolean {
|
|
||||||
return "statusCode" in this.proto;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,17 +1,9 @@
|
|||||||
import type { AutoSharding, IProtoMessage } from "@waku/interfaces";
|
import type { AutoSharding, IProtoMessage } from "@waku/interfaces";
|
||||||
import { createRoutingInfo } from "@waku/utils";
|
import { createRoutingInfo } from "@waku/utils";
|
||||||
import { bytesToHex } from "@waku/utils/bytes";
|
|
||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
import fc from "fast-check";
|
import fc from "fast-check";
|
||||||
|
|
||||||
import { messageHash } from "../message_hash/index.js";
|
import { createDecoder, createEncoder, DecodedMessage } from "./version_0.js";
|
||||||
|
|
||||||
import {
|
|
||||||
createDecoder,
|
|
||||||
createEncoder,
|
|
||||||
DecodedMessage,
|
|
||||||
proto
|
|
||||||
} from "./version_0.js";
|
|
||||||
|
|
||||||
const testContentTopic = "/js-waku/1/tests/bytes";
|
const testContentTopic = "/js-waku/1/tests/bytes";
|
||||||
|
|
||||||
@ -173,54 +165,3 @@ describe("Sets sharding configuration correctly", () => {
|
|||||||
expect(staticshardingEncoder.pubsubTopic).to.be.eq("/waku/2/rs/0/3");
|
expect(staticshardingEncoder.pubsubTopic).to.be.eq("/waku/2/rs/0/3");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("DecodedMessage lazy hash initialization", () => {
|
|
||||||
it("should compute hash only when first accessed", () => {
|
|
||||||
const pubsubTopic = "/waku/2/default-waku/proto";
|
|
||||||
const protoMessage: proto.WakuMessage = {
|
|
||||||
payload: new Uint8Array([1, 2, 3]),
|
|
||||||
contentTopic: "/test/1/test-proto/proto",
|
|
||||||
timestamp: BigInt(1234567890000000),
|
|
||||||
ephemeral: false
|
|
||||||
};
|
|
||||||
|
|
||||||
const message = new DecodedMessage(pubsubTopic, protoMessage);
|
|
||||||
|
|
||||||
expect((message as any)._hash).to.be.undefined;
|
|
||||||
expect((message as any)._hashStr).to.be.undefined;
|
|
||||||
|
|
||||||
const hash = message.hash;
|
|
||||||
expect((message as any)._hash).to.not.be.undefined;
|
|
||||||
expect((message as any)._hashStr).to.be.undefined;
|
|
||||||
|
|
||||||
const hashStr = message.hashStr;
|
|
||||||
expect((message as any)._hashStr).to.not.be.undefined;
|
|
||||||
|
|
||||||
const expectedHash = messageHash(
|
|
||||||
pubsubTopic,
|
|
||||||
protoMessage as IProtoMessage
|
|
||||||
);
|
|
||||||
expect(hash).to.deep.equal(expectedHash);
|
|
||||||
expect(hashStr).to.equal(bytesToHex(expectedHash));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return cached hash on subsequent access", () => {
|
|
||||||
const pubsubTopic = "/waku/2/default-waku/proto";
|
|
||||||
const protoMessage: proto.WakuMessage = {
|
|
||||||
payload: new Uint8Array([1, 2, 3]),
|
|
||||||
contentTopic: "/test/1/test-proto/proto",
|
|
||||||
timestamp: BigInt(1234567890000000),
|
|
||||||
ephemeral: false
|
|
||||||
};
|
|
||||||
|
|
||||||
const message = new DecodedMessage(pubsubTopic, protoMessage);
|
|
||||||
|
|
||||||
const hash1 = message.hash;
|
|
||||||
const hash2 = message.hash;
|
|
||||||
expect(hash1).to.equal(hash2);
|
|
||||||
|
|
||||||
const hashStr1 = message.hashStr;
|
|
||||||
const hashStr2 = message.hashStr;
|
|
||||||
expect(hashStr1).to.equal(hashStr2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@ -12,9 +12,6 @@ import type {
|
|||||||
} from "@waku/interfaces";
|
} from "@waku/interfaces";
|
||||||
import { proto_message as proto } from "@waku/proto";
|
import { proto_message as proto } from "@waku/proto";
|
||||||
import { Logger } from "@waku/utils";
|
import { Logger } from "@waku/utils";
|
||||||
import { bytesToHex } from "@waku/utils/bytes";
|
|
||||||
|
|
||||||
import { messageHash } from "../message_hash/index.js";
|
|
||||||
|
|
||||||
const log = new Logger("message:version-0");
|
const log = new Logger("message:version-0");
|
||||||
const OneMillion = BigInt(1_000_000);
|
const OneMillion = BigInt(1_000_000);
|
||||||
@ -23,9 +20,6 @@ export const Version = 0;
|
|||||||
export { proto };
|
export { proto };
|
||||||
|
|
||||||
export class DecodedMessage implements IDecodedMessage {
|
export class DecodedMessage implements IDecodedMessage {
|
||||||
private _hash: Uint8Array | undefined;
|
|
||||||
private _hashStr: string | undefined;
|
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
public pubsubTopic: string,
|
public pubsubTopic: string,
|
||||||
private proto: proto.WakuMessage
|
private proto: proto.WakuMessage
|
||||||
@ -43,20 +37,6 @@ export class DecodedMessage implements IDecodedMessage {
|
|||||||
return this.proto.contentTopic;
|
return this.proto.contentTopic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get hash(): Uint8Array {
|
|
||||||
if (this._hash === undefined) {
|
|
||||||
this._hash = messageHash(this.pubsubTopic, this.proto as IProtoMessage);
|
|
||||||
}
|
|
||||||
return this._hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get hashStr(): string {
|
|
||||||
if (this._hashStr === undefined) {
|
|
||||||
this._hashStr = bytesToHex(this.hash);
|
|
||||||
}
|
|
||||||
return this._hashStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get timestamp(): Date | undefined {
|
public get timestamp(): Date | undefined {
|
||||||
// In the case we receive a value that is bigger than JS's max number,
|
// In the case we receive a value that is bigger than JS's max number,
|
||||||
// we catch the error and return undefined.
|
// we catch the error and return undefined.
|
||||||
|
|||||||
@ -35,10 +35,6 @@ export class StoreCore {
|
|||||||
this.streamManager = new StreamManager(StoreCodec, libp2p.components);
|
this.streamManager = new StreamManager(StoreCodec, libp2p.components);
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop(): void {
|
|
||||||
this.streamManager.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public get maxTimeLimit(): number {
|
public get maxTimeLimit(): number {
|
||||||
return MAX_TIME_RANGE;
|
return MAX_TIME_RANGE;
|
||||||
}
|
}
|
||||||
@ -72,11 +68,6 @@ export class StoreCore {
|
|||||||
|
|
||||||
let currentCursor = queryOpts.paginationCursor;
|
let currentCursor = queryOpts.paginationCursor;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (queryOpts.abortSignal?.aborted) {
|
|
||||||
log.info("Store query aborted by signal");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const storeQueryRequest = StoreQueryRequest.create({
|
const storeQueryRequest = StoreQueryRequest.create({
|
||||||
...queryOpts,
|
...queryOpts,
|
||||||
paginationCursor: currentCursor
|
paginationCursor: currentCursor
|
||||||
@ -98,22 +89,13 @@ export class StoreCore {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let res;
|
const res = await pipe(
|
||||||
try {
|
[storeQueryRequest.encode()],
|
||||||
res = await pipe(
|
lp.encode,
|
||||||
[storeQueryRequest.encode()],
|
stream,
|
||||||
lp.encode,
|
lp.decode,
|
||||||
stream,
|
async (source) => await all(source)
|
||||||
lp.decode,
|
);
|
||||||
async (source) => await all(source)
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof Error && error.name === "AbortError") {
|
|
||||||
log.info(`Store query aborted for peer ${peerId.toString()}`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bytes = new Uint8ArrayList();
|
const bytes = new Uint8ArrayList();
|
||||||
res.forEach((chunk) => {
|
res.forEach((chunk) => {
|
||||||
@ -140,11 +122,6 @@ export class StoreCore {
|
|||||||
`${storeQueryResponse.messages.length} messages retrieved from store`
|
`${storeQueryResponse.messages.length} messages retrieved from store`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (queryOpts.abortSignal?.aborted) {
|
|
||||||
log.info("Store query aborted by signal before processing messages");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const decodedMessages = storeQueryResponse.messages.map((protoMsg) => {
|
const decodedMessages = storeQueryResponse.messages.map((protoMsg) => {
|
||||||
if (!protoMsg.message) {
|
if (!protoMsg.message) {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
|
|||||||
@ -27,10 +27,6 @@ describe("StreamManager", () => {
|
|||||||
} as any as Libp2pComponents);
|
} as any as Libp2pComponents);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
sinon.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should return usable stream attached to connection", async () => {
|
it("should return usable stream attached to connection", async () => {
|
||||||
for (const writeStatus of ["ready", "writing"]) {
|
for (const writeStatus of ["ready", "writing"]) {
|
||||||
const con1 = createMockConnection();
|
const con1 = createMockConnection();
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export class StreamManager {
|
|||||||
private streamPool: Map<string, Promise<void>> = new Map();
|
private streamPool: Map<string, Promise<void>> = new Map();
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly multicodec: string,
|
private multicodec: string,
|
||||||
private readonly libp2p: Libp2pComponents
|
private readonly libp2p: Libp2pComponents
|
||||||
) {
|
) {
|
||||||
this.log = new Logger(`stream-manager:${multicodec}`);
|
this.log = new Logger(`stream-manager:${multicodec}`);
|
||||||
@ -23,15 +23,6 @@ export class StreamManager {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public stop(): void {
|
|
||||||
this.libp2p.events.removeEventListener(
|
|
||||||
"peer:update",
|
|
||||||
this.handlePeerUpdateStreamPool
|
|
||||||
);
|
|
||||||
this.streamPool.clear();
|
|
||||||
this.ongoingCreation.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getStream(peerId: PeerId): Promise<Stream | undefined> {
|
public async getStream(peerId: PeerId): Promise<Stream | undefined> {
|
||||||
try {
|
try {
|
||||||
const peerIdStr = peerId.toString();
|
const peerIdStr = peerId.toString();
|
||||||
|
|||||||
@ -1,28 +1,5 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [0.0.13](https://github.com/waku-org/js-waku/compare/discovery-v0.0.12...discovery-v0.0.13) (2025-10-31)
|
|
||||||
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
* The following workspace dependencies were updated
|
|
||||||
* dependencies
|
|
||||||
* @waku/core bumped from 0.0.39 to 0.0.40
|
|
||||||
* @waku/proto bumped from ^0.0.14 to ^0.0.15
|
|
||||||
|
|
||||||
## [0.0.12](https://github.com/waku-org/js-waku/compare/discovery-v0.0.11...discovery-v0.0.12) (2025-09-20)
|
|
||||||
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
* The following workspace dependencies were updated
|
|
||||||
* dependencies
|
|
||||||
* @waku/core bumped from 0.0.38 to 0.0.39
|
|
||||||
* @waku/enr bumped from 0.0.32 to 0.0.33
|
|
||||||
* @waku/interfaces bumped from 0.0.33 to 0.0.34
|
|
||||||
* @waku/proto bumped from ^0.0.13 to ^0.0.14
|
|
||||||
* @waku/utils bumped from 0.0.26 to 0.0.27
|
|
||||||
|
|
||||||
## [0.0.11](https://github.com/waku-org/js-waku/compare/discovery-v0.0.10...discovery-v0.0.11) (2025-08-14)
|
## [0.0.11](https://github.com/waku-org/js-waku/compare/discovery-v0.0.10...discovery-v0.0.11) (2025-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@waku/discovery",
|
"name": "@waku/discovery",
|
||||||
"version": "0.0.13",
|
"version": "0.0.11",
|
||||||
"description": "Contains various discovery mechanisms: DNS Discovery (EIP-1459, Peer Exchange, Local Peer Cache Discovery.",
|
"description": "Contains various discovery mechanisms: DNS Discovery (EIP-1459, Peer Exchange, Local Peer Cache Discovery.",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@ -15,7 +15,7 @@
|
|||||||
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/discovery#readme",
|
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/discovery#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/waku-org/js-waku.git"
|
"url": "https://github.com/waku-org/js-waku.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/waku-org/js-waku/issues"
|
"url": "https://github.com/waku-org/js-waku/issues"
|
||||||
@ -51,11 +51,11 @@
|
|||||||
"node": ">=22"
|
"node": ">=22"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waku/core": "0.0.40",
|
"@waku/core": "0.0.38",
|
||||||
"@waku/enr": "0.0.33",
|
"@waku/enr": "0.0.32",
|
||||||
"@waku/interfaces": "0.0.34",
|
"@waku/interfaces": "0.0.33",
|
||||||
"@waku/proto": "^0.0.15",
|
"@waku/proto": "^0.0.13",
|
||||||
"@waku/utils": "0.0.27",
|
"@waku/utils": "0.0.26",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"dns-over-http-resolver": "^3.0.8",
|
"dns-over-http-resolver": "^3.0.8",
|
||||||
"hi-base32": "^0.5.1",
|
"hi-base32": "^0.5.1",
|
||||||
|
|||||||
@ -99,17 +99,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
* devDependencies
|
* devDependencies
|
||||||
* @waku/interfaces bumped from 0.0.27 to 0.0.28
|
* @waku/interfaces bumped from 0.0.27 to 0.0.28
|
||||||
|
|
||||||
## [0.0.33](https://github.com/waku-org/js-waku/compare/enr-v0.0.32...enr-v0.0.33) (2025-09-20)
|
|
||||||
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
* The following workspace dependencies were updated
|
|
||||||
* dependencies
|
|
||||||
* @waku/utils bumped from 0.0.26 to 0.0.27
|
|
||||||
* devDependencies
|
|
||||||
* @waku/interfaces bumped from 0.0.33 to 0.0.34
|
|
||||||
|
|
||||||
## [0.0.32](https://github.com/waku-org/js-waku/compare/enr-v0.0.31...enr-v0.0.32) (2025-08-14)
|
## [0.0.32](https://github.com/waku-org/js-waku/compare/enr-v0.0.31...enr-v0.0.32) (2025-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@waku/enr",
|
"name": "@waku/enr",
|
||||||
"version": "0.0.33",
|
"version": "0.0.32",
|
||||||
"description": "ENR (EIP-778) for Waku",
|
"description": "ENR (EIP-778) for Waku",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@ -15,7 +15,7 @@
|
|||||||
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/enr#readme",
|
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/enr#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/waku-org/js-waku.git"
|
"url": "https://github.com/waku-org/js-waku.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/waku-org/js-waku/issues"
|
"url": "https://github.com/waku-org/js-waku/issues"
|
||||||
@ -56,7 +56,7 @@
|
|||||||
"@libp2p/peer-id": "5.1.7",
|
"@libp2p/peer-id": "5.1.7",
|
||||||
"@multiformats/multiaddr": "^12.0.0",
|
"@multiformats/multiaddr": "^12.0.0",
|
||||||
"@noble/secp256k1": "^1.7.1",
|
"@noble/secp256k1": "^1.7.1",
|
||||||
"@waku/utils": "0.0.27",
|
"@waku/utils": "0.0.26",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"js-sha3": "^0.9.2"
|
"js-sha3": "^0.9.2"
|
||||||
},
|
},
|
||||||
@ -67,7 +67,7 @@
|
|||||||
"@types/chai": "^4.3.11",
|
"@types/chai": "^4.3.11",
|
||||||
"@types/mocha": "^10.0.6",
|
"@types/mocha": "^10.0.6",
|
||||||
"@waku/build-utils": "*",
|
"@waku/build-utils": "*",
|
||||||
"@waku/interfaces": "0.0.34",
|
"@waku/interfaces": "0.0.33",
|
||||||
"chai": "^4.3.10",
|
"chai": "^4.3.10",
|
||||||
"cspell": "^8.6.1",
|
"cspell": "^8.6.1",
|
||||||
"fast-check": "^3.19.0",
|
"fast-check": "^3.19.0",
|
||||||
|
|||||||
34
packages/headless-tests/.eslintrc.cjs
Normal file
34
packages/headless-tests/.eslintrc.cjs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
env: {
|
||||||
|
browser: true,
|
||||||
|
node: true,
|
||||||
|
es2021: true
|
||||||
|
},
|
||||||
|
plugins: ["import"],
|
||||||
|
extends: ["eslint:recommended"],
|
||||||
|
parserOptions: {
|
||||||
|
ecmaVersion: 2022,
|
||||||
|
sourceType: "module"
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// Disable rules that might cause issues with this package
|
||||||
|
"no-undef": "off"
|
||||||
|
},
|
||||||
|
ignorePatterns: [
|
||||||
|
"node_modules",
|
||||||
|
"build",
|
||||||
|
"coverage"
|
||||||
|
],
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ["*.spec.ts", "**/test_utils/*.ts", "*.js", "*.cjs"],
|
||||||
|
rules: {
|
||||||
|
"@typescript-eslint/no-non-null-assertion": "off",
|
||||||
|
"@typescript-eslint/no-explicit-any": "off",
|
||||||
|
"no-console": "off",
|
||||||
|
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
23
packages/headless-tests/README.md
Normal file
23
packages/headless-tests/README.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Waku Headless Tests
|
||||||
|
|
||||||
|
This package contains a minimal browser application used for testing the Waku SDK in a browser environment. It is used by the browser-tests package to run end-to-end tests on the SDK.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Build the app
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Start the app
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
This will start a server on port 8080 by default.
|
||||||
|
|
||||||
|
## Integration with browser-tests
|
||||||
|
|
||||||
|
This package is designed to be used with the browser-tests package to run end-to-end tests on the SDK. It exposes the Waku API via a global object in the browser.
|
||||||
BIN
packages/headless-tests/favicon.ico
Normal file
BIN
packages/headless-tests/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
BIN
packages/headless-tests/favicon.png
Normal file
BIN
packages/headless-tests/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
50
packages/headless-tests/index.html
Normal file
50
packages/headless-tests/index.html
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||||
|
<title>Headless</title>
|
||||||
|
<link rel="stylesheet" href="./style.css" />
|
||||||
|
<link rel="apple-touch-icon" href="./favicon.png" />
|
||||||
|
<link rel="manifest" href="./manifest.json" />
|
||||||
|
<link rel="icon" href="./favicon.ico" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="state"></div>
|
||||||
|
<div class="content">
|
||||||
|
<div class="header">
|
||||||
|
<h3>Status: <span id="status"></span></h3>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Peer's information</summary>
|
||||||
|
|
||||||
|
<h4>Content topic</h4>
|
||||||
|
<p id="contentTopic"></p>
|
||||||
|
|
||||||
|
<h4>Local Peer Id</h4>
|
||||||
|
<p id="localPeerId"></p>
|
||||||
|
|
||||||
|
<h4>Remote Peer Id</h4>
|
||||||
|
<p id="remotePeerId"></p>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="messages"></div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<div class="inputArea">
|
||||||
|
<input type="text" id="nickText" placeholder="Nickname" />
|
||||||
|
<textarea id="messageText" placeholder="Message"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="controls">
|
||||||
|
<button id="send">Send</button>
|
||||||
|
<button id="exit">Exit chat</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="./build/bundle.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
14
packages/headless-tests/index.js
Normal file
14
packages/headless-tests/index.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
import { API } from "../browser-tests/src/api/shared.ts";
|
||||||
|
|
||||||
|
runApp().catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function runApp() {
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
// Expose shared API functions for browser communication
|
||||||
|
window.wakuAPI = API;
|
||||||
|
window.subscriptions = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
19
packages/headless-tests/manifest.json
Normal file
19
packages/headless-tests/manifest.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "Light Chat",
|
||||||
|
"description": "Send messages between several users (or just one) using light client targeted protocols.",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.ico",
|
||||||
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
|
"type": "image/x-icon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "favicon.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "192x192"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"display": "standalone",
|
||||||
|
"theme_color": "#ffffff",
|
||||||
|
"background_color": "#ffffff"
|
||||||
|
}
|
||||||
27
packages/headless-tests/package.json
Normal file
27
packages/headless-tests/package.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "@waku/headless-tests",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"homepage": "/headless",
|
||||||
|
"type": "module",
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.24.0",
|
||||||
|
"@babel/preset-env": "^7.24.0",
|
||||||
|
"@babel/preset-typescript": "^7.23.3",
|
||||||
|
"babel-loader": "^9.1.3",
|
||||||
|
"filter-obj": "^2.0.2",
|
||||||
|
"it-first": "^3.0.9",
|
||||||
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
||||||
|
"serve": "^14.1.2",
|
||||||
|
"webpack": "^5.99.5",
|
||||||
|
"webpack-cli": "^5.1.4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@waku/sdk": "^0.0.30"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "serve .",
|
||||||
|
"build": "webpack",
|
||||||
|
"format": "eslint --fix webpack.config.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
153
packages/headless-tests/style.css
Normal file
153
packages/headless-tests/style.css
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
word-wrap: break-word;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-size: 16px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10px;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
details {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
details p {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary {
|
||||||
|
cursor: pointer;
|
||||||
|
max-width: 100%;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
font-weight: 300;
|
||||||
|
}
|
||||||
|
|
||||||
|
input, textarea {
|
||||||
|
line-height: 1rem;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
min-height: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
width: 800px;
|
||||||
|
min-width: 300px;
|
||||||
|
max-width: 800px;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messages {
|
||||||
|
overflow-y: scroll;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message + .message {
|
||||||
|
margin-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message :first-child {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message p + p {
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.message span {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inputArea {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
margin-top: 10px;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls button {
|
||||||
|
flex-grow: 1;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#send {
|
||||||
|
background-color: #32d1a0;
|
||||||
|
border: none;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
#send:hover {
|
||||||
|
background-color: #3abd96;
|
||||||
|
}
|
||||||
|
#send:active {
|
||||||
|
background-color: #3ba183;
|
||||||
|
}
|
||||||
|
|
||||||
|
#exit {
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
background-color: #ff3a31;
|
||||||
|
}
|
||||||
|
#exit:hover {
|
||||||
|
background-color: #e4423a;
|
||||||
|
}
|
||||||
|
#exit:active {
|
||||||
|
background-color: #c84740;
|
||||||
|
}
|
||||||
|
|
||||||
|
.success {
|
||||||
|
color: #3ba183;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress {
|
||||||
|
color: #9ea13b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.terminated {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: #c84740;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
flex-direction: column;
|
||||||
|
align-self: flex-end;
|
||||||
|
}
|
||||||
14
packages/headless-tests/tsconfig.json
Normal file
14
packages/headless-tests/tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2020",
|
||||||
|
"module": "commonjs",
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": false,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"**/*.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
47
packages/headless-tests/webpack.config.js
Normal file
47
packages/headless-tests/webpack.config.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
/**
|
||||||
|
* This webpack configuration file uses ES Module syntax.
|
||||||
|
*/
|
||||||
|
import path from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
export default {
|
||||||
|
entry: "./index.js",
|
||||||
|
output: {
|
||||||
|
filename: "bundle.js",
|
||||||
|
path: path.resolve(__dirname, "build")
|
||||||
|
},
|
||||||
|
mode: "production",
|
||||||
|
target: "web",
|
||||||
|
plugins: [new NodePolyfillPlugin()],
|
||||||
|
resolve: {
|
||||||
|
extensions: [".js", ".ts", ".tsx", ".jsx"],
|
||||||
|
fallback: {
|
||||||
|
fs: false,
|
||||||
|
net: false,
|
||||||
|
tls: false
|
||||||
|
},
|
||||||
|
alias: {
|
||||||
|
// Create an alias to easily import from src
|
||||||
|
"@src": path.resolve(__dirname, "../src")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.(js|ts|tsx)$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: {
|
||||||
|
loader: "babel-loader",
|
||||||
|
options: {
|
||||||
|
presets: ["@babel/preset-env", "@babel/preset-typescript"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -5,17 +5,6 @@ All notable changes to this project will be documented in this file.
|
|||||||
The file is maintained by [Release Please](https://github.com/googleapis/release-please) based on [Conventional Commits](https://www.conventionalcommits.org) specification,
|
The file is maintained by [Release Please](https://github.com/googleapis/release-please) based on [Conventional Commits](https://www.conventionalcommits.org) specification,
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [0.0.34](https://github.com/waku-org/js-waku/compare/interfaces-v0.0.33...interfaces-v0.0.34) (2025-09-20)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* Add start/stop to filter ([#2592](https://github.com/waku-org/js-waku/issues/2592)) ([2fba052](https://github.com/waku-org/js-waku/commit/2fba052b8b98cb64f6383de95d01b33beb771448))
|
|
||||||
* Expose message hash from IDecodedMessage ([#2578](https://github.com/waku-org/js-waku/issues/2578)) ([836d6b8](https://github.com/waku-org/js-waku/commit/836d6b8793a5124747684f6ea76b6dd47c73048b))
|
|
||||||
* Implement lp-v3 error codes with backwards compatibility ([#2501](https://github.com/waku-org/js-waku/issues/2501)) ([1625302](https://github.com/waku-org/js-waku/commit/16253026c6e30052d87d9975b58480951de469d8))
|
|
||||||
* Query on connect ([#2602](https://github.com/waku-org/js-waku/issues/2602)) ([8542d04](https://github.com/waku-org/js-waku/commit/8542d04bf5c9472f955ef8c9e5bc9e89c70f4738))
|
|
||||||
* StoreConnect events ([#2601](https://github.com/waku-org/js-waku/issues/2601)) ([0dfbcf6](https://github.com/waku-org/js-waku/commit/0dfbcf6b6bd9225dcb0dec540aeb1eb2703c8397))
|
|
||||||
|
|
||||||
## [0.0.33](https://github.com/waku-org/js-waku/compare/interfaces-v0.0.32...interfaces-v0.0.33) (2025-08-14)
|
## [0.0.33](https://github.com/waku-org/js-waku/compare/interfaces-v0.0.32...interfaces-v0.0.33) (2025-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@waku/interfaces",
|
"name": "@waku/interfaces",
|
||||||
"version": "0.0.34",
|
"version": "0.0.33",
|
||||||
"description": "Definition of Waku interfaces",
|
"description": "Definition of Waku interfaces",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@ -15,7 +15,7 @@
|
|||||||
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/interfaces#readme",
|
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/interfaces#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/waku-org/js-waku.git"
|
"url": "https://github.com/waku-org/js-waku.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/waku-org/js-waku/issues"
|
"url": "https://github.com/waku-org/js-waku/issues"
|
||||||
|
|||||||
@ -4,16 +4,6 @@ import type { Callback } from "./protocols.js";
|
|||||||
export type IFilter = {
|
export type IFilter = {
|
||||||
readonly multicodec: string;
|
readonly multicodec: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the filter protocol.
|
|
||||||
*/
|
|
||||||
start(): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stops the filter protocol.
|
|
||||||
*/
|
|
||||||
stop(): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribes to messages that match the filtering criteria defined in the specified decoders.
|
* Subscribes to messages that match the filtering criteria defined in the specified decoders.
|
||||||
* Executes a callback upon receiving each message.
|
* Executes a callback upon receiving each message.
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
import { IEncoder, IMessage } from "./message.js";
|
import type { ISender, ISendOptions } from "./sender.js";
|
||||||
import { LightPushSDKResult } from "./protocols.js";
|
|
||||||
import type { ISendOptions } from "./sender.js";
|
|
||||||
|
|
||||||
export type LightPushProtocolOptions = ISendOptions & {
|
export type LightPushProtocolOptions = ISendOptions & {
|
||||||
/**
|
/**
|
||||||
@ -17,40 +15,8 @@ export type LightPushProtocolOptions = ISendOptions & {
|
|||||||
numPeersToUse?: number;
|
numPeersToUse?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ILightPush = {
|
export type ILightPush = ISender & {
|
||||||
readonly multicodec: string[];
|
readonly multicodec: string;
|
||||||
start: () => void;
|
start: () => void;
|
||||||
stop: () => void;
|
stop: () => void;
|
||||||
send: (
|
|
||||||
encoder: IEncoder,
|
|
||||||
message: IMessage,
|
|
||||||
options?: ISendOptions
|
|
||||||
) => Promise<LightPushSDKResult>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export enum LightPushStatusCode {
|
|
||||||
SUCCESS = 200,
|
|
||||||
BAD_REQUEST = 400,
|
|
||||||
PAYLOAD_TOO_LARGE = 413,
|
|
||||||
INVALID_MESSAGE = 420,
|
|
||||||
UNSUPPORTED_TOPIC = 421,
|
|
||||||
TOO_MANY_REQUESTS = 429,
|
|
||||||
INTERNAL_ERROR = 500,
|
|
||||||
UNAVAILABLE = 503,
|
|
||||||
NO_RLN_PROOF = 504,
|
|
||||||
NO_PEERS = 505
|
|
||||||
}
|
|
||||||
|
|
||||||
export const StatusDescriptions: Record<LightPushStatusCode, string> = {
|
|
||||||
[LightPushStatusCode.SUCCESS]: "Message sent successfully",
|
|
||||||
[LightPushStatusCode.BAD_REQUEST]: "Bad request format",
|
|
||||||
[LightPushStatusCode.PAYLOAD_TOO_LARGE]:
|
|
||||||
"Message payload exceeds maximum size",
|
|
||||||
[LightPushStatusCode.INVALID_MESSAGE]: "Message validation failed",
|
|
||||||
[LightPushStatusCode.UNSUPPORTED_TOPIC]: "Unsupported pubsub topic",
|
|
||||||
[LightPushStatusCode.TOO_MANY_REQUESTS]: "Rate limit exceeded",
|
|
||||||
[LightPushStatusCode.INTERNAL_ERROR]: "Internal server error",
|
|
||||||
[LightPushStatusCode.UNAVAILABLE]: "Service temporarily unavailable",
|
|
||||||
[LightPushStatusCode.NO_RLN_PROOF]: "RLN proof generation failed",
|
|
||||||
[LightPushStatusCode.NO_PEERS]: "No relay peers available"
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -20,8 +20,6 @@ export interface IDecodedMessage {
|
|||||||
rateLimitProof: IRateLimitProof | undefined;
|
rateLimitProof: IRateLimitProof | undefined;
|
||||||
ephemeral: boolean | undefined;
|
ephemeral: boolean | undefined;
|
||||||
meta: Uint8Array | undefined;
|
meta: Uint8Array | undefined;
|
||||||
hash: Uint8Array;
|
|
||||||
hashStr: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IRlnMessage extends IDecodedMessage {
|
export interface IRlnMessage extends IDecodedMessage {
|
||||||
|
|||||||
@ -130,123 +130,117 @@ export type Callback<T extends IDecodedMessage> = (
|
|||||||
msg: T
|
msg: T
|
||||||
) => void | Promise<void>;
|
) => void | Promise<void>;
|
||||||
|
|
||||||
export enum LightPushError {
|
export enum ProtocolError {
|
||||||
|
//
|
||||||
|
// GENERAL ERRORS SECTION
|
||||||
|
//
|
||||||
|
/**
|
||||||
|
* Could not determine the origin of the fault. Best to check connectivity and try again
|
||||||
|
* */
|
||||||
GENERIC_FAIL = "Generic error",
|
GENERIC_FAIL = "Generic error",
|
||||||
DECODE_FAILED = "Failed to decode",
|
|
||||||
NO_PEER_AVAILABLE = "No peer available",
|
|
||||||
NO_STREAM_AVAILABLE = "No stream available",
|
|
||||||
NO_RESPONSE = "No response received",
|
|
||||||
STREAM_ABORTED = "Stream aborted",
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The remote peer rejected the message. Information provided by the remote peer
|
||||||
|
* is logged. Review message validity, or mitigation for `NO_PEER_AVAILABLE`
|
||||||
|
* or `DECODE_FAILED` can be used.
|
||||||
|
*/
|
||||||
|
REMOTE_PEER_REJECTED = "Remote peer rejected",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Failure to protobuf decode the message. May be due to a remote peer issue,
|
||||||
|
* ensuring that messages are sent via several peer enable mitigation of this error.
|
||||||
|
*/
|
||||||
|
DECODE_FAILED = "Failed to decode",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Failure to find a peer with suitable protocols. This may due to a connection issue.
|
||||||
|
* Mitigation can be: retrying after a given time period, display connectivity issue
|
||||||
|
* to user or listening for `peer:connected:bootstrap` or `peer:connected:peer-exchange`
|
||||||
|
* on the connection manager before retrying.
|
||||||
|
*/
|
||||||
|
NO_PEER_AVAILABLE = "No peer available",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Failure to find a stream to the peer. This may be because the connection with the peer is not still alive.
|
||||||
|
* Mitigation can be: retrying after a given time period, or mitigation for `NO_PEER_AVAILABLE` can be used.
|
||||||
|
*/
|
||||||
|
NO_STREAM_AVAILABLE = "No stream available",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The remote peer did not behave as expected. Mitigation for `NO_PEER_AVAILABLE`
|
||||||
|
* or `DECODE_FAILED` can be used.
|
||||||
|
*/
|
||||||
|
NO_RESPONSE = "No response received",
|
||||||
|
|
||||||
|
//
|
||||||
|
// SEND ERRORS SECTION
|
||||||
|
//
|
||||||
|
/**
|
||||||
|
* Failure to protobuf encode the message. This is not recoverable and needs
|
||||||
|
* further investigation.
|
||||||
|
*/
|
||||||
ENCODE_FAILED = "Failed to encode",
|
ENCODE_FAILED = "Failed to encode",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The message payload is empty, making the message invalid. Ensure that a non-empty
|
||||||
|
* payload is set on the outgoing message.
|
||||||
|
*/
|
||||||
EMPTY_PAYLOAD = "Payload is empty",
|
EMPTY_PAYLOAD = "Payload is empty",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The message size is above the maximum message size allowed on the Waku Network.
|
||||||
|
* Compressing the message or using an alternative strategy for large messages is recommended.
|
||||||
|
*/
|
||||||
SIZE_TOO_BIG = "Size is too big",
|
SIZE_TOO_BIG = "Size is too big",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The PubsubTopic passed to the send function is not configured on the Waku node.
|
||||||
|
* Please ensure that the PubsubTopic is used when initializing the Waku node.
|
||||||
|
*/
|
||||||
TOPIC_NOT_CONFIGURED = "Topic not configured",
|
TOPIC_NOT_CONFIGURED = "Topic not configured",
|
||||||
RLN_PROOF_GENERATION = "Proof generation failed",
|
|
||||||
REMOTE_PEER_REJECTED = "Remote peer rejected",
|
|
||||||
|
|
||||||
BAD_REQUEST = "Bad request format",
|
/**
|
||||||
PAYLOAD_TOO_LARGE = "Message payload exceeds maximum size",
|
* Fails when
|
||||||
INVALID_MESSAGE = "Message validation failed",
|
*/
|
||||||
UNSUPPORTED_TOPIC = "Unsupported pubsub topic",
|
|
||||||
TOO_MANY_REQUESTS = "Rate limit exceeded",
|
|
||||||
INTERNAL_ERROR = "Internal server error",
|
|
||||||
UNAVAILABLE = "Service temporarily unavailable",
|
|
||||||
NO_RLN_PROOF = "RLN proof generation failed",
|
|
||||||
NO_PEERS = "No relay peers available"
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum FilterError {
|
|
||||||
// General errors
|
|
||||||
GENERIC_FAIL = "Generic error",
|
|
||||||
DECODE_FAILED = "Failed to decode",
|
|
||||||
NO_PEER_AVAILABLE = "No peer available",
|
|
||||||
NO_STREAM_AVAILABLE = "No stream available",
|
|
||||||
NO_RESPONSE = "No response received",
|
|
||||||
STREAM_ABORTED = "Stream aborted",
|
STREAM_ABORTED = "Stream aborted",
|
||||||
|
|
||||||
// Filter specific errors
|
/**
|
||||||
REMOTE_PEER_REJECTED = "Remote peer rejected",
|
* General proof generation error message.
|
||||||
TOPIC_NOT_CONFIGURED = "Topic not configured",
|
* nwaku: https://github.com/waku-org/nwaku/blob/c3cb06ac6c03f0f382d3941ea53b330f6a8dd127/waku/waku_rln_relay/group_manager/group_manager_base.nim#L201C19-L201C42
|
||||||
SUBSCRIPTION_FAILED = "Subscription failed",
|
*/
|
||||||
UNSUBSCRIBE_FAILED = "Unsubscribe failed",
|
RLN_PROOF_GENERATION = "Proof generation failed",
|
||||||
PING_FAILED = "Ping failed",
|
|
||||||
|
//
|
||||||
|
// RECEIVE ERRORS SECTION
|
||||||
|
//
|
||||||
|
/**
|
||||||
|
* The pubsub topic configured on the decoder does not match the pubsub topic setup on the protocol.
|
||||||
|
* Ensure that the pubsub topic used for decoder creation is the same as the one used for protocol.
|
||||||
|
*/
|
||||||
TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
|
TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
|
||||||
INVALID_DECODER_TOPICS = "Invalid decoder topics",
|
|
||||||
SUBSCRIPTION_LIMIT_EXCEEDED = "Subscription limit exceeded",
|
/**
|
||||||
INVALID_CONTENT_TOPIC = "Invalid content topic",
|
* The topics passed in the decoders do not match each other, or don't exist at all.
|
||||||
PUSH_MESSAGE_FAILED = "Push message failed",
|
* Ensure that all the pubsub topics used in the decoders are valid and match each other.
|
||||||
EMPTY_MESSAGE = "Empty message received",
|
*/
|
||||||
MISSING_PUBSUB_TOPIC = "Pubsub topic missing from push message"
|
INVALID_DECODER_TOPICS = "Invalid decoder topics"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LightPushFailure {
|
export interface Failure {
|
||||||
error: LightPushError;
|
error: ProtocolError;
|
||||||
peerId?: PeerId;
|
peerId?: PeerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FilterFailure {
|
export type CoreProtocolResult = ThisOrThat<
|
||||||
error: FilterError;
|
|
||||||
peerId?: PeerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type LightPushCoreResult = ThisOrThat<
|
|
||||||
"success",
|
"success",
|
||||||
PeerId,
|
PeerId,
|
||||||
"failure",
|
"failure",
|
||||||
LightPushFailure
|
Failure
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export type FilterCoreResult = ThisOrThat<
|
|
||||||
"success",
|
|
||||||
PeerId,
|
|
||||||
"failure",
|
|
||||||
FilterFailure
|
|
||||||
>;
|
|
||||||
|
|
||||||
export type LightPushSDKResult = ThisAndThat<
|
|
||||||
"successes",
|
|
||||||
PeerId[],
|
|
||||||
"failures",
|
|
||||||
LightPushFailure[]
|
|
||||||
>;
|
|
||||||
|
|
||||||
export type FilterSDKResult = ThisAndThat<
|
|
||||||
"successes",
|
|
||||||
PeerId[],
|
|
||||||
"failures",
|
|
||||||
FilterFailure[]
|
|
||||||
>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated replace usage by specific result types
|
|
||||||
*/
|
|
||||||
export type SDKProtocolResult = ThisAndThat<
|
export type SDKProtocolResult = ThisAndThat<
|
||||||
"successes",
|
"successes",
|
||||||
PeerId[],
|
PeerId[],
|
||||||
"failures",
|
"failures",
|
||||||
Array<{
|
Failure[]
|
||||||
error: ProtocolError;
|
|
||||||
peerId?: PeerId;
|
|
||||||
}>
|
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated replace usage by specific result types
|
|
||||||
*/
|
|
||||||
export enum ProtocolError {
|
|
||||||
GENERIC_FAIL = "Generic error",
|
|
||||||
REMOTE_PEER_REJECTED = "Remote peer rejected",
|
|
||||||
DECODE_FAILED = "Failed to decode",
|
|
||||||
NO_PEER_AVAILABLE = "No peer available",
|
|
||||||
NO_STREAM_AVAILABLE = "No stream available",
|
|
||||||
NO_RESPONSE = "No response received",
|
|
||||||
ENCODE_FAILED = "Failed to encode",
|
|
||||||
EMPTY_PAYLOAD = "Payload is empty",
|
|
||||||
SIZE_TOO_BIG = "Size is too big",
|
|
||||||
TOPIC_NOT_CONFIGURED = "Topic not configured",
|
|
||||||
STREAM_ABORTED = "Stream aborted",
|
|
||||||
RLN_PROOF_GENERATION = "Proof generation failed",
|
|
||||||
TOPIC_DECODER_MISMATCH = "Topic decoder mismatch",
|
|
||||||
INVALID_DECODER_TOPICS = "Invalid decoder topics"
|
|
||||||
}
|
|
||||||
|
|||||||
@ -16,7 +16,6 @@ export interface IRelayAPI {
|
|||||||
readonly pubsubTopics: Set<PubsubTopic>;
|
readonly pubsubTopics: Set<PubsubTopic>;
|
||||||
readonly gossipSub: GossipSub;
|
readonly gossipSub: GossipSub;
|
||||||
start: () => Promise<void>;
|
start: () => Promise<void>;
|
||||||
stop: () => Promise<void>;
|
|
||||||
waitForPeers: () => Promise<void>;
|
waitForPeers: () => Promise<void>;
|
||||||
getMeshPeers: (topic?: TopicStr) => PeerIdStr[];
|
getMeshPeers: (topic?: TopicStr) => PeerIdStr[];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { IEncoder, IMessage } from "./message.js";
|
import type { IEncoder, IMessage } from "./message.js";
|
||||||
import { LightPushSDKResult } from "./protocols.js";
|
import { SDKProtocolResult } from "./protocols.js";
|
||||||
|
|
||||||
export type ISendOptions = {
|
export type ISendOptions = {
|
||||||
/**
|
/**
|
||||||
@ -13,13 +13,6 @@ export type ISendOptions = {
|
|||||||
* @default 3
|
* @default 3
|
||||||
*/
|
*/
|
||||||
maxAttempts?: number;
|
maxAttempts?: number;
|
||||||
|
|
||||||
/**
|
|
||||||
* Use v2 of the light push protocol.
|
|
||||||
* This parameter will be removed in the future.
|
|
||||||
* @default false
|
|
||||||
*/
|
|
||||||
useLegacy?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ISender {
|
export interface ISender {
|
||||||
@ -27,5 +20,5 @@ export interface ISender {
|
|||||||
encoder: IEncoder,
|
encoder: IEncoder,
|
||||||
message: IMessage,
|
message: IMessage,
|
||||||
sendOptions?: ISendOptions
|
sendOptions?: ISendOptions
|
||||||
) => Promise<LightPushSDKResult>;
|
) => Promise<SDKProtocolResult>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import type { PeerId } from "@libp2p/interface";
|
|
||||||
|
|
||||||
import type { IDecodedMessage, IDecoder } from "./message.js";
|
import type { IDecodedMessage, IDecoder } from "./message.js";
|
||||||
|
|
||||||
export type StoreCursor = Uint8Array;
|
export type StoreCursor = Uint8Array;
|
||||||
@ -75,31 +73,11 @@ export type QueryRequestParams = {
|
|||||||
* @default undefined
|
* @default undefined
|
||||||
*/
|
*/
|
||||||
paginationLimit?: number;
|
paginationLimit?: number;
|
||||||
|
|
||||||
/**
|
|
||||||
* The service node to use for queries. Will fail if:
|
|
||||||
* - this peer is not in the peer store.
|
|
||||||
* - we are not connected to this peer
|
|
||||||
* No fallback is done. Overrides any other peer selection option.
|
|
||||||
*
|
|
||||||
* Expected to be used with [[PeerManagerEventNames.StoreConnect]] so that
|
|
||||||
* we know we are connected to this peer before doing the store query.
|
|
||||||
*
|
|
||||||
* Only use if you know what you are doing.
|
|
||||||
*/
|
|
||||||
peerId?: PeerId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An optional AbortSignal to cancel the query.
|
|
||||||
* When the signal is aborted, the query will stop processing and return early.
|
|
||||||
*/
|
|
||||||
abortSignal?: AbortSignal;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IStore = {
|
export type IStore = {
|
||||||
readonly multicodec: string;
|
readonly multicodec: string;
|
||||||
|
|
||||||
stop(): void;
|
|
||||||
createCursor(message: IDecodedMessage): StoreCursor;
|
createCursor(message: IDecodedMessage): StoreCursor;
|
||||||
queryGenerator: <T extends IDecodedMessage>(
|
queryGenerator: <T extends IDecodedMessage>(
|
||||||
decoders: IDecoder<T>[],
|
decoders: IDecoder<T>[],
|
||||||
|
|||||||
@ -25,33 +25,28 @@ export type CreateEncoderParams = CreateDecoderParams & {
|
|||||||
ephemeral?: boolean;
|
ephemeral?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum WakuEvent {
|
|
||||||
Connection = "waku:connection",
|
|
||||||
Health = "waku:health"
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IWakuEvents {
|
export interface IWakuEvents {
|
||||||
/**
|
/**
|
||||||
* Emitted when a connection is established or lost.
|
* Emitted when a connection is established or lost.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* waku.addEventListener(WakuEvent.Connection, (event) => {
|
* waku.addEventListener("waku:connection", (event) => {
|
||||||
* console.log(event.detail); // true if connected, false if disconnected
|
* console.log(event.detail); // true if connected, false if disconnected
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
[WakuEvent.Connection]: CustomEvent<boolean>;
|
"waku:connection": CustomEvent<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted when the health status changes.
|
* Emitted when the health status changes.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* waku.addEventListener(WakuEvent.Health, (event) => {
|
* waku.addEventListener("waku:health", (event) => {
|
||||||
* console.log(event.detail); // 'Unhealthy', 'MinimallyHealthy', or 'SufficientlyHealthy'
|
* console.log(event.detail); // 'Unhealthy', 'MinimallyHealthy', or 'SufficientlyHealthy'
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
[WakuEvent.Health]: CustomEvent<HealthStatus>;
|
"waku:health": CustomEvent<HealthStatus>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IWakuEventEmitter = TypedEventEmitter<IWakuEvents>;
|
export type IWakuEventEmitter = TypedEventEmitter<IWakuEvents>;
|
||||||
@ -66,12 +61,12 @@ export interface IWaku {
|
|||||||
/**
|
/**
|
||||||
* Emits events related to the Waku node.
|
* Emits events related to the Waku node.
|
||||||
* Those are:
|
* Those are:
|
||||||
* - WakuEvent.Connection
|
* - "waku:connection"
|
||||||
* - WakuEvent.Health
|
* - "waku:health"
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* waku.events.addEventListener(WakuEvent.Connection, (event) => {
|
* waku.events.addEventListener("waku:connection", (event) => {
|
||||||
* console.log(event.detail); // true if connected, false if disconnected
|
* console.log(event.detail); // true if connected, false if disconnected
|
||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
|
|||||||
@ -101,28 +101,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
* @waku/interfaces bumped from 0.0.27 to 0.0.28
|
* @waku/interfaces bumped from 0.0.27 to 0.0.28
|
||||||
* @waku/utils bumped from 0.0.20 to 0.0.21
|
* @waku/utils bumped from 0.0.20 to 0.0.21
|
||||||
|
|
||||||
## [0.0.38](https://github.com/waku-org/js-waku/compare/message-encryption-v0.0.37...message-encryption-v0.0.38) (2025-10-31)
|
|
||||||
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
* The following workspace dependencies were updated
|
|
||||||
* dependencies
|
|
||||||
* @waku/core bumped from 0.0.39 to 0.0.40
|
|
||||||
* @waku/proto bumped from 0.0.14 to 0.0.15
|
|
||||||
|
|
||||||
## [0.0.37](https://github.com/waku-org/js-waku/compare/message-encryption-v0.0.36...message-encryption-v0.0.37) (2025-09-20)
|
|
||||||
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
* The following workspace dependencies were updated
|
|
||||||
* dependencies
|
|
||||||
* @waku/core bumped from 0.0.38 to 0.0.39
|
|
||||||
* @waku/interfaces bumped from 0.0.33 to 0.0.34
|
|
||||||
* @waku/proto bumped from 0.0.13 to 0.0.14
|
|
||||||
* @waku/utils bumped from 0.0.26 to 0.0.27
|
|
||||||
|
|
||||||
## [0.0.36](https://github.com/waku-org/js-waku/compare/message-encryption-v0.0.35...message-encryption-v0.0.36) (2025-08-14)
|
## [0.0.36](https://github.com/waku-org/js-waku/compare/message-encryption-v0.0.35...message-encryption-v0.0.36) (2025-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@waku/message-encryption",
|
"name": "@waku/message-encryption",
|
||||||
"version": "0.0.38",
|
"version": "0.0.36",
|
||||||
"description": "Waku Message Payload Encryption",
|
"description": "Waku Message Payload Encryption",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@ -36,7 +36,7 @@
|
|||||||
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/message-encryption#readme",
|
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/message-encryption#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/waku-org/js-waku.git"
|
"url": "https://github.com/waku-org/js-waku.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/waku-org/js-waku/issues"
|
"url": "https://github.com/waku-org/js-waku/issues"
|
||||||
@ -76,10 +76,10 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/secp256k1": "^1.7.1",
|
"@noble/secp256k1": "^1.7.1",
|
||||||
"@waku/core": "0.0.40",
|
"@waku/core": "0.0.38",
|
||||||
"@waku/interfaces": "0.0.34",
|
"@waku/interfaces": "0.0.33",
|
||||||
"@waku/proto": "0.0.15",
|
"@waku/proto": "0.0.13",
|
||||||
"@waku/utils": "0.0.27",
|
"@waku/utils": "0.0.26",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"js-sha3": "^0.9.2",
|
"js-sha3": "^0.9.2",
|
||||||
"uint8arrays": "^5.0.1"
|
"uint8arrays": "^5.0.1"
|
||||||
|
|||||||
@ -1,28 +1,5 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [0.0.15](https://github.com/waku-org/js-waku/compare/proto-v0.0.14...proto-v0.0.15) (2025-10-31)
|
|
||||||
|
|
||||||
|
|
||||||
### ⚠ BREAKING CHANGES
|
|
||||||
|
|
||||||
* SDS lamport timestamp overflow and keep it to current time ([#2664](https://github.com/waku-org/js-waku/issues/2664))
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* Add SDS-Repair (SDS-R) to the SDS implementation ([#2698](https://github.com/waku-org/js-waku/issues/2698)) ([5334a7f](https://github.com/waku-org/js-waku/commit/5334a7fcc91544d33294beaad9b45e641ecf404d))
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* SDS lamport timestamp overflow and keep it to current time ([#2664](https://github.com/waku-org/js-waku/issues/2664)) ([c0ecb6a](https://github.com/waku-org/js-waku/commit/c0ecb6abbaae0544f352b89293f59f274600a916))
|
|
||||||
|
|
||||||
## [0.0.14](https://github.com/waku-org/js-waku/compare/proto-v0.0.13...proto-v0.0.14) (2025-09-20)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* Implement lp-v3 error codes with backwards compatibility ([#2501](https://github.com/waku-org/js-waku/issues/2501)) ([1625302](https://github.com/waku-org/js-waku/commit/16253026c6e30052d87d9975b58480951de469d8))
|
|
||||||
|
|
||||||
## [0.0.13](https://github.com/waku-org/js-waku/compare/proto-v0.0.12...proto-v0.0.13) (2025-08-14)
|
## [0.0.13](https://github.com/waku-org/js-waku/compare/proto-v0.0.12...proto-v0.0.13) (2025-08-14)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@waku/proto",
|
"name": "@waku/proto",
|
||||||
"version": "0.0.15",
|
"version": "0.0.13",
|
||||||
"description": "Protobuf definitions for Waku",
|
"description": "Protobuf definitions for Waku",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
@ -15,7 +15,7 @@
|
|||||||
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/proto#readme",
|
"homepage": "https://github.com/waku-org/js-waku/tree/master/packages/proto#readme",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/waku-org/js-waku.git"
|
"url": "https://github.com/waku-org/js-waku.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/waku-org/js-waku/issues"
|
"url": "https://github.com/waku-org/js-waku/issues"
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import type { Uint8ArrayList } from 'uint8arraylist'
|
|||||||
export interface HistoryEntry {
|
export interface HistoryEntry {
|
||||||
messageId: string
|
messageId: string
|
||||||
retrievalHint?: Uint8Array
|
retrievalHint?: Uint8Array
|
||||||
senderId?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace HistoryEntry {
|
export namespace HistoryEntry {
|
||||||
@ -36,11 +35,6 @@ export namespace HistoryEntry {
|
|||||||
w.bytes(obj.retrievalHint)
|
w.bytes(obj.retrievalHint)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.senderId != null) {
|
|
||||||
w.uint32(26)
|
|
||||||
w.string(obj.senderId)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opts.lengthDelimited !== false) {
|
if (opts.lengthDelimited !== false) {
|
||||||
w.ldelim()
|
w.ldelim()
|
||||||
}
|
}
|
||||||
@ -63,10 +57,6 @@ export namespace HistoryEntry {
|
|||||||
obj.retrievalHint = reader.bytes()
|
obj.retrievalHint = reader.bytes()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 3: {
|
|
||||||
obj.senderId = reader.string()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
default: {
|
default: {
|
||||||
reader.skipType(tag & 7)
|
reader.skipType(tag & 7)
|
||||||
break
|
break
|
||||||
@ -94,10 +84,9 @@ export interface SdsMessage {
|
|||||||
senderId: string
|
senderId: string
|
||||||
messageId: string
|
messageId: string
|
||||||
channelId: string
|
channelId: string
|
||||||
lamportTimestamp?: bigint
|
lamportTimestamp?: number
|
||||||
causalHistory: HistoryEntry[]
|
causalHistory: HistoryEntry[]
|
||||||
bloomFilter?: Uint8Array
|
bloomFilter?: Uint8Array
|
||||||
repairRequest: HistoryEntry[]
|
|
||||||
content?: Uint8Array
|
content?: Uint8Array
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +117,7 @@ export namespace SdsMessage {
|
|||||||
|
|
||||||
if (obj.lamportTimestamp != null) {
|
if (obj.lamportTimestamp != null) {
|
||||||
w.uint32(80)
|
w.uint32(80)
|
||||||
w.uint64(obj.lamportTimestamp)
|
w.int32(obj.lamportTimestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.causalHistory != null) {
|
if (obj.causalHistory != null) {
|
||||||
@ -143,13 +132,6 @@ export namespace SdsMessage {
|
|||||||
w.bytes(obj.bloomFilter)
|
w.bytes(obj.bloomFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.repairRequest != null) {
|
|
||||||
for (const value of obj.repairRequest) {
|
|
||||||
w.uint32(106)
|
|
||||||
HistoryEntry.codec().encode(value, w)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj.content != null) {
|
if (obj.content != null) {
|
||||||
w.uint32(162)
|
w.uint32(162)
|
||||||
w.bytes(obj.content)
|
w.bytes(obj.content)
|
||||||
@ -163,8 +145,7 @@ export namespace SdsMessage {
|
|||||||
senderId: '',
|
senderId: '',
|
||||||
messageId: '',
|
messageId: '',
|
||||||
channelId: '',
|
channelId: '',
|
||||||
causalHistory: [],
|
causalHistory: []
|
||||||
repairRequest: []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const end = length == null ? reader.len : reader.pos + length
|
const end = length == null ? reader.len : reader.pos + length
|
||||||
@ -186,7 +167,7 @@ export namespace SdsMessage {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 10: {
|
case 10: {
|
||||||
obj.lamportTimestamp = reader.uint64()
|
obj.lamportTimestamp = reader.int32()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 11: {
|
case 11: {
|
||||||
@ -203,16 +184,6 @@ export namespace SdsMessage {
|
|||||||
obj.bloomFilter = reader.bytes()
|
obj.bloomFilter = reader.bytes()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 13: {
|
|
||||||
if (opts.limits?.repairRequest != null && obj.repairRequest.length === opts.limits.repairRequest) {
|
|
||||||
throw new MaxLengthError('Decode error - map field "repairRequest" had too many elements')
|
|
||||||
}
|
|
||||||
|
|
||||||
obj.repairRequest.push(HistoryEntry.codec().decode(reader, reader.uint32(), {
|
|
||||||
limits: opts.limits?.repairRequest$
|
|
||||||
}))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 20: {
|
case 20: {
|
||||||
obj.content = reader.bytes()
|
obj.content = reader.bytes()
|
||||||
break
|
break
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user