mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-26 06:11:33 +00:00
Add simple test
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
"description": "Tool for generating aqua wrapper",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "vitest run"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Fluence Labs",
|
||||
|
@ -14,8 +14,28 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe } from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import * as fs from 'fs';
|
||||
import generate from '../index.js';
|
||||
import { compileFromPath } from '@fluencelabs/aqua-api';
|
||||
import * as url from 'url';
|
||||
|
||||
describe('Aqua to js/ts compiler', () => {
|
||||
it('compiles smoke tests successfully', async () => {
|
||||
const res = await compileFromPath({
|
||||
filePath: url.fileURLToPath(new URL('./sources/smoke_test.aqua', import.meta.url)),
|
||||
imports: ['./node_modules'],
|
||||
targetType: 'air'
|
||||
});
|
||||
|
||||
const jsResult = generate(res, 'js');
|
||||
const jsSnapshot = fs.readFileSync(new URL('./snapshots/smoke_test.js', import.meta.url))
|
||||
|
||||
expect(jsResult).toEqual(jsSnapshot.toString());
|
||||
|
||||
const tsResult = generate(res, 'ts');
|
||||
const tsSnapshot = fs.readFileSync(new URL('./snapshots/smoke_test.ts', import.meta.url))
|
||||
|
||||
expect(tsResult).toEqual(tsSnapshot.toString());
|
||||
});
|
||||
});
|
@ -0,0 +1,763 @@
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
/**
|
||||
*
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||
* Aqua version: 0.12.0
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
import {
|
||||
v5_callFunction as callFunction$$,
|
||||
v5_registerService as registerService$$,
|
||||
} from '@fluencelabs/js-client';
|
||||
|
||||
// Services
|
||||
|
||||
export function registerSrv(...args) {
|
||||
registerService$$(
|
||||
args,
|
||||
{
|
||||
"defaultServiceId": "single_module_srv",
|
||||
"functions": {
|
||||
"fields": {
|
||||
"create": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"wasm_b64_content": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "ServiceCreationResult",
|
||||
"fields": {
|
||||
"error": {
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "option"
|
||||
},
|
||||
"service_id": {
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "option"
|
||||
},
|
||||
"success": {
|
||||
"name": "bool",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "struct"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"list": {
|
||||
"domain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "array"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"remove": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"service_id": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "RemoveResult",
|
||||
"fields": {
|
||||
"error": {
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "option"
|
||||
},
|
||||
"success": {
|
||||
"name": "bool",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "struct"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function registerCalcService(...args) {
|
||||
registerService$$(
|
||||
args,
|
||||
{
|
||||
"functions": {
|
||||
"fields": {
|
||||
"add": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"num": {
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"clear_state": {
|
||||
"domain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"codomain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"divide": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"num": {
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"multiply": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"num": {
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"state": {
|
||||
"domain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"subtract": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"num": {
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"test_logs": {
|
||||
"domain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"codomain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"tag": "arrow"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export function registerHelloWorld(...args) {
|
||||
registerService$$(
|
||||
args,
|
||||
{
|
||||
"defaultServiceId": "hello-world",
|
||||
"functions": {
|
||||
"fields": {
|
||||
"hello": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"str": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Functions
|
||||
export const resourceTest_script = `
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "label") [] label)
|
||||
)
|
||||
(xor
|
||||
(new $resource_id
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("peer" "timestamp_sec") [] t)
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("registry" "get_key_bytes") [label [] t [] ""] bytes)
|
||||
(xor
|
||||
(call %init_peer_id% ("sig" "sign") [bytes] result)
|
||||
(fail %last_error%)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match result.$.success false
|
||||
(ap result.$.error.[0] $error)
|
||||
)
|
||||
(new $successful
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(ap result.$.signature result_flat)
|
||||
(call -relay- ("registry" "get_key_id") [label %init_peer_id%] id)
|
||||
)
|
||||
(call -relay- ("op" "string_to_b58") [id] k)
|
||||
)
|
||||
(call -relay- ("kad" "neighborhood") [k [] []] nodes)
|
||||
)
|
||||
(par
|
||||
(fold nodes n-0
|
||||
(par
|
||||
(xor
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call n-0 ("peer" "timestamp_sec") [] t-0)
|
||||
(call n-0 ("trust-graph" "get_weight") [%init_peer_id% t-0] weight)
|
||||
)
|
||||
(call n-0 ("registry" "register_key") [label [] t [] "" result_flat.$.[0] weight t-0] result-0)
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(match result-0.$.success true
|
||||
(ap true $successful)
|
||||
)
|
||||
(new $-ephemeral-stream-
|
||||
(new #-ephemeral-canon-
|
||||
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(ap result-0.$.error $error)
|
||||
(new $-ephemeral-stream-
|
||||
(new #-ephemeral-canon-
|
||||
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(fail %last_error%)
|
||||
)
|
||||
(next n-0)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
(new $status
|
||||
(new $result-1
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "sub") [1 1] sub)
|
||||
(new $successful_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [sub 1] successful_incr)
|
||||
(fold $successful successful_fold_var
|
||||
(seq
|
||||
(seq
|
||||
(ap successful_fold_var $successful_test)
|
||||
(canon -relay- $successful_test #successful_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #successful_iter_canon.length successful_incr
|
||||
(null)
|
||||
)
|
||||
(next successful_fold_var)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $successful_test #successful_result_canon)
|
||||
)
|
||||
(ap #successful_result_canon successful_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("math" "sub") [1 1] sub-0)
|
||||
)
|
||||
(ap "ok" $status)
|
||||
)
|
||||
(call -relay- ("peer" "timeout") [6000 "timeout"] $status)
|
||||
)
|
||||
(new $status_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [0 1] status_incr)
|
||||
(fold $status status_fold_var
|
||||
(seq
|
||||
(seq
|
||||
(ap status_fold_var $status_test)
|
||||
(canon -relay- $status_test #status_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #status_iter_canon.length status_incr
|
||||
(null)
|
||||
)
|
||||
(next status_fold_var)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $status_test #status_result_canon)
|
||||
)
|
||||
(ap #status_result_canon status_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match status_gate.$.[0] "ok"
|
||||
(ap true $result-1)
|
||||
)
|
||||
(ap false $result-1)
|
||||
)
|
||||
)
|
||||
(new $result-1_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [0 1] result-1_incr)
|
||||
(fold $result-1 result-1_fold_var
|
||||
(seq
|
||||
(seq
|
||||
(ap result-1_fold_var $result-1_test)
|
||||
(canon -relay- $result-1_test #result-1_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #result-1_iter_canon.length result-1_incr
|
||||
(null)
|
||||
)
|
||||
(next result-1_fold_var)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $result-1_test #result-1_result_canon)
|
||||
)
|
||||
(ap #result-1_result_canon result-1_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match result-1_gate.$.[0] false
|
||||
(ap "resource wasn't created: timeout exceeded" $error)
|
||||
)
|
||||
(ap id $resource_id)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(fail %last_error%)
|
||||
)
|
||||
)
|
||||
(canon %init_peer_id% $resource_id #-resource_id-fix-0)
|
||||
)
|
||||
(ap #-resource_id-fix-0 -resource_id-flat-0)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
(canon %init_peer_id% $error #error_canon)
|
||||
)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [-resource_id-flat-0 #error_canon])
|
||||
)
|
||||
`;
|
||||
|
||||
|
||||
export function resourceTest(...args) {
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName": "resourceTest",
|
||||
"arrow": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"label": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "option"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "array"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"names": {
|
||||
"relay": "-relay-",
|
||||
"getDataSrv": "getDataSrv",
|
||||
"callbackSrv": "callbackSrv",
|
||||
"responseSrv": "callbackSrv",
|
||||
"responseFnName": "response",
|
||||
"errorHandlingSrv": "errorHandlingSrv",
|
||||
"errorFnName": "error"
|
||||
}
|
||||
},
|
||||
resourceTest_script
|
||||
);
|
||||
}
|
||||
|
||||
export const helloTest_script = `
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(xor
|
||||
(call %init_peer_id% ("hello-world" "hello") ["Fluence user"] hello)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [hello])
|
||||
)
|
||||
`;
|
||||
|
||||
|
||||
export function helloTest(...args) {
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName": "helloTest",
|
||||
"arrow": {
|
||||
"domain": {
|
||||
"fields": {},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"names": {
|
||||
"relay": "-relay-",
|
||||
"getDataSrv": "getDataSrv",
|
||||
"callbackSrv": "callbackSrv",
|
||||
"responseSrv": "callbackSrv",
|
||||
"responseFnName": "response",
|
||||
"errorHandlingSrv": "errorHandlingSrv",
|
||||
"errorFnName": "error"
|
||||
}
|
||||
},
|
||||
helloTest_script
|
||||
);
|
||||
}
|
||||
|
||||
export const demo_calculation_script = `
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% (service_id "test_logs") [])
|
||||
(call %init_peer_id% (service_id "add") [10])
|
||||
)
|
||||
(call %init_peer_id% (service_id "multiply") [5])
|
||||
)
|
||||
(call %init_peer_id% (service_id "subtract") [8])
|
||||
)
|
||||
(call %init_peer_id% (service_id "divide") [6])
|
||||
)
|
||||
(call %init_peer_id% (service_id "state") [] res)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||
)
|
||||
`;
|
||||
|
||||
|
||||
export function demo_calculation(...args) {
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName": "demo_calculation",
|
||||
"arrow": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"service_id": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"names": {
|
||||
"relay": "-relay-",
|
||||
"getDataSrv": "getDataSrv",
|
||||
"callbackSrv": "callbackSrv",
|
||||
"responseSrv": "callbackSrv",
|
||||
"responseFnName": "response",
|
||||
"errorHandlingSrv": "errorHandlingSrv",
|
||||
"errorFnName": "error"
|
||||
}
|
||||
},
|
||||
demo_calculation_script
|
||||
);
|
||||
}
|
||||
|
||||
export const marineTest_script = `
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "wasm64") [] wasm64)
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("single_module_srv" "create") [wasm64] serviceResult)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "test_logs") [])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "add") [10])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "multiply") [5])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "subtract") [8])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "divide") [6])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "state") [] res)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||
)
|
||||
`;
|
||||
|
||||
|
||||
export function marineTest(...args) {
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName": "marineTest",
|
||||
"arrow": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"wasm64": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"names": {
|
||||
"relay": "-relay-",
|
||||
"getDataSrv": "getDataSrv",
|
||||
"callbackSrv": "callbackSrv",
|
||||
"responseSrv": "callbackSrv",
|
||||
"responseFnName": "response",
|
||||
"errorHandlingSrv": "errorHandlingSrv",
|
||||
"errorFnName": "error"
|
||||
}
|
||||
},
|
||||
marineTest_script
|
||||
);
|
||||
}
|
||||
|
||||
/* eslint-enable */
|
@ -0,0 +1,829 @@
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
/**
|
||||
*
|
||||
* This file is auto-generated. Do not edit manually: changes may be erased.
|
||||
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
|
||||
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
|
||||
* Aqua version: 0.12.0
|
||||
*
|
||||
*/
|
||||
import type { IFluenceClient as IFluenceClient$$, CallParams as CallParams$$ } from '@fluencelabs/js-client';
|
||||
|
||||
import {
|
||||
v5_callFunction as callFunction$$,
|
||||
v5_registerService as registerService$$,
|
||||
} from '@fluencelabs/js-client';
|
||||
|
||||
// Services
|
||||
export interface SrvDef {
|
||||
create: (wasm_b64_content: string, callParams: CallParams$$<'wasm_b64_content'>) => { error: string | null; service_id: string | null; success: boolean; } | Promise<{ error: string | null; service_id: string | null; success: boolean; }>;
|
||||
list: (callParams: CallParams$$<null>) => string[] | Promise<string[]>;
|
||||
remove: (service_id: string, callParams: CallParams$$<'service_id'>) => { error: string | null; success: boolean; } | Promise<{ error: string | null; success: boolean; }>;
|
||||
}
|
||||
export function registerSrv(service: SrvDef): void;
|
||||
export function registerSrv(serviceId: string, service: SrvDef): void;
|
||||
export function registerSrv(peer: IFluenceClient$$, service: SrvDef): void;
|
||||
export function registerSrv(peer: IFluenceClient$$, serviceId: string, service: SrvDef): void;
|
||||
export function registerSrv(...args: any[]) {
|
||||
registerService$$(
|
||||
args,
|
||||
{
|
||||
"defaultServiceId": "single_module_srv",
|
||||
"functions": {
|
||||
"fields": {
|
||||
"create": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"wasm_b64_content": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "ServiceCreationResult",
|
||||
"fields": {
|
||||
"error": {
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "option"
|
||||
},
|
||||
"service_id": {
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "option"
|
||||
},
|
||||
"success": {
|
||||
"name": "bool",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "struct"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"list": {
|
||||
"domain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "array"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"remove": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"service_id": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "RemoveResult",
|
||||
"fields": {
|
||||
"error": {
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "option"
|
||||
},
|
||||
"success": {
|
||||
"name": "bool",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "struct"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export interface CalcServiceDef {
|
||||
add: (num: number, callParams: CallParams$$<'num'>) => number | Promise<number>;
|
||||
clear_state: (callParams: CallParams$$<null>) => void | Promise<void>;
|
||||
divide: (num: number, callParams: CallParams$$<'num'>) => number | Promise<number>;
|
||||
multiply: (num: number, callParams: CallParams$$<'num'>) => number | Promise<number>;
|
||||
state: (callParams: CallParams$$<null>) => number | Promise<number>;
|
||||
subtract: (num: number, callParams: CallParams$$<'num'>) => number | Promise<number>;
|
||||
test_logs: (callParams: CallParams$$<null>) => void | Promise<void>;
|
||||
}
|
||||
export function registerCalcService(service: CalcServiceDef): void;
|
||||
export function registerCalcService(serviceId: string, service: CalcServiceDef): void;
|
||||
export function registerCalcService(peer: IFluenceClient$$, service: CalcServiceDef): void;
|
||||
export function registerCalcService(peer: IFluenceClient$$, serviceId: string, service: CalcServiceDef): void;
|
||||
export function registerCalcService(...args: any[]) {
|
||||
registerService$$(
|
||||
args,
|
||||
{
|
||||
"functions": {
|
||||
"fields": {
|
||||
"add": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"num": {
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"clear_state": {
|
||||
"domain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"codomain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"divide": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"num": {
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"multiply": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"num": {
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"state": {
|
||||
"domain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"subtract": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"num": {
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"test_logs": {
|
||||
"domain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"codomain": {
|
||||
"tag": "nil"
|
||||
},
|
||||
"tag": "arrow"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export interface HelloWorldDef {
|
||||
hello: (str: string, callParams: CallParams$$<'str'>) => string | Promise<string>;
|
||||
}
|
||||
export function registerHelloWorld(service: HelloWorldDef): void;
|
||||
export function registerHelloWorld(serviceId: string, service: HelloWorldDef): void;
|
||||
export function registerHelloWorld(peer: IFluenceClient$$, service: HelloWorldDef): void;
|
||||
export function registerHelloWorld(peer: IFluenceClient$$, serviceId: string, service: HelloWorldDef): void;
|
||||
export function registerHelloWorld(...args: any[]) {
|
||||
registerService$$(
|
||||
args,
|
||||
{
|
||||
"defaultServiceId": "hello-world",
|
||||
"functions": {
|
||||
"fields": {
|
||||
"hello": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"str": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Functions
|
||||
export const resourceTest_script = `
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "label") [] label)
|
||||
)
|
||||
(xor
|
||||
(new $resource_id
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("peer" "timestamp_sec") [] t)
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("registry" "get_key_bytes") [label [] t [] ""] bytes)
|
||||
(xor
|
||||
(call %init_peer_id% ("sig" "sign") [bytes] result)
|
||||
(fail %last_error%)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match result.$.success false
|
||||
(ap result.$.error.[0] $error)
|
||||
)
|
||||
(new $successful
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(ap result.$.signature result_flat)
|
||||
(call -relay- ("registry" "get_key_id") [label %init_peer_id%] id)
|
||||
)
|
||||
(call -relay- ("op" "string_to_b58") [id] k)
|
||||
)
|
||||
(call -relay- ("kad" "neighborhood") [k [] []] nodes)
|
||||
)
|
||||
(par
|
||||
(fold nodes n-0
|
||||
(par
|
||||
(xor
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call n-0 ("peer" "timestamp_sec") [] t-0)
|
||||
(call n-0 ("trust-graph" "get_weight") [%init_peer_id% t-0] weight)
|
||||
)
|
||||
(call n-0 ("registry" "register_key") [label [] t [] "" result_flat.$.[0] weight t-0] result-0)
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(match result-0.$.success true
|
||||
(ap true $successful)
|
||||
)
|
||||
(new $-ephemeral-stream-
|
||||
(new #-ephemeral-canon-
|
||||
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
|
||||
)
|
||||
)
|
||||
)
|
||||
(seq
|
||||
(ap result-0.$.error $error)
|
||||
(new $-ephemeral-stream-
|
||||
(new #-ephemeral-canon-
|
||||
(canon -relay- $-ephemeral-stream- #-ephemeral-canon-)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
(fail %last_error%)
|
||||
)
|
||||
(next n-0)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
(null)
|
||||
)
|
||||
)
|
||||
(new $status
|
||||
(new $result-1
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(par
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "sub") [1 1] sub)
|
||||
(new $successful_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [sub 1] successful_incr)
|
||||
(fold $successful successful_fold_var
|
||||
(seq
|
||||
(seq
|
||||
(ap successful_fold_var $successful_test)
|
||||
(canon -relay- $successful_test #successful_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #successful_iter_canon.length successful_incr
|
||||
(null)
|
||||
)
|
||||
(next successful_fold_var)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $successful_test #successful_result_canon)
|
||||
)
|
||||
(ap #successful_result_canon successful_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
(call -relay- ("math" "sub") [1 1] sub-0)
|
||||
)
|
||||
(ap "ok" $status)
|
||||
)
|
||||
(call -relay- ("peer" "timeout") [6000 "timeout"] $status)
|
||||
)
|
||||
(new $status_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [0 1] status_incr)
|
||||
(fold $status status_fold_var
|
||||
(seq
|
||||
(seq
|
||||
(ap status_fold_var $status_test)
|
||||
(canon -relay- $status_test #status_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #status_iter_canon.length status_incr
|
||||
(null)
|
||||
)
|
||||
(next status_fold_var)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $status_test #status_result_canon)
|
||||
)
|
||||
(ap #status_result_canon status_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match status_gate.$.[0] "ok"
|
||||
(ap true $result-1)
|
||||
)
|
||||
(ap false $result-1)
|
||||
)
|
||||
)
|
||||
(new $result-1_test
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call -relay- ("math" "add") [0 1] result-1_incr)
|
||||
(fold $result-1 result-1_fold_var
|
||||
(seq
|
||||
(seq
|
||||
(ap result-1_fold_var $result-1_test)
|
||||
(canon -relay- $result-1_test #result-1_iter_canon)
|
||||
)
|
||||
(xor
|
||||
(match #result-1_iter_canon.length result-1_incr
|
||||
(null)
|
||||
)
|
||||
(next result-1_fold_var)
|
||||
)
|
||||
)
|
||||
(never)
|
||||
)
|
||||
)
|
||||
(canon -relay- $result-1_test #result-1_result_canon)
|
||||
)
|
||||
(ap #result-1_result_canon result-1_gate)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(match result-1_gate.$.[0] false
|
||||
(ap "resource wasn't created: timeout exceeded" $error)
|
||||
)
|
||||
(ap id $resource_id)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(fail %last_error%)
|
||||
)
|
||||
)
|
||||
(canon %init_peer_id% $resource_id #-resource_id-fix-0)
|
||||
)
|
||||
(ap #-resource_id-fix-0 -resource_id-flat-0)
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
(canon %init_peer_id% $error #error_canon)
|
||||
)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [-resource_id-flat-0 #error_canon])
|
||||
)
|
||||
`;
|
||||
|
||||
export type ResourceTestResult = [string | null, string[]]
|
||||
|
||||
export function resourceTest(
|
||||
label: string,
|
||||
config?: {ttl?: number}
|
||||
): Promise<ResourceTestResult>;
|
||||
|
||||
export function resourceTest(
|
||||
peer: IFluenceClient$$,
|
||||
label: string,
|
||||
config?: {ttl?: number}
|
||||
): Promise<ResourceTestResult>;
|
||||
|
||||
export function resourceTest(...args: any[]) {
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName": "resourceTest",
|
||||
"arrow": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"label": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "option"
|
||||
},
|
||||
{
|
||||
"type": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
},
|
||||
"tag": "array"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"names": {
|
||||
"relay": "-relay-",
|
||||
"getDataSrv": "getDataSrv",
|
||||
"callbackSrv": "callbackSrv",
|
||||
"responseSrv": "callbackSrv",
|
||||
"responseFnName": "response",
|
||||
"errorHandlingSrv": "errorHandlingSrv",
|
||||
"errorFnName": "error"
|
||||
}
|
||||
},
|
||||
resourceTest_script
|
||||
);
|
||||
}
|
||||
|
||||
export const helloTest_script = `
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(xor
|
||||
(call %init_peer_id% ("hello-world" "hello") ["Fluence user"] hello)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [hello])
|
||||
)
|
||||
`;
|
||||
|
||||
export function helloTest(
|
||||
config?: {ttl?: number}
|
||||
): Promise<string>;
|
||||
|
||||
export function helloTest(
|
||||
peer: IFluenceClient$$,
|
||||
config?: {ttl?: number}
|
||||
): Promise<string>;
|
||||
|
||||
export function helloTest(...args: any[]) {
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName": "helloTest",
|
||||
"arrow": {
|
||||
"domain": {
|
||||
"fields": {},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"names": {
|
||||
"relay": "-relay-",
|
||||
"getDataSrv": "getDataSrv",
|
||||
"callbackSrv": "callbackSrv",
|
||||
"responseSrv": "callbackSrv",
|
||||
"responseFnName": "response",
|
||||
"errorHandlingSrv": "errorHandlingSrv",
|
||||
"errorFnName": "error"
|
||||
}
|
||||
},
|
||||
helloTest_script
|
||||
);
|
||||
}
|
||||
|
||||
export const demo_calculation_script = `
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "service_id") [] service_id)
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% (service_id "test_logs") [])
|
||||
(call %init_peer_id% (service_id "add") [10])
|
||||
)
|
||||
(call %init_peer_id% (service_id "multiply") [5])
|
||||
)
|
||||
(call %init_peer_id% (service_id "subtract") [8])
|
||||
)
|
||||
(call %init_peer_id% (service_id "divide") [6])
|
||||
)
|
||||
(call %init_peer_id% (service_id "state") [] res)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||
)
|
||||
`;
|
||||
|
||||
export function demo_calculation(
|
||||
service_id: string,
|
||||
config?: {ttl?: number}
|
||||
): Promise<number>;
|
||||
|
||||
export function demo_calculation(
|
||||
peer: IFluenceClient$$,
|
||||
service_id: string,
|
||||
config?: {ttl?: number}
|
||||
): Promise<number>;
|
||||
|
||||
export function demo_calculation(...args: any[]) {
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName": "demo_calculation",
|
||||
"arrow": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"service_id": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"names": {
|
||||
"relay": "-relay-",
|
||||
"getDataSrv": "getDataSrv",
|
||||
"callbackSrv": "callbackSrv",
|
||||
"responseSrv": "callbackSrv",
|
||||
"responseFnName": "response",
|
||||
"errorHandlingSrv": "errorHandlingSrv",
|
||||
"errorFnName": "error"
|
||||
}
|
||||
},
|
||||
demo_calculation_script
|
||||
);
|
||||
}
|
||||
|
||||
export const marineTest_script = `
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "wasm64") [] wasm64)
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("single_module_srv" "create") [wasm64] serviceResult)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "test_logs") [])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "add") [10])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "multiply") [5])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "subtract") [8])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "divide") [6])
|
||||
)
|
||||
(call %init_peer_id% (serviceResult.$.service_id.[0] "state") [] res)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 0])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("callbackSrv" "response") [res])
|
||||
)
|
||||
`;
|
||||
|
||||
export function marineTest(
|
||||
wasm64: string,
|
||||
config?: {ttl?: number}
|
||||
): Promise<number>;
|
||||
|
||||
export function marineTest(
|
||||
peer: IFluenceClient$$,
|
||||
wasm64: string,
|
||||
config?: {ttl?: number}
|
||||
): Promise<number>;
|
||||
|
||||
export function marineTest(...args: any[]) {
|
||||
return callFunction$$(
|
||||
args,
|
||||
{
|
||||
"functionName": "marineTest",
|
||||
"arrow": {
|
||||
"domain": {
|
||||
"fields": {
|
||||
"wasm64": {
|
||||
"name": "string",
|
||||
"tag": "scalar"
|
||||
}
|
||||
},
|
||||
"tag": "labeledProduct"
|
||||
},
|
||||
"codomain": {
|
||||
"items": [
|
||||
{
|
||||
"name": "f64",
|
||||
"tag": "scalar"
|
||||
}
|
||||
],
|
||||
"tag": "unlabeledProduct"
|
||||
},
|
||||
"tag": "arrow"
|
||||
},
|
||||
"names": {
|
||||
"relay": "-relay-",
|
||||
"getDataSrv": "getDataSrv",
|
||||
"callbackSrv": "callbackSrv",
|
||||
"responseSrv": "callbackSrv",
|
||||
"responseFnName": "response",
|
||||
"errorHandlingSrv": "errorHandlingSrv",
|
||||
"errorFnName": "error"
|
||||
}
|
||||
},
|
||||
marineTest_script
|
||||
);
|
||||
}
|
||||
|
||||
/* eslint-enable */
|
@ -1,87 +0,0 @@
|
||||
aqua Main
|
||||
|
||||
use DECLARE_CONST, decl_bar from "imports_exports/declare.aqua" as Declare
|
||||
|
||||
export handleAb, SomeService, bug214, checkAbCalls
|
||||
|
||||
service SomeService("wed"):
|
||||
getStr(s: string) -> string
|
||||
|
||||
ability SomeAb:
|
||||
someArrow(s: string) -> string, string
|
||||
str: string
|
||||
|
||||
ability SecondAb:
|
||||
arrow(s: string) -> string
|
||||
num: u32
|
||||
|
||||
func funcStr(s: string) -> string, string:
|
||||
strInFunc <- SomeService.getStr(Declare.DECLARE_CONST)
|
||||
strInFunc2 <- SomeService.getStr(s)
|
||||
<- strInFunc, strInFunc2
|
||||
|
||||
func handleSecAb {SomeAb, SecondAb}() -> string, string, string, u32:
|
||||
SomeAb.someArrow("eferfrfrf")
|
||||
b, c <- SomeAb.someArrow("efre")
|
||||
d <- SecondAb.arrow(SomeAb.str)
|
||||
<- b, c, d, SecondAb.num
|
||||
|
||||
func returnAb(s: string) -> SomeAb:
|
||||
SomeAb = SomeAb(someArrow = funcStr, str = s)
|
||||
<- SomeAb
|
||||
|
||||
func handleAb(fff: string) -> string, string, string, u32:
|
||||
SomeAb = returnAb(fff)
|
||||
SecondAb = SecondAb(arrow = funcStr, num = 12)
|
||||
res1, res2, res3, res4 <- handleSecAb{SomeAb, SecondAb}()
|
||||
<- res1, res2, res3, res4
|
||||
|
||||
data Struct:
|
||||
int: i8
|
||||
|
||||
ability Simple:
|
||||
st: Struct
|
||||
arrow(x: i8) -> bool
|
||||
|
||||
ability Complex:
|
||||
simple: Simple
|
||||
field: string
|
||||
|
||||
func foo{Complex, Simple}() -> bool, bool:
|
||||
closure = () -> bool:
|
||||
<- Simple.st.int >= 0
|
||||
res <- closure()
|
||||
<- Complex.simple.arrow(
|
||||
Complex.simple.st.int
|
||||
), res
|
||||
|
||||
func bug214() -> bool, bool:
|
||||
closure = (x: i8) -> bool:
|
||||
<- x > 0
|
||||
|
||||
MyComplex = Complex(
|
||||
simple = Simple(
|
||||
st = Struct(int = 0),
|
||||
arrow = closure
|
||||
),
|
||||
field = "complex"
|
||||
)
|
||||
|
||||
res1, res2 <- foo{MyComplex, MyComplex.simple}()
|
||||
<- res1, res2
|
||||
|
||||
ability SSS:
|
||||
arrow(x: i8) -> bool
|
||||
|
||||
ability CCCC:
|
||||
arrow(x: i8) -> bool
|
||||
simple: SSS
|
||||
|
||||
func checkAbCalls() -> bool, bool:
|
||||
closure = (x: i8) -> bool:
|
||||
<- x > 20
|
||||
|
||||
MySSS = SSS(arrow = closure)
|
||||
MyCCCC = CCCC(simple = MySSS, arrow = MySSS.arrow)
|
||||
|
||||
<- MySSS.arrow(42), MyCCCC.arrow(12)
|
@ -1,24 +0,0 @@
|
||||
data SomeData:
|
||||
value: string
|
||||
otherValue: u64
|
||||
|
||||
data SubData:
|
||||
someStr: string
|
||||
someNum: i32
|
||||
|
||||
data SecondData:
|
||||
value: string
|
||||
complex: SubData
|
||||
|
||||
data ThirdData:
|
||||
value: string
|
||||
complex: SomeData
|
||||
|
||||
service ComplexService("op-ha"):
|
||||
call(d: SomeData, sd: SecondData) -> SubData
|
||||
identity() -> SecondData
|
||||
|
||||
func doSmth(d: SomeData, d2: SomeData, sd: SecondData, c: SubData, SecondData -> ThirdData) -> ThirdData:
|
||||
res <- ComplexService.call(d, sd)
|
||||
res2 <- c(res, sd)
|
||||
<- res2
|
@ -1,13 +0,0 @@
|
||||
data Prod:
|
||||
value: string
|
||||
|
||||
service OpHa("op"):
|
||||
array(a: string, b: string) -> []string
|
||||
identity(a: string) -> string
|
||||
|
||||
func doSmth(arg: Prod) -> []string:
|
||||
v = arg.value
|
||||
a <- OpHa.identity(v)
|
||||
b = "hello"
|
||||
res <- OpHa.array(a, b)
|
||||
<- res
|
@ -1,65 +0,0 @@
|
||||
aqua Bool
|
||||
|
||||
export main, compareStreams, compareStructs, Effector
|
||||
|
||||
service Effector("effector"):
|
||||
effect(name: string) -> bool
|
||||
|
||||
func foo(x: i8) -> bool:
|
||||
y = x + 1
|
||||
<- y < 5
|
||||
|
||||
func bar(x: i8) -> i8:
|
||||
y = x - 1
|
||||
<- y
|
||||
|
||||
func compareStreams(peer: string) -> bool:
|
||||
s1: *i8
|
||||
s2: *i8
|
||||
|
||||
on peer:
|
||||
s1 <<- bar(43)
|
||||
s2 <<- bar(43)
|
||||
|
||||
<- s1 == s2
|
||||
|
||||
data Struct:
|
||||
field: i8
|
||||
str: string
|
||||
|
||||
func compareStructs(peer: string, str: string) -> bool:
|
||||
on peer:
|
||||
st1 = Struct(field = 42, str = str)
|
||||
st2 = Struct(field = 24, str = str)
|
||||
|
||||
<- st1 == st2
|
||||
|
||||
func main(peer: string) -> []bool:
|
||||
res: *bool
|
||||
|
||||
on peer:
|
||||
a = 1 + 2
|
||||
b = 2 - 1
|
||||
res <<- true || false && true -- true
|
||||
res <<- (true || false) && true -- true
|
||||
res <<- foo(3) && b > 0 || a > 4 -- true
|
||||
res <<- bar(a) > 2 || true -- true
|
||||
res <<- foo(4) && bar(2) < 2 -- false
|
||||
res <<- !foo(10) && !!true -- true
|
||||
res <<- !(bar(2) < 1) || !!(a < 2) -- true
|
||||
res <<- bar(42) == bar(40 + 2) && foo(10) -- false
|
||||
res <<- bar(2) < 5 || bar(2) != 1 -- true
|
||||
|
||||
-- Effector is only registered on init_peer
|
||||
res <<- true || Effector.effect("impossible") -- true
|
||||
res <<- !!false && Effector.effect("impossible") -- false
|
||||
res <<- foo(0) || Effector.effect("impossible") -- true
|
||||
res <<- foo(10) && Effector.effect("impossible") -- false
|
||||
res <<- Effector.effect("true") || true -- true
|
||||
res <<- Effector.effect("true") && false -- false
|
||||
res <<- !foo(10) || Effector.effect("impossible") -- true
|
||||
res <<- !(1 < 2) && !Effector.effect("impossible") -- false
|
||||
res <<- !(bar(5) == 5) || Effector.effect("impossible") -- true
|
||||
res <<- bar(5) != 4 && Effector.effect("impossible") -- false
|
||||
|
||||
<- res
|
@ -1,16 +0,0 @@
|
||||
import "println.aqua"
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
-- functions like `c` are called an 'arrow function' in Aqua
|
||||
-- `c` passed to a function from a client, so, it could be called only on a client
|
||||
func passFunctionAsArg(node: string, str: string, c: string -> string):
|
||||
on node:
|
||||
Peer.identify()
|
||||
-- we go here back on a client
|
||||
res <- c(str)
|
||||
-- then return on a node
|
||||
Peer.identify()
|
||||
print(res)
|
||||
|
||||
func reproArgsBug426(log: string -> (), arg: string):
|
||||
log(arg)
|
@ -1,14 +0,0 @@
|
||||
data Record:
|
||||
relay_id: []string
|
||||
peer_id: string
|
||||
|
||||
service Ser("ser"):
|
||||
getRecord: -> Record
|
||||
|
||||
func bugLng79(log: string -> ()) -> u32:
|
||||
stream: *Record
|
||||
stream <- Ser.getRecord()
|
||||
someone = stream[0]
|
||||
on someone.peer_id via someone.relay_id:
|
||||
a = 1 + 1
|
||||
<- a
|
@ -1,18 +0,0 @@
|
||||
aqua ClosureReturnRename
|
||||
|
||||
export lng193Bug
|
||||
|
||||
func getClosure(arg: u16, peer: string) -> u16 -> u16:
|
||||
on peer:
|
||||
closure = (x: u16) -> u16:
|
||||
<- arg + x
|
||||
<- closure
|
||||
|
||||
func lng193Bug(peer: string, closurePeer: string) -> u16:
|
||||
on peer:
|
||||
c = getClosure(42, closurePeer)
|
||||
b = c
|
||||
a = b
|
||||
res1 = a(1) + a(2) -- Call two times for
|
||||
res2 = b(3) + b(4) -- bug to appear
|
||||
<- res1 + res2
|
@ -1,73 +0,0 @@
|
||||
module Closure declares *
|
||||
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
export LocalSrv, closureIn, closureOut, closureBig, closureOut2, lng58Bug
|
||||
|
||||
service MyOp("op"):
|
||||
identity(s: string) -> string
|
||||
|
||||
service LocalSrv("local_srv"):
|
||||
inside: -> ()
|
||||
|
||||
func closureIn(peer1: string) -> string:
|
||||
variable = "const"
|
||||
co on peer1:
|
||||
p1Id <- MyOp.identity("co on")
|
||||
closure = (s: string) -> string:
|
||||
if s == "in":
|
||||
LocalSrv.inside()
|
||||
p2Id <- MyOp.identity(s)
|
||||
<- p2Id
|
||||
p <- closure("in")
|
||||
<- p
|
||||
|
||||
func closureOut(peer2: string) -> Info:
|
||||
on peer2:
|
||||
closure = (s: string) -> Info:
|
||||
if s == "in":
|
||||
LocalSrv.inside()
|
||||
p2Id <- Peer.identify()
|
||||
<- p2Id
|
||||
p2Id <- closure("on")
|
||||
<- p2Id
|
||||
|
||||
func closureOut2(peer2: string) -> Info:
|
||||
closure = func (s: string) -> Info:
|
||||
if s == "in":
|
||||
LocalSrv.inside()
|
||||
p2Id <- Peer.identify()
|
||||
<- p2Id
|
||||
on peer2:
|
||||
p2Id <- closure("on")
|
||||
<- p2Id
|
||||
|
||||
|
||||
func closureBig(peer1: string, peer2: string) -> string, string:
|
||||
variable = "const"
|
||||
co on peer1:
|
||||
p1Id <- MyOp.identity("co on")
|
||||
closure = func (s: string) -> string:
|
||||
p2Id: *string
|
||||
if s == "in":
|
||||
p2 <- MyOp.identity(s)
|
||||
p2Id <<- p2
|
||||
else:
|
||||
p2Info <- Peer.identify()
|
||||
p2Id <<- p2Info.external_addresses!0
|
||||
<- p2Id!
|
||||
p <- closure("in")
|
||||
on peer2:
|
||||
p2Id <- closure("on")
|
||||
<- p, p2Id
|
||||
|
||||
func lng58Bug() -> string:
|
||||
status: *string
|
||||
waiting = ():
|
||||
avava: *string
|
||||
avava <<- "frerf"
|
||||
status <<- "ok"
|
||||
|
||||
waiting()
|
||||
|
||||
<- status!
|
@ -1,13 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service CoService("coservice-id"):
|
||||
call: -> string
|
||||
|
||||
-- here we go to another node and not waiting for execution there
|
||||
-- all `ParService.call()` will be executed instantly
|
||||
func coFunc( node: string, c: Info -> () ):
|
||||
y <- CoService.call()
|
||||
on node:
|
||||
t <- Peer.identify()
|
||||
co c(t)
|
||||
x <- CoService.call()
|
@ -1,43 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
func arraySugar(n: u32, m: u32) -> []u32, []u32:
|
||||
arr = [1,2,n]
|
||||
str: *u32
|
||||
for i <- [4,5,m]:
|
||||
str <<- i
|
||||
<- arr, str
|
||||
|
||||
func streamSugar(n: u32, m: u32) -> []u32, []u32:
|
||||
arr = *[1,2,n]
|
||||
str: *u32
|
||||
for i <- *[4,5,m]:
|
||||
str <<- i
|
||||
<- arr, str
|
||||
|
||||
func optionSugar(numSome: ?u32, strSome: ?string, numNone: ?u32, strNone: ?string) -> []u32, []string, []string:
|
||||
arr = ?[numNone!, numSome!]
|
||||
str: *string
|
||||
str2 = ?[strNone!, strNone!, strNone!, strNone!, strNone!]
|
||||
for i <- ?[strSome!,strNone!, "random string"]:
|
||||
str <<- i
|
||||
|
||||
for i <- ?[strNone!,strNone!]:
|
||||
str <<- i
|
||||
<- arr, str, str2
|
||||
|
||||
service OpO("op"):
|
||||
identity: string -> string
|
||||
|
||||
service GetArr("getArr"):
|
||||
getArr: -> []string
|
||||
|
||||
func getNeighbours() -> []string:
|
||||
nodes <- GetArr.getArr()
|
||||
<- nodes
|
||||
|
||||
func bugLNG59() -> string:
|
||||
nodes <- getNeighbours()
|
||||
n = nodes[1]
|
||||
on n via [HOST_PEER_ID]:
|
||||
res <- OpO.identity("some str")
|
||||
<- res
|
@ -1,40 +0,0 @@
|
||||
import "helloWorld.aqua"
|
||||
import "println.aqua"
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
import "func.aqua"
|
||||
|
||||
service TestS("some-id"):
|
||||
t: string -> string
|
||||
multiline( -- comments
|
||||
a: string, -- comments
|
||||
b: string, -- comments
|
||||
c: bool -- comments
|
||||
) -> string -- comments
|
||||
|
||||
-- just a lot of imports and calls
|
||||
func doStuff( -- comments
|
||||
a: string, -- comments
|
||||
b: string, -- comments
|
||||
c: bool,
|
||||
d: bool, e: []string, g: []string, str: string -- comments
|
||||
) -> []string: -- comments
|
||||
stream: *string
|
||||
stream <- TestS.t(str)
|
||||
par Println.print(a)
|
||||
par on a:
|
||||
Peer.identify()
|
||||
on a:
|
||||
on b:
|
||||
if c:
|
||||
if d:
|
||||
for eEl <- e:
|
||||
for gEl <- g:
|
||||
stream <- TestS.t(gEl) -- comments
|
||||
stream <- TestS.t(eEl)
|
||||
stream <- TestS.t(eEl)
|
||||
stream <- TestS.multiline( -- comments
|
||||
a, -- comments
|
||||
b, -- comments
|
||||
c -- comments
|
||||
) -- comments
|
||||
<- stream
|
@ -1,33 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service Getter("test"):
|
||||
createStr: u32 -> string
|
||||
|
||||
service OpO("op"):
|
||||
identity: string -> string
|
||||
|
||||
service OpN("op"):
|
||||
identity: i32 -> i32
|
||||
|
||||
-- a question mark means that this constant could be rewritten before this definition
|
||||
const ANOTHER_CONST ?= "default-str"
|
||||
const UNIQUE_CONST ?= 5
|
||||
|
||||
func callConstant() -> []string:
|
||||
res: *string
|
||||
res <- Getter.createStr(UNIQUE_CONST)
|
||||
res <- OpO.identity(ANOTHER_CONST)
|
||||
<- res
|
||||
|
||||
func timestampAndTtl() -> u32, u64:
|
||||
Op.noop()
|
||||
<- PARTICLE_TTL, PARTICLE_TIMESTAMP
|
||||
|
||||
const A = 2
|
||||
const B = -3
|
||||
|
||||
func compareConstants():
|
||||
if A == B:
|
||||
OpN.identity(A)
|
||||
else:
|
||||
OpN.identity(B)
|
@ -1,17 +0,0 @@
|
||||
-- set `PeerId` name to be a type alias for `string` type
|
||||
alias PeerId : string
|
||||
|
||||
-- define data structure (ADT)
|
||||
data NodeId:
|
||||
peerId: PeerId
|
||||
name: string
|
||||
|
||||
-- define service `NodeIdGetter` that will be callable on local client via `somesrv` service id
|
||||
service NodeIdGetter("somesrv"):
|
||||
get: -> NodeId
|
||||
|
||||
-- showcases a function that gets data structure from a local service,
|
||||
-- and then retrieves aliased data type from that structure
|
||||
func getAliasedData() -> PeerId:
|
||||
res <- NodeIdGetter.get()
|
||||
<- res.peerId
|
@ -1,20 +0,0 @@
|
||||
service Peer("peer"):
|
||||
is_connected: string -> bool
|
||||
|
||||
service Op("op"):
|
||||
identity: -> ()
|
||||
|
||||
data User:
|
||||
peer_id: string
|
||||
relay_id: string
|
||||
name: string
|
||||
|
||||
service Test("test"):
|
||||
getUserList: -> []User
|
||||
doSomething: -> bool
|
||||
|
||||
func betterMessage(relay: string):
|
||||
on relay:
|
||||
isOnline <- Peer.is_connected(relay)
|
||||
if isOnline:
|
||||
Test.doSomething()
|
@ -1,24 +0,0 @@
|
||||
import "println.aqua"
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
-- showcases `for` instruction that compiles to `fold` in AIR
|
||||
func iterateAndPrint(strings: []string):
|
||||
for s <- strings:
|
||||
print(s)
|
||||
|
||||
func iterateAndPrintParallel(nodes: []string, c: Info -> ()):
|
||||
for s <- nodes par:
|
||||
on s:
|
||||
ads <- Peer.identify()
|
||||
c(ads)
|
||||
|
||||
func to_i_64(i: u32) -> i64:
|
||||
<- i
|
||||
|
||||
func forBug499() -> []i64:
|
||||
num = 5
|
||||
numbers: *i64
|
||||
for i <- [""]:
|
||||
ali64 <- to_i_64(num)
|
||||
numbers <<- ali64
|
||||
<- numbers
|
@ -1,19 +0,0 @@
|
||||
module FoldJoin
|
||||
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
export getTwoResults
|
||||
|
||||
service Op2("op"):
|
||||
identity(s: u64)
|
||||
|
||||
func getTwoResults(node: string) -> []u64:
|
||||
on node:
|
||||
nodes <- Kademlia.neighborhood(%init_peer_id%, nil, nil)
|
||||
res: *u64
|
||||
for n <- nodes par:
|
||||
on n:
|
||||
try:
|
||||
res <- Peer.timestamp_sec()
|
||||
join res!2
|
||||
<- res
|
@ -1,6 +0,0 @@
|
||||
service TestSrv("test-service-id"):
|
||||
str: -> string
|
||||
|
||||
func testFunc() -> string:
|
||||
res <- TestSrv.str()
|
||||
<- res
|
@ -1,39 +0,0 @@
|
||||
module Funcs declares main, A, calc
|
||||
|
||||
export main, A, calc, calc2, ifCalc
|
||||
|
||||
service A("a"):
|
||||
getJ(i: u32) -> u32
|
||||
|
||||
func main(log: string, []u32 -> ()) -> u32:
|
||||
closure = (i: []u32, j: u32) -> u32:
|
||||
some <- A.getJ(i[j])
|
||||
<- some
|
||||
closure2 = func (i: []u32, j: u32) -> u32:
|
||||
some <- A.getJ(i[j])
|
||||
<- some
|
||||
arr = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
|
||||
idx1 <- A.getJ(arr[A.getJ(3) + 2]) -- 5
|
||||
idx2 <- A.getJ(arr[A.getJ(3) + 3] + arr[A.getJ(1) - 1] - 3) -- 3
|
||||
<- A.getJ(arr[(idx1 + idx2) + closure(arr, 2) + closure2(arr, 3)]) -- should be 13
|
||||
|
||||
|
||||
func calc(log: string, []u32 -> ()) -> u32:
|
||||
arr = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
|
||||
num <- A.getJ((5-2)*3-3) -- 6
|
||||
log("calc 2", [num])
|
||||
<- arr[num] -- should be 6
|
||||
|
||||
func calc2(log: string, []u32 -> ()) -> u32:
|
||||
arr = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
|
||||
num <- A.getJ((5-2) * 3 - 3 ** (A.getJ(5 + 5) - A.getJ(3 ** (3 - 1)))) -- 6
|
||||
<- arr[num + num - A.getJ(num) - 3] -- should be 3
|
||||
|
||||
func ifCalc() -> u64:
|
||||
arr = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
|
||||
res: *u64
|
||||
if A.getJ(8 - 2) + A.getJ(4 % 2) > arr[5 - 3 + A.getJ(3)] - 2:
|
||||
res <<- 1
|
||||
else:
|
||||
res <<- 2
|
||||
<- res!0
|
@ -1,6 +0,0 @@
|
||||
func lng119Bug() -> []u32:
|
||||
nums = [1,2,3,4,5]
|
||||
results: *u32
|
||||
results <<- 1
|
||||
join results[nums.length-5]
|
||||
<- results
|
@ -1,6 +0,0 @@
|
||||
service StringExtra("service-id"):
|
||||
addNameToHello: string -> string
|
||||
|
||||
func helloWorld(name: string) -> string:
|
||||
res <- StringExtra.addNameToHello(name)
|
||||
<- res
|
@ -1,36 +0,0 @@
|
||||
import "println.aqua"
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service OpR("op"):
|
||||
identity(s: string) -> string
|
||||
|
||||
func ifElseCall(condition: bool):
|
||||
if condition:
|
||||
Println.print("it is true")
|
||||
else:
|
||||
Println.print("it is false")
|
||||
|
||||
func ifElseNumCall(condition: u32):
|
||||
if condition == 1:
|
||||
Println.print("it is 1")
|
||||
else:
|
||||
Println.print("it is not 1")
|
||||
|
||||
func ifCorrectXorWrap(node: string) -> string:
|
||||
service_id: *string
|
||||
on node:
|
||||
res <- OpR.identity("1234")
|
||||
if res == "":
|
||||
service_id <<- "0x"
|
||||
else:
|
||||
service_id <<- "1x"
|
||||
<- service_id!
|
||||
|
||||
func bugLNG69(other_node: PeerId) -> bool:
|
||||
on other_node:
|
||||
Op.noop()
|
||||
|
||||
if false:
|
||||
Op.noop()
|
||||
|
||||
<- true
|
@ -1,15 +0,0 @@
|
||||
module FooBars declares decl_foo, decl_bar, SuperFoo, DECLARE_CONST, DECLARE_CONST2
|
||||
export SuperFoo
|
||||
|
||||
const DECLARE_CONST = "declare_const"
|
||||
const DECLARE_CONST2 = "declare_const2"
|
||||
|
||||
service SuperFoo("super_foo"):
|
||||
small_foo() -> string
|
||||
|
||||
func decl_foo() -> string:
|
||||
res1 <- SuperFoo.small_foo()
|
||||
<- res1
|
||||
|
||||
func decl_bar() -> string:
|
||||
<- "declare all bar"
|
@ -1,16 +0,0 @@
|
||||
module Export declares foobar, foo
|
||||
|
||||
import Op as Noop from "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
func bar() -> string:
|
||||
<- " I am MyFooBar bar"
|
||||
|
||||
func foo() -> string:
|
||||
<- "I am MyFooBar foo"
|
||||
|
||||
func foobar() -> []string:
|
||||
Noop.noop()
|
||||
res: *string
|
||||
res <- foo()
|
||||
res <- bar()
|
||||
<- res
|
@ -1,8 +0,0 @@
|
||||
-- exports3.aqua
|
||||
module Export3 declares *
|
||||
|
||||
import Op as Noop from "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
func foo() -> string:
|
||||
Noop.noop()
|
||||
<- "I am MyFooBar foo"
|
@ -1,18 +0,0 @@
|
||||
module Exports declares some_string, MyExportSrv, EXPORT_CONST, some_random_func
|
||||
|
||||
import Op as Noop from "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
export some_string as string_from_lib
|
||||
export MyExportSrv
|
||||
|
||||
const EXPORT_CONST = "export_const"
|
||||
|
||||
service MyExportSrv("my_export_srv"):
|
||||
another_str() -> string
|
||||
|
||||
func some_string() -> string:
|
||||
Noop.noop()
|
||||
<- "some_string_func"
|
||||
|
||||
func some_random_func() -> string:
|
||||
<- "wow, so random"
|
@ -1,2 +0,0 @@
|
||||
service OneMore:
|
||||
more_call()
|
@ -1,18 +0,0 @@
|
||||
module Import
|
||||
import foobar from "export2.aqua"
|
||||
|
||||
use foo as f from "export2.aqua" as Exp
|
||||
|
||||
import "gen/OneMore.aqua"
|
||||
|
||||
import OneMore as OM from "gen/OneMore.aqua"
|
||||
|
||||
export foo_wrapper as wrap, foobar as barfoo
|
||||
|
||||
func foo_wrapper() -> string:
|
||||
z <- Exp.f()
|
||||
OneMore "hello"
|
||||
OneMore.more_call()
|
||||
OM "ohmygod"
|
||||
OM.more_call()
|
||||
<- z
|
@ -1,12 +0,0 @@
|
||||
-- imports3.aqua
|
||||
module Import3 declares *
|
||||
import Op as Noop from "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
export foo_wrapper
|
||||
|
||||
use "export3.aqua"
|
||||
|
||||
func foo_wrapper() -> string:
|
||||
Noop.noop()
|
||||
z <- Export3.foo()
|
||||
<- z
|
@ -1,6 +0,0 @@
|
||||
import decl_foo, decl_bar from "declare.aqua"
|
||||
use DECLARE_CONST, SuperFoo, DECLARE_CONST2 as DC2 from "declare.aqua" as Declare
|
||||
import Op as Noop from "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
import some_string, MyExportSrv, EXPORT_CONST, some_random_func from "exports.aqua"
|
||||
|
||||
export some_string as some_str, some_random_func, MyExportSrv, EXPORT_CONST
|
@ -1,23 +0,0 @@
|
||||
import decl_foo, decl_bar from "declare.aqua"
|
||||
use DECLARE_CONST, SuperFoo, DECLARE_CONST2 as DC2 from "declare.aqua" as Declare
|
||||
import Op as Noop from "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
import some_string, MyExportSrv, EXPORT_CONST from "exports.aqua"
|
||||
use "export3.aqua"
|
||||
|
||||
service StringService("string_service"):
|
||||
concat(a: string, b: string) -> string
|
||||
|
||||
func concat_foobars() -> string:
|
||||
Noop.noop()
|
||||
Export3.foo()
|
||||
res1 <- decl_foo()
|
||||
res2 <- decl_bar()
|
||||
res3 <- StringService.concat(res1, res2)
|
||||
res4 <- Declare.SuperFoo.small_foo()
|
||||
Noop.noop()
|
||||
res5 <- StringService.concat(res3, res4)
|
||||
res6 <- StringService.concat(res5, EXPORT_CONST)
|
||||
res7 <- StringService.concat(res6, Declare.DECLARE_CONST)
|
||||
Noop.noop()
|
||||
res8 <- StringService.concat(res7, Declare.DC2)
|
||||
<- res8
|
@ -1,13 +0,0 @@
|
||||
|
||||
alias SomeString : string
|
||||
|
||||
data SomeResult:
|
||||
one: SomeString
|
||||
two: u32
|
||||
|
||||
service SubService("sub_service"):
|
||||
sub(s: SomeString) -> SomeResult
|
||||
|
||||
func subImport() -> SomeResult:
|
||||
res <- SubService.sub("some thing")
|
||||
<- res
|
@ -1,26 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
func joinIdxLocal(idx: i16, nodes: []string) -> []string:
|
||||
nodes2: *string
|
||||
for node <- nodes par:
|
||||
nodes2 <<- node
|
||||
join nodes2[idx], nodes
|
||||
<- nodes2
|
||||
|
||||
func joinIdxRelay(idx: i16, nodes: []string) -> []string:
|
||||
on HOST_PEER_ID:
|
||||
nodes2: *string
|
||||
for node <- nodes par:
|
||||
nodes2 <<- node
|
||||
join nodes2[idx], nodes
|
||||
<- nodes2
|
||||
|
||||
func joinIdx(idx: i16, nodes: []string) -> []Info:
|
||||
infos: *Info
|
||||
nodes2: *string
|
||||
for node <- nodes par:
|
||||
on node:
|
||||
infos <- Peer.identify()
|
||||
nodes2 <<- node
|
||||
join infos[idx-1+1], nodes2[idx-1+1]
|
||||
<- infos
|
@ -1,79 +0,0 @@
|
||||
aqua Math
|
||||
|
||||
export test1, test2, testI16, testI32, testI64, testU64
|
||||
|
||||
func test1() -> u64:
|
||||
res = 1 + 2 - 3 * 5 - 2 * 3 / 2 + 5
|
||||
<- res
|
||||
|
||||
func test2() -> u64:
|
||||
res = 2 ** 2 ** (2 * 2 - 2) + 2 - 3 * 5 - 2 * 3 / 2 + 5 + (4 % 2 - 2)
|
||||
<- res
|
||||
|
||||
func getI8() -> i8:
|
||||
<- -8
|
||||
|
||||
func getI16() -> i16:
|
||||
<- -16
|
||||
|
||||
func getI32() -> i32:
|
||||
<- -32
|
||||
|
||||
func getI64() -> i64:
|
||||
<- -64
|
||||
|
||||
func getU8() -> u8:
|
||||
<- 8
|
||||
|
||||
func getU16() -> u16:
|
||||
<- 16
|
||||
|
||||
func getU32() -> u32:
|
||||
<- 32
|
||||
|
||||
func getU64() -> u64:
|
||||
<- 64
|
||||
|
||||
func testI16(peer: string) -> []i16:
|
||||
res: *i16
|
||||
|
||||
on peer:
|
||||
res <<- getI16() + getI16()
|
||||
res <<- getI8() * getU8()
|
||||
res <<- getI8() % getI16()
|
||||
res <<- getI16() - getI8()
|
||||
|
||||
<- res
|
||||
|
||||
func testI32(peer: string) -> []i32:
|
||||
res: *i32
|
||||
|
||||
on peer:
|
||||
res <<- getI32() + getU16()
|
||||
res <<- getI16() * getU16()
|
||||
res <<- getI8() % getU16()
|
||||
res <<- getI16() - getI32()
|
||||
|
||||
<- res
|
||||
|
||||
func testI64(peer: string) -> []i64:
|
||||
res: *i64
|
||||
|
||||
on peer:
|
||||
res <<- getI32() + getU32()
|
||||
res <<- getI16() * getU32()
|
||||
res <<- getI64() % getI64()
|
||||
res <<- getU8() - getI64()
|
||||
|
||||
<- res
|
||||
|
||||
func testU64(peer: string) -> []u64:
|
||||
res: *u64
|
||||
|
||||
on peer:
|
||||
res <<- getU32() + getU64()
|
||||
res <<- getU64() * getU64()
|
||||
res <<- getU64() % getU16()
|
||||
res <<- getU8() - getU64()
|
||||
|
||||
<- res
|
@ -1,22 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service GetStr("multiret-test"):
|
||||
retStr: string -> string
|
||||
|
||||
service GetNum("multiret-num"):
|
||||
retNum: -> u8
|
||||
|
||||
const SOME_NUM = 5
|
||||
const SOME_STR = "some-str"
|
||||
|
||||
func tupleFunc() -> string, u8:
|
||||
str <- GetStr.retStr(SOME_STR)
|
||||
n <- GetNum.retNum()
|
||||
<- str, n
|
||||
|
||||
func multiReturnFunc(somethingToReturn: []u8, smthOption: ?string) -> []string, u8, string, []u8, ?string, u8 :
|
||||
res: *string
|
||||
res <- GetStr.retStr(SOME_STR)
|
||||
res <- GetStr.retStr("random-str")
|
||||
res, tNum <- tupleFunc()
|
||||
<- res, SOME_NUM, SOME_STR, somethingToReturn, smthOption, tNum
|
@ -1,18 +0,0 @@
|
||||
data NestedType:
|
||||
val: string
|
||||
|
||||
data NestedStruct:
|
||||
one: NestedType
|
||||
|
||||
service Test("service"):
|
||||
test1() -> NestedStruct
|
||||
test2(arg1: NestedType, arg2: string) -> NestedStruct
|
||||
|
||||
func test3() -> NestedType:
|
||||
res <- Test.test1()
|
||||
<- res.one
|
||||
|
||||
func test() -> NestedStruct:
|
||||
struct <- test3()
|
||||
res <- Test.test2(struct, struct.val)
|
||||
<- res
|
@ -1,12 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service OpH("opa"):
|
||||
identity(s: string) -> string
|
||||
|
||||
func a(b: string) -> string:
|
||||
c <- OpH.identity(b)
|
||||
<- c
|
||||
|
||||
func d(e: string) -> string:
|
||||
f <- a(e)
|
||||
<- f
|
@ -1,40 +0,0 @@
|
||||
aqua StructCreation declares getObj, getObjRelay, getObjAssign
|
||||
|
||||
export getObj, getObjRelay, getObjAssign
|
||||
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
data InnerObj:
|
||||
arr: []string
|
||||
num: u32
|
||||
|
||||
data SomeObj:
|
||||
str: string
|
||||
num: u64
|
||||
inner: InnerObj
|
||||
|
||||
service OpNum("op"):
|
||||
identity(n: u32) -> u32
|
||||
|
||||
service OpStr("op"):
|
||||
identity(n: string) -> string
|
||||
|
||||
service OpArr("op"):
|
||||
identity(arr: []string) -> []string
|
||||
|
||||
func getObj() -> SomeObj:
|
||||
<- SomeObj(str = OpStr.identity("some str"), num = 5, inner = InnerObj(arr = ["a", "b", "c"], num = 6))
|
||||
|
||||
func getObjRelay() -> SomeObj:
|
||||
on HOST_PEER_ID:
|
||||
obj = SomeObj(str = "diff str", num = 5, inner = InnerObj(arr = OpArr.identity(["a", "b", "c"]), num = 6))
|
||||
Op.noop()
|
||||
<- obj.copy(str = "some str")
|
||||
|
||||
func getObjAssign() -> SomeObj, SomeObj, u32:
|
||||
obj = SomeObj(str = "first str",
|
||||
num = OpNum.identity(5),
|
||||
inner = InnerObj(arr = ["d", "e", "f"], num = 7)
|
||||
)
|
||||
copiedObj = obj.copy(str = "some str", inner = obj.inner.copy(arr = ["a", "b", "c"])).copy(num = 6)
|
||||
<- obj, copiedObj, copiedObj.inner.copy(arr = ["g"]).arr.length
|
@ -1,12 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
func getPeerExternalAddresses(otherNodePeerId: string) -> []string:
|
||||
on otherNodePeerId:
|
||||
res <- Peer.identify()
|
||||
<- res.external_addresses
|
||||
|
||||
-- it is possible to use `via` to built complex routes
|
||||
func getDistantAddresses(target: string, viaNode: string) -> []string:
|
||||
on target via viaNode:
|
||||
res <- Peer.identify()
|
||||
<- res.external_addresses
|
@ -1,39 +0,0 @@
|
||||
service Test("test-service"):
|
||||
fail(err: string)
|
||||
|
||||
func onPropagate(peer: string, relay: string) -> u16:
|
||||
res: *u16
|
||||
on peer via relay:
|
||||
res <<- 0 + 1
|
||||
Test.fail("propagated error")
|
||||
res <<- 0 + 2
|
||||
|
||||
join res[3] -- Unreachable
|
||||
|
||||
<- res[3]
|
||||
|
||||
func nestedOnPropagate(peer: string, relay: string, iPeer: string, iRelay: string, friend: string) -> u16:
|
||||
res: *u16
|
||||
on iPeer via iRelay:
|
||||
res <<- 40 + 2
|
||||
on friend:
|
||||
res <<- 2 + 40
|
||||
on peer via relay:
|
||||
Test.fail("propagated error")
|
||||
res <<- 30 + 7
|
||||
|
||||
join res[3] -- Unreachable
|
||||
|
||||
<- res[3]
|
||||
|
||||
func seqOnPropagate(peer: string, relay: string, iPeer: string, iRelay: string) -> u16:
|
||||
res: *u16
|
||||
on iPeer via iRelay:
|
||||
res <<- 40 + 2
|
||||
on peer via relay:
|
||||
Test.fail("propagated error")
|
||||
res <<- 30 + 7
|
||||
|
||||
join res[2] -- Unreachable
|
||||
|
||||
<- res[2]
|
@ -1,25 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service SomeS("test2"):
|
||||
getStr: ?string -> ?string
|
||||
getStr1: -> ?string
|
||||
getStr2: string -> string
|
||||
checkU32(u: ?u32)
|
||||
|
||||
func checkU32AndU8(a: ?u8):
|
||||
SomeS.checkU32(a)
|
||||
|
||||
func useOptional(opt: ?string) -> string:
|
||||
res <- SomeS.getStr(opt)
|
||||
for i <- opt:
|
||||
SomeS.getStr2(i)
|
||||
<- res!
|
||||
|
||||
func returnOptional() -> ?string:
|
||||
res <- SomeS.getStr1()
|
||||
<- res
|
||||
|
||||
func returnNone() -> ?string:
|
||||
result: *string
|
||||
Op.noop()
|
||||
<- result
|
@ -1,21 +0,0 @@
|
||||
service OptionString("opt_str"):
|
||||
checkOption(str: ?string) -> string
|
||||
|
||||
func emptyString() -> ?string:
|
||||
valueEmpty: ?string
|
||||
<- valueEmpty
|
||||
|
||||
func checkEmpty() -> string:
|
||||
empty <- emptyString()
|
||||
res <- OptionString.checkOption(empty)
|
||||
<- res
|
||||
|
||||
func stringAsOption(str: string) -> ?string:
|
||||
valueEmpty: ?string
|
||||
valueEmpty <<- str
|
||||
<- valueEmpty
|
||||
|
||||
func checkNoneEmpty(str: string) -> string:
|
||||
nonEmpty <- stringAsOption(str)
|
||||
res <- OptionString.checkOption(nonEmpty)
|
||||
<- res
|
@ -1,34 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service ParService("parservice-id"):
|
||||
call: -> string
|
||||
|
||||
-- here we go to another node and not waiting for execution there
|
||||
-- all `ParService.call()` will be executed instantly
|
||||
func parFunc( node: string, c: Info -> () ):
|
||||
y <- ParService.call()
|
||||
par on node:
|
||||
t <- Peer.identify()
|
||||
c(t)
|
||||
par x <- ParService.call()
|
||||
|
||||
func testTimeout(nodes: []string) -> string:
|
||||
on HOST_PEER_ID:
|
||||
|
||||
results: *Info
|
||||
|
||||
for node <- nodes par:
|
||||
on node:
|
||||
results <- Peer.identify()
|
||||
|
||||
timeout: *string
|
||||
join results[999]
|
||||
par timeout <- Peer.timeout(400, "timeout")
|
||||
|
||||
status: *string
|
||||
if timeout == nil:
|
||||
status <<- "ok"
|
||||
else:
|
||||
status <<- timeout!
|
||||
|
||||
<- status!
|
@ -1,26 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service NumOp("op"):
|
||||
identity(n: u64) -> u64
|
||||
|
||||
data PeerRelay:
|
||||
peer: string
|
||||
relay: string
|
||||
|
||||
func testParSeq(peer1: string, peer2: string, peer3: string, relay1: string, relay2: string, relay3: string) -> string:
|
||||
pr1 = PeerRelay(peer = peer1, relay = relay1)
|
||||
pr2 = PeerRelay(peer = peer2, relay = relay2)
|
||||
pr3 = PeerRelay(peer = peer3, relay = relay3)
|
||||
peers = [pr1, pr2, pr3]
|
||||
stream: *u64
|
||||
stream2: *u64
|
||||
parseq p <- peers on p.peer via p.relay:
|
||||
stream <- Peer.timestamp_ms()
|
||||
|
||||
for p <- peers par:
|
||||
on p.peer via p.relay:
|
||||
join stream[peers.length - 1]
|
||||
stream2 <<- Peer.timestamp_ms()
|
||||
|
||||
join stream2[peers.length - 1]
|
||||
<- "ok"
|
@ -1,24 +0,0 @@
|
||||
import Op from "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service AquaDHT("test-dht"):
|
||||
put_host_value(key: string, value: string, service_id: []string) -> string
|
||||
|
||||
func putHostValue(key: string, value: string, service_id: ?string) -> string:
|
||||
res <- AquaDHT.put_host_value(key, value, service_id)
|
||||
<- res
|
||||
|
||||
func create_client_util(service_id: string) -> string:
|
||||
res <- putHostValue("client-util", service_id, nil)
|
||||
<- res
|
||||
|
||||
func wait(successful: *bool, n: i16):
|
||||
join successful[n - 1]
|
||||
|
||||
func bugLNG60(node: string) -> bool:
|
||||
successful: *bool
|
||||
nodes = [node]
|
||||
for n <- nodes:
|
||||
successful <<- true
|
||||
|
||||
wait(successful, 1)
|
||||
<- true
|
@ -1,5 +0,0 @@
|
||||
service Println("println-service-id"):
|
||||
print: string -> ()
|
||||
|
||||
func print(str: string):
|
||||
Println.print(str)
|
@ -1,9 +0,0 @@
|
||||
service OpA("pop"):
|
||||
get_str() -> string
|
||||
|
||||
func get_results() -> []string:
|
||||
results: *string
|
||||
results <<- "hello"
|
||||
str <- OpA.get_str()
|
||||
results <<- str
|
||||
<- results
|
@ -1,13 +0,0 @@
|
||||
|
||||
service YesNoService("yesno"):
|
||||
get() -> string
|
||||
|
||||
func recursiveStream() -> []string, []string:
|
||||
result: *string
|
||||
loop: *string
|
||||
loop <<- "yes"
|
||||
for l <- loop:
|
||||
if l == "yes":
|
||||
loop <- YesNoService.get()
|
||||
result <<- "success"
|
||||
<- result, loop
|
@ -1,25 +0,0 @@
|
||||
aqua RenameVars
|
||||
|
||||
export rename_s
|
||||
|
||||
func append_func(s: *string):
|
||||
s <<- "ok"
|
||||
|
||||
func append(s: string, closure: *string -> ()) -> *string:
|
||||
status: *string
|
||||
|
||||
append_func(status)
|
||||
closure(status)
|
||||
|
||||
<- status
|
||||
|
||||
func rename_s() -> []string:
|
||||
on HOST_PEER_ID:
|
||||
append_closure = (s: *string):
|
||||
s <<- "ok"
|
||||
-- s inside append_func and append_closure
|
||||
-- are not related to this s and should be
|
||||
-- renamed to `status` and not `s-<n>`
|
||||
s = "s"
|
||||
res <- append(s, append_closure)
|
||||
<- res
|
@ -1,33 +0,0 @@
|
||||
aqua ReturnArrow
|
||||
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
export callReturnedArrow, callReturnedChainArrow
|
||||
|
||||
func returnCall(arg: string) -> string -> string, string:
|
||||
str <- Op.concat_strings(arg, " literal")
|
||||
closure = (s: string) -> string, string:
|
||||
<- s, Op.concat_strings(s, str)
|
||||
<- closure
|
||||
|
||||
func callReturnedArrow(argForFunc: string, argForClosure: string) -> string, string:
|
||||
a = returnCall(argForFunc)
|
||||
b, c <- a(argForClosure)
|
||||
<- b, c
|
||||
|
||||
func secondReturnCall(arg: string) -> (string -> string, string), (string -> string, string), (string -> string, string):
|
||||
str <- Op.concat_strings(arg, " second literal")
|
||||
closure = (s: string) -> string, string:
|
||||
<- s, Op.concat_strings(s, str)
|
||||
b = closure
|
||||
a = returnCall(" from second")
|
||||
<- b, closure, a
|
||||
|
||||
func callReturnedChainArrow(argForFirst: string, argForSecond: string) -> string, string, string, string, string, string, string, string:
|
||||
first = returnCall(argForFirst)
|
||||
second, third, fourth <- secondReturnCall(argForSecond)
|
||||
a, b <- first("first")
|
||||
c, d <- second("second")
|
||||
e, f <- third("third")
|
||||
g, h <- fourth("fourth")
|
||||
<- a, b, c, d, e, f, g, h
|
@ -1,2 +0,0 @@
|
||||
func returnLiteral() -> string:
|
||||
<- "some literal"
|
@ -0,0 +1,55 @@
|
||||
import "@fluencelabs/registry/resources-api.aqua"
|
||||
|
||||
service HelloWorld("hello-world"):
|
||||
hello(str: string) -> string
|
||||
|
||||
func resourceTest(label: string) -> ?string, *string:
|
||||
res, errors <- createResource(label)
|
||||
<- res, errors
|
||||
|
||||
func helloTest() -> string:
|
||||
hello <- HelloWorld.hello("Fluence user")
|
||||
<- hello
|
||||
|
||||
service CalcService:
|
||||
add(num: f64) -> f64
|
||||
clear_state()
|
||||
divide(num: f64) -> f64
|
||||
multiply(num: f64) -> f64
|
||||
state() -> f64
|
||||
subtract(num: f64) -> f64
|
||||
test_logs()
|
||||
|
||||
data ServiceCreationResult:
|
||||
success: bool
|
||||
service_id: ?string
|
||||
error: ?string
|
||||
|
||||
data RemoveResult:
|
||||
success: bool
|
||||
error: ?string
|
||||
|
||||
alias ListServiceResult: []string
|
||||
|
||||
service Srv("single_module_srv"):
|
||||
create(wasm_b64_content: string) -> ServiceCreationResult
|
||||
remove(service_id: string) -> RemoveResult
|
||||
list() -> ListServiceResult
|
||||
|
||||
|
||||
func demo_calculation(service_id: string) -> f64:
|
||||
CalcService service_id
|
||||
CalcService.test_logs()
|
||||
CalcService.add(10)
|
||||
CalcService.multiply(5)
|
||||
CalcService.subtract(8)
|
||||
CalcService.divide(6)
|
||||
res <- CalcService.state()
|
||||
<- res
|
||||
|
||||
func marineTest(wasm64: string) -> f64:
|
||||
serviceResult <- Srv.create(wasm64)
|
||||
res <- demo_calculation(serviceResult.service_id!)
|
||||
<- res
|
||||
|
||||
|
@ -1,69 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
import "println.aqua"
|
||||
|
||||
service Stringer("stringer-id"):
|
||||
returnString: string -> string
|
||||
|
||||
func checkStreams(ch: []string) -> []string:
|
||||
stream: *string
|
||||
stream <- Stringer.returnString("first")
|
||||
stream <- Stringer.returnString("second")
|
||||
for b <- ch:
|
||||
stream <- Stringer.returnString(b)
|
||||
<- stream
|
||||
|
||||
func getStream() -> *u32:
|
||||
nums = *[1,2,3,4]
|
||||
<- nums
|
||||
|
||||
func returnStreamFromFunc() -> *u32:
|
||||
nums <- getStream()
|
||||
<- nums
|
||||
|
||||
func stringNil() -> *string:
|
||||
valueNil: *string
|
||||
<- valueNil
|
||||
|
||||
func returnNil() -> *string:
|
||||
relayNil <- stringNil()
|
||||
<- relayNil
|
||||
|
||||
func returnNilLiteral() -> *string:
|
||||
<- nil
|
||||
|
||||
func returnNilLength() -> u32:
|
||||
arr = nil
|
||||
<- arr.length
|
||||
|
||||
func stringNone() -> ?string:
|
||||
valueNone: ?string
|
||||
<- valueNone
|
||||
|
||||
func returnNone() -> ?string:
|
||||
relayNone <- stringNone()
|
||||
<- relayNone
|
||||
|
||||
func streamFunctor(arr: []string) -> string:
|
||||
stream: *[]string
|
||||
stream <<- ["123"]
|
||||
a = stream[arr.length - 1][0]
|
||||
<- a
|
||||
|
||||
func streamAssignment(arr: []string) -> string:
|
||||
stream: *[]u32
|
||||
stream <<- [0]
|
||||
a = stream[arr.length - 1][0]
|
||||
b = arr[a]
|
||||
<- b
|
||||
|
||||
func streamIntFunctor(arr: []u32) -> string:
|
||||
stream: *[]string
|
||||
stream <<- ["123"]
|
||||
a = stream[arr[0]][arr[0]]
|
||||
<- a
|
||||
|
||||
func streamJoin(arr: []string) -> string:
|
||||
streamJ: *[]string
|
||||
streamJ <<- ["111", "222"]
|
||||
streamJ <<- ["333", "444"]
|
||||
<- streamJ[arr.length][1]
|
@ -1,10 +0,0 @@
|
||||
service TestService("test-service"):
|
||||
get_records(key: string) -> []string
|
||||
|
||||
func append_records(peer: string, srum: *[]string):
|
||||
srum <- TestService.get_records(peer)
|
||||
|
||||
func retrieve_records(peer: string) -> [][]string:
|
||||
records: *[]string
|
||||
append_records(peer, records)
|
||||
<- records
|
@ -1,7 +0,0 @@
|
||||
module Ret declares *
|
||||
|
||||
export someFunc
|
||||
|
||||
func someFunc(cb: []string -> ()):
|
||||
ifaces: *string
|
||||
cb(ifaces)
|
@ -1,46 +0,0 @@
|
||||
export accumRes, bugLNG63, bugLNG63_2
|
||||
|
||||
func toOpt(s: string) -> ?string:
|
||||
str: *string
|
||||
str <<- s
|
||||
<- str
|
||||
|
||||
func accumRes() -> *?string:
|
||||
res_accum: *?string
|
||||
a <- toOpt("a")
|
||||
res_accum <<- a
|
||||
res_accum <- toOpt("b")
|
||||
res_accum <<- nil
|
||||
<- res_accum
|
||||
|
||||
func returnCanStream() -> string:
|
||||
status: *string
|
||||
status <<- "ok"
|
||||
stat = status!
|
||||
<- stat
|
||||
|
||||
service Op1("op"):
|
||||
array_length(array: []string) -> u32
|
||||
|
||||
func bugLNG63() -> string:
|
||||
res <- returnCanStream()
|
||||
<- res
|
||||
|
||||
func returnMultipleStreamResults() -> string, []string, []string, []string:
|
||||
status: *string
|
||||
status <<- "ok"
|
||||
stat = status!
|
||||
<- stat, status, [status!, stat], [status!, "no", status!]
|
||||
|
||||
func bugLNG63_2() -> string, []string, []string:
|
||||
res, res2, res3, res4 <- returnMultipleStreamResults()
|
||||
<- res, res2, res4
|
||||
|
||||
func bugLNG63_3() -> string, u32, []u32:
|
||||
status: *string
|
||||
status <<- "ok"
|
||||
stat = status!
|
||||
num: *u32
|
||||
num <<- 2
|
||||
res = [Op1.array_length(status), num!]
|
||||
<- status!, Op1.array_length(status), [Op1.array_length(status), 3, num!]
|
@ -1,10 +0,0 @@
|
||||
func streamFold(arr: []string) -> []string:
|
||||
res: *string
|
||||
for n <- arr:
|
||||
res <<- n
|
||||
<- res
|
||||
|
||||
func streamRes(arr: []string) -> []string, []string:
|
||||
res: *string
|
||||
res2 <- streamFold(arr)
|
||||
<- res, res2
|
@ -1,16 +0,0 @@
|
||||
data DT:
|
||||
field: string
|
||||
|
||||
service DTGetter("get-dt"):
|
||||
get_dt(s: string) -> DT
|
||||
|
||||
func use_name1(name: string) -> string:
|
||||
results <- DTGetter.get_dt(name)
|
||||
<- results.field
|
||||
|
||||
func use_name2(name: string) -> []string:
|
||||
results: *string
|
||||
results <- use_name1(name)
|
||||
results <- use_name1(name)
|
||||
results <- use_name1(name)
|
||||
<- results
|
@ -1,83 +0,0 @@
|
||||
aqua StreamExports
|
||||
|
||||
export FailureSrv, streamIf, streamTry, streamFor, streamComplex
|
||||
|
||||
service FailureSrv("failure"):
|
||||
fail(msg: string)
|
||||
|
||||
func streamIf() -> i8:
|
||||
on HOST_PEER_ID:
|
||||
if true:
|
||||
stream: *i8
|
||||
stream <<- 1
|
||||
else:
|
||||
stream: *i8
|
||||
stream <<- 2
|
||||
|
||||
if false:
|
||||
stream: *i8
|
||||
stream <<- 3
|
||||
else:
|
||||
stream: *i8
|
||||
stream <<- 4
|
||||
|
||||
stream: *i8
|
||||
stream <<- 5
|
||||
|
||||
<- stream!
|
||||
|
||||
func streamTry() -> i8:
|
||||
on HOST_PEER_ID:
|
||||
try:
|
||||
stream: *i8
|
||||
stream <<- 1
|
||||
FailureSrv.fail("try")
|
||||
catch e:
|
||||
stream: *i8
|
||||
stream <<- 2
|
||||
FailureSrv.fail("catch")
|
||||
otherwise:
|
||||
stream: *i8
|
||||
stream <<- 3
|
||||
|
||||
stream: *i8
|
||||
stream <<- 4
|
||||
|
||||
<- stream!
|
||||
|
||||
func streamFor() -> i8:
|
||||
on HOST_PEER_ID:
|
||||
for i <- [1, 2, 3]:
|
||||
stream: *i8
|
||||
stream <<- i
|
||||
|
||||
stream: *i8
|
||||
stream <<- 4
|
||||
|
||||
<- stream!
|
||||
|
||||
func streamComplex() -> i8:
|
||||
on HOST_PEER_ID:
|
||||
for i <- [1, 2, 3]:
|
||||
try:
|
||||
if i == 2:
|
||||
stream: *i8
|
||||
stream <<- i
|
||||
FailureSrv.fail("if")
|
||||
else:
|
||||
stream: *i8
|
||||
stream <<- i
|
||||
|
||||
stream: *i8
|
||||
stream <<- i + 3
|
||||
catch e:
|
||||
stream: *i8
|
||||
stream <<- i + 6
|
||||
|
||||
stream: *i8
|
||||
stream <<- i + 9
|
||||
|
||||
stream: *i8
|
||||
stream <<- 13
|
||||
|
||||
<- stream!
|
@ -1,35 +0,0 @@
|
||||
aqua Aaa
|
||||
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
export structuralTypingTest
|
||||
|
||||
data WideData:
|
||||
s: string
|
||||
n: u32
|
||||
|
||||
data ExactData:
|
||||
s: string
|
||||
|
||||
ability ExactAbility:
|
||||
s: string
|
||||
arr(s: string, s2: string, s3: string, s4: string) -> string
|
||||
exact: ExactData
|
||||
|
||||
ability WideAbility:
|
||||
s: string
|
||||
arr(s: string, s2: string, s3: string, s4: string) -> string
|
||||
g: string
|
||||
exact: WideData
|
||||
|
||||
func ss(s1: string, s2: string, s3: string, s4: string) -> string:
|
||||
<- Op.concat_strings(Op.concat_strings(Op.concat_strings(s1, s2), s3), s4)
|
||||
|
||||
func main{ExactAbility}(someData: ExactData, secondData: ExactData) -> string:
|
||||
<- ExactAbility.arr(someData.s, ExactAbility.exact.s, secondData.s, ExactAbility.s)
|
||||
|
||||
func structuralTypingTest() -> string:
|
||||
wd = WideData(s = "some_string", n = 32)
|
||||
|
||||
WAbility = WideAbility(s = "ab_string", g = "", arr = ss, exact = wd)
|
||||
<- main{WAbility}(wd, WAbility.exact)
|
@ -1,11 +0,0 @@
|
||||
import "imports_exports/subImport.aqua"
|
||||
|
||||
service ConcatSubs("concat_subs"):
|
||||
get_some(s: SomeString, sr: SomeResult) -> SomeResult
|
||||
|
||||
func subImportUsage(s: SomeString) -> SomeResult:
|
||||
sr1 <- SubService.sub(s)
|
||||
sr2 <- subImport()
|
||||
result <- ConcatSubs.get_some(sr1.one, sr2)
|
||||
<- result
|
||||
|
@ -1,12 +0,0 @@
|
||||
aqua TopBottom
|
||||
|
||||
export S, topBottom
|
||||
|
||||
-- this file should just compile
|
||||
|
||||
service S(""):
|
||||
top(t: ⊤) -> ⊤
|
||||
bottom(b: ⊥) -> ⊥
|
||||
|
||||
func topBottom(t: ⊤, b: ⊥) -> ⊤, ⊥:
|
||||
<- S.top(t), S.bottom(b)
|
@ -1,53 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service Testo("testo"):
|
||||
getString: string -> string
|
||||
|
||||
service LocalPrint("lp"):
|
||||
print: string -> ()
|
||||
|
||||
service Opop("op"):
|
||||
identity(s: string) -> string
|
||||
|
||||
|
||||
func topologyTest(me: string, myRelay: string, friend: string, friendRelay: string) -> string:
|
||||
on friend via friendRelay:
|
||||
str2 <- Testo.getString("friends string via")
|
||||
par LocalPrint.print("my string in par")
|
||||
LocalPrint.print(str2)
|
||||
<- "finish"
|
||||
|
||||
func topologyBug205(node_id: string, n2: ?string) -> []string:
|
||||
nodes: *PeerId
|
||||
on node_id:
|
||||
a <- Op.identity(n2)
|
||||
nodes <<- a!
|
||||
on node_id:
|
||||
for n <- nodes par:
|
||||
on n:
|
||||
Peer.identify()
|
||||
<- nodes
|
||||
|
||||
service IOp("op"):
|
||||
identity: string -> string
|
||||
|
||||
func topologyBug394(peer: string, peer2: string, peer3: string) -> string:
|
||||
-- execute computation on a Peer in the network
|
||||
on peer:
|
||||
comp <- IOp.identity(%init_peer_id%)
|
||||
|
||||
-- send the result to target browser in the background
|
||||
co on peer2 via peer3:
|
||||
res <- IOp.identity(%init_peer_id%)
|
||||
|
||||
-- send the result to the initiator
|
||||
<- comp
|
||||
|
||||
func topologyBug427(peers: []string) -> []string:
|
||||
results: *string
|
||||
for peer <- peers par:
|
||||
on peer:
|
||||
results <- Opop.identity("some string")
|
||||
|
||||
join results[1]
|
||||
<- results
|
@ -1,25 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
service Unexisted("unex"):
|
||||
getStr() -> string
|
||||
|
||||
data LastError:
|
||||
instruction: string
|
||||
message: string
|
||||
peer_id: string
|
||||
|
||||
service OpA("op"):
|
||||
identity(s: string) -> string
|
||||
|
||||
func tryCatchTest(node_id: string) -> []string:
|
||||
on node_id:
|
||||
f: *string
|
||||
try:
|
||||
f <- Unexisted.getStr()
|
||||
catch err:
|
||||
c: *string
|
||||
f <- OpA.identity(err.message)
|
||||
-- check if the call takes place on the node
|
||||
i <- Peer.identify()
|
||||
f <- OpA.identity(i.external_addresses!)
|
||||
<- f
|
@ -1,19 +0,0 @@
|
||||
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!
|
@ -1,17 +0,0 @@
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
|
||||
func viaArr(node_id: string, viaAr: []string) -> Info:
|
||||
on node_id via viaAr:
|
||||
p <- Peer.identify()
|
||||
<- p
|
||||
|
||||
|
||||
func viaStream(node_id: string, viaStr: *string) -> Info:
|
||||
on node_id via viaStr:
|
||||
p <- Peer.identify()
|
||||
<- p
|
||||
|
||||
func viaOpt(relay: string, node_id: string, viaOpt: ?string) -> Info:
|
||||
on node_id via viaOpt:
|
||||
p <- Peer.identify()
|
||||
<- p
|
@ -35,14 +35,14 @@ import * as fs from 'fs';
|
||||
import generate from './generate/index.js';
|
||||
|
||||
const res = await compileFromPath({
|
||||
filePath: './src/generate/__test__/sources/abilities.aqua',
|
||||
filePath: './src/generate/__test__/sources/smoke_test.aqua',
|
||||
imports: ['./node_modules'],
|
||||
targetType: 'ts'
|
||||
targetType: 'air'
|
||||
});
|
||||
|
||||
// const data = generate(res, 'ts');
|
||||
const data = generate(res, 'ts');
|
||||
|
||||
fs.writeFileSync('./src/generate/__test__/snapshots/abilities.ts', res.generatedSources[0].tsSource);
|
||||
fs.writeFileSync('./src/generate/__test__/snapshots/smoke_test.ts', data);
|
||||
|
||||
|
||||
process.exit();
|
||||
|
Reference in New Issue
Block a user