More tests
@ -21,3 +21,5 @@
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
public/js-client.min.js
|
@ -1,27 +1,29 @@
|
||||
{
|
||||
"name": "@test/react",
|
||||
"name": "cra-ts",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client.web": "workspace:*",
|
||||
"@fluencelabs/fluence-network-environment": "^1.0.13",
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"@types/jest": "^27.5.2",
|
||||
"@types/node": "16.11.59",
|
||||
"@types/react": "^18.0.18",
|
||||
"@types/react-dom": "^18.0.6",
|
||||
"@fluencelabs/js-client.api": "workspace:*",
|
||||
"@testing-library/jest-dom": "5.16.5",
|
||||
"@testing-library/react": "13.4.0",
|
||||
"@testing-library/user-event": "13.5.0",
|
||||
"@types/jest": "27.5.2",
|
||||
"@types/node": "16.18.12",
|
||||
"@types/react": "18.0.27",
|
||||
"@types/react-dom": "18.0.10",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"typescript": "^4.8.2",
|
||||
"web-vitals": "^2.1.4"
|
||||
"typescript": "4.9.5",
|
||||
"web-vitals": "2.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/js-client.web.standalone": "workspace:*"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"_test": "react-scripts test",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
@ -1,21 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta name="description" content="Web site created using create-react-app" />
|
||||
<script src='./js-client.min.js' async></script>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
@ -24,12 +23,13 @@
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
<title>React App</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
@ -39,5 +39,6 @@
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
</body>
|
||||
|
||||
</html>
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
9
packages/@tests/frameworks/cra-ts/src/App.test.tsx_
Normal file
@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
26
packages/@tests/frameworks/cra-ts/src/App.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Edit <code>src/App.tsx</code> and save to reload.
|
||||
</p>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
@ -6,8 +6,8 @@
|
||||
* Aqua version: 0.7.2-314
|
||||
*
|
||||
*/
|
||||
import type { IFluencePeer, CallParams } from '@fluencelabs/interface';
|
||||
import { callFunction$$, registerService$$ } from '@fluencelabs/js-client.api/dist/compilerSupport/v4';
|
||||
import type { IFluencePeer, CallParams } from '@fluencelabs/js-client.api';
|
||||
import { callFunction$$, registerService$$ } from '@fluencelabs/js-client.api';
|
||||
|
||||
// Services
|
||||
|
23
packages/@tests/frameworks/cra-ts/src/fluence/index.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Fluence } from '@fluencelabs/js-client.api';
|
||||
import { getRelayTime } from './_aqua/smoke_test';
|
||||
|
||||
const relay = {
|
||||
multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
};
|
||||
|
||||
export const main = async () => {
|
||||
console.log('starting fluence...');
|
||||
await Fluence.start({
|
||||
connectTo: relay,
|
||||
});
|
||||
console.log('started fluence');
|
||||
|
||||
console.log('getting relay time...');
|
||||
const res = await getRelayTime(relay.peerId);
|
||||
console.log('got relay time, ', res);
|
||||
|
||||
console.log('stopping fluence...');
|
||||
await Fluence.stop();
|
||||
console.log('stopped fluence...');
|
||||
};
|
@ -3,17 +3,20 @@ import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
import { main } from './fluence/';
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById('root') as HTMLElement
|
||||
);
|
||||
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
|
||||
main()
|
||||
.then(() => console.log('done!'))
|
||||
.catch((err) => console.error('error: ', err));
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
26
packages/@tests/frameworks/cra-ts/tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import logo from "./logo.svg";
|
||||
import "./App.css";
|
||||
|
||||
import { makeDefaultPeer } from "@fluencelabs/js-client.web";
|
||||
import { krasnodar } from "@fluencelabs/fluence-network-environment";
|
||||
|
||||
const relayNode = krasnodar[4];
|
||||
|
||||
const peer = makeDefaultPeer();
|
||||
|
||||
function App() {
|
||||
const [connected, setConnected] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
peer.start({ connectTo: relayNode })
|
||||
.then(() => {
|
||||
setConnected(true);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("Client initialization failed", err);
|
||||
setConnected(false);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>Connected: ${connected}</p>
|
||||
<p>
|
||||
Edit <code>src/App.tsx</code> and save to reload.
|
||||
</p>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
@ -9,22 +9,16 @@
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"compile-aqua": "aqua -i ../aqua/ -o ./src/_aqua",
|
||||
"build": "pnpm copy-script",
|
||||
"serve": "http-server public",
|
||||
"copy-script": "cp ../../client/js-client.web.standalone/dist/js-client.min.js ./public"
|
||||
},
|
||||
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||
"author": "Fluence Labs",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fluencelabs/js-client.api": "workspace:*",
|
||||
"@fluencelabs/interface": "workspace:*",
|
||||
"@fluencelabs/fluence-network-environment": "1.0.13"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@fluencelabs/js-peer": "workspace:*",
|
||||
"@fluencelabs/aqua": "0.9.1-374",
|
||||
"http-server": "14.1.1"
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Smoke test for web</title>
|
||||
<script src="./js-client.min.js" async></script>
|
||||
<script src="./js-client.min.js"></script>
|
||||
<script src="./index.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
@ -14,7 +15,6 @@
|
||||
<main>
|
||||
<h1>Open console f12</h1>
|
||||
</main>
|
||||
<script src="../src/index.ts" type="module"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
103
packages/@tests/smoke_web/public/index.js
Normal file
@ -0,0 +1,103 @@
|
||||
const peer = globalThis.defaultPeer;
|
||||
|
||||
const relay = {
|
||||
multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
};
|
||||
|
||||
const getRelayTime = (relayPeerId) => {
|
||||
const script = `
|
||||
(xor
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(seq
|
||||
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
|
||||
(call %init_peer_id% ("getDataSrv" "relayPeerId") [] relayPeerId)
|
||||
)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(xor
|
||||
(seq
|
||||
(call relayPeerId ("peer" "timestamp_ms") [] ts)
|
||||
(call -relay- ("op" "noop") [])
|
||||
)
|
||||
(seq
|
||||
(call -relay- ("op" "noop") [])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
|
||||
)
|
||||
)
|
||||
)
|
||||
(xor
|
||||
(call %init_peer_id% ("callbackSrv" "response") [ts])
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
|
||||
)
|
||||
)
|
||||
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
|
||||
)
|
||||
`;
|
||||
|
||||
const def = {
|
||||
functionName: 'getRelayTime',
|
||||
arrow: {
|
||||
tag: 'arrow',
|
||||
domain: {
|
||||
tag: 'labeledProduct',
|
||||
fields: {
|
||||
relayPeerId: {
|
||||
tag: 'scalar',
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
codomain: {
|
||||
tag: 'unlabeledProduct',
|
||||
items: [
|
||||
{
|
||||
tag: 'scalar',
|
||||
name: 'u64',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
names: {
|
||||
relay: '-relay-',
|
||||
getDataSrv: 'getDataSrv',
|
||||
callbackSrv: 'callbackSrv',
|
||||
responseSrv: 'callbackSrv',
|
||||
responseFnName: 'response',
|
||||
errorHandlingSrv: 'errorHandlingSrv',
|
||||
errorFnName: 'error',
|
||||
},
|
||||
};
|
||||
|
||||
const config = {};
|
||||
|
||||
const args = {};
|
||||
return peer.compilerSupport.callFunction({
|
||||
args,
|
||||
def,
|
||||
config,
|
||||
script,
|
||||
});
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
console.log('starting fluence...');
|
||||
await peer.start({
|
||||
connectTo: relay,
|
||||
});
|
||||
console.log('started fluence');
|
||||
|
||||
console.log('getting relay time...');
|
||||
const res = await getRelayTime(relay.peerId);
|
||||
console.log('got relay time, ', res);
|
||||
|
||||
console.log('stopping fluence...');
|
||||
await peer.stop();
|
||||
console.log('stopped fluence...');
|
||||
};
|
||||
|
||||
main()
|
||||
.then(() => console.log('done!'))
|
||||
.catch((err) => console.error('error: ', err));
|
@ -1,16 +0,0 @@
|
||||
import { Fluence } from '@fluencelabs/js-client.api';
|
||||
|
||||
const relay = {
|
||||
multiaddr: '/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
peerId: '12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3',
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
await Fluence.start({
|
||||
connectTo: relay,
|
||||
});
|
||||
};
|
||||
|
||||
main()
|
||||
.then(() => console.log('done!'))
|
||||
.catch((err) => console.error('error: ', err));
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"target": "ES5",
|
||||
"outDir": "./dist",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
@ -21,6 +21,14 @@
|
||||
"./compilerSupport/v4": {
|
||||
"import": "./dist/compilerSupport/v4.js",
|
||||
"types": "./dist/compilerSupport/v4.d.ts"
|
||||
},
|
||||
"./dist/compilerSupport/v3": {
|
||||
"import": "./dist/compilerSupport/v3.js",
|
||||
"types": "./dist/compilerSupport/v3.d.ts"
|
||||
},
|
||||
"./dist/compilerSupport/v4": {
|
||||
"import": "./dist/compilerSupport/v4.js",
|
||||
"types": "./dist/compilerSupport/v4.d.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
@ -14,8 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { IFluencePeer } from './v3';
|
||||
export { CallParams as CallParams$$ } from './v3';
|
||||
export { IFluencePeer } from './v3.js';
|
||||
export { CallParams as CallParams$$ } from './v3.js';
|
||||
export {
|
||||
ArrayType as ArrayType$$,
|
||||
ArrowType as ArrowType$$,
|
||||
@ -38,4 +38,4 @@ export {
|
||||
UnlabeledProductType as UnlabeledProductType$$,
|
||||
callFunction as callFunction$$,
|
||||
registerService as registerService$$,
|
||||
} from './v3';
|
||||
} from './v3.js';
|
||||
|
@ -1,5 +1,8 @@
|
||||
import type { IFluencePeer, PeerConfig } from '@fluencelabs/interface';
|
||||
|
||||
export { IFluencePeer, PeerConfig, CallParams } from '@fluencelabs/interface';
|
||||
export { registerService$$, callFunction$$ } from './compilerSupport/v4.js';
|
||||
|
||||
const getPeerFromGlobalThis = (): IFluencePeer | undefined => {
|
||||
// @ts-ignore
|
||||
return globalThis.defaultPeer;
|
||||
|
@ -372,18 +372,19 @@ export class FluencePeer implements IFluencePeer {
|
||||
|
||||
registerDefaultServices(this);
|
||||
|
||||
this._classServices = {
|
||||
sig: new Sig(this._keyPair),
|
||||
srv: new Srv(this),
|
||||
};
|
||||
this._classServices.sig.securityGuard = defaultSigGuard(peerId);
|
||||
registerSig(this, 'sig', this._classServices.sig);
|
||||
registerSig(this, peerId, this._classServices.sig);
|
||||
// TODO: doesn't work in web, fix!
|
||||
// this._classServices = {
|
||||
// sig: new Sig(this._keyPair),
|
||||
// srv: new Srv(this),
|
||||
// };
|
||||
// this._classServices.sig.securityGuard = defaultSigGuard(peerId);
|
||||
// registerSig(this, 'sig', this._classServices.sig);
|
||||
// registerSig(this, peerId, this._classServices.sig);
|
||||
|
||||
registerSrv(this, 'single_module_srv', this._classServices.srv);
|
||||
registerNodeUtils(this, 'node_utils', new NodeUtils(this));
|
||||
// registerSrv(this, 'single_module_srv', this._classServices.srv);
|
||||
// registerNodeUtils(this, 'node_utils', new NodeUtils(this));
|
||||
|
||||
this._startParticleProcessing();
|
||||
// this._startParticleProcessing();
|
||||
}
|
||||
|
||||
/**
|
||||
|