Caliper stress testing, custom test cases, and error handling summary (2)

1. caliper test

Continued from the previous articlecaliper stress testing, custom test cases, and error handling summary (1)_Evening Breeze is a Passer-by.’s Blog-CSDN Blog

Deploy caliper and complete testing

2. Summary of error handling

2.1 错误1    fatal: unable to access 'https://github.com/creationix/nvm.git/': Could not resolve host: github.com

 Solution

sudo vim /etc/hosts

Open the hosts file and add this domain name to localhost.

140.82.114.4    github.com

 problem solved

 2.2 Error 2

Command 'npm' not found

When this is npm init, we need to re-download npm.

sudo apt install npm

2.3 Error 3

npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm ERR! Linux 5.4.0-124-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "--only=prod" "@hyperledger/[email protected]"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /home/fisco/benchmarks/node_modules/.staging/@types/node-77814c16/package.json
npm ERR! code ENOTDIR
npm ERR! errno -20
npm ERR! syscall open
 
npm ERR! ENOTDIR: not a directory, open '/home/fisco/benchmarks/node_modules/.staging/@types/node-77814c16/package.json'
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>
 
npm ERR! Please include the following file with any support request:
npm ERR!     /home/fisco/benchmarks/npm-debug.log

The problem is that the versions of Npm and nodejs are incorrect {"node":">=8.10.0","npm":">=5.6.0"} 

 Requires nvm 8

nvm use 8

2.4 错误4  dial unix /var/run/docker.sock: connect: permission denied

 error [caliper] [fiscoBcosApi.js] 	Compiling error: 
docker: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

2023.07.23-01:30:05.744 error [caliper] [installSmartContract.js] 	Depolying error: undefined
2023.07.23-01:30:05.744 error [caliper] [installSmartContract.js] 	Failed to install smart contract helloworld, path=/home/csdn/testFisco/benchmarks/caliper-benchmarks/src/fisco-bcos/helloworld/HelloWorld.sol

 

 This is because the user has not joined the docker user group

Solution

sudo groupadd docker               #添加用户组
sudo gpasswd -a username docker    #将当前用户添加至用户组
#sudo gpasswd -a csdn docker
newgrp docker                      #更新用户组

2.5 错误5    Depolying error: Error: Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings and this string was given: 982005432c484060b0c89ec0b321ad72Failed to install smart contract helloworld, path=/home/shijianfeng/fisco/benchmarks/caliper-benchmarks/src/fisco-bcos/helloworld/HelloWorld.sol
 

error [caliper] [installSmartContract.js] 	Depolying error: Error: Cannot convert string to buffer. toBuffer only supports 0x-prefixed hex strings and this string was given: 46bcc91063db42968a300e3a32d96b88
2023.07.23-01:35:01.776 error [caliper] [installSmartContract.js] 	Failed to install smart contract helloworld, path=/home/csdn/testFisco/benchmarks/caliper-benchmarks/src/fisco-bcos/helloworld/HelloWorld.sol
2023.07.23-01:35:01.777 error [caliper] [caliper-flow] 	Error: TypeError: Color.error is not a function
    at FiscoBcos.installSmartContract (/home/csdn/testFisco/benchmarks/node_modules/@hyperledger/caliper-fisco-bcos/lib/fiscoBcos.js:62:36)
    at <anonymous>

 This is because according to the official documentation, some file configurations have not been modified.

Enter the /node_modules/@hyperledger/caliper-fisco-bcos/lib directory and modify fiscoBcos.js

 

 fiscoBcos.js

sudo vim fiscoBcos.js
......

​const invokeSmartContractImpl = require('./invokeSmartContract');
const generateRawTransactionImpl = require('./generateRawTransactions');
const sendRawTransactionImpl = require('./sendRawTransactions');
#const Color = require('./common');#删除掉这一行
const Color = require('./common').Color;#修改为这一行
const commLogger = CaliperUtils.getLogger('fiscoBcos.js');

​......

 this.bcType = 'fisco-bcos';
        this.workspaceRoot = workspace_root;
        this.fiscoBcosSettings = CaliperUtils.parseYaml(this.configPath)['fisco-bcos'];
        #从这里开始添加
        if (this.fiscoBcosSettings.network && this.fiscoBcosSettings.network.authentication) {
            for (let k in this.fiscoBcosSettings.network.authentication) {
                this.fiscoBcosSettings.network.authentication[k] = CaliperUtils.resolvePath(this.fiscoBcosSettings.network.authentication[k], workspace_root);
            }
        }
        #到这里结束
    }

