Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit 619c8a6

Browse files
authored
Update builtins to new version (#27)
* Update builtins to new version * Running integration tests in docker container
1 parent d65153e commit 619c8a6

File tree

8 files changed

+137
-173
lines changed

8 files changed

+137
-173
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Make a particle
6464
const particle = new Particle(
6565
`
6666
(seq
67-
(call myRelay ("op" "identify") [] result)
67+
(call myRelay ("peer" "identify") [] result)
6868
(call %init_peer_id% ("helloService" "helloFunction") [result])
6969
)`,
7070
{
@@ -112,10 +112,34 @@ npm install
112112

113113
### Running tests
114114

115-
To run test execute
115+
Tests are split into unit and integration categories. By default integration tests require a locally running Fluence node with 4310 port open for ws connections. The dependency can be started with docker
116116

117117
```bash
118-
npm test
118+
docker run --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence:freeze -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj
119+
```
120+
121+
To run all tests in interactive mode
122+
123+
```bash
124+
npm run test
125+
```
126+
127+
To run only unit tests
128+
129+
```bash
130+
npm run test:unit
131+
```
132+
133+
To run only integration tests
134+
135+
```bash
136+
npm run test:unit
137+
```
138+
139+
To run all tests
140+
141+
```bash
142+
npm run test:all
119143
```
120144

121145
## Contributing

src/__test__/connection.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { generatePeerId } from '..';
2+
import { createClient } from '../api';
3+
import { FluenceClientImpl } from '../internal/FluenceClientImpl';
4+
5+
// Uncomment to test on dev nodes
6+
// export const nodes = [
7+
// {
8+
// multiaddr: '/dns4/dev.fluence.dev/tcp/19003/wss/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb',
9+
// peerId: '12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb',
10+
// },
11+
// {
12+
// multiaddr: '/dns4/dev.fluence.dev/tcp/19004/wss/p2p/12D3KooWJbJFaZ3k5sNd8DjQgg3aERoKtBAnirEvPV8yp76kEXHB',
13+
// peerId: '12D3KooWJbJFaZ3k5sNd8DjQgg3aERoKtBAnirEvPV8yp76kEXHB',
14+
// },
15+
// ];
16+
17+
// start docker container to run integration tests locally
18+
// > docker run --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence:freeze -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj
19+
export const nodes = [
20+
{
21+
multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
22+
peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
23+
},
24+
];
25+
26+
export const createLocalClient = async () => {
27+
const peerId = await generatePeerId();
28+
const client = new FluenceClientImpl(peerId);
29+
await client.local();
30+
return client;
31+
};
32+
33+
export const createConnectedClient = async (node: string) => {
34+
return (await createClient(node)) as FluenceClientImpl;
35+
};

src/__test__/integration/builtins.spec.ts

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
11
import {
22
addBlueprint,
3-
addProvider,
43
addScript,
54
createService,
65
getBlueprints,
76
getInterfaces,
87
getModules,
9-
getProviders,
108
removeScript,
119
uploadModule,
1210
} from '../../internal/builtins';
1311
import { ModuleConfig } from '../../internal/moduleConfig';
14-
import { createConnectedClient } from '../util';
1512
import { checkConnection } from '../../api';
1613
import log from 'loglevel';
1714
import { generatePeerId } from '../..';
1815
import { FluenceClientImpl } from '../../internal/FluenceClientImpl';
19-
20-
const dev2multiaddr = '/dns4/dev.fluence.dev/tcp/19003/wss/p2p/12D3KooWBUJifCTgaxAUrcM9JysqCcS4CS8tiYH5hExbdWCAoNwb';
21-
const dev3multiaddr = '/dns4/dev.fluence.dev/tcp/19004/wss/p2p/12D3KooWJbJFaZ3k5sNd8DjQgg3aERoKtBAnirEvPV8yp76kEXHB';
22-
23-
const dev2peerId = '12D3KooWEXNUbCXooUwHrHBbrmjsrpHXoEphPwbjQXEGyzbqKnE9';
16+
import { createConnectedClient, nodes } from '../connection';
2417

2518
describe('Builtins usage suite', () => {
19+
jest.setTimeout(10000);
20+
2621
it('get_modules', async function () {
27-
const client = await createConnectedClient(dev2multiaddr);
22+
const client = await createConnectedClient(nodes[0].multiaddr);
2823

2924
let modulesList = await getModules(client);
3025

3126
expect(modulesList).not.toBeUndefined;
3227
});
3328

3429
it('get_interfaces', async function () {
35-
const client = await createConnectedClient(dev2multiaddr);
30+
const client = await createConnectedClient(nodes[0].multiaddr);
3631

3732
let interfaces = await getInterfaces(client);
3833

3934
expect(interfaces).not.toBeUndefined;
4035
});
4136

4237
it('get_blueprints', async function () {
43-
const client = await createConnectedClient(dev2multiaddr);
38+
const client = await createConnectedClient(nodes[0].multiaddr);
4439

4540
let bpList = await getBlueprints(client);
4641

@@ -51,15 +46,15 @@ describe('Builtins usage suite', () => {
5146
const peerId = await generatePeerId();
5247
const client = new FluenceClientImpl(peerId);
5348
await client.local();
54-
await client.connect(dev2multiaddr);
49+
await client.connect(nodes[0].multiaddr);
5550

5651
let isConnected = await checkConnection(client);
5752

5853
expect(isConnected).toEqual(true);
5954
});
6055

6156
it('upload_modules', async function () {
62-
const client = await createConnectedClient(dev2multiaddr);
57+
const client = await createConnectedClient(nodes[0].multiaddr);
6358

6459
console.log('peerid: ' + client.selfPeerId);
6560

@@ -81,7 +76,7 @@ describe('Builtins usage suite', () => {
8176
});
8277

8378
it('add_blueprint', async function () {
84-
const client = await createConnectedClient(dev2multiaddr);
79+
const client = await createConnectedClient(nodes[0].multiaddr);
8580

8681
let bpId = 'some';
8782

@@ -92,31 +87,16 @@ describe('Builtins usage suite', () => {
9287

9388
// FIXME:: there is no error on broken blueprint from a node
9489
it.skip('create_service', async function () {
95-
const client = await createConnectedClient(dev2multiaddr);
90+
const client = await createConnectedClient(nodes[0].multiaddr);
9691

9792
let serviceId = await createService(client, 'test_broken_blueprint');
9893

9994
// TODO there is no error on broken blueprint from a node
10095
expect(serviceId).not.toBeUndefined;
10196
});
10297

103-
it('add_provider', async function () {
104-
const client = await createConnectedClient(dev2multiaddr);
105-
106-
let key = Math.random().toString(36).substring(7);
107-
let buf = Buffer.from(key);
108-
109-
let r = Math.random().toString(36).substring(7);
110-
await addProvider(client, buf, dev2peerId, r, undefined, 10000);
111-
112-
let pr = await getProviders(client, buf, undefined, 10000);
113-
console.log(pr);
114-
console.log(r);
115-
expect(r).toEqual(pr[0][0].service_id);
116-
});
117-
11898
it('add and remove script', async function () {
119-
const client = await createConnectedClient(dev3multiaddr);
99+
const client = await createConnectedClient(nodes[0].multiaddr);
120100

121101
console.log('peerid: ' + client.selfPeerId);
122102

src/__test__/integration/client.spec.ts

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { encode } from 'bs58';
22
import { generatePeerId, peerIdToSeed, seedToPeerId } from '../../internal/peerIdUtils';
33
import { FluenceClientImpl } from '../../internal/FluenceClientImpl';
4-
import { createConnectedClient } from '../util';
54
import log from 'loglevel';
65
import { createClient } from '../../api';
76
import Multiaddr from 'multiaddr';
8-
9-
const devNodeAddress = '/dns4/dev.fluence.dev/tcp/19001/wss/p2p/12D3KooWEXNUbCXooUwHrHBbrmjsrpHXoEphPwbjQXEGyzbqKnE9';
10-
const devNodePeerId = '12D3KooWEXNUbCXooUwHrHBbrmjsrpHXoEphPwbjQXEGyzbqKnE9';
7+
import { createConnectedClient, nodes } from '../connection';
118

129
describe('Typescript usage suite', () => {
1310
it('should create private key from seed and back', async function () {
@@ -45,7 +42,7 @@ describe('Typescript usage suite', () => {
4542

4643
it('address as string', async function () {
4744
// arrange
48-
const addr = devNodeAddress;
45+
const addr = nodes[0].multiaddr;
4946

5047
// act
5148
const client = (await createClient(addr)) as FluenceClientImpl;
@@ -57,7 +54,7 @@ describe('Typescript usage suite', () => {
5754

5855
it('address as multiaddr', async function () {
5956
// arrange
60-
const addr = new Multiaddr(devNodeAddress);
57+
const addr = new Multiaddr(nodes[0].multiaddr);
6158

6259
// act
6360
const client = (await createClient(addr)) as FluenceClientImpl;
@@ -69,10 +66,7 @@ describe('Typescript usage suite', () => {
6966

7067
it('address as node', async function () {
7168
// arrange
72-
const addr = {
73-
multiaddr: devNodeAddress,
74-
peerId: devNodePeerId,
75-
};
69+
const addr = nodes[0];
7670

7771
// act
7872
const client = (await createClient(addr)) as FluenceClientImpl;
@@ -84,7 +78,7 @@ describe('Typescript usage suite', () => {
8478

8579
it('peerid as peer id', async function () {
8680
// arrange
87-
const addr = devNodeAddress;
81+
const addr = nodes[0].multiaddr;
8882
const pid = await generatePeerId();
8983

9084
// act
@@ -97,7 +91,7 @@ describe('Typescript usage suite', () => {
9791

9892
it('peerid as seed', async function () {
9993
// arrange
100-
const addr = devNodeAddress;
94+
const addr = nodes[0].multiaddr;
10195
const pid = peerIdToSeed(await generatePeerId());
10296

10397
// act
@@ -111,7 +105,7 @@ describe('Typescript usage suite', () => {
111105

112106
it('should make a call through the network', async function () {
113107
// arrange
114-
const client = await createConnectedClient(devNodeAddress);
108+
const client = await createConnectedClient(nodes[0].multiaddr);
115109

116110
client.registerCallback('test', 'test', (args, _) => {
117111
log.trace('should make a call through the network, called "test" "test" with args', args);
@@ -151,7 +145,7 @@ describe('Typescript usage suite', () => {
151145

152146
it('fireAndForget should work', async function () {
153147
// arrange
154-
const client = await createConnectedClient(devNodeAddress);
148+
const client = await createConnectedClient(nodes[0].multiaddr);
155149

156150
let resMakingPromise = new Promise((resolve) => {
157151
client.registerCallback('test', 'reverse_args', (args, _) => {
@@ -180,11 +174,11 @@ describe('Typescript usage suite', () => {
180174

181175
it('fetch should work', async function () {
182176
// arrange
183-
const client = await createConnectedClient(devNodeAddress);
177+
const client = await createConnectedClient(nodes[0].multiaddr);
184178

185179
// act
186180
let script = `
187-
(call "${client.relayPeerId}" ("op" "identify") [] result)
181+
(call "${client.relayPeerId}" ("peer" "identify") [] result)
188182
`;
189183
const data = new Map();
190184
data.set('__relay', client.relayPeerId);
@@ -197,8 +191,8 @@ describe('Typescript usage suite', () => {
197191

198192
it('two clients should work inside the same time browser', async function () {
199193
// arrange
200-
const client1 = await createConnectedClient(devNodeAddress);
201-
const client2 = await createConnectedClient(devNodeAddress);
194+
const client1 = await createConnectedClient(nodes[0].multiaddr);
195+
const client2 = await createConnectedClient(nodes[0].multiaddr);
202196

203197
let resMakingPromise = new Promise((resolve) => {
204198
client2.registerCallback('test', 'test', (args, _) => {
@@ -225,32 +219,4 @@ describe('Typescript usage suite', () => {
225219
let res = await resMakingPromise;
226220
expect(res).toEqual(['some a', 'some b', 'some c', 'some d']);
227221
});
228-
229-
it('event registration should work', async function () {
230-
// arrange
231-
const client1 = await createConnectedClient(devNodeAddress);
232-
const client2 = await createConnectedClient(devNodeAddress);
233-
234-
client2.registerEvent('event_stream', 'test');
235-
const resMakingPromise = new Promise((resolve) => {
236-
client2.subscribe('event_stream', resolve);
237-
});
238-
239-
// act
240-
let script = `
241-
(call "${client2.selfPeerId}" ("event_stream" "test") [hello])
242-
`;
243-
244-
let data: Map<string, any> = new Map();
245-
data.set('hello', 'world');
246-
247-
await client1.fireAndForget(script, data);
248-
249-
// assert
250-
let res = await resMakingPromise;
251-
expect(res).toEqual({
252-
type: 'test',
253-
args: ['world'],
254-
});
255-
});
256222
});

src/__test__/unit/air.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createLocalClient } from '../util';
1+
import { createLocalClient } from '../connection';
22

33
describe('== AIR suite', () => {
44
it('check init_peer_id', async function () {
@@ -57,7 +57,7 @@ describe('== AIR suite', () => {
5757

5858
const script = `(call %init_peer_id% ("" "") [""])`;
5959

60-
await expect(client.sendScript(script, undefined, 1)).rejects.toContain("Particle expired");
60+
await expect(client.sendScript(script, undefined, 1)).rejects.toContain('Particle expired');
6161
});
6262

6363
it.skip('call broken script by fetch', async function () {

src/__test__/util.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)