Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
data
**/.env
**/.*.env
bin/
bin/
reddio
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PROJECT=reddio
default: build

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

## for local dev

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

build_uniswap_benchmark_test:
go build -v -o ./bin/uniswap_benchmark_test ./test/cmd/uniswap_benchmark/main.go

build_transfer_erc20_test_no_race:
go build -v -o ./bin/transfer_erc20_test ./test/cmd/erc20/main.go

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

build_uniswap_benchmark_test:
go build -v -o ./bin/uniswap_benchmark_test ./test/cmd/uniswap_benchmark/main.go

reset:
@if [ -d "yu" ]; then \
echo "Deleting 'yu' directory..."; \
Expand Down
2 changes: 1 addition & 1 deletion conf/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
evmProcessorSelector = "serial"
enableAsyncCommit = false
maxConcurrency = 4
isBenchmarkMode = false
isBenchmarkMode = true
ignoreConflict = false

[rateLimitConfig]
Expand Down
25 changes: 8 additions & 17 deletions test/cmd/uniswap_benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

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

"github.com/reddio-com/reddio/evm"
Expand All @@ -15,9 +14,8 @@ import (
)

var (
configPath string
dataPath string
evmConfigPath string
maxBlock int
qps int
action string
duration time.Duration
Expand All @@ -28,33 +26,26 @@ var (
)

func init() {
flag.StringVar(&configPath, "configPath", "", "")
flag.StringVar(&dataPath, "data-path", "./bin/prepared_test_data.json", "Path to uniswap data")
flag.StringVar(&evmConfigPath, "evmConfigPath", "./conf/evm.toml", "")
flag.IntVar(&maxBlock, "maxBlock", 500, "")
flag.IntVar(&qps, "qps", 1500, "")
flag.StringVar(&action, "action", "run", "")
flag.DurationVar(&duration, "duration", time.Minute*5, "")
flag.IntVar(&deployUsers, "deployUsers", 10, "")
flag.IntVar(&testUsers, "testUsers", 100, "")
flag.IntVar(&qps, "qps", 5, "")
flag.StringVar(&action, "action", "prepare", "")
flag.DurationVar(&duration, "duration", time.Minute*3, "")
flag.IntVar(&deployUsers, "deployUsers", 1, "")
flag.IntVar(&testUsers, "testUsers", 2, "")
flag.BoolVar(&nonConflict, "nonConflict", false, "")
flag.IntVar(&maxUsers, "maxUsers", 0, "")
}

func main() {
flag.Parse()
if err := conf.LoadConfig(configPath); err != nil {
panic(err)
}
yuCfg := startup.InitDefaultKernelConfig()
yuCfg.IsAdmin = true
yuCfg.Txpool.PoolSize = 10000000
evmConfig := evm.LoadEvmConfig(evmConfigPath)
ethManager := &uniswap.EthManager{}
cfg := conf.Config.EthCaseConf
limiter := rate.NewLimiter(rate.Limit(qps), qps)
ethManager.Configure(cfg, evmConfig)
ethManager.AddTestCase(
uniswap.NewUniswapV2TPSStatisticsTestCase("UniswapV2 TPS StatisticsTestCase", deployUsers, testUsers, maxUsers, limiter, action == "run", nonConflict))
uniswap.NewUniswapV2TPSStatisticsTestCase("UniswapV2 TPS StatisticsTestCase", deployUsers, testUsers, maxUsers, limiter, action == "run", nonConflict, dataPath))
switch action {
case "prepare":
prepareBenchmark(context.Background(), ethManager)
Expand Down
14 changes: 9 additions & 5 deletions test/uniswap/uniswapTPS_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"math/rand"
"os"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -33,6 +34,7 @@ const (
)

type UniswapV2TPSStatisticsTestCase struct {
dataPath string
MaxUsers int
NonConflict bool
TestUsers int
Expand All @@ -54,21 +56,23 @@ func (cd *UniswapV2TPSStatisticsTestCase) Name() string {
return cd.CaseName
}

func NewUniswapV2TPSStatisticsTestCase(name string, t, d, maxUser int, rm *rate.Limiter, needLoad, nonConflict bool) *UniswapV2TPSStatisticsTestCase {
func NewUniswapV2TPSStatisticsTestCase(name string, t, d, maxUser int, rm *rate.Limiter, needLoad, nonConflict bool, dataPath string) *UniswapV2TPSStatisticsTestCase {
tc := &UniswapV2TPSStatisticsTestCase{
MaxUsers: maxUser,
NonConflict: nonConflict,
DeployedUsers: t,
TestUsers: d,
CaseName: name,
rm: rm,
dataPath: dataPath,
}
if needLoad {
loadedTestData, err := loadTestDataFromFile("test/tmp/prepared_test_data.json")
loadedTestData, err := loadTestDataFromFile(dataPath)
if err != nil {
logrus.Fatalf("Failed to load test data: %v", err)
return nil
}
logrus.Infof("loaded test data, testUsers:%v, testContracts:%v", len(loadedTestData.TestUsers), len(loadedTestData.TestContracts))
tc.loadTestData = loadedTestData
}
return tc
Expand Down Expand Up @@ -201,6 +205,7 @@ func (cd *UniswapV2TPSStatisticsTestCase) prepareDeployerContract(deployerUser *
}

func (cd *UniswapV2TPSStatisticsTestCase) Prepare(ctx context.Context, m *pkg.WalletManager) error {
os.Remove(cd.dataPath)
deployerUsers, err := m.GenerateRandomWallets(cd.DeployedUsers, accountInitialFunds)
if err != nil {
return fmt.Errorf("failed to generate deployer user: %v", err.Error())
Expand All @@ -223,15 +228,15 @@ func (cd *UniswapV2TPSStatisticsTestCase) Prepare(ctx context.Context, m *pkg.Wa
TestContracts: make([]TestContract, 0),
}
for index, deployerUser := range deployerUsers {
logrus.Infof("start to deploy %v contract", index)
logrus.Infof("start to deploy %v contract", index+1)
router, tokenPairs, err := cd.prepareDeployerContract(deployerUser, testUsers, gasPrice, client)
if err != nil {
return fmt.Errorf("prepare contract failed, err:%v", err)
}
preparedTestData.TestContracts = append(preparedTestData.TestContracts, TestContract{router, tokenPairs})
logrus.Infof("create %v deploy contract done", index+1)
}
saveTestDataToFile("test/tmp/prepared_test_data.json", preparedTestData)
saveTestDataToFile(cd.dataPath, preparedTestData)
return err
}

Expand All @@ -253,7 +258,6 @@ func (cd *UniswapV2TPSStatisticsTestCase) executeTest(nodeUrl string, chainID in
logrus.Infof("Failed to perform swap steps: %v", err)
return err
}

return nil
}

Expand Down