Skip to content

Commit 0e0d254

Browse files
authored
revise (#410)
Signed-off-by: ReyisaRuby <yisa@reddio.com>
1 parent f353b01 commit 0e0d254

5 files changed

Lines changed: 24 additions & 28 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
data
99
**/.env
1010
**/.*.env
11-
bin/
11+
bin/
12+
reddio

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PROJECT=reddio
33
default: build
44

55
build:
6-
go build -v -o ./bin/$(PROJECT) ./cmd/node/main.go ./cmd/node/testrequest.go
6+
go build -v -o ./$(PROJECT) ./cmd/node/main.go ./cmd/node/testrequest.go
77

88
## for local dev
99

@@ -13,9 +13,6 @@ build_transfer_test_no_race:
1313
build_uniswap_test_no_race:
1414
go build -v -o ./bin/uniswap_test ./test/cmd/uniswap/main.go
1515

16-
build_uniswap_benchmark_test:
17-
go build -v -o ./bin/uniswap_benchmark_test ./test/cmd/uniswap_benchmark/main.go
18-
1916
build_transfer_erc20_test_no_race:
2017
go build -v -o ./bin/transfer_erc20_test ./test/cmd/erc20/main.go
2118

@@ -62,6 +59,9 @@ ci_parallel_single_transfer_erc20_test: reset
6259
build_benchmark_test:
6360
go build -v -o ./bin/benchmark_test ./test/cmd/benchmark/main.go
6461

62+
build_uniswap_benchmark_test:
63+
go build -v -o ./bin/uniswap_benchmark_test ./test/cmd/uniswap_benchmark/main.go
64+
6565
reset:
6666
@if [ -d "yu" ]; then \
6767
echo "Deleting 'yu' directory..."; \

conf/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
evmProcessorSelector = "serial"
22
enableAsyncCommit = false
33
maxConcurrency = 4
4-
isBenchmarkMode = false
4+
isBenchmarkMode = true
55
ignoreConflict = false
66

77
[rateLimitConfig]

test/cmd/uniswap_benchmark/main.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/sirupsen/logrus"
9-
"github.com/yu-org/yu/core/startup"
109
"golang.org/x/time/rate"
1110

1211
"github.com/reddio-com/reddio/evm"
@@ -15,9 +14,8 @@ import (
1514
)
1615

1716
var (
18-
configPath string
17+
dataPath string
1918
evmConfigPath string
20-
maxBlock int
2119
qps int
2220
action string
2321
duration time.Duration
@@ -28,33 +26,26 @@ var (
2826
)
2927

3028
func init() {
31-
flag.StringVar(&configPath, "configPath", "", "")
29+
flag.StringVar(&dataPath, "data-path", "./bin/prepared_test_data.json", "Path to uniswap data")
3230
flag.StringVar(&evmConfigPath, "evmConfigPath", "./conf/evm.toml", "")
33-
flag.IntVar(&maxBlock, "maxBlock", 500, "")
34-
flag.IntVar(&qps, "qps", 1500, "")
35-
flag.StringVar(&action, "action", "run", "")
36-
flag.DurationVar(&duration, "duration", time.Minute*5, "")
37-
flag.IntVar(&deployUsers, "deployUsers", 10, "")
38-
flag.IntVar(&testUsers, "testUsers", 100, "")
31+
flag.IntVar(&qps, "qps", 5, "")
32+
flag.StringVar(&action, "action", "prepare", "")
33+
flag.DurationVar(&duration, "duration", time.Minute*3, "")
34+
flag.IntVar(&deployUsers, "deployUsers", 1, "")
35+
flag.IntVar(&testUsers, "testUsers", 2, "")
3936
flag.BoolVar(&nonConflict, "nonConflict", false, "")
4037
flag.IntVar(&maxUsers, "maxUsers", 0, "")
4138
}
4239

4340
func main() {
4441
flag.Parse()
45-
if err := conf.LoadConfig(configPath); err != nil {
46-
panic(err)
47-
}
48-
yuCfg := startup.InitDefaultKernelConfig()
49-
yuCfg.IsAdmin = true
50-
yuCfg.Txpool.PoolSize = 10000000
5142
evmConfig := evm.LoadEvmConfig(evmConfigPath)
5243
ethManager := &uniswap.EthManager{}
5344
cfg := conf.Config.EthCaseConf
5445
limiter := rate.NewLimiter(rate.Limit(qps), qps)
5546
ethManager.Configure(cfg, evmConfig)
5647
ethManager.AddTestCase(
57-
uniswap.NewUniswapV2TPSStatisticsTestCase("UniswapV2 TPS StatisticsTestCase", deployUsers, testUsers, maxUsers, limiter, action == "run", nonConflict))
48+
uniswap.NewUniswapV2TPSStatisticsTestCase("UniswapV2 TPS StatisticsTestCase", deployUsers, testUsers, maxUsers, limiter, action == "run", nonConflict, dataPath))
5849
switch action {
5950
case "prepare":
6051
prepareBenchmark(context.Background(), ethManager)

test/uniswap/uniswapTPS_testcase.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"math/big"
88
"math/rand"
9+
"os"
910
"time"
1011

1112
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -33,6 +34,7 @@ const (
3334
)
3435

3536
type UniswapV2TPSStatisticsTestCase struct {
37+
dataPath string
3638
MaxUsers int
3739
NonConflict bool
3840
TestUsers int
@@ -54,21 +56,23 @@ func (cd *UniswapV2TPSStatisticsTestCase) Name() string {
5456
return cd.CaseName
5557
}
5658

57-
func NewUniswapV2TPSStatisticsTestCase(name string, t, d, maxUser int, rm *rate.Limiter, needLoad, nonConflict bool) *UniswapV2TPSStatisticsTestCase {
59+
func NewUniswapV2TPSStatisticsTestCase(name string, t, d, maxUser int, rm *rate.Limiter, needLoad, nonConflict bool, dataPath string) *UniswapV2TPSStatisticsTestCase {
5860
tc := &UniswapV2TPSStatisticsTestCase{
5961
MaxUsers: maxUser,
6062
NonConflict: nonConflict,
6163
DeployedUsers: t,
6264
TestUsers: d,
6365
CaseName: name,
6466
rm: rm,
67+
dataPath: dataPath,
6568
}
6669
if needLoad {
67-
loadedTestData, err := loadTestDataFromFile("test/tmp/prepared_test_data.json")
70+
loadedTestData, err := loadTestDataFromFile(dataPath)
6871
if err != nil {
6972
logrus.Fatalf("Failed to load test data: %v", err)
7073
return nil
7174
}
75+
logrus.Infof("loaded test data, testUsers:%v, testContracts:%v", len(loadedTestData.TestUsers), len(loadedTestData.TestContracts))
7276
tc.loadTestData = loadedTestData
7377
}
7478
return tc
@@ -201,6 +205,7 @@ func (cd *UniswapV2TPSStatisticsTestCase) prepareDeployerContract(deployerUser *
201205
}
202206

203207
func (cd *UniswapV2TPSStatisticsTestCase) Prepare(ctx context.Context, m *pkg.WalletManager) error {
208+
os.Remove(cd.dataPath)
204209
deployerUsers, err := m.GenerateRandomWallets(cd.DeployedUsers, accountInitialFunds)
205210
if err != nil {
206211
return fmt.Errorf("failed to generate deployer user: %v", err.Error())
@@ -223,15 +228,15 @@ func (cd *UniswapV2TPSStatisticsTestCase) Prepare(ctx context.Context, m *pkg.Wa
223228
TestContracts: make([]TestContract, 0),
224229
}
225230
for index, deployerUser := range deployerUsers {
226-
logrus.Infof("start to deploy %v contract", index)
231+
logrus.Infof("start to deploy %v contract", index+1)
227232
router, tokenPairs, err := cd.prepareDeployerContract(deployerUser, testUsers, gasPrice, client)
228233
if err != nil {
229234
return fmt.Errorf("prepare contract failed, err:%v", err)
230235
}
231236
preparedTestData.TestContracts = append(preparedTestData.TestContracts, TestContract{router, tokenPairs})
232237
logrus.Infof("create %v deploy contract done", index+1)
233238
}
234-
saveTestDataToFile("test/tmp/prepared_test_data.json", preparedTestData)
239+
saveTestDataToFile(cd.dataPath, preparedTestData)
235240
return err
236241
}
237242

@@ -253,7 +258,6 @@ func (cd *UniswapV2TPSStatisticsTestCase) executeTest(nodeUrl string, chainID in
253258
logrus.Infof("Failed to perform swap steps: %v", err)
254259
return err
255260
}
256-
257261
return nil
258262
}
259263

0 commit comments

Comments
 (0)