From 6948fe11b68eb46900475c70d0811a8eb81493cf Mon Sep 17 00:00:00 2001 From: Pavel Murygin Date: Mon, 31 Oct 2022 23:41:19 +0400 Subject: [PATCH] tmp --- packages/fluence-js/aqua/tests/shit.aqua | 10 ++ .../fluence-js/src/__test__/_aqua/shit.ts | 139 ++++++++++++++++++ .../src/__test__/integration/temp.spec.ts | 28 ++++ 3 files changed, 177 insertions(+) create mode 100644 packages/fluence-js/aqua/tests/shit.aqua create mode 100644 packages/fluence-js/src/__test__/_aqua/shit.ts create mode 100644 packages/fluence-js/src/__test__/integration/temp.spec.ts diff --git a/packages/fluence-js/aqua/tests/shit.aqua b/packages/fluence-js/aqua/tests/shit.aqua new file mode 100644 index 00000000..b851583b --- /dev/null +++ b/packages/fluence-js/aqua/tests/shit.aqua @@ -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" \ No newline at end of file diff --git a/packages/fluence-js/src/__test__/_aqua/shit.ts b/packages/fluence-js/src/__test__/_aqua/shit.ts new file mode 100644 index 00000000..143a2010 --- /dev/null +++ b/packages/fluence-js/src/__test__/_aqua/shit.ts @@ -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; +} +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; + +export function test( + peer: FluencePeer, + time: number, + config?: {ttl?: number} +): Promise; + +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 + ) +} diff --git a/packages/fluence-js/src/__test__/integration/temp.spec.ts b/packages/fluence-js/src/__test__/integration/temp.spec.ts new file mode 100644 index 00000000..47f5f2ae --- /dev/null +++ b/packages/fluence-js/src/__test__/integration/temp.spec.ts @@ -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); + }); + +}); + + \ No newline at end of file