try-otherwise test

This commit is contained in:
DieMyst
2021-06-11 17:49:57 +03:00
parent b8b96cc7c5
commit 7cc080df57
3 changed files with 32 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,7 @@
import {FluenceClient, registerServiceFunction} from "@fluencelabs/fluence";
import {tryOtherwiseTest} from "../compiled/examples/tryOtherwise";
export async function tryOtherwiseCall(client: FluenceClient): Promise<string[]> {
return await tryOtherwiseTest(client, client.relayPeerId!)
}

View File

@ -20,6 +20,7 @@ import {viaCall} from "./examples/viaCall";
import {nestedFuncsCall} from "./examples/nestedFuncsCall"; import {nestedFuncsCall} from "./examples/nestedFuncsCall";
import {assignmentCall} from "./examples/assignment"; import {assignmentCall} from "./examples/assignment";
import {tryCatchCall} from "./examples/tryCatchCall"; import {tryCatchCall} from "./examples/tryCatchCall";
import {tryOtherwiseCall} from "./examples/tryOtherwiseCall";
let deepEqual = require('deep-equal') let deepEqual = require('deep-equal')
function checkCall(name: string, expected: any, actual: any, callBackOnError: () => void) { function checkCall(name: string, expected: any, actual: any, callBackOnError: () => void) {
@ -109,6 +110,9 @@ const main = async () => {
// assignment.aqua // assignment.aqua
let assignmentResult = await assignmentCall(client) let assignmentResult = await assignmentCall(client)
// tryOtherwise.aqua
let tryOtherwiseResult = await tryOtherwiseCall(client)
// tryCatch.aqua // tryCatch.aqua
let tryCatchResult = await tryCatchCall(client) let tryCatchResult = await tryCatchCall(client)
@ -153,6 +157,8 @@ const main = async () => {
checkCall("assignmentCall", assignmentResult, ["abc", "hello"], cb) 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) checkCallBy("tryCatchCall", tryCatchResult, (res) => (res[0] as string).includes("Local service error: ret_code is 1024"), cb)
if (success) { if (success) {