区块链安全应用------压力测试

server/2024/9/23 3:23:21/

测试要求:

  • 1. 对以下AccountManager智能合约进行压测(基础要求set函数测试,balanceOf涵为20分加分项)
  • 2. 在本地链进行测试,需要监控本地进程的资源使用情况。每个进程的multiOutput属性为Avg
  • 3. 需要将每一个更改的配置文件截图,和执行命令截图放在word中。提交word代码。

第一步:智能合约添加到caliper-bench中,操作和代码截图

在benchmarks/caliper-benchmarks/src/fisco-bcos/文件下创建AccountManager文件存放智能合约

mkdir -p /root/benchmarks/caliper-benchmarks/src/fisco-bcos/AccountManager
cd /root/benchmarks/caliper-benchmarks/src/fisco-bcos/AccountManager
vim AccountManager.sol

第二步:更改网络配置参数,操作和代码截图

  • a) 在/root/benchmarks/caliper-benchmarks/networks/fisco-bcos目录下创建test目录
  • b) 在该目录下添加网络配置文件fisco-bcos.json
mkdir -p /root/benchmarks/caliper-benchmarks/networks/fisco-bcos/test
cd /root/benchmarks/caliper-benchmarks/networks/fisco-bcos/test
vim fisco-bcos.json

 

{"caliper": {"blockchain": "fisco-bcos","command": {"start": "docker-compose -f networks/fisco-bcos/4nodes1group/docker-compose.yaml up -d; sleep 3s","end": "docker-compose -f networks/fisco-bcos/4nodes1group/docker-compose.yaml down"}},"fisco-bcos": {"config": {"privateKey": "bcec428d5205abe0f0cc8a734083908d9eb8563e31f943d760786edf42ad67dd","account": "0x64fa644d2a694681bd6addd6c5e36cccd8dcdde3"},"network": {"nodes": [{"ip": "127.0.0.1","rpcPort": "8914","channelPort": "20914"},{"ip": "127.0.0.1","rpcPort": "8915","channelPort": "20915"},{"ip": "127.0.0.1","rpcPort": "8916","channelPort": "20916"},{"ip": "127.0.0.1","rpcPort": "8917","channelPort": "20917"}],"authentication": {"key": "/home/myy/Desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/sdk/node.key","cert": "/home/myy/Desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/sdk/node.crt","ca": "/home/myy/Desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/sdk/ca.crt"},"groupID": 1,"timeout": 100000},"smartContracts": [{"id": "helloworld","path": "src/fisco-bcos/helloworld/HelloWorld.sol","language": "solidity","version": "v0"},{"id": "parallelok","path": "src/fisco-bcos/transfer/ParallelOk.sol","language": "solidity","version": "v0"},{"id": "dagtransfer","address": "0x0000000000000000000000000000000000005002","language": "precompiled","version": "v0"},{"id": "AccountManager","path": "src/fisco-bcos/AccountManager/AccountManager.sol" ,"language": "solidity" ,"version": "v1"}]},"info": {"Version": "2.0.0","Size": "4 Nodes","Distribution": "Single Host"}
}

第三步:测试配置文件参数,操作和代码截图

  • a)在/root/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos目录下创建AccountManager文件
  • b)编辑配置测试文件配置
mkdir -p /root/benchmarks/caliper-benchmarks/benchmarks/samples/fiscobcos/AccountManagercd /root/benchmarks/caliper-benchmarks/benchmarks/samples/fiscobcos/AccountManagervim config.yaml

#
# 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.
#---
test:name: AccountManagerdescription: This is a AccountManager benchmark of FISCO BCOS for caliperclients:type: localnumber: 1rounds:- label: setAccountdescription: Test performance of getting accounttxNumber:- 10000rateControl:- type: fixed-rateopts:tps: 1000callback: /home/myy/Desktop/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos/AccountManager/set.jsmonitor:type:- docker- processdocker:name:- node0- node1- node2- node3process:- command: nodearguments: fiscoBcosClientWorker.jsmultiOutput: avginterval: 0.5

第四步:测试文件编写,操作和代码截图

  • a)在/root/benchmarks/caliper-benchmarks/benchmarks/samples/fiscobcos/AccountManager目录下编辑测试文件配置  
cd /root/benchmarks/caliper-benchmarks/benchmarks/samples/fiscobcos/AccountManagervim set.js

