This commit is contained in:
Pavel Murygin 2022-10-31 23:41:19 +04:00
parent fb1fc409ff
commit 6948fe11b6
3 changed files with 177 additions and 0 deletions

View File

@ -0,0 +1,10 @@
service Peer("peer"):
-- Blocks for the given number of milliseconds. Meant to be used within `par` blocks.
-- message is returned after duration has passed
timeout(duration_ms: u64, message: string) -> string
func test(time: u8) -> string:
on HOST_PEER_ID:
Peer.timeout(time, "")
<- "success"

View File

@ -0,0 +1,139 @@
/**
*
* 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.7.2-314
*
*/
import { Fluence, FluencePeer } from '../../index';
import { CallParams, callFunction, registerService } from '../../internal/compilerSupport/v3';
// Services
export interface PeerDef {
timeout: (duration_ms: number, message: string, callParams: CallParams<'duration_ms' | 'message'>) => string | Promise<string>;
}
export function registerPeer(service: PeerDef): void;
export function registerPeer(serviceId: string, service: PeerDef): void;
export function registerPeer(peer: FluencePeer, service: PeerDef): void;
export function registerPeer(peer: FluencePeer, serviceId: string, service: PeerDef): void;
export function registerPeer(...args: any) {
registerService(
args,
{
"defaultServiceId" : "peer",
"functions" : {
"tag" : "labeledProduct",
"fields" : {
"timeout" : {
"tag" : "arrow",
"domain" : {
"tag" : "labeledProduct",
"fields" : {
"duration_ms" : {
"tag" : "scalar",
"name" : "u64"
},
"message" : {
"tag" : "scalar",
"name" : "string"
}
}
},
"codomain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "scalar",
"name" : "string"
}
]
}
}
}
}
}
);
}
// Functions
export function test(
time: number,
config?: {ttl?: number}
): Promise<string>;
export function test(
peer: FluencePeer,
time: number,
config?: {ttl?: number}
): Promise<string>;
export function test(...args: any) {
let script = `
(xor
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "time") [] time)
)
(xor
(call -relay- ("peer" "timeout") [time ""])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") ["success"])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
`
return callFunction(
args,
{
"functionName" : "test",
"arrow" : {
"tag" : "arrow",
"domain" : {
"tag" : "labeledProduct",
"fields" : {
"time" : {
"tag" : "scalar",
"name" : "u8"
}
}
},
"codomain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "scalar",
"name" : "string"
}
]
}
},
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
}

View File

@ -0,0 +1,28 @@
import { FluencePeer } from '../../index';
import { test } from '../_aqua/shit';
let peer: FluencePeer;
describe('Test test', () => {
afterEach(async () => {
if (peer) {
await peer.stop();
}
});
beforeEach(async () => {
peer = new FluencePeer();
await peer.start({
connectTo: '/dns4/stage.fluence.dev/tcp/19002/wss/p2p/12D3KooWMigkP4jkVyufq5JnDJL6nXvyjeaDNpRfEZqQhsG3sYCU'
});
});
it('shit', async () => {
const res = await test(peer, 1, {ttl: 5000})
expect(res).toBe(1);
});
});