Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add compound #47

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
.DS_Store
.idea
.vscode
agile
frigate
hyperbench
result.html
detail.js
*.[oa]
benchmark/ethereum/compare/
benchmark/ethereum/erc20/eth/keystore
benchmark/ethereum/transfer/eth/keystore
benchmark/ethereum/uniswap/eth/keystore
benchmark/ethereum/keys
benchmark/fabric/compare/
assets
*.so
Expand Down
29 changes: 3 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Go parameters
GOCMD=go
PACKR=packr
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
Expand All @@ -18,9 +17,6 @@ importpath=github.com/meshplus/hyperbench/cmd
ldflags=-X ${importpath}.branch=${branch} -X ${importpath}.commitID=${commitID} -X ${importpath}.date=${date}

# path
ASSETS=filesystem/assets
DIRS=benchmark
GET=github.com/gobuffalo/packr/v2/... github.com/gobuffalo/packr/v2/packr2
FAILPOINT=github.com/pingcap/failpoint/failpoint-ctl

# export gomodule
Expand All @@ -29,15 +25,10 @@ export GO111MODULE=on
all: build

## build: build the binary with pre-packed static resource
build: dep assets
build:
@export GOPROXY=https://goproxy.cn,direct
@packr2 build -o $(BINARY_NAME) -trimpath -ldflags "${ldflags}"
@-rm -rf $(ASSETS)

## pack: build the binary with local static resource
pack: assets
@packr2 build -o $(BINARY_NAME) -ldflags "${ldflags}"
@-rm -rf $(ASSETS)
@$(GOCMD) mod tidy
@$(GOCMD) build -o $(BINARY_NAME) -trimpath -ldflags "${ldflags}"

## test: run all test
test:
Expand All @@ -48,21 +39,7 @@ test:

## clean: clean all file generated by make
clean:
@packr2 clean
@-rm -rf $(BINARY_NAME)
@-rm -rf $(ASSETS)

.PHONY: assets
## assets: prepare asserts
assets:
@-rm -rf $(ASSETS)
@mkdir $(ASSETS)
@cp -r $(DIRS) $(ASSETS)

.PHONY: dep
## dep: install the dependencies outside (may need to use proxy to download some packages)
dep:
@go get -u $(GET)

help: Makefile
@echo " Choose a command run in "$(PROJECTNAME)":"
Expand Down
125 changes: 125 additions & 0 deletions benchmark/ethereum/account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package ethereum

import (
"bufio"
"crypto/ecdsa"
"encoding/hex"
"io"
"os"
"strings"
"testing"

"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/assert"
)

var keys = []string{
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6",
"0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a",
"0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba",
"0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e",
"0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356",
"0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97",
"0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6",
}

var keyFilePaths = []string{
"transfer/eth/keystore/keys",
"invoke/eth/keystore/keys",
}

const TotalAccount = 2000000

func TestAccount(t *testing.T) {
for _, key := range keys {
sk, err := crypto.HexToECDSA(strings.TrimPrefix(key, "0x"))
assert.Nil(t, err)
addr := crypto.PubkeyToAddress(sk.PublicKey)

t.Logf("address is: %s", addr.String())
}
}

func TestGenerateAccount(t *testing.T) {
var dstFile *os.File
var err error
for i, keyFilePath := range keyFilePaths {
if i == 0 {
dstFile, err = os.OpenFile(keyFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
assert.Nil(t, err)

var sk *ecdsa.PrivateKey
for i := 0; i < TotalAccount; i++ {
sk, err = crypto.GenerateKey()
assert.Nil(t, err)

//t.Logf("key is: %+v", *sk)
privKey := hex.EncodeToString(crypto.FromECDSA(sk))
//t.Logf("priv key: %s", privKey)

_, err = dstFile.Write([]byte(privKey))
assert.Nil(t, err)
_, err = dstFile.Write([]byte("\n"))
assert.Nil(t, err)
}
err = dstFile.Close()
assert.Nil(t, err)
} else {
f, err := os.OpenFile(keyFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
assert.Nil(t, err)
_, err = io.Copy(f, dstFile)
assert.Nil(t, err)
err = f.Close()
assert.Nil(t, err)
}
}
}

func TestSplitAndSaveKeys(t *testing.T) {
srcFile, err := os.Open("./keys")
if err != nil {
panic(err)
}
defer srcFile.Close()

var keys []string
scanner := bufio.NewScanner(srcFile)
for scanner.Scan() {
line := scanner.Text()
keys = append(keys, line)
}

if err := scanner.Err(); err != nil {
panic(err)
}

totalKeys := len(keys)
partSize := totalKeys / 3

part1 := keys[:partSize]
part2 := keys[partSize : 2*partSize]
part3 := keys[2*partSize:]

paths := []string{
"stability-erc20/eth/keystore/keys",
"stability-transfer/eth/keystore/keys",
"stability-uniswap/eth/keystore/keys"}

for i, part := range [][]string{part1, part2, part3} {
file, err := os.Create(paths[i])
if err != nil {
panic(err)
}
defer file.Close()

for _, key := range part {
_, err := file.WriteString(key + "\n")
if err != nil {
panic(err)
}
}
}
}
24 changes: 24 additions & 0 deletions benchmark/ethereum/compound/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[engine]
rate = 1 # 速率,重点压测指标
duration = "10s" # 持续时间
cap = 2 # 客户端虚拟机数量,类似CPU核心数
accounts = 1000 # 总账户数

[client]
script = "benchmark/ethereum/compound/script.lua" # 脚本
type = "eth" # 区块链类型
contract = "benchmark/ethereum/compound/contract" # 合约目录路径
contract_num = 0 # 合约部署数量
config = "benchmark/ethereum/compound/eth" # 区块链SDK配置路径
plugin = "./eth.so" # 插件路径
args = [] # 合约参数路径

[client.options] # 客户端选项

[recorder.log]
dump = false
dir = "./logs"
level = "info"

[recorder.csv]
dir = "./csv"
Loading