/*
* 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.
*/'use strict';module.exports.info = ' setting account';let initMoney = 100000000;
let bc, contx;
let txnPerBatch;module.exports.init = function (blockchain, context, args) {txnPerBatch = 1;bc = blockchain;contx = context;return Promise.resolve();
};/*** Generates simple workload* @return {Object} array of json objects*/
function generateWorkload() {let workload = [];for (let i = 0; i < txnPerBatch; i++) {let w = {'transaction_type': 'set(string,uint256)','name': 'hello! - from ' + process.pid.toString(),'num': initMoney};workload.push(w);}return workload;
}module.exports.run = function () {let args = generateWorkload();return bc.invokeSmartContract(contx, 'AccountManager', 'v0', args, null);
};module.exports.end = function () {// Do nothingreturn Promise.resolve();
};

第五步:运行压测结果命令和结果截图

运行benchmark代码:

cd benchmarks
npx caliper benchmark run --caliper-workspace /home/myy/Desktop/benchmarks/caliper-benchmarks --caliper-benchconfig /home/myy/Desktop/benchmarks/caliper-benchmarks/benchmarks/samples/fisco-bcos/AccountManager/config.yaml --caliper-networkconfig /home/myy/Desktop/benchmarks/caliper-benchmarks/networks/fisco-bcos/4nodes1group/fisco-bcos.json

第六步:生成报告截图


http://www.ppmy.cn/server/13971.html

相关文章

Linux时间同步练习

题目如下&#xff1a; 一.配置server主机要求如下&#xff1a; 1.server主机的主机名称为 ntp_server.example.com 2.server主机的IP为&#xff1a; 172.25.254.100 3.server主机的时间为1984-11-11 11&#xff1a;11&#xff1a;11 4.配置server主机的时间同步服务要求可以被所…

react脚手架创建的项目配置.env环境以及package.json配置

## 在根目录下创建 .env .env.prod等等配置 比如 REACT_APP_API_URLhttp://127.0.0.1:7001/api REACT_APP_ENVdev// 注意&#xff1a;必须以 REACT_APP_ 开头 // 不能有;分号 会在加 / 干脆不要 ## 在package.json 中的配置 安装 &#xff1a; npm install dotenv-cli -…

LeetCode 42. 接雨水 - PHP

给定 n 个非负整数表示每个宽度为 1 的柱子的高度图&#xff0c;计算按此排列的柱子&#xff0c;下雨之后能接多少雨水。 左右两边是漏的&#xff0c;就是第一个柱子和最后一个柱子不接雨水。 暴力递归 class Solution {/*** param Integer[] $height* return Integer*/functi…

设计模式- 适配器模式(Adapter Pattern)结构|原理|优缺点|场景|示例

设计模式&#xff08;分类&#xff09; 设计模式&#xff08;六大原则&#xff09; 创建型&#xff08;5种&#xff09; 工厂方法 抽象工厂模式 单例模式 建造者模式 原型模式 结构型&#xff08;7种&#xff09; 适配器…

ADB 命令大全

Case1&#xff1a;报错Remote couldnt create file&#xff1a;Read-only file system 输入 adb disable-verity adb reboot adb root adb remount Case2&#xff1a;/system/bin/sh: cant create C:xxx.txt: Read-only file system Android设备的文件系统是基于Linux的&…

安卓手机APP开发__媒体开发部分__音轨的选择

安卓手机APP开发__媒体开发部分__音轨的选择 目录 概述 查询可用的音轨 修改轨道选择参数 基于约束的轨道选择 选择特定的轨道 禁用轨道的类型和组 定制化轨道选择器

搭建电商网站跨境电商独立站|网上商城接口/电商数据接口详情

电商运营中&#xff0c;数据分析这项工作越来越重要&#xff0c;许多品牌方也越来越热衷去做电商数据分析。不过&#xff0c;全面的数据该如何获取呢&#xff0c;此时&#xff0c;电商数据接口的重要性便凸显出来了。 监控范围广&#xff1a; 可监控的范围包含京东、天猫、淘…

解决:第一次用python的pip报错

报错内容如下&#xff1a; Fatal error in launcher: Unable to create process using "C:\Users\admin\AppData\Local\Programs\Python\Python312\python.exe" "C:\Program Files\Python\Python312\Scripts\pip.exe" : ??????????? 参考 如何…