Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"license": "Apache-2.0",
"dependencies": {
"@chainsafe/libp2p-noise": "4.0.0",
"@fluencelabs/avm": "0.15.4",
"@fluencelabs/avm": "0.16.6",
"async": "3.2.0",
"base64-js": "1.5.1",
"bs58": "4.0.1",
Expand Down
7 changes: 3 additions & 4 deletions src/__test__/integration/avm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FluencePeer } from '../../index';
import { Particle } from '../../internal/Particle';
import { handleTimeout } from '../../internal/utils';
import { registerHandlersHelper } from '../util';

describe('Avm spec', () => {
Expand All @@ -21,10 +22,9 @@ describe('Avm spec', () => {
resolve(res);
},
},
_timeout: reject,
});

peer.internals.initiateParticle(particle);
peer.internals.initiateParticle(particle, handleTimeout(reject));
});

// assert
Expand Down Expand Up @@ -61,10 +61,9 @@ describe('Avm spec', () => {
}
},
},
_timeout: reject,
});

peer.internals.initiateParticle(particle);
peer.internals.initiateParticle(particle, handleTimeout(reject));
});

// assert
Expand Down
37 changes: 33 additions & 4 deletions src/__test__/integration/compiler/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Fluence, FluencePeer } from '../../..';
import { Particle } from '../../../internal/Particle';
import { registerHandlersHelper } from '../../util';
import { callMeBack, registerHelloWorld } from './gen1';
import { callFunction } from '../../../internal/compilerSupport/v2';
import { handleTimeout } from '../../../internal/utils';

describe('Compiler support infrastructure tests', () => {
it('Compiled code for function should work', async () => {
Expand Down Expand Up @@ -78,10 +80,9 @@ describe('Compiler support infrastructure tests', () => {
resolve(val);
},
},
_timeout: reject,
});

Fluence.getPeer().internals.initiateParticle(particle);
Fluence.getPeer().internals.initiateParticle(particle, handleTimeout(reject));
});

// assert
Expand Down Expand Up @@ -166,9 +167,8 @@ describe('Compiler support infrastructure tests', () => {
resolve(val);
},
},
_timeout: reject,
});
anotherPeer.internals.initiateParticle(particle);
anotherPeer.internals.initiateParticle(particle, handleTimeout(reject));
});

// assert
Expand All @@ -177,4 +177,33 @@ describe('Compiler support infrastructure tests', () => {

await anotherPeer.stop();
});

it('Should throw error if particle with incorrect AIR script is initiated', async () => {
// arrange;
const anotherPeer = new FluencePeer();
await anotherPeer.start();

// act
const action = callFunction(
[anotherPeer],
{
functionName: 'dontcare',
argDefs: [],
returnType: { tag: 'void' },
names: {
relay: '-relay-',
getDataSrv: 'getDataSrv',
callbackSrv: 'callbackSrv',
responseSrv: 'callbackSrv',
responseFnName: 'response',
errorHandlingSrv: 'errorHandlingSrv',
errorFnName: 'error',
},
},
'incorrect air script',
);

// assert
await expect(action).rejects.toMatch(/incorrect air script/);
});
});
38 changes: 24 additions & 14 deletions src/__test__/integration/peer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Multiaddr } from 'multiaddr';
import { nodes } from '../connection';
import { Fluence, FluencePeer, setLogLevel } from '../../index';
import { checkConnection } from '../../internal/utils';
import { checkConnection, doNothing, handleTimeout } from '../../internal/utils';
import { Particle } from '../../internal/Particle';
import { registerHandlersHelper } from '../util';

Expand Down Expand Up @@ -121,10 +121,9 @@ describe('Typescript usage suite', () => {
reject(error);
},
},
_timeout: reject,
});

anotherPeer.internals.initiateParticle(particle);
anotherPeer.internals.initiateParticle(particle, handleTimeout(reject));
});

// assert
Expand Down Expand Up @@ -169,7 +168,7 @@ describe('Typescript usage suite', () => {
)
`;
const particle = Particle.createNew(script);
await peer1.internals.initiateParticle(particle);
await peer1.internals.initiateParticle(particle, doNothing);

// assert
const res = await resMakingPromise;
Expand Down Expand Up @@ -309,10 +308,9 @@ describe('Typescript usage suite', () => {
resolve(res);
},
},
_timeout: reject,
});

anotherPeer.internals.initiateParticle(particle);
anotherPeer.internals.initiateParticle(particle, handleTimeout(reject));
});

// assert
Expand Down Expand Up @@ -368,10 +366,9 @@ describe('Typescript usage suite', () => {
reject(error);
},
},
_timeout: reject,
});

anotherPeer.internals.initiateParticle(particle);
anotherPeer.internals.initiateParticle(particle, handleTimeout(reject));
});

// assert
Expand All @@ -381,7 +378,6 @@ describe('Typescript usage suite', () => {

it('Should not crash if an error ocurred in user-defined handler', async () => {
// arrange;
setLogLevel('trace');
await anotherPeer.start();

// act
Expand All @@ -405,10 +401,9 @@ describe('Typescript usage suite', () => {
reject(error);
},
},
_timeout: reject,
});

anotherPeer.internals.initiateParticle(particle);
anotherPeer.internals.initiateParticle(particle, handleTimeout(reject));
});

// assert
Expand All @@ -417,6 +412,22 @@ describe('Typescript usage suite', () => {
});
});

it('Should throw error if particle is initiated on a stopped peer', async () => {
// arrange;
const stoppedPeer = new FluencePeer();

// act
const action = () => {
const script = `(null)`;
const particle = Particle.createNew(script);

stoppedPeer.internals.initiateParticle(particle, doNothing);
};

// assert
await expect(action).toThrow('Cannot initiate new particle: peer is not initialized');
});

it.skip('Should throw correct error when the client tries to send a particle not to the relay', async () => {
// arrange;
await anotherPeer.start({ connectTo: nodes[0] });
Expand All @@ -439,7 +450,7 @@ describe('Typescript usage suite', () => {
},
});

anotherPeer.internals.initiateParticle(particle);
anotherPeer.internals.initiateParticle(particle, doNothing);
});

// assert
Expand Down Expand Up @@ -468,10 +479,9 @@ async function callIncorrectService(peer: FluencePeer): Promise<string[]> {
reject(error);
},
},
_timeout: reject,
});

peer.internals.initiateParticle(particle);
peer.internals.initiateParticle(particle, handleTimeout(reject));
});

return promise;
Expand Down
10 changes: 3 additions & 7 deletions src/__test__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { Particle } from '../internal/Particle';
import { MakeServiceCall } from '../internal/utils';

export const registerHandlersHelper = (peer: FluencePeer, particle: Particle, handlers) => {
const { _timeout, ...rest } = handlers;
if (_timeout) {
peer.internals.regHandler.timeout(particle.id, _timeout);
}
for (let serviceId in rest) {
for (let fnName in rest[serviceId]) {
for (let serviceId in handlers) {
for (let fnName in handlers[serviceId]) {
// of type [args] => result
const h = rest[serviceId][fnName];
const h = handlers[serviceId][fnName];
peer.internals.regHandler.forParticle(particle.id, serviceId, fnName, MakeServiceCall(h));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Fluence = {
},

/**
* Uninitializes the default peer: stops all the underltying workflows, stops the Aqua VM
* Un-initializes the default peer: stops all the underlying workflows, stops the Aqua VM
* and disconnects from the Fluence network
*/
stop: (): Promise<void> => {
Expand Down
Loading