2021-05-25 13:35:52 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2021-06-02 20:56:44 +03:00
|
|
|
import {createClient, registerServiceFunction, setLogLevel} from "@fluencelabs/fluence";
|
2021-08-24 18:51:00 +03:00
|
|
|
import {krasnodar, testNet, stage} from "@fluencelabs/fluence-network-environment";
|
2021-05-25 13:35:52 +03:00
|
|
|
import {callArrowCall} from "./examples/callArrowCall";
|
|
|
|
import {dataAliasCall} from "./examples/dataAliasCall";
|
|
|
|
import {onCall} from "./examples/onCall";
|
|
|
|
import {funcCall} from "./examples/funcCall";
|
|
|
|
import {helloWorldCall} from "./examples/helloWorldCall";
|
|
|
|
import {foldCall} from "./examples/foldCall";
|
|
|
|
import {ifCall} from "./examples/if";
|
|
|
|
import {parCall} from "./examples/parCall";
|
|
|
|
import {complexCall} from "./examples/complex";
|
|
|
|
import {constantsCall} from "./examples/constantsCall";
|
|
|
|
import {streamCall} from "./examples/streamCall";
|
|
|
|
import {topologyCall} from "./examples/topologyCall";
|
2021-06-01 19:41:30 +03:00
|
|
|
import {foldJoinCall} from "./examples/foldJoinCall";
|
2021-07-28 16:24:07 +03:00
|
|
|
import {returnNull, returnOptionalCall, useOptionalCall} from "./examples/useOptionalCall";
|
2021-06-03 17:27:32 +03:00
|
|
|
import {viaCall} from "./examples/viaCall";
|
2021-06-04 14:10:34 +03:00
|
|
|
import {nestedFuncsCall} from "./examples/nestedFuncsCall";
|
2021-06-07 17:23:27 +03:00
|
|
|
import {assignmentCall} from "./examples/assignment";
|
2021-06-10 17:55:30 +03:00
|
|
|
import {tryCatchCall} from "./examples/tryCatchCall";
|
2021-06-11 17:49:57 +03:00
|
|
|
import {tryOtherwiseCall} from "./examples/tryOtherwiseCall";
|
2021-06-24 18:17:14 +03:00
|
|
|
import {coCall} from "./examples/coCall";
|
2021-07-23 11:57:44 +03:00
|
|
|
import {passArgsCall} from "./examples/passArgsCall";
|
|
|
|
import {streamArgsCall} from "./examples/streamArgsCall";
|
|
|
|
import {streamResultsCall} from "./examples/streamResultsCall";
|
2021-07-23 16:47:31 +03:00
|
|
|
import {pushToStreamCall} from "./examples/pushToStreamCall";
|
2021-08-04 12:26:59 +03:00
|
|
|
import {literalCall} from "./examples/returnLiteralCall";
|
2021-08-09 21:06:54 +03:00
|
|
|
import {multiReturnCall} from "./examples/multiReturnCall";
|
2021-08-23 12:58:38 +03:00
|
|
|
import {declareCall} from "./examples/declareCall";
|
2021-05-25 13:35:52 +03:00
|
|
|
let deepEqual = require('deep-equal')
|
|
|
|
|
2021-08-10 23:31:19 +03:00
|
|
|
function checkCall(name: string, actual: any, expected: any, callBackOnError: () => void) {
|
|
|
|
if (!deepEqual(expected, actual)) {
|
2021-05-25 13:35:52 +03:00
|
|
|
console.error(`${name} call has the wrong result`)
|
2021-06-02 20:56:44 +03:00
|
|
|
console.error("actual: ")
|
|
|
|
console.dir(actual)
|
2021-08-10 23:31:19 +03:00
|
|
|
console.error("expected: ")
|
|
|
|
console.dir(expected)
|
2021-05-25 13:35:52 +03:00
|
|
|
callBackOnError()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 19:41:30 +03:00
|
|
|
function checkCallBy(name: string, actual: any, by: (res: any) => boolean, callBackOnError: () => void) {
|
|
|
|
if (!by(actual)) {
|
|
|
|
console.error(`${name} call has the wrong result`)
|
|
|
|
console.error("actual: " + actual)
|
|
|
|
callBackOnError()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-25 13:35:52 +03:00
|
|
|
const main = async () => {
|
2021-06-02 20:56:44 +03:00
|
|
|
// setLogLevel("trace")
|
2021-08-24 18:51:00 +03:00
|
|
|
const client = await createClient(stage[0]);
|
|
|
|
const client2 = await createClient(stage[1]);
|
2021-05-25 13:35:52 +03:00
|
|
|
|
|
|
|
// this could be called from `println.aqua`
|
|
|
|
registerServiceFunction(client, "println-service-id", "print", (args: any[], _) => {
|
|
|
|
console.log("println: " + args[0])
|
|
|
|
return {}
|
|
|
|
})
|
|
|
|
|
|
|
|
// these is only list of calls. Take a look into functions to see what's going on
|
|
|
|
|
|
|
|
// these calls return void, so they could be executed at any time,
|
|
|
|
// because promise waits only a fact that particle was sent
|
|
|
|
|
|
|
|
// callArrow.aqua
|
|
|
|
let callArrowResult = await callArrowCall(client)
|
|
|
|
|
|
|
|
// fold.aqua
|
|
|
|
let foldCallResult = await foldCall(client)
|
|
|
|
|
|
|
|
//if.aqua
|
|
|
|
await ifCall(client)
|
|
|
|
|
|
|
|
// par.aqua
|
|
|
|
let parCallResult = await parCall(client)
|
|
|
|
|
|
|
|
// these calls waiting for a result, so it will be called sequentially
|
|
|
|
// helloWorld.aqua
|
|
|
|
let helloWorldResult = await helloWorldCall(client)
|
|
|
|
|
|
|
|
// func.aqua
|
|
|
|
let funcCallResult = await funcCall(client)
|
|
|
|
|
|
|
|
// on.aqua
|
|
|
|
let onCallResult = await onCall(client)
|
|
|
|
|
|
|
|
// dataAlias.aqua
|
|
|
|
let dataAliasResult = await dataAliasCall(client)
|
|
|
|
|
|
|
|
// complex.aqua
|
|
|
|
let complexCallResult = await complexCall(client)
|
|
|
|
|
|
|
|
// constants.aqua
|
|
|
|
let constantCallResult = await constantsCall(client)
|
|
|
|
|
|
|
|
// stream.aqua
|
|
|
|
let streamResult = await streamCall(client)
|
|
|
|
|
|
|
|
// topology.aqua
|
|
|
|
let topologyResult = await topologyCall(client, client2)
|
|
|
|
|
2021-06-01 19:41:30 +03:00
|
|
|
// foldJoin.aqua
|
|
|
|
let foldJoinResult = await foldJoinCall(client)
|
|
|
|
|
2021-06-02 20:56:44 +03:00
|
|
|
// option.aqua
|
|
|
|
let optionResult = await useOptionalCall(client)
|
2021-07-28 16:24:07 +03:00
|
|
|
let optionalResult = await returnOptionalCall(client)
|
|
|
|
let noneResult = await returnNull(client)
|
2021-06-02 20:56:44 +03:00
|
|
|
|
2021-06-03 17:27:32 +03:00
|
|
|
// via.aqua
|
|
|
|
let viaResult = await viaCall(client)
|
|
|
|
|
2021-06-04 14:10:34 +03:00
|
|
|
// nestedFuncs.aqua
|
|
|
|
let nestedFuncsResult = await nestedFuncsCall(client)
|
|
|
|
|
2021-06-07 17:23:27 +03:00
|
|
|
// assignment.aqua
|
|
|
|
let assignmentResult = await assignmentCall(client)
|
|
|
|
|
2021-06-11 17:49:57 +03:00
|
|
|
// tryOtherwise.aqua
|
|
|
|
let tryOtherwiseResult = await tryOtherwiseCall(client)
|
|
|
|
|
2021-06-10 17:55:30 +03:00
|
|
|
// tryCatch.aqua
|
|
|
|
let tryCatchResult = await tryCatchCall(client)
|
|
|
|
|
2021-06-24 18:17:14 +03:00
|
|
|
// coCall.aqua
|
|
|
|
let coCallResult = await coCall(client)
|
|
|
|
|
2021-07-23 11:57:44 +03:00
|
|
|
// passArgsCall.aqua
|
|
|
|
let passArgsResult = await passArgsCall(client)
|
|
|
|
|
|
|
|
// streamArgs.aqua
|
2021-07-28 10:42:35 +03:00
|
|
|
let streamArgsResult = await streamArgsCall(client)
|
2021-07-23 11:57:44 +03:00
|
|
|
|
|
|
|
// streamResults.aqua
|
2021-07-28 10:42:35 +03:00
|
|
|
let streamResultsResult = await streamResultsCall(client)
|
2021-07-23 16:47:31 +03:00
|
|
|
|
|
|
|
// pushToStream.aqua
|
|
|
|
let pushToStreamResult = await pushToStreamCall(client)
|
2021-06-10 17:55:30 +03:00
|
|
|
|
2021-08-04 12:26:59 +03:00
|
|
|
// literalCall.aqua
|
|
|
|
let literalCallResult = await literalCall(client)
|
|
|
|
|
2021-08-09 21:06:54 +03:00
|
|
|
// multiReturn.aqua
|
|
|
|
let multiReturnResult = await multiReturnCall(client)
|
|
|
|
|
2021-08-23 12:58:38 +03:00
|
|
|
// declare.aqua
|
|
|
|
let declareResult = await declareCall(client)
|
|
|
|
|
2021-05-25 13:35:52 +03:00
|
|
|
await client.disconnect();
|
|
|
|
|
|
|
|
let success = true;
|
|
|
|
let cb: () => void = () => {
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
checkCall("callArrow", callArrowResult, "Hello, callArrow call!", cb)
|
|
|
|
|
2021-08-24 18:51:00 +03:00
|
|
|
checkCall("foldCall", foldCallResult, ['/ip4/134.209.186.43/tcp/7001', '/ip4/134.209.186.43/tcp/9001/ws'], cb)
|
2021-05-25 13:35:52 +03:00
|
|
|
|
2021-08-24 18:51:00 +03:00
|
|
|
checkCall("onCall", onCallResult, ['/ip4/134.209.186.43/tcp/7001', '/ip4/134.209.186.43/tcp/9001/ws'], cb)
|
2021-05-25 13:35:52 +03:00
|
|
|
|
|
|
|
checkCall("parArrow", parCallResult, "hello", cb)
|
|
|
|
|
|
|
|
checkCall("helloWorldCall", helloWorldResult, "Hello, NAME!", cb)
|
|
|
|
|
|
|
|
checkCall("funcCall", funcCallResult, "some str", cb)
|
|
|
|
|
|
|
|
checkCall("dataAliasCall", dataAliasResult, "peer id str", cb)
|
|
|
|
|
2021-06-16 11:38:49 +03:00
|
|
|
checkCall("complexCall", complexCallResult, ["some str", "3", "1", "4", "1", "1", "3", "2", "4", "2", "2", client.selfPeerId], cb)
|
2021-05-25 13:35:52 +03:00
|
|
|
|
2021-06-15 17:06:08 +03:00
|
|
|
checkCall("constantCall", constantCallResult, ['1', 'ab'], cb)
|
2021-05-25 13:35:52 +03:00
|
|
|
|
|
|
|
checkCall("streamCall", streamResult, ["first updated", "second updated", "third updated", "fourth updated"], cb)
|
|
|
|
|
|
|
|
checkCall("topologyCall", topologyResult, "finish", cb)
|
|
|
|
|
2021-06-01 19:41:30 +03:00
|
|
|
checkCallBy("foldJoinCall", foldJoinResult, (res) => res.length == 3, cb)
|
|
|
|
|
2021-06-02 20:56:44 +03:00
|
|
|
checkCall("useOptional", optionResult, "hello", cb)
|
2021-07-28 16:24:07 +03:00
|
|
|
checkCall("returnOptional", optionalResult, "optional", cb)
|
|
|
|
checkCall("returnNone", noneResult, null, cb)
|
2021-06-02 20:56:44 +03:00
|
|
|
|
2021-06-03 17:27:32 +03:00
|
|
|
checkCallBy("via", viaResult, (res) => res.every( (val, i, arr) => deepEqual(val, arr[0]) ), cb)
|
|
|
|
|
2021-06-04 15:51:01 +03:00
|
|
|
checkCall("nestedFuncsCall", nestedFuncsResult, "some-str", cb)
|
2021-06-04 14:10:34 +03:00
|
|
|
|
2021-06-07 18:17:01 +03:00
|
|
|
checkCall("assignmentCall", assignmentResult, ["abc", "hello"], cb)
|
2021-06-07 17:23:27 +03:00
|
|
|
|
2021-06-11 17:49:57 +03:00
|
|
|
checkCall("tryOtherwiseCall", tryOtherwiseResult, "error", cb)
|
|
|
|
|
2021-08-24 18:51:00 +03:00
|
|
|
checkCall("coCall", coCallResult, [ '/ip4/134.209.186.43/tcp/7001', '/ip4/134.209.186.43/tcp/9001/ws' ], cb)
|
2021-06-24 18:17:14 +03:00
|
|
|
|
2021-07-23 11:57:44 +03:00
|
|
|
checkCall("passArgsCall", passArgsResult, "client-utilsid", cb)
|
|
|
|
|
2021-07-28 10:42:35 +03:00
|
|
|
checkCall("streamArgsCall", streamArgsResult, [["peer_id", "peer_id"]], cb)
|
2021-07-23 16:47:31 +03:00
|
|
|
|
2021-07-28 10:42:35 +03:00
|
|
|
checkCall("streamResultsCall", streamResultsResult, ["new_name", "new_name", "new_name"], cb)
|
2021-07-23 11:57:44 +03:00
|
|
|
|
2021-07-23 16:47:31 +03:00
|
|
|
checkCall("pushToStreamCall", pushToStreamResult, ["hello", "get_string"], cb)
|
2021-07-23 11:57:44 +03:00
|
|
|
|
2021-08-04 12:26:59 +03:00
|
|
|
checkCall("literalCall", literalCallResult, "some literal", cb)
|
|
|
|
|
2021-08-10 23:31:19 +03:00
|
|
|
checkCall("multiReturnResult", multiReturnResult, [ [ 'some-str', 'random-str', 'some-str' ], 5, 'some-str', [ 1, 2 ], null, 10], cb)
|
2021-08-09 21:06:54 +03:00
|
|
|
|
2021-08-23 12:58:38 +03:00
|
|
|
checkCall("declareResult", declareResult, 'declare all foodeclare all barsmall_foo', cb)
|
|
|
|
|
2021-06-12 12:03:46 +03:00
|
|
|
checkCallBy("tryCatchCall", tryCatchResult, (res) => {
|
2021-08-24 18:51:00 +03:00
|
|
|
return (res[0] as string).includes("Error: Service with id 'unex' not found") && res[1] === '/ip4/134.209.186.43/tcp/7001'
|
2021-06-12 12:03:46 +03:00
|
|
|
}, cb)
|
2021-06-10 17:55:30 +03:00
|
|
|
|
2021-05-25 13:35:52 +03:00
|
|
|
if (success) {
|
|
|
|
process.exit(0)
|
|
|
|
} else {
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
main().catch((err) => {
|
|
|
|
console.log(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|