mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2025-06-25 22:01:32 +00:00
feat(logs): Use debug.js
library for logging [DXJ-327] (#285)
This commit is contained in:
@ -3,7 +3,53 @@ import "@fluencelabs/registry/resources-api.aqua"
|
||||
service HelloWorld("hello-world"):
|
||||
hello(str: string) -> string
|
||||
|
||||
func smokeTest(label: string) -> ?string, *string, string:
|
||||
func resourceTest(label: string) -> ?string, *string:
|
||||
res, errors <- createResource(label)
|
||||
<- res, errors
|
||||
|
||||
func helloTest() -> string:
|
||||
hello <- HelloWorld.hello("Fluence user")
|
||||
<- res, errors, hello
|
||||
<- 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
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"compile-aqua": "aqua -i ./_aqua -o ./src/_aqua"
|
||||
"compile-aqua": "fluence aqua -i ./_aqua -o ./src/_aqua"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
@ -22,7 +22,9 @@
|
||||
"base64-js": "1.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/aqua": "0.9.4",
|
||||
"@fluencelabs/registry": "0.7.0"
|
||||
"@fluencelabs/cli": "0.3.9",
|
||||
"@fluencelabs/registry": "0.8.2",
|
||||
"@fluencelabs/aqua-lib": "0.6.0",
|
||||
"@fluencelabs/trust-graph": "3.1.2"
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,8 @@
|
||||
import { fromByteArray } from 'base64-js';
|
||||
import { Fluence } from '@fluencelabs/js-client.api';
|
||||
import { kras, randomKras } from '@fluencelabs/fluence-network-environment';
|
||||
import { registerHelloWorld, smokeTest } from './_aqua/smoke_test.js';
|
||||
import { registerHelloWorld, helloTest, marineTest, resourceTest } from './_aqua/smoke_test.js';
|
||||
import { wasm } from './wasmb64.js';
|
||||
|
||||
// Relay running on local machine
|
||||
// const relay = {
|
||||
@ -29,7 +30,7 @@ const optsWithRandomKeyPair = () => {
|
||||
} as const;
|
||||
};
|
||||
|
||||
export type TestResult = { res: string | null; errors: string[]; hello: string };
|
||||
export type TestResult = { type: 'success'; data: string } | { type: 'failure'; error: string };
|
||||
|
||||
export const runTest = async (): Promise<TestResult> => {
|
||||
try {
|
||||
@ -54,16 +55,32 @@ export const runTest = async (): Promise<TestResult> => {
|
||||
console.log('my peer id: ', client.getPeerId());
|
||||
console.log('my sk id: ', fromByteArray(client.getPeerSecretKey()));
|
||||
|
||||
console.log('running some aqua...');
|
||||
const [res, errors, hello] = await smokeTest('my_resource');
|
||||
console.log(hello);
|
||||
console.log('running resource test...');
|
||||
const [res, errors] = await resourceTest('my_resource');
|
||||
if (res === null) {
|
||||
console.log('aqua failed, errors', errors);
|
||||
console.log('resource test failed, errors', errors);
|
||||
return { type: 'failure', error: errors.join(', ') };
|
||||
} else {
|
||||
console.log('aqua finished, result', res);
|
||||
console.log('resource test finished, result', res);
|
||||
}
|
||||
|
||||
return { res, errors, hello };
|
||||
console.log('running hello test...');
|
||||
const hello = await helloTest();
|
||||
console.log('hello test finished, result: ', hello);
|
||||
|
||||
// TODO: some wired error shit about SharedArrayBuffer
|
||||
// console.log('running marine test...');
|
||||
// const marine = await marineTest(wasm);
|
||||
// console.log('marine test finished, result: ', marine);
|
||||
|
||||
const returnVal = {
|
||||
res,
|
||||
hello,
|
||||
// marine,
|
||||
};
|
||||
return { type: 'success', data: JSON.stringify(returnVal) };
|
||||
} catch (err: any) {
|
||||
return { type: 'failure', error: err.toString() };
|
||||
} finally {
|
||||
console.log('disconnecting from Fluence Network...');
|
||||
await Fluence.disconnect();
|
||||
|
1
packages/@tests/aqua/src/wasmb64.ts
Normal file
1
packages/@tests/aqua/src/wasmb64.ts
Normal file
File diff suppressed because one or more lines are too long
@ -11,7 +11,8 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "node --loader ts-node/esm ./src/index.ts"
|
||||
"test": "node --loader ts-node/esm ./src/index.ts",
|
||||
"test_logs": "DEBUG=fluence:particle:* node --loader ts-node/esm ./src/index.ts"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
|
@ -23,7 +23,7 @@
|
||||
"@test/test-utils": "workspace:^"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --loader ts-node/esm ./test/index.ts",
|
||||
"test_commented_out": "node --loader ts-node/esm ./test/index.ts",
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"_test": "react-scripts test",
|
||||
|
@ -1,26 +1,18 @@
|
||||
import { runTest } from '@test/aqua_for_test';
|
||||
import { runTest, TestResult } from '@test/aqua_for_test';
|
||||
import React from 'react';
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
const [result, setResult] = React.useState<string | null>(null);
|
||||
const [error, setError] = React.useState<string | null>(null);
|
||||
const [result, setResult] = React.useState<TestResult | null>(null);
|
||||
|
||||
const onButtonClick = () => {
|
||||
runTest()
|
||||
.then((res) => {
|
||||
if (res.errors.length === 0) {
|
||||
setResult(JSON.stringify(res));
|
||||
setError(null);
|
||||
} else {
|
||||
setResult(null);
|
||||
setError(res.errors.toString());
|
||||
}
|
||||
setResult(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
setResult('');
|
||||
setError(err.toString());
|
||||
setResult({ type: 'failure', error: err.toString() });
|
||||
});
|
||||
};
|
||||
|
||||
@ -35,8 +27,8 @@ function App() {
|
||||
Click to run test
|
||||
</button>
|
||||
|
||||
{result && <div id="res">{result}</div>}
|
||||
{error && <div id="error">{error}</div>}
|
||||
{result && result.type === 'success' && <div id="res">{result.data}</div>}
|
||||
{result && result.type === 'failure' && <div id="error">{result.error}</div>}
|
||||
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
|
||||
Learn React
|
||||
</a>
|
||||
|
@ -11,7 +11,7 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "node --loader ts-node/esm ./src/index.ts",
|
||||
"test_commented_out": "node --loader ts-node/esm ./src/index.ts",
|
||||
"serve": "http-server public"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
|
Reference in New Issue
Block a user