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
51bf0b17
Commit
51bf0b17
authored
Jan 30, 2019
by
caopingcp
Committed by
vipwzw
Jan 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update tendermint unit test
parent
ccfe557f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
66 deletions
+42
-66
tendermint_test.go
plugin/consensus/tendermint/tendermint_test.go
+42
-66
No files found.
plugin/consensus/tendermint/tendermint_test.go
View file @
51bf0b17
...
...
@@ -5,40 +5,32 @@
package
tendermint
import
(
"context"
"encoding/binary"
"errors"
"flag"
"fmt"
"math/rand"
"os"
"testing"
"time"
"github.com/33cn/chain33/blockchain"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/limits"
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/executor"
"github.com/33cn/chain33/mempool"
"github.com/33cn/chain33/p2p"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/rpc"
"github.com/33cn/chain33/store"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/norm/types"
"google.golang.org/grpc"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
_
"github.com/33cn/plugin/plugin/dapp/init"
pty
"github.com/33cn/plugin/plugin/dapp/norm/types"
_
"github.com/33cn/plugin/plugin/store/init"
"math/rand"
"os"
"testing"
"time"
)
var
(
random
*
rand
.
Rand
txNumber
=
10
loopCount
=
10
conn
*
grpc
.
ClientConn
c
types
.
Chain33Client
)
func
init
()
{
...
...
@@ -49,74 +41,47 @@ func init() {
random
=
rand
.
New
(
rand
.
NewSource
(
types
.
Now
()
.
UnixNano
()))
log
.
SetLogLevel
(
"info"
)
}
func
TestTendermintPerf
(
t
*
testing
.
T
)
{
Raf
tPerf
()
Tendermin
tPerf
()
fmt
.
Println
(
"=======start clear test data!======="
)
clearTestData
()
}
func
Raf
tPerf
()
{
q
,
chain
,
s
,
mem
,
exec
,
cs
,
p2p
:=
initEnvTendermint
()
func
Tendermin
tPerf
()
{
q
,
chain
,
s
,
exec
,
cs
,
p2p
:=
initEnvTendermint
()
defer
chain
.
Close
()
defer
mem
.
Close
()
defer
exec
.
Close
()
defer
s
.
Close
()
defer
q
.
Close
()
defer
cs
.
Close
()
defer
p2p
.
Close
()
err
:=
createConn
()
for
err
!=
nil
{
err
=
createConn
()
}
time
.
Sleep
(
10
*
time
.
Second
)
for
i
:=
0
;
i
<
loopCount
;
i
++
{
NormPut
()
time
.
Sleep
(
time
.
Second
)
}
time
.
Sleep
(
10
*
time
.
Second
)
sendReplyList
(
q
)
}
func
initEnvTendermint
()
(
queue
.
Queue
,
*
blockchain
.
BlockChain
,
queue
.
Module
,
queue
.
Module
,
*
executor
.
Executor
,
queue
.
Module
,
queue
.
Module
)
{
func
initEnvTendermint
()
(
queue
.
Queue
,
*
blockchain
.
BlockChain
,
queue
.
Module
,
*
executor
.
Executor
,
queue
.
Module
,
queue
.
Module
)
{
var
q
=
queue
.
New
(
"channel"
)
flag
.
Parse
()
cfg
,
sub
:=
types
.
InitCfg
(
"chain33.test.toml"
)
types
.
Init
(
cfg
.
Title
,
cfg
)
chain
:=
blockchain
.
New
(
cfg
.
BlockChain
)
chain
.
SetQueueClient
(
q
.
Client
())
exec
:=
executor
.
New
(
cfg
.
Exec
,
sub
.
Exec
)
exec
.
SetQueueClient
(
q
.
Client
())
types
.
SetMinFee
(
0
)
s
:=
store
.
New
(
cfg
.
Store
,
sub
.
Store
)
s
.
SetQueueClient
(
q
.
Client
())
cs
:=
New
(
cfg
.
Consensus
,
sub
.
Consensus
[
"tendermint"
])
cs
.
SetQueueClient
(
q
.
Client
())
mem
:=
mempool
.
New
(
cfg
.
Mempool
,
nil
)
mem
.
SetQueueClient
(
q
.
Client
())
network
:=
p2p
.
New
(
cfg
.
P2P
)
network
.
SetQueueClient
(
q
.
Client
())
rpc
.
InitCfg
(
cfg
.
RPC
)
gapi
:=
rpc
.
NewGRpcServer
(
q
.
Client
(),
nil
)
go
gapi
.
Listen
()
return
q
,
chain
,
s
,
mem
,
exec
,
cs
,
network
}
func
createConn
()
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
return
q
,
chain
,
s
,
exec
,
cs
,
network
}
func
generateKey
(
i
,
valI
int
)
string
{
...
...
@@ -149,31 +114,42 @@ func prepareTxList() *types.Transaction {
nput
:=
&
pty
.
NormAction_Nput
{
Nput
:
&
pty
.
NormPut
{
Key
:
[]
byte
(
key
),
Value
:
[]
byte
(
value
)}}
action
:=
&
pty
.
NormAction
{
Value
:
nput
,
Ty
:
pty
.
NormActionPut
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"norm"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
fee
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
"norm"
),
Payload
:
types
.
Encode
(
action
),
Fee
:
0
}
tx
.
To
=
address
.
ExecAddress
(
"norm"
)
tx
.
Nonce
=
random
.
Int63
()
tx
.
Sign
(
types
.
SECP256K1
,
getprivkey
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
))
return
tx
}
func
clearTestData
()
{
err
:=
os
.
RemoveAll
(
"datadir"
)
if
err
!=
nil
{
fmt
.
Println
(
"delete datadir have a err:"
,
err
.
Error
())
func
getReplyList
(
n
int
)
(
txs
[]
*
types
.
Transaction
)
{
for
i
:=
0
;
i
<
int
(
n
);
i
++
{
txs
=
append
(
txs
,
prepareTxList
())
}
fmt
.
Println
(
"test data clear successfully!"
)
return
txs
}
func
NormPut
()
{
tx
:=
prepareTxList
()
func
sendReplyList
(
q
queue
.
Queue
)
{
client
:=
q
.
Client
()
client
.
Sub
(
"mempool"
)
var
count
int
for
msg
:=
range
client
.
Recv
()
{
if
msg
.
Ty
==
types
.
EventTxList
{
count
++
msg
.
Reply
(
client
.
NewMessage
(
"consensus"
,
types
.
EventReplyTxList
,
&
types
.
ReplyTxList
{
Txs
:
getReplyList
(
txNumber
)}))
//tendermint call RequestTx twice
if
count
>=
loopCount
*
2
{
time
.
Sleep
(
4
*
time
.
Second
)
break
}
}
}
}
reply
,
err
:=
c
.
SendTransaction
(
context
.
Background
(),
tx
)
func
clearTestData
()
{
err
:=
os
.
RemoveAll
(
"datadir"
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
return
}
if
!
reply
.
IsOk
{
fmt
.
Fprintln
(
os
.
Stderr
,
errors
.
New
(
string
(
reply
.
GetMsg
())))
return
fmt
.
Println
(
"delete datadir have a err:"
,
err
.
Error
())
}
fmt
.
Println
(
"test data clear successfully!"
)
}
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