mirror of
https://github.com/fluencelabs/aqua-playground
synced 2025-06-26 15:01:49 +00:00
try-otherwise test
This commit is contained in:
19
aqua/examples/tryOtherwise.aqua
Normal file
19
aqua/examples/tryOtherwise.aqua
Normal 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
|
7
src/examples/tryOtherwiseCall.ts
Normal file
7
src/examples/tryOtherwiseCall.ts
Normal 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!)
|
||||
}
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user