2023-10-17 22:14:08 +07:00
|
|
|
/**
|
2024-05-16 11:34:31 +02:00
|
|
|
* Copyright 2024 Fluence DAO
|
2023-10-17 22:14:08 +07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-11-06 17:42:24 +07:00
|
|
|
import { Fluence, type ClientConfig } from "@fluencelabs/js-client";
|
2023-10-17 22:14:08 +07:00
|
|
|
|
|
|
|
import { test as particleTest } from "./_aqua/finalize_particle.js";
|
|
|
|
import {
|
|
|
|
registerHelloWorld,
|
|
|
|
helloTest,
|
|
|
|
marineTest,
|
|
|
|
} from "./_aqua/smoke_test.js";
|
|
|
|
import { wasm } from "./wasmb64.js";
|
2023-02-13 17:41:35 +03:00
|
|
|
|
2023-06-20 21:52:41 +02:00
|
|
|
const relay = {
|
2023-10-17 22:14:08 +07:00
|
|
|
multiaddr:
|
2024-09-23 18:08:31 +02:00
|
|
|
"/ip4/127.0.0.1/tcp/999/ws/p2p/12D3KooWBbMuqJJZT7FTFN4fWg3k3ipUKx6KEy7pDy8mdorK5g5o",
|
2024-02-27 09:53:18 +02:00
|
|
|
peerId: "12D3KooWBbMuqJJZT7FTFN4fWg3k3ipUKx6KEy7pDy8mdorK5g5o",
|
2023-06-20 21:52:41 +02:00
|
|
|
};
|
2023-02-13 17:41:35 +03:00
|
|
|
|
2023-02-16 14:38:48 +03:00
|
|
|
function generateRandomUint8Array() {
|
2023-10-17 22:14:08 +07:00
|
|
|
const uint8Array = new Uint8Array(32);
|
|
|
|
|
|
|
|
for (let i = 0; i < uint8Array.length; i++) {
|
|
|
|
uint8Array[i] = Math.floor(Math.random() * 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
return uint8Array;
|
2023-02-16 14:38:48 +03:00
|
|
|
}
|
|
|
|
|
2023-04-03 21:52:40 +04:00
|
|
|
const optsWithRandomKeyPair = (): ClientConfig => {
|
2023-10-17 22:14:08 +07:00
|
|
|
return {
|
|
|
|
keyPair: {
|
|
|
|
type: "Ed25519",
|
|
|
|
source: generateRandomUint8Array(),
|
|
|
|
},
|
|
|
|
} as const;
|
2023-02-13 17:41:35 +03:00
|
|
|
};
|
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
export type TestResult =
|
|
|
|
| { type: "success"; data: string }
|
|
|
|
| { type: "failure"; error: string };
|
2023-03-07 20:07:52 +04:00
|
|
|
|
|
|
|
export const runTest = async (): Promise<TestResult> => {
|
2023-10-17 22:14:08 +07:00
|
|
|
try {
|
|
|
|
console.log("connecting to Fluence Network...");
|
|
|
|
console.log("multiaddr: ", relay.multiaddr);
|
2023-10-18 11:54:27 +07:00
|
|
|
|
|
|
|
await Fluence.connect(relay, {
|
|
|
|
...optsWithRandomKeyPair(),
|
|
|
|
CDNUrl: "http://localhost:3001",
|
|
|
|
});
|
2023-10-17 22:14:08 +07:00
|
|
|
|
|
|
|
console.log("connected");
|
|
|
|
|
|
|
|
const relayPeerId = Fluence.getClient().getRelayPeerId();
|
|
|
|
console.log("relay:", relayPeerId);
|
|
|
|
|
|
|
|
registerHelloWorld({
|
|
|
|
hello(str) {
|
|
|
|
return "Hello, " + str + "!";
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const client = Fluence.getClient();
|
|
|
|
|
|
|
|
console.log("my peer id: ", client.getPeerId());
|
|
|
|
|
|
|
|
console.log("running hello test...");
|
|
|
|
const hello = await helloTest();
|
|
|
|
console.log("hello test finished, result: ", hello);
|
|
|
|
|
|
|
|
console.log("running marine test...");
|
|
|
|
const marine = await marineTest(wasm);
|
2023-11-19 09:04:10 +07:00
|
|
|
console.log("marine test finished, result: ", marine);
|
2023-10-17 22:14:08 +07:00
|
|
|
|
|
|
|
console.log("running particle test...");
|
|
|
|
|
2023-11-19 09:04:10 +07:00
|
|
|
await particleTest();
|
2023-10-17 22:14:08 +07:00
|
|
|
|
|
|
|
const returnVal = {
|
|
|
|
hello,
|
|
|
|
marine,
|
|
|
|
};
|
|
|
|
|
|
|
|
return { type: "success", data: JSON.stringify(returnVal) };
|
|
|
|
} finally {
|
|
|
|
console.log("disconnecting from Fluence Network...");
|
|
|
|
await Fluence.disconnect();
|
|
|
|
console.log("disconnected");
|
|
|
|
}
|
2023-02-13 17:41:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export const runMain = () => {
|
2023-10-17 22:14:08 +07:00
|
|
|
runTest()
|
|
|
|
.then(() => {
|
|
|
|
console.log("done!");
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error("error: ", err);
|
|
|
|
});
|
2023-02-13 17:41:35 +03:00
|
|
|
};
|