import-export tests

This commit is contained in:
DieMyst
2021-08-31 12:51:07 +03:00
parent 95cdd7313e
commit 71c8fc6d9e
33 changed files with 89 additions and 1208 deletions

View File

@ -3,7 +3,7 @@
* 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.2.0-SNAPSHOT
* Aqua version: 0.2.1-SNAPSHOT
*
*/
import { FluenceClient, PeerIdB58 } from '@fluencelabs/fluence';
@ -13,20 +13,6 @@ import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
// Services
//Srv
//defaultId = "srv"
//add_alias: (alias: string, service_id: string) => void
//create: (blueprint_id: string) => string
//get_interface: (service_id: string) => {function_signatures:{arguments:string[][];name:string;output_types:string[]}[];record_types:{fields:string[][];id:number;name:string}[]}
//list: () => {blueprint_id:string;id:string;owner_id:string}[]
//remove: (service_id: string) => void
//resolve_alias: (alias: string) => string
//END Srv
//TestS
//defaultId = "some-id"
@ -36,264 +22,8 @@ import { RequestFlow } from '@fluencelabs/fluence/dist/internal/RequestFlow';
//Peer
//defaultId = "peer"
//connect: (id: string, multiaddrs: string[] | null) => boolean
//get_contact: (peer: string) => {addresses:string[];peer_id:string}
//identify: () => {external_addresses:string[]}
//is_connected: (peer: string) => boolean
//timestamp_ms: () => number
//timestamp_sec: () => number
//END Peer
//StringExtra
//defaultId = "service-id"
//addNameToHello: (arg0: string) => string
//END StringExtra
//Op
//defaultId = "op"
//array: (a: string, b: string | null, c: string | null, d: string | null) => string[]
//array_length: (array: string[]) => number
//bytes_from_b58: (b: string) => number[]
//bytes_to_b58: (bs: number[]) => string
//concat: (a: string[], b: string[] | null, c: string[] | null, d: string[] | null) => string[]
//concat_strings: (a: string, b: string) => string
//identity: (s: string | null) => string | null
//noop: () => void
//sha256_string: (s: string) => string
//string_from_b58: (b: string) => string
//string_to_b58: (s: string) => string
//END Op
//Script
//defaultId = "script"
//add: (air_script: string, interval: string | null) => string
//list: () => {failures:number;id:string;interval:string;owner:string;src:string}
//remove: (script_id: string) => boolean
//END Script
//TestSrv
//defaultId = "test-service-id"
//str: () => string
//END TestSrv
//Dist
//defaultId = "dist"
//add_blueprint: (blueprint: {dependencies:string[];name:string}) => string
//add_module: (wasm_b56_content: number[], conf: {name:string}) => string
//add_module_from_vault: (path: string, config: {name:string}) => string
//default_module_config: (module_name: string) => {name:string}
//get_interface: (module_id: string) => {function_signatures:{arguments:string[][];name:string;output_types:string[]}[];record_types:{fields:string[][];id:number;name:string}[]}
//list_blueprints: () => {dependencies:string[];id:string;name:string}[]
//list_modules: () => {config:{name:string};hash:string;name:string}[]
//make_blueprint: (name: string, dependencies: string[]) => {dependencies:string[];name:string}
//make_module_config: (name: string, mem_pages_count: number | null, logger_enabled: boolean | null, preopened_files: string[] | null, envs: string[][] | null, mapped_dirs: string[][] | null, mounted_binaries: string[][] | null, logging_mask: number | null) => {name:string}
//END Dist
//Kademlia
//defaultId = "kad"
//merge: (target: string, left: string[], right: string[], count: number | null) => string[]
//neighborhood: (key: string, already_hashed: boolean | null, count: number | null) => string[]
//END Kademlia
//Println
//defaultId = "println-service-id"
//print: (arg0: string) => void
//END Println
// Functions
export async function helloWorld(client: FluenceClient, name: string, config?: {ttl?: number}): Promise<string> {
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "name") [] name)
)
(call %init_peer_id% ("service-id" "addNameToHello") [name] res)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [res])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.on('getDataSrv', 'name', () => {return name;});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for helloWorld');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
await client.initiateFlow(request!);
return promise;
}
export async function print(client: FluenceClient, str: string, config?: {ttl?: number}): Promise<void> {
let request: RequestFlow;
const promise = new Promise<void>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "str") [] str)
)
(call %init_peer_id% ("println-service-id" "print") [str])
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.on('getDataSrv', 'str', () => {return str;});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for print');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
await client.initiateFlow(request!);
return Promise.race([promise, Promise.resolve()]);
}
export async function testFunc(client: FluenceClient, config?: {ttl?: number}): Promise<string> {
let request: RequestFlow;
const promise = new Promise<string>((resolve, reject) => {
const r = new RequestFlowBuilder()
.disableInjections()
.withRawScript(
`
(xor
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("test-service-id" "str") [] res)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [res])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`,
)
.configHandler((h) => {
h.on('getDataSrv', '-relay-', () => {
return client.relayPeerId!;
});
h.onEvent('callbackSrv', 'response', (args) => {
const [res] = args;
resolve(res);
});
h.onEvent('errorHandlingSrv', 'error', (args) => {
// assuming error is the single argument
const [err] = args;
reject(err);
});
})
.handleScriptError(reject)
.handleTimeout(() => {
reject('Request timed out for testFunc');
})
if(config && config.ttl) {
r.withTTL(config.ttl)
}
request = r.build();
});
await client.initiateFlow(request!);
return promise;
}
export async function doStuff(client: FluenceClient, a: string, b: string, c: boolean, d: boolean, e: string[], g: string[], str: string, config?: {ttl?: number}): Promise<string[]> {
let request: RequestFlow;
const promise = new Promise<string[]>((resolve, reject) => {