mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-12 21:45:32 +00:00
Add test for FluenceConnection
This commit is contained in:
parent
2b752492c1
commit
cc582a4a7d
@ -1,12 +1,12 @@
|
|||||||
// Uncomment to test on dev nodes
|
// Uncomment to test on krasnodar nodes
|
||||||
// export const nodes = [
|
// export const nodes = [
|
||||||
// {
|
// {
|
||||||
// multiaddr: '/dns4/dev.fluence.dev/tcp/19003/wss/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb',
|
// multiaddr: '/dns4/kras-00.fluence.dev/tcp/19990/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e',
|
||||||
// peerId: '12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb',
|
// peerId: '12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e',
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// multiaddr: '/dns4/dev.fluence.dev/tcp/19004/wss/p2p/12D3KooWJbJFaZ3k5sNd8DjQgg3aERoKtBAnirEvPV8yp76kEXHB',
|
// multiaddr: '/dns4/kras-00.fluence.dev/tcp/19001/wss/p2p/12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51',
|
||||||
// peerId: '12D3KooWJbJFaZ3k5sNd8DjQgg3aERoKtBAnirEvPV8yp76kEXHB',
|
// peerId: '12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51',
|
||||||
// },
|
// },
|
||||||
// ];
|
// ];
|
||||||
|
|
||||||
|
40
src/__test__/integration/FluenceConnection.spec.ts
Normal file
40
src/__test__/integration/FluenceConnection.spec.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { Multiaddr } from 'multiaddr';
|
||||||
|
import PeerId from 'peer-id';
|
||||||
|
import { FluenceConnection } from '../../internal/FluenceConnection';
|
||||||
|
import { Particle } from '../../internal/Particle';
|
||||||
|
import { nodes } from '../connection';
|
||||||
|
|
||||||
|
const relay = nodes[0];
|
||||||
|
|
||||||
|
describe('Fluence connection integration tests', () => {
|
||||||
|
it('should work, bitch!', async () => {
|
||||||
|
const pidStructure = await PeerId.create();
|
||||||
|
const pid = pidStructure.toB58String();
|
||||||
|
|
||||||
|
const script = `
|
||||||
|
(seq
|
||||||
|
(call "${relay.peerId}" ("op" "noop") [])
|
||||||
|
(call "${pid}" ("op" "noop") [])
|
||||||
|
)`;
|
||||||
|
|
||||||
|
const promise = new Promise(async (resolve) => {
|
||||||
|
const conn = await FluenceConnection.createConnection({
|
||||||
|
peerId: pidStructure,
|
||||||
|
relayAddress: new Multiaddr(relay.multiaddr),
|
||||||
|
onIncomingParticle: (p) => {
|
||||||
|
resolve(p);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
conn.connect();
|
||||||
|
|
||||||
|
const p = Particle.createNew(script, 5000, pid);
|
||||||
|
|
||||||
|
await conn.sendParticle(p);
|
||||||
|
});
|
||||||
|
|
||||||
|
const res: any = await promise;
|
||||||
|
const json = JSON.parse(res);
|
||||||
|
expect(json.script).toBe(script);
|
||||||
|
});
|
||||||
|
});
|
@ -76,6 +76,55 @@ describe('Typescript usage suite', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should make a call through network1', async () => {
|
||||||
|
// arrange
|
||||||
|
await peer.start({ connectTo: nodes[0] });
|
||||||
|
|
||||||
|
const result = await new Promise<string[]>((resolve, reject) => {
|
||||||
|
const script = `
|
||||||
|
(xor
|
||||||
|
(seq
|
||||||
|
(call %init_peer_id% ("load" "relay") [] init_relay)
|
||||||
|
(seq
|
||||||
|
(call init_relay ("op" "identity") ["hello world!"] result)
|
||||||
|
(call %init_peer_id% ("callback" "callback") [result])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(seq
|
||||||
|
(call init_relay ("op" "identity") [])
|
||||||
|
(call %init_peer_id% ("callback" "error") [%last_error%])
|
||||||
|
)
|
||||||
|
)`;
|
||||||
|
const particle = peer.internals.createNewParticle(script);
|
||||||
|
|
||||||
|
if (particle instanceof Error) {
|
||||||
|
return reject(particle.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
registerHandlersHelper(peer, particle, {
|
||||||
|
load: {
|
||||||
|
relay: () => {
|
||||||
|
return peer.getStatus().relayPeerId;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
callback: {
|
||||||
|
callback: (args: any) => {
|
||||||
|
const [val] = args;
|
||||||
|
resolve(val);
|
||||||
|
},
|
||||||
|
error: (args: any) => {
|
||||||
|
const [error] = args;
|
||||||
|
reject(error);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
peer.internals.initiateParticle(particle, handleTimeout(reject));
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toBe('hello world!');
|
||||||
|
});
|
||||||
|
|
||||||
it('should make a call through network', async () => {
|
it('should make a call through network', async () => {
|
||||||
// arrange
|
// arrange
|
||||||
await peer.start({ connectTo: nodes[0] });
|
await peer.start({ connectTo: nodes[0] });
|
||||||
|
Loading…
Reference in New Issue
Block a user