Skip to content

Commit b0ed007

Browse files
authored
Particle lifecycle (#21)
Complete rethinking and refactoring of the codebase. The codebase basically consists these 5 moving parts now: 1. Fluence client (and the Particle processor which might be merged with the client) - This part is responsible for initiating Request flows, managing existing requests flows (it keeps the queue of received particles), pulling right strings on request flows to update their state etc 2. Fluence connection - This part is responsible for connecting to network, sending\receiving particles 3. RequestFlow - This is where the state of particle execution process is kept. It is basically a state storage with some control levers to update the state. Each request flow contains some particle lifecycle methods and the AquaCallHandler where all callback logic is kept 4. RequestFlowBuilder - This is where requests are prepared by the user (the developer of the client application) before they are ready to be sent into the network. 5. AquaCallHandler - This is how interpreter callbacks are handled. It is very similar to express.js app and is made of middlewares. Aqua handler is the unified api for both callbacks for our Request flows and non-ours (i.e services that are expected to be called be other peers). See `AquaHandler.ts` for details
1 parent 77ca550 commit b0ed007

28 files changed

+1801
-1129
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"author": "Fluence Labs",
1717
"license": "Apache-2.0",
1818
"dependencies": {
19-
"@fluencelabs/aquamarine-interpreter": "^0.7.0",
19+
"@fluencelabs/aquamarine-interpreter": "0.7.2",
2020
"async": "3.2.0",
2121
"base64-js": "1.3.1",
2222
"bs58": "4.0.1",

src/FluenceClient.ts

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

src/__test__/connection.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import { generatePeerId } from '..';
2-
import { createClient } from '../api';
3-
import { FluenceClientImpl } from '../internal/FluenceClientImpl';
4-
51
// Uncomment to test on dev nodes
62
// export const nodes = [
73
// {
@@ -14,22 +10,15 @@ import { FluenceClientImpl } from '../internal/FluenceClientImpl';
1410
// },
1511
// ];
1612

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
13+
/*
14+
* start docker container to run integration tests locally:
15+
16+
docker run --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj
17+
18+
*/
1919
export const nodes = [
2020
{
2121
multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
2222
peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
2323
},
2424
];
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: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,53 +9,46 @@ import {
99
uploadModule,
1010
} from '../../internal/builtins';
1111
import { ModuleConfig } from '../../internal/moduleConfig';
12-
import { checkConnection } from '../../api';
13-
import { generatePeerId } from '../..';
14-
import { FluenceClientImpl } from '../../internal/FluenceClientImpl';
15-
import { createConnectedClient, nodes } from '../connection';
12+
import { createClient, FluenceClient } from '../../api.unstable';
13+
import { nodes } from '../connection';
14+
15+
let client: FluenceClient;
1616

1717
describe('Builtins usage suite', () => {
18+
afterEach(async () => {
19+
if (client) {
20+
await client.disconnect();
21+
}
22+
});
23+
1824
jest.setTimeout(10000);
1925

2026
it('get_modules', async function () {
21-
const client = await createConnectedClient(nodes[0].multiaddr);
27+
client = await createClient(nodes[0].multiaddr);
2228

2329
let modulesList = await getModules(client);
2430

2531
expect(modulesList).not.toBeUndefined;
2632
});
2733

2834
it('get_interfaces', async function () {
29-
const client = await createConnectedClient(nodes[0].multiaddr);
35+
client = await createClient(nodes[0].multiaddr);
3036

3137
let interfaces = await getInterfaces(client);
3238

3339
expect(interfaces).not.toBeUndefined;
3440
});
3541

3642
it('get_blueprints', async function () {
37-
const client = await createConnectedClient(nodes[0].multiaddr);
43+
client = await createClient(nodes[0].multiaddr);
3844

3945
let bpList = await getBlueprints(client);
4046

4147
expect(bpList).not.toBeUndefined;
4248
});
4349

44-
it('check_connection', async function () {
45-
const peerId = await generatePeerId();
46-
const client = new FluenceClientImpl(peerId);
47-
await client.local();
48-
await client.connect(nodes[0].multiaddr);
49-
50-
let isConnected = await checkConnection(client);
51-
52-
expect(isConnected).toEqual(true);
53-
});
54-
5550
it('upload_modules', async function () {
56-
const client = await createConnectedClient(nodes[0].multiaddr);
57-
58-
console.log('peerid: ' + client.selfPeerId);
51+
client = await createClient(nodes[0].multiaddr);
5952

6053
let config: ModuleConfig = {
6154
name: 'test_broken_module',
@@ -75,7 +68,7 @@ describe('Builtins usage suite', () => {
7568
});
7669

7770
it('add_blueprint', async function () {
78-
const client = await createConnectedClient(nodes[0].multiaddr);
71+
client = await createClient(nodes[0].multiaddr);
7972

8073
let bpId = 'some';
8174

@@ -84,20 +77,19 @@ describe('Builtins usage suite', () => {
8477
expect(bpIdReturned).toEqual(bpId);
8578
});
8679

87-
// FIXME:: there is no error on broken blueprint from a node
88-
it.skip('create_service', async function () {
89-
const client = await createConnectedClient(nodes[0].multiaddr);
80+
it('create broken blueprint', async function () {
81+
client = await createClient(nodes[0].multiaddr);
9082

91-
let serviceId = await createService(client, 'test_broken_blueprint');
83+
let promise = createService(client, 'test_broken_blueprint');
9284

93-
// TODO there is no error on broken blueprint from a node
94-
expect(serviceId).not.toBeUndefined;
85+
await expect(promise).rejects.toMatchObject({
86+
error: expect.stringContaining("Blueprint wasn't found at"),
87+
instruction: expect.stringContaining('blueprint_id'),
88+
});
9589
});
9690

9791
it('add and remove script', async function () {
98-
const client = await createConnectedClient(nodes[0].multiaddr);
99-
100-
console.log('peerid: ' + client.selfPeerId);
92+
client = await createClient(nodes[0].multiaddr);
10193

10294
let script = `
10395
(seq
@@ -107,7 +99,7 @@ describe('Builtins usage suite', () => {
10799
`;
108100

109101
let resMakingPromise = new Promise((resolve) => {
110-
client.registerCallback('test', 'test1', (args, _) => {
102+
client.aquaCallHandler.on('test', 'test1', (args, _) => {
111103
resolve([...args]);
112104
return {};
113105
});
@@ -117,7 +109,6 @@ describe('Builtins usage suite', () => {
117109

118110
await resMakingPromise
119111
.then((args) => {
120-
console.log('final!');
121112
expect(args as string[]).toEqual(['1', '2', '3']);
122113
})
123114
.finally(() => {

0 commit comments

Comments
 (0)