​......

    async installSmartContract() {
        #const fiscoBcosSettings = CaliperUtils.parseYaml(this.configPath)['fisco-bcos'];#删除掉这一行
        const fiscoBcosSettings = this.fiscoBcosSettings;#替换为这一行
        try {
            await installSmartContractImpl.run(fiscoBcosSettings, this.workspaceRoot);
        } catch (error) {

......

channelPromise.js  

sudo vim channelPromise.js 
......

function parseResponse(response) {
    let seq = response.slice(6, 38).toString();
    let result = JSON.parse(response.slice(42).toString());
    #let emitter = emitters.get(seq).emitter;#删除掉这一行
    #从这里开始添加
    let emitter = emitters.get(seq);
    if(!emitter) {
        //Stale message receieved
        return;
    }
    emitter = emitter.emitter;
    #到这里结束

    if (emitter) {
        let readOnly = Object.getOwnPropertyDescriptor(emitter, 'readOnly').value;

web3sync.js

 Go to the /node_modules/@hyperledger/caliper-fisco-bcos/lib/web3lib directory and modify web3sync.js

sudo vim web3sync.js
......

function genRandomID() {
    let uuid = uuidv4();
    #uuid = uuid.replace(/-/g, '');#删除掉这一行
    uuid = '0x' + uuid.replace(/-/g, '');#替换为这一行

    return uuid;
}

......

        blockLimit: blockLimit,
        chainId: 1,
        groupId: groupId,
        extraData: ''
        extraData: '0x0'#修改为这行
    };

    return signTransaction(postdata, privateKey, null);

......

        blockLimit: blockLimit,
        chainId: 1,
        groupId: groupId,
        extraData: ''
        extraData: '0x0'#修改为这行
    };

    return signTransaction(postdata, privateKey, null);

......

2.6 错误6  Depolying error: TypeError: secp256k1.sign is not a function

  

 error [caliper] [installSmartContract.js] 	Depolying error: TypeError: secp256k1.sign is not a function
2023.07.23-01:56:04.406 error [caliper] [installSmartContract.js] 	Failed to install smart contract helloworld, path=/home/csdn/testFisco/benchmarks/caliper-benchmarks/src/fisco-bcos/helloworld/HelloWorld.sol
2023.07.23-01:56:04.407 error [caliper] [fiscoBcos.js] 	FISCO BCOS smart contract install failed: TypeError: secp256k1.sign is not a function
    at Object.ecsign (/home/csdn/testFisco/benchmarks/node_modules/@hyperledger/caliper-fisco-bcos/lib/web3lib/utils.js:141:29)
    at Transaction.sign (/home/csdn/testFisco/benchmarks/node_modules/@hyperledger/caliper-fisco-bcos/lib/web3lib/transactionObject.js:272:23)
    at signTransaction (/home/csdn/testFisco/benchmarks/node_modules/@hyperledger/caliper-fisco-bcos/lib/web3lib/web3sync.js:42:8)
    at Object.getSignDeployTx (/home/csdn/testFisco/benchmarks/node_modules/@hyperledger/caliper-fisco-bcos/lib/web3lib/web3sync.js:121:12)
    at Object.module.exports.deploy (/home/csdn/testFisco/benchmarks/node_modules/@hyperledger/caliper-fisco-bcos/lib/fiscoBcosApi.js:165:27)
    at <anonymous>

 Solution

The version limit was not written correctly when specifying the secp256k1 dependent package. As a result, the 4.0 version of the secp256k1 package was automatically installed during binding. However, all the latest 4.0 package APIs have changed, resulting in an execution error.

There is a temporary solution. Go to the node_modules/@hyperledger/caliper-fisco-bcos directory, edit the package.json file in this directory, and add an item "secp256k1": "^3.8.0" in "dependencies". ;, and then execute npm i in the directory. After the update is completed, the test program can be started.

 Just npm i in this directory

Guess you like

Origin blog.csdn.net/m0_72435337/article/details/131880476
Recommended