Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
9e17640c
Commit
9e17640c
authored
Sep 19, 2019
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
f7fdf9e0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
4 deletions
+54
-4
chain33.test.toml
plugin/consensus/dpos/chain33.test.toml
+1
-1
dpos_test.go
plugin/consensus/dpos/dpos_test.go
+50
-3
genesis_test.go
plugin/consensus/dpos/types/genesis_test.go
+3
-0
No files found.
plugin/consensus/dpos/chain33.test.toml
View file @
9e17640c
...
...
@@ -99,7 +99,7 @@ timeoutVoting=3000
timeoutWaitNotify
=
2000
createEmptyBlocks
=
false
createEmptyBlocksInterval
=
0
validatorNodes
=
["127.0.0.1:
4
6656"]
validatorNodes
=
["127.0.0.1:
3
6656"]
delegateNum
=
1
blockInterval
=
2
continueBlockNum
=
12
...
...
plugin/consensus/dpos/dpos_test.go
View file @
9e17640c
...
...
@@ -12,6 +12,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"math/rand"
"os"
"testing"
...
...
@@ -69,12 +70,20 @@ func init() {
pubkey
,
_
=
hex
.
DecodeString
(
strPubkey
)
}
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!======="
)
clearTestData
()
}
func
DposPerf
()
{
fmt
.
Println
(
"=======start dpos test!======="
)
q
,
chain
,
s
,
mem
,
exec
,
cs
,
p2p
:=
initEnvDpos
()
defer
chain
.
Close
()
defer
mem
.
Close
()
...
...
@@ -84,15 +93,19 @@ func DposPerf() {
defer
cs
.
Close
()
defer
p2p
.
Close
()
var
err
error
conn
,
c
,
err
=
createConn
(
"127.0.0.1:8802"
)
err
=
createConn2
(
)
for
err
!=
nil
{
conn
,
c
,
err
=
createConn
(
"127.0.0.1:8802"
)
err
=
createConn2
(
)
}
time
.
Sleep
(
10
*
time
.
Second
)
fmt
.
Println
(
"=======start NormPut!======="
)
for
i
:=
0
;
i
<
loopCount
;
i
++
{
NormPut
()
time
.
Sleep
(
time
.
Second
)
}
fmt
.
Println
(
"=======start sendTransferTx sendTransferToExecTx!======="
)
//从创世地址向测试地址转入代币
sendTransferTx
(
genesisKey
,
validatorAddr
,
2000000000000
)
time
.
Sleep
(
3
*
time
.
Second
)
...
...
@@ -109,6 +122,8 @@ func DposPerf() {
time
.
Sleep
(
3
*
time
.
Second
)
fmt
.
Println
(
"=======start GetBalance!======="
)
in2
:=
&
types
.
ReqBalance
{}
in2
.
Addresses
=
append
(
in2
.
Addresses
,
validatorAddr
)
acct
,
err
=
c
.
GetBalance
(
context
.
Background
(),
in2
)
...
...
@@ -118,10 +133,14 @@ func DposPerf() {
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
)
time
.
Sleep
(
3
*
time
.
Second
)
fmt
.
Println
(
"=======start query many things!======="
)
now
:=
time
.
Now
()
.
Unix
()
task
:=
DecideTaskByTime
(
now
)
...
...
@@ -141,6 +160,8 @@ func DposPerf() {
dposClient
.
QueryTopNCandidators
(
1
)
time
.
Sleep
(
1
*
time
.
Second
)
fmt
.
Println
(
"=======start SendCBTx!======="
)
info
:=
&
dty
.
DposCBInfo
{
Cycle
:
task
.
Cycle
,
StopHeight
:
dposClient
.
GetCurrentHeight
(),
...
...
@@ -151,6 +172,8 @@ func DposPerf() {
sendCBTx
(
dposClient
.
csState
,
info
)
time
.
Sleep
(
2
*
time
.
Second
)
fmt
.
Println
(
"=======start SendRegistVrfMTx!======="
)
for
{
now
=
time
.
Now
()
.
Unix
()
task
=
DecideTaskByTime
(
now
)
...
...
@@ -174,6 +197,8 @@ func DposPerf() {
time
.
Sleep
(
2
*
time
.
Second
)
fmt
.
Println
(
"=======start QueryVrf!======="
)
vrfInfo
,
err
:=
dposClient
.
csState
.
QueryVrf
(
pubkey
,
task
.
Cycle
)
if
err
!=
nil
||
vrfInfo
==
nil
{
fmt
.
Println
(
"QueryVrf failed"
)
...
...
@@ -189,6 +214,9 @@ func DposPerf() {
}
time
.
Sleep
(
1
*
time
.
Second
)
}
fmt
.
Println
(
"=======start SendRegistVrfRPTx!======="
)
vrfRP
:=
&
dty
.
DposVrfRPRegist
{
Pubkey
:
strPubkey
,
Cycle
:
task
.
Cycle
,
...
...
@@ -204,6 +232,7 @@ func DposPerf() {
sendRegistVrfRPTx
(
dposClient
.
csState
,
vrfRP
)
time
.
Sleep
(
2
*
time
.
Second
)
fmt
.
Println
(
"=======start QueryVrf2!======="
)
vrfInfo
,
err
=
dposClient
.
csState
.
QueryVrf
(
pubkey
,
task
.
Cycle
)
if
err
!=
nil
||
vrfInfo
==
nil
{
...
...
@@ -212,6 +241,7 @@ func DposPerf() {
fmt
.
Println
(
"QueryVrf ok,"
,
vrfInfo
.
Cycle
,
"|"
,
len
(
vrfInfo
.
M
),
"|"
,
len
(
vrfInfo
.
R
),
"|"
,
len
(
vrfInfo
.
P
))
}
time
.
Sleep
(
2
*
time
.
Second
)
fmt
.
Println
(
"=======start SendTopNRegistTx!======="
)
var
cands
[]
*
dty
.
Candidator
cand
:=
&
dty
.
Candidator
{
...
...
@@ -240,6 +270,7 @@ func DposPerf() {
//sendTopNRegistTx(dposClient.csState, reg)
time
.
Sleep
(
2
*
time
.
Second
)
fmt
.
Println
(
"=======start QueryTopNCandidators!======="
)
dposClient
.
QueryTopNCandidators
(
dposClient
.
GetCurrentHeight
()
/
blockNumToUpdateDelegate
)
...
...
@@ -289,6 +320,20 @@ func createConn(url string) (*grpc.ClientConn, types.Chain33Client, error) {
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
{
key
:=
make
([]
byte
,
valI
)
binary
.
PutUvarint
(
key
[
:
10
],
uint64
(
valI
))
...
...
@@ -343,6 +388,8 @@ func clearTestData() {
if
err
!=
nil
{
fmt
.
Println
(
"delete datadir have a err:"
,
err
.
Error
())
}
os
.
Remove
(
"genesis.json"
)
os
.
Remove
(
"priv_validator.json"
)
fmt
.
Println
(
"test data clear successfully!"
)
}
...
...
plugin/consensus/dpos/types/genesis_test.go
View file @
9e17640c
...
...
@@ -28,6 +28,9 @@ func init() {
}
func
TestGenesisDocFromFile
(
t
*
testing
.
T
)
{
os
.
Remove
(
"./genesis.json"
)
os
.
Remove
(
"../genesis.json"
)
ioutil
.
WriteFile
(
"genesis.json"
,
[]
byte
(
genesisFile
),
0664
)
genDoc
,
err
:=
GenesisDocFromFile
(
"../genesis.json"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment