mirror of https://github.com/waku-org/js-waku.git
Adopt more typescript-y syntax, do not lint generated files
This commit is contained in:
parent
5e64708111
commit
8e91ca6d01
|
@ -3,7 +3,7 @@
|
|||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": { "project": "./tsconfig.json" },
|
||||
"env": { "es6": true },
|
||||
"ignorePatterns": ["node_modules", "build", "coverage"],
|
||||
"ignorePatterns": ["node_modules", "build", "coverage", "gen"],
|
||||
"plugins": ["import", "eslint-comments", "functional"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
|
|
|
@ -4,40 +4,34 @@ import test from 'ava';
|
|||
|
||||
import { createNode } from './node';
|
||||
|
||||
function delay(ms: number)
|
||||
{
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
function delay(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
test('Can publish message', async (t) => {
|
||||
const topic = 'news';
|
||||
|
||||
const topic = 'news'
|
||||
|
||||
const [node1, node2] = await Promise.all([
|
||||
createNode(),
|
||||
createNode()
|
||||
])
|
||||
const [node1, node2] = await Promise.all([createNode(), createNode()]);
|
||||
|
||||
// Add node's 2 data to the PeerStore
|
||||
node1.peerStore.addressBook.set(node2.peerId, node2.multiaddrs)
|
||||
await node1.dial(node2.peerId)
|
||||
node1.peerStore.addressBook.set(node2.peerId, node2.multiaddrs);
|
||||
await node1.dial(node2.peerId);
|
||||
|
||||
let node1Received = "";
|
||||
let node1Received = '';
|
||||
|
||||
node1.pubsub.on(topic, (msg) => {
|
||||
node1Received = new TextDecoder().decode(msg.data);
|
||||
console.log(`node1 received: ${node1Received}`)
|
||||
console.log(`node1 received: ${node1Received}`);
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
await node1.pubsub.subscribe(topic)
|
||||
await node1.pubsub.subscribe(topic);
|
||||
|
||||
// Will not receive own published messages by default
|
||||
node2.pubsub.on(topic, (msg) => {
|
||||
console.log(`node2 received: ${new TextDecoder().decode(msg.data)}`)
|
||||
})
|
||||
console.log(`node2 received: ${new TextDecoder().decode(msg.data)}`);
|
||||
});
|
||||
|
||||
await node2.pubsub.subscribe(topic)
|
||||
await node2.pubsub.subscribe(topic);
|
||||
|
||||
const message = 'Bird bird bird, bird is the word!';
|
||||
|
||||
|
@ -47,5 +41,5 @@ test('Can publish message', async (t) => {
|
|||
|
||||
await delay(1000);
|
||||
|
||||
t.deepEqual(node1Received, message)
|
||||
t.deepEqual(node1Received, message);
|
||||
});
|
||||
|
|
|
@ -4,20 +4,21 @@ import Mplex from 'libp2p-mplex';
|
|||
import { NOISE } from 'libp2p-noise';
|
||||
import TCP from 'libp2p-tcp';
|
||||
|
||||
export const createNode = async () => {
|
||||
export async function createNode() {
|
||||
const node = await Libp2p.create({
|
||||
addresses: {
|
||||
listen: ['/ip4/0.0.0.0/tcp/0']
|
||||
listen: ['/ip4/0.0.0.0/tcp/0'],
|
||||
},
|
||||
modules: {
|
||||
transport: [TCP],
|
||||
streamMuxer: [Mplex],
|
||||
connEncryption: [NOISE],
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Type needs update
|
||||
pubsub: Gossipsub
|
||||
}
|
||||
})
|
||||
pubsub: Gossipsub,
|
||||
},
|
||||
});
|
||||
|
||||
await node.start()
|
||||
return node
|
||||
}
|
||||
await node.start();
|
||||
return node;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue