Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/__test__/integration/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,63 @@ describe('Typescript usage suite', () => {
// assert
await expect(promise).rejects.toMatch('service failed internally');
});

it('Should throw correct message when calling non existing local service', async function () {
// arrange
client = await createClient();

// act
const res = getPeerExternalAddresses(client);

// assert
await expect(res).rejects.toMatch(
"The handler did not set any result. Make sure you are calling the right peer and the handler has been registered. Original request data was: serviceId='peer' fnName='identify' args=''",
);
});
});

async function getPeerExternalAddresses(client: FluenceClient): Promise<string[]> {
let request;
const promise = new Promise<string[]>((resolve, reject) => {
request = new RequestFlowBuilder()
.withRawScript(
`
(seq
(seq
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
(call %init_peer_id% ("peer" "identify") [] res)
)
(call %init_peer_id% ("callbackSrv" "response") [res.$.external_addresses!])
)

`,
)
.configHandler((h) => {
h.on('getDataSrv', 'relay', () => {
return client.relayPeerId;
});
h.on('getRelayService', 'hasReleay', () => {
// Not Used
return client.relayPeerId !== undefined;
});

h.on('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});

h.on('nameOfServiceWhereToSendXorError', 'errorProbably', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out');
})
.build();
});
await client.initiateFlow(request);
return promise;
}
4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ const makeKey = (client: FluenceClient, serviceId: string, fnName: string) => {
* @param { FluenceClient } client - The Fluence Client instance.
* @param { string } serviceId - The identifier of service which would be used to make calls from Aquamarine
* @param { string } fnName - The identifier of function which would be used to make calls from Aquamarine
* @param { (args: any[], tetraplets: SecurityTetraplet[][]) => object } handler - The handler which would be called by Aquamarine infrastructure. The result is any object passed back to Aquamarine
* @param { (args: any[], tetraplets: SecurityTetraplet[][]) => any } handler - The handler which would be called by Aquamarine infrastructure. The result is any object passed back to Aquamarine
*/
export const registerServiceFunction = (
client: FluenceClient,
serviceId: string,
fnName: string,
handler: (args: any[], tetraplets: SecurityTetraplet[][]) => object,
handler: (args: any[], tetraplets: SecurityTetraplet[][]) => any,
) => {
const unregister = client.aquaCallHandler.on(serviceId, fnName, handler);
handlersUnregistratorsMap.set(makeKey(client, serviceId, fnName), unregister);
Expand Down
1 change: 1 addition & 0 deletions src/internal/AquaHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class AquaCallHandler {
execute(req: AquaCall): AquaCallResult {
const res: AquaCallResult = {
retCode: ResultCodes.unkownError,
result: `The handler did not set any result. Make sure you are calling the right peer and the handler has been registered. Original request data was: serviceId='${req.serviceId}' fnName='${req.fnName}' args='${req.args}'`,
};
this.buildFunction()(req, res);
return res;
Expand Down