From 7cc080df57cdbb766dbdd836e31e302a72b0f603 Mon Sep 17 00:00:00 2001 From: DieMyst Date: Fri, 11 Jun 2021 17:49:57 +0300 Subject: [PATCH] try-otherwise test --- aqua/examples/tryOtherwise.aqua | 19 +++++++++++++++++++ src/examples/tryOtherwiseCall.ts | 7 +++++++ src/run-examples.ts | 6 ++++++ 3 files changed, 32 insertions(+) create mode 100644 aqua/examples/tryOtherwise.aqua create mode 100644 src/examples/tryOtherwiseCall.ts diff --git a/aqua/examples/tryOtherwise.aqua b/aqua/examples/tryOtherwise.aqua new file mode 100644 index 0000000..659ac92 --- /dev/null +++ b/aqua/examples/tryOtherwise.aqua @@ -0,0 +1,19 @@ +service Unexisted("unex"): + getStr() -> string + +data LastError: + instruction: string + msg: string + peer_id: string + +service OpE("op"): + identity(s: string) -> string + +func tryOtherwiseTest(node_id: string) -> []string: + on node_id: + f: *string + try: + f <- Unexisted.getStr() + otherwise: + f <- OpE.identity("error") + <- f \ No newline at end of file diff --git a/src/examples/tryOtherwiseCall.ts b/src/examples/tryOtherwiseCall.ts new file mode 100644 index 0000000..ab3c5d8 --- /dev/null +++ b/src/examples/tryOtherwiseCall.ts @@ -0,0 +1,7 @@ +import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence"; +import {tryOtherwiseTest} from "../compiled/examples/tryOtherwise"; + +export async function tryOtherwiseCall(client: FluenceClient): Promise { + + return await tryOtherwiseTest(client, client.relayPeerId!) +} \ No newline at end of file diff --git a/src/run-examples.ts b/src/run-examples.ts index e2ab33f..836b6ef 100644 --- a/src/run-examples.ts +++ b/src/run-examples.ts @@ -20,6 +20,7 @@ import {viaCall} from "./examples/viaCall"; import {nestedFuncsCall} from "./examples/nestedFuncsCall"; import {assignmentCall} from "./examples/assignment"; import {tryCatchCall} from "./examples/tryCatchCall"; +import {tryOtherwiseCall} from "./examples/tryOtherwiseCall"; let deepEqual = require('deep-equal') function checkCall(name: string, expected: any, actual: any, callBackOnError: () => void) { @@ -109,6 +110,9 @@ const main = async () => { // assignment.aqua let assignmentResult = await assignmentCall(client) + // tryOtherwise.aqua + let tryOtherwiseResult = await tryOtherwiseCall(client) + // tryCatch.aqua let tryCatchResult = await tryCatchCall(client) @@ -153,6 +157,8 @@ const main = async () => { checkCall("assignmentCall", assignmentResult, ["abc", "hello"], cb) + checkCall("tryOtherwiseCall", tryOtherwiseResult, "error", cb) + checkCallBy("tryCatchCall", tryCatchResult, (res) => (res[0] as string).includes("Local service error: ret_code is 1024"), cb) if (success) {