Skip to content

Commit 1507100

Browse files
paschal533acul71
authored andcommitted
Add interoperability test for py-libp2p and js-libp2p with enhanced logging
1 parent 505d3b2 commit 1507100

File tree

13 files changed

+1632
-5
lines changed

13 files changed

+1632
-5
lines changed

tests/interop/js_libp2p/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# py-libp2p and js-libp2p Interoperability Tests
2+
3+
This repository contains interoperability tests for py-libp2p and js-libp2p using the /ipfs/ping/1.0.0 protocol. The goal is to verify compatibility in stream multiplexing, protocol negotiation, ping handling, transport layer, and multiaddr parsing.
4+
5+
## Directory Structure
6+
7+
- js_node/ping.js: JavaScript implementation of a ping server and client using libp2p.
8+
- py_node/ping.py: Python implementation of a ping server and client using py-libp2p.
9+
- scripts/run_test.sh: Shell script to automate running the server and client for testing.
10+
- README.md: This file.
11+
12+
## Prerequisites
13+
14+
- Python 3.8+ with `py-libp2p` and dependencies (`pip install libp2p trio cryptography multiaddr`).
15+
- Node.js 16+ with `libp2p` dependencies (`npm install @libp2p/core @libp2p/tcp @chainsafe/libp2p-noise @chainsafe/libp2p-yamux @libp2p/ping @libp2p/identify @multiformats/multiaddr`).
16+
- Bash shell for running `run_test.sh`.
17+
18+
## Running Tests
19+
20+
1. Change directory:
21+
22+
```
23+
cd tests/interop/js_libp2p
24+
```
25+
26+
2. Install dependencies:
27+
28+
```
29+
For JavaScript: cd js_node && npm install && cd ...
30+
```
31+
32+
3. Run the automated test:
33+
34+
For Linux and Mac users:
35+
36+
```
37+
chmod +x scripts/run_test.sh
38+
./scripts/run_test.sh
39+
```
40+
41+
For Windows users:
42+
43+
```
44+
.\scripts\run_test.ps1
45+
```
46+
47+
This starts the Python server on port 8000 and runs the JavaScript client to send 5 pings.
48+
49+
## Debugging
50+
51+
- Logs are saved in py_node/py_server.log and js_node/js_client.log.
52+
- Check for:
53+
- Successful connection establishment.
54+
- Protocol negotiation (/ipfs/ping/1.0.0).
55+
- 32-byte payload echo in server logs.
56+
- RTT and payload hex in client logs.
57+
58+
## Test Plan
59+
60+
### The test verifies:
61+
62+
- Stream Multiplexer Compatibility: Yamux is used and negotiates correctly.
63+
- Multistream Protocol Negotiation: /ipfs/ping/1.0.0 is selected via multistream-select.
64+
- Ping Protocol Handler: Handles 32-byte payloads per the libp2p ping spec.
65+
- Transport Layer Support: TCP is used; WebSocket support is optional.
66+
- Multiaddr Parsing: Correctly resolves multiaddr strings.
67+
- Logging: Includes peer ID, RTT, and payload hex for debugging.
68+
69+
## Current Status
70+
71+
### Working:
72+
73+
- TCP transport and Noise encryption are functional.
74+
- Yamux multiplexing is implemented in both nodes.
75+
- Multiaddr parsing works correctly.
76+
- Logging provides detailed debug information.
77+
78+
## Not Working:
79+
80+
- Ping protocol handler fails to complete pings (JS client reports "operation aborted").
81+
- Potential issues with stream handling or protocol negotiation.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules
2+
/package-lock.json
3+
/dist
4+
.log
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ⚠️ IMPORTANT ⚠️
2+
3+
# Please do not create a Pull Request for this repository
4+
5+
The contents of this repository are automatically synced from the parent [js-libp2p Examples Project](https://github.com/libp2p/js-libp2p-examples) so any changes made to the standalone repository will be lost after the next sync.
6+
7+
Please open a PR against [js-libp2p Examples](https://github.com/libp2p/js-libp2p-examples) instead.
8+
9+
## Contributing
10+
11+
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
12+
13+
1. Fork the [js-libp2p Examples Project](https://github.com/libp2p/js-libp2p-examples)
14+
1. Create your Feature Branch (`git checkout -b feature/amazing-example`)
15+
1. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`)
16+
1. Push to the Branch (`git push origin feature/amazing-example`)
17+
1. Open a Pull Request
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: pull
2+
3+
on:
4+
workflow_dispatch
5+
6+
jobs:
7+
sync:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Pull from another repository
12+
uses: ipfs-examples/actions-pull-directory-from-repo@main
13+
with:
14+
source-repo: libp2p/js-libp2p-examples
15+
source-folder-path: examples/${{ github.event.repository.name }}
16+
source-branch: main
17+
target-branch: main
18+
git-username: github-actions
19+
git-email: [email protected]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# @libp2p/example-chat <!-- omit in toc -->
2+
3+
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4+
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
5+
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-examples.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-examples)
6+
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-examples/ci.yml?branch=main&style=flat-square)](https://github.com/libp2p/js-libp2p-examples/actions/workflows/ci.yml?query=branch%3Amain)
7+
8+
> An example chat app using libp2p
9+
10+
## Table of contents <!-- omit in toc -->
11+
12+
- [Setup](#setup)
13+
- [Running](#running)
14+
- [Need help?](#need-help)
15+
- [License](#license)
16+
- [Contribution](#contribution)
17+
18+
## Setup
19+
20+
1. Install example dependencies
21+
```console
22+
$ npm install
23+
```
24+
1. Open 2 terminal windows in the `./src` directory.
25+
26+
## Running
27+
28+
1. Run the listener in window 1, `node listener.js`
29+
1. Run the dialer in window 2, `node dialer.js`
30+
1. Wait until the two peers discover each other
31+
1. Type a message in either window and hit *enter*
32+
1. Tell yourself secrets to your hearts content!
33+
34+
## Need help?
35+
36+
- Read the [js-libp2p documentation](https://github.com/libp2p/js-libp2p/tree/main/doc)
37+
- Check out the [js-libp2p API docs](https://libp2p.github.io/js-libp2p/)
38+
- Check out the [general libp2p documentation](https://docs.libp2p.io) for tips, how-tos and more
39+
- Read the [libp2p specs](https://github.com/libp2p/specs)
40+
- Ask a question on the [js-libp2p discussion board](https://github.com/libp2p/js-libp2p/discussions)
41+
42+
## License
43+
44+
Licensed under either of
45+
46+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
47+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
48+
49+
## Contribution
50+
51+
Unless you explicitly state otherwise, any contribution intentionally submitted
52+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
53+
dual licensed as above, without any additional terms or conditions.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@libp2p/example-chat",
3+
"version": "0.0.0",
4+
"description": "An example chat app using libp2p",
5+
"license": "Apache-2.0 OR MIT",
6+
"homepage": "https://github.com/libp2p/js-libp2p-example-chat#readme",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/libp2p/js-libp2p-examples.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/libp2p/js-libp2p-examples/issues"
13+
},
14+
"type": "module",
15+
"scripts": {
16+
"test": "test-node-example test/*"
17+
},
18+
"dependencies": {
19+
"@chainsafe/libp2p-noise": "^16.0.0",
20+
"@chainsafe/libp2p-yamux": "^7.0.0",
21+
"@libp2p/identify": "^3.0.33",
22+
"@libp2p/mdns": "^11.0.1",
23+
"@libp2p/ping": "^2.0.33",
24+
"@libp2p/tcp": "^10.0.0",
25+
"@libp2p/websockets": "^9.0.0",
26+
"@multiformats/multiaddr": "^12.3.1",
27+
"@nodeutils/defaults-deep": "^1.1.0",
28+
"it-length-prefixed": "^10.0.1",
29+
"it-map": "^3.0.3",
30+
"it-pipe": "^3.0.1",
31+
"libp2p": "^2.0.0",
32+
"p-defer": "^4.0.0",
33+
"uint8arrays": "^5.1.0"
34+
},
35+
"devDependencies": {
36+
"test-ipfs-example": "^1.1.0"
37+
},
38+
"private": true
39+
}

0 commit comments

Comments
 (0)