Commit 9e17640c authored by 张振华's avatar 张振华

update

parent f7fdf9e0
...@@ -99,7 +99,7 @@ timeoutVoting=3000 ...@@ -99,7 +99,7 @@ timeoutVoting=3000
timeoutWaitNotify=2000 timeoutWaitNotify=2000
createEmptyBlocks=false createEmptyBlocks=false
createEmptyBlocksInterval=0 createEmptyBlocksInterval=0
validatorNodes=["127.0.0.1:46656"] validatorNodes=["127.0.0.1:36656"]
delegateNum=1 delegateNum=1
blockInterval=2 blockInterval=2
continueBlockNum=12 continueBlockNum=12
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"testing" "testing"
...@@ -69,12 +70,20 @@ func init() { ...@@ -69,12 +70,20 @@ func init() {
pubkey, _ = hex.DecodeString(strPubkey) pubkey, _ = hex.DecodeString(strPubkey)
} }
func TestDposPerf(t *testing.T) { func TestDposPerf(t *testing.T) {
//DposPerf()
os.Remove("genesis.json")
os.Remove("priv_validator.json")
ioutil.WriteFile("genesis.json", []byte(localGenesis), 0664)
ioutil.WriteFile("priv_validator.json", []byte(localPriv), 0664)
DposPerf()
fmt.Println("=======start clear test data!=======") fmt.Println("=======start clear test data!=======")
clearTestData() clearTestData()
} }
func DposPerf() { func DposPerf() {
fmt.Println("=======start dpos test!=======")
q, chain, s, mem, exec, cs, p2p := initEnvDpos() q, chain, s, mem, exec, cs, p2p := initEnvDpos()
defer chain.Close() defer chain.Close()
defer mem.Close() defer mem.Close()
...@@ -84,15 +93,19 @@ func DposPerf() { ...@@ -84,15 +93,19 @@ func DposPerf() {
defer cs.Close() defer cs.Close()
defer p2p.Close() defer p2p.Close()
var err error var err error
conn, c, err = createConn("127.0.0.1:8802") err = createConn2()
for err != nil { for err != nil {
conn, c, err = createConn("127.0.0.1:8802") err = createConn2()
} }
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
fmt.Println("=======start NormPut!=======")
for i := 0; i < loopCount; i++ { for i := 0; i < loopCount; i++ {
NormPut() NormPut()
time.Sleep(time.Second) time.Sleep(time.Second)
} }
fmt.Println("=======start sendTransferTx sendTransferToExecTx!=======")
//从创世地址向测试地址转入代币 //从创世地址向测试地址转入代币
sendTransferTx(genesisKey, validatorAddr, 2000000000000) sendTransferTx(genesisKey, validatorAddr, 2000000000000)
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
...@@ -109,6 +122,8 @@ func DposPerf() { ...@@ -109,6 +122,8 @@ func DposPerf() {
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
fmt.Println("=======start GetBalance!=======")
in2 := &types.ReqBalance{} in2 := &types.ReqBalance{}
in2.Addresses = append(in2.Addresses, validatorAddr) in2.Addresses = append(in2.Addresses, validatorAddr)
acct, err = c.GetBalance(context.Background(), in2) acct, err = c.GetBalance(context.Background(), in2)
...@@ -118,10 +133,14 @@ func DposPerf() { ...@@ -118,10 +133,14 @@ func DposPerf() {
fmt.Println(validatorAddr, " balance:", acct.Acc[0].Balance, "frozen:", acct.Acc[0].Frozen) fmt.Println(validatorAddr, " balance:", acct.Acc[0].Balance, "frozen:", acct.Acc[0].Frozen)
} }
fmt.Println("=======start sendRegistCandidatorTx!=======")
sendRegistCandidatorTx(strPubkey, validatorAddr, "127.0.0.1", validatorKey) sendRegistCandidatorTx(strPubkey, validatorAddr, "127.0.0.1", validatorKey)
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
fmt.Println("=======start query many things!=======")
now := time.Now().Unix() now := time.Now().Unix()
task := DecideTaskByTime(now) task := DecideTaskByTime(now)
...@@ -141,6 +160,8 @@ func DposPerf() { ...@@ -141,6 +160,8 @@ func DposPerf() {
dposClient.QueryTopNCandidators(1) dposClient.QueryTopNCandidators(1)
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
fmt.Println("=======start SendCBTx!=======")
info := &dty.DposCBInfo{ info := &dty.DposCBInfo{
Cycle: task.Cycle, Cycle: task.Cycle,
StopHeight: dposClient.GetCurrentHeight(), StopHeight: dposClient.GetCurrentHeight(),
...@@ -151,6 +172,8 @@ func DposPerf() { ...@@ -151,6 +172,8 @@ func DposPerf() {
sendCBTx(dposClient.csState, info) sendCBTx(dposClient.csState, info)
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
fmt.Println("=======start SendRegistVrfMTx!=======")
for { for {
now = time.Now().Unix() now = time.Now().Unix()
task = DecideTaskByTime(now) task = DecideTaskByTime(now)
...@@ -174,6 +197,8 @@ func DposPerf() { ...@@ -174,6 +197,8 @@ func DposPerf() {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
fmt.Println("=======start QueryVrf!=======")
vrfInfo, err := dposClient.csState.QueryVrf(pubkey, task.Cycle) vrfInfo, err := dposClient.csState.QueryVrf(pubkey, task.Cycle)
if err != nil || vrfInfo == nil { if err != nil || vrfInfo == nil {
fmt.Println("QueryVrf failed") fmt.Println("QueryVrf failed")
...@@ -189,6 +214,9 @@ func DposPerf() { ...@@ -189,6 +214,9 @@ func DposPerf() {
} }
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
fmt.Println("=======start SendRegistVrfRPTx!=======")
vrfRP := &dty.DposVrfRPRegist{ vrfRP := &dty.DposVrfRPRegist{
Pubkey: strPubkey, Pubkey: strPubkey,
Cycle: task.Cycle, Cycle: task.Cycle,
...@@ -204,6 +232,7 @@ func DposPerf() { ...@@ -204,6 +232,7 @@ func DposPerf() {
sendRegistVrfRPTx(dposClient.csState, vrfRP) sendRegistVrfRPTx(dposClient.csState, vrfRP)
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
fmt.Println("=======start QueryVrf2!=======")
vrfInfo, err = dposClient.csState.QueryVrf(pubkey, task.Cycle) vrfInfo, err = dposClient.csState.QueryVrf(pubkey, task.Cycle)
if err != nil || vrfInfo == nil { if err != nil || vrfInfo == nil {
...@@ -212,6 +241,7 @@ func DposPerf() { ...@@ -212,6 +241,7 @@ func DposPerf() {
fmt.Println("QueryVrf ok,", vrfInfo.Cycle, "|", len(vrfInfo.M), "|", len(vrfInfo.R), "|", len(vrfInfo.P)) fmt.Println("QueryVrf ok,", vrfInfo.Cycle, "|", len(vrfInfo.M), "|", len(vrfInfo.R), "|", len(vrfInfo.P))
} }
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
fmt.Println("=======start SendTopNRegistTx!=======")
var cands []*dty.Candidator var cands []*dty.Candidator
cand := &dty.Candidator{ cand := &dty.Candidator{
...@@ -240,6 +270,7 @@ func DposPerf() { ...@@ -240,6 +270,7 @@ func DposPerf() {
//sendTopNRegistTx(dposClient.csState, reg) //sendTopNRegistTx(dposClient.csState, reg)
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
fmt.Println("=======start QueryTopNCandidators!=======")
dposClient.QueryTopNCandidators(dposClient.GetCurrentHeight() / blockNumToUpdateDelegate) dposClient.QueryTopNCandidators(dposClient.GetCurrentHeight() / blockNumToUpdateDelegate)
...@@ -289,6 +320,20 @@ func createConn(url string) (*grpc.ClientConn, types.Chain33Client, error) { ...@@ -289,6 +320,20 @@ func createConn(url string) (*grpc.ClientConn, types.Chain33Client, error) {
return conn1, c1, nil return conn1, c1, nil
} }
func createConn2() error {
var err error
url := "127.0.0.1:8802"
fmt.Println("grpc url:", url)
conn, err = grpc.Dial(url, grpc.WithInsecure())
if err != nil {
fmt.Fprintln(os.Stderr, err)
return err
}
c = types.NewChain33Client(conn)
//r = rand.New(rand.NewSource(types.Now().UnixNano()))
return nil
}
func generateKey(i, valI int) string { func generateKey(i, valI int) string {
key := make([]byte, valI) key := make([]byte, valI)
binary.PutUvarint(key[:10], uint64(valI)) binary.PutUvarint(key[:10], uint64(valI))
...@@ -343,6 +388,8 @@ func clearTestData() { ...@@ -343,6 +388,8 @@ func clearTestData() {
if err != nil { if err != nil {
fmt.Println("delete datadir have a err:", err.Error()) fmt.Println("delete datadir have a err:", err.Error())
} }
os.Remove("genesis.json")
os.Remove("priv_validator.json")
fmt.Println("test data clear successfully!") fmt.Println("test data clear successfully!")
} }
......
...@@ -28,6 +28,9 @@ func init() { ...@@ -28,6 +28,9 @@ func init() {
} }
func TestGenesisDocFromFile(t *testing.T) { func TestGenesisDocFromFile(t *testing.T) {
os.Remove("./genesis.json")
os.Remove("../genesis.json")
ioutil.WriteFile("genesis.json", []byte(genesisFile), 0664) ioutil.WriteFile("genesis.json", []byte(genesisFile), 0664)
genDoc, err := GenesisDocFromFile("../genesis.json") genDoc, err := GenesisDocFromFile("../genesis.json")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment