Skip to content

Commit

Permalink
build(socket.io, socket.io-client): upgrade to common socket
Browse files Browse the repository at this point in the history
Some packages use socket.io and socket.io-client V2, while other use V4.
In order for these components to communicate, we must use common
socket.io version in all cactus packages (V4.1.3). This commit introduce
some other related changes, like merging socketio unit tests to common
setup (to assert changes are correct) and fixes some strict-flag
warnings and minor bugs. It also updates python packages requirements
and updates readme when it was necessary.

Closes: #1679
Signed-off-by: Michal Bajer <michal.bajer@fujitsu.com>
  • Loading branch information
outSH committed Jan 11, 2022
1 parent 15d4793 commit 4992983
Show file tree
Hide file tree
Showing 48 changed files with 192 additions and 318 deletions.
2 changes: 1 addition & 1 deletion examples/cartrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"log4js": "^3.0.6",
"morgan": "~1.9.1",
"shelljs": "^0.8.4",
"socket.io": "^2.0.4",
"socket.io": "4.1.3",
"ts-node": "8.9.1",
"web3": "^1.2.9",
"xmlhttprequest": "^1.8.0"
Expand Down
17 changes: 8 additions & 9 deletions examples/cartrade/script-test-getFunctions/fabric/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "validatorDriver",
"version": "0.0.0",
"private": true,
"dependencies": {
"config": "^1.26.1",
"socket.io": "^2.0.4",
"fabric-ca-client": "2.2.10",
"fabric-network": "2.2.10"
}
"name": "validatorDriver",
"version": "0.0.0",
"private": true,
"dependencies": {
"config": "^1.26.1",
"fabric-ca-client": "2.2.10",
"fabric-network": "2.2.10"
}
}
2 changes: 1 addition & 1 deletion examples/cartrade/validatorDriver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"log4js": "^3.0.6",
"morgan": "~1.8.1",
"serve-favicon": "~2.4.2",
"socket.io": "^2.0.4",
"socket.io": "4.1.3",
"ethereumjs-common": "^1.5.1",
"ethereumjs-tx": "^2.1.2",
"web3": "^1.2.9",
Expand Down
5 changes: 3 additions & 2 deletions examples/discounted-cartrade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"copy-static-assets": "ts-node copyStaticAssets.ts",
"copy-blp-config": "ts-node copyBLPConfig.ts",
"replace-blp-config-path": "ts-node replaceBLPConfigPath.ts",
"init-discounted-cartrade": "ln -s ../examples/discounted-cartrade/node_modules ../../dist/node_modules"
"init-discounted-cartrade": "ln -fs ../examples/discounted-cartrade/node_modules ../../dist/node_modules"
},
"dependencies": {
"@types/node": "^14.0.24",
Expand All @@ -22,13 +22,14 @@
"express": "~4.16.1",
"fabric-ca-client": "2.2.10",
"fabric-network": "2.2.10",
"fabric-client": "^1.4.0",
"http-errors": "~1.6.3",
"indy-sdk": "^1.16.0-dev-1636",
"jsonwebtoken": "^8.5.1",
"log4js": "^3.0.6",
"morgan": "~1.9.1",
"shelljs": "^0.8.4",
"socket.io": "^2.0.4",
"socket.io": "4.1.3",
"ts-node": "8.9.1",
"web3": "^1.2.9",
"xmlhttprequest": "^1.8.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "validatorDriver",
"version": "0.0.0",
"private": true,
"dependencies": {
"config": "^1.26.1",
"socket.io": "^2.0.4",
"fabric-ca-client": "2.2.10",
"fabric-network": "2.2.10"
}
"name": "validatorDriver",
"version": "0.0.0",
"private": true,
"dependencies": {
"config": "^1.26.1",
"fabric-ca-client": "2.2.10",
"fabric-network": "2.2.10"
}
}
2 changes: 1 addition & 1 deletion examples/discounted-cartrade/validatorDriver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"log4js": "^3.0.6",
"morgan": "~1.8.1",
"serve-favicon": "~2.4.2",
"socket.io": "^2.0.4",
"socket.io": "4.1.3",
"ethereumjs-common": "^1.5.1",
"ethereumjs-tx": "^2.1.2",
"web3": "^1.2.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export function json2str(jsonObj: object) {
}
}

// Validator test program.(socket.io client)
const io = require("socket.io-client");
//var config = require('config');

export function makeApiInfoList(targetApiInfo: any): Array<ApiInfo> {
const retApiInfoList: Array<ApiInfo> = [];
for (const item of targetApiInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
deleteAndDisconnectSocke,
} from "./driver-common";

const io = require("socket.io-client");
import { io } from "socket.io-client";

const targetValidatorUrl = "https://localhost:5050";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
deleteAndDisconnectSocke,
} from "./driver-common";

const io = require("socket.io-client");
import { io } from "socket.io-client";

const targetValidatorUrl = "https://localhost:5040";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ function sendRequest() {
.then((returnvalue) => {
//console.log('success : ' + json2str(returnvalue));

////socket.emit('request', returnvalue);

// call WebAPI
console.log("##call WebAPI");
var param = {
Expand Down
2 changes: 1 addition & 1 deletion examples/electricity-trade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"log4js": "^3.0.6",
"morgan": "~1.9.1",
"shelljs": "^0.8.4",
"socket.io": "^2.0.4",
"socket.io": "4.1.3",
"ts-node": "8.9.1",
"web3": "^1.2.9",
"xmlhttprequest": "^1.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"ethereumjs-tx": "^2.1.2",
"ts-node": "^9.0.0",
"web3": "^1.2.9",
"socket.io": "^2.0.4"
"socket.io": "4.1.3"
},
"devDependencies": {
"typescript": "^3.9.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* transferNumericAsset.ts
*/

import { io } from "socket.io-client";

{
// Validator test program.(socket.io client)
const io = require("socket.io-client");
const config = require("config");

// Specify the server (Validator) of the communication destination
Expand All @@ -32,7 +33,7 @@
}

console.log(
`execution parameter : fromAddress = ${process.argv[2]}, toAddress = ${process.argv[3]}, amount = ${process.argv[4]}`
`execution parameter : fromAddress = ${process.argv[2]}, toAddress = ${process.argv[3]}, amount = ${process.argv[4]}`,
);

const fromAddress = process.argv[2];
Expand Down
2 changes: 1 addition & 1 deletion examples/test-run-transaction/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"log4js": "^3.0.6",
"morgan": "~1.9.1",
"shelljs": "^0.8.4",
"socket.io": "^2.0.4",
"socket.io": "4.1.3",
"ts-node": "8.9.1",
"web3": "^1.2.9",
"xmlhttprequest": "^1.8.0"
Expand Down
1 change: 0 additions & 1 deletion jest.config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"socket.io-client": "^4.1.2"
"socket.io-client": "4.1.3"
}
}
135 changes: 69 additions & 66 deletions packages-python/cactus_validator_socketio_iroha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,74 +19,77 @@ This validator codes provides the following features:
### How to execute test client (in the current status, only the monitor feature can be tested)

1. Launch [iroha-testnet](https://github.com/hyperledger/cactus/tree/main/tools/docker/iroha-testnet) docker and execute its wallet script
```
$ cd cactus/tools/docker/iroha-testnet/
$ docker-compose up -d
$ cd example/iroha-wallet
$ bash setup-iroha-wallet.sh
```
```
$ cd cactus/tools/docker/iroha-testnet/
$ docker-compose up -d
$ cd example/iroha-wallet
$ bash setup-iroha-wallet.sh
```
1. Launch validator server on the first console
```
$ cd cactus/packages-python/cactus_validator_socketio_iroha/validator-python
$ pip3 install websocket eventlet flask requests flask-socketio==4.3.2 pyyaml pyjwt cryptography iroha schedule
$ python3 -m main
```
- If there is the following message on your first console, the validator is successfully launched.

```
socket port: 5060
Server initialized for eventlet.
```
```
$ cd cactus/packages-python/cactus_validator_socketio_iroha/
$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip3 install websocket eventlet flask requests flask-socketio==5.1.1 pyyaml pyjwt cryptography iroha schedule
$ cd ./validator-python
$ python3 -m main
```
- If there is the following message on your first console, the validator is successfully launched.
```
socket port: 5060
Server initialized for eventlet.
```
1. Execute test script on the second console
```
$ cd cactus/packages-python/cactus_validator_socketio_iroha/testcli
$ npm install
$ node testsock.js
```

- If there is the following message on your second console, the block monitoring request is successfully executed.

```
connect
81680a4dc06a4685b8219b22fd002023
polling
call nop!
##exec requestStartMonitor()
```

- After this request is executed, the messages about monitoring blocks (`##get_block block num is : n`) will appear on your first console.

```
81680a4dc06a4685b8219b22fd002023: Sending packet OPEN data {'sid': '81680a4dc06a4685b8219b22fd002023', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
on connect (sessionid: 81680a4dc06a4685b8219b22fd002023)
##called getValidatorInstance()
##IrohaConnector.__init__
81680a4dc06a4685b8219b22fd002023: Sending packet MESSAGE data 0
81680a4dc06a4685b8219b22fd002023: Received request to upgrade to websocket
81680a4dc06a4685b8219b22fd002023: Received packet MESSAGE data 2["test-event"]
received event "test-event" from 81680a4dc06a4685b8219b22fd002023 [/]
##IrohaConnector.cb()
81680a4dc06a4685b8219b22fd002023: Upgrade to websocket successful
81680a4dc06a4685b8219b22fd002023: Received packet MESSAGE data 2["nop"]
received event "nop" from 81680a4dc06a4685b8219b22fd002023 [/]
received nop
##IrohaConnector.nop()
81680a4dc06a4685b8219b22fd002023: Received packet MESSAGE data 2["startMonitor"]
received event "startMonitor" from 81680a4dc06a4685b8219b22fd002023 [/]
on startMonitor
##called monitoring_routine()
##get_block block num is : 1
##get_block block num is : 2
##get_block block num is : 3
...
##get_block block num is : 12
```

- After 180 seconds on the second console, run requestStopMonitor and the test script will stop running.

```
##exec requestStopMonitor()
```
```
$ cd cactus/packages-python/cactus_validator_socketio_iroha/testcli
$ npm install
$ node testsock.js
```
- If there is the following message on your second console, the block monitoring request is successfully executed.
```
connect
81680a4dc06a4685b8219b22fd002023
polling
call nop!
##exec requestStartMonitor()
```
- After this request is executed, the messages about monitoring blocks (`##get_block block num is : n`) will appear on your first console.
```
81680a4dc06a4685b8219b22fd002023: Sending packet OPEN data {'sid': '81680a4dc06a4685b8219b22fd002023', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
on connect (sessionid: 81680a4dc06a4685b8219b22fd002023)
##called getValidatorInstance()
##IrohaConnector.__init__
81680a4dc06a4685b8219b22fd002023: Sending packet MESSAGE data 0
81680a4dc06a4685b8219b22fd002023: Received request to upgrade to websocket
81680a4dc06a4685b8219b22fd002023: Received packet MESSAGE data 2["test-event"]
received event "test-event" from 81680a4dc06a4685b8219b22fd002023 [/]
##IrohaConnector.cb()
81680a4dc06a4685b8219b22fd002023: Upgrade to websocket successful
81680a4dc06a4685b8219b22fd002023: Received packet MESSAGE data 2["nop"]
received event "nop" from 81680a4dc06a4685b8219b22fd002023 [/]
received nop
##IrohaConnector.nop()
81680a4dc06a4685b8219b22fd002023: Received packet MESSAGE data 2["startMonitor"]
received event "startMonitor" from 81680a4dc06a4685b8219b22fd002023 [/]
on startMonitor
##called monitoring_routine()
##get_block block num is : 1
##get_block block num is : 2
##get_block block num is : 3
...
##get_block block num is : 12
```
- After 180 seconds on the second console, run requestStopMonitor and the test script will stop running.
```
##exec requestStopMonitor()
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"dependencies": {
"json-bigint": "^1.0.0",
"jsonwebtoken": "^8.5.1",
"socket.io-client": "^2.4.0"
"socket.io-client": "4.1.3"
}
}
9 changes: 0 additions & 9 deletions packages/cactus-cmd-socketio-server/jest.config.js

This file was deleted.

Loading

0 comments on commit 4992983

Please sign in to comment.