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
461958b4
Commit
461958b4
authored
Oct 10, 2019
by
harrylee
Committed by
vipwzw
Oct 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify raft test
parent
d3b0a7fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
159 deletions
+46
-159
chain33.test.toml
plugin/consensus/raft/chain33.test.toml
+19
-1
listener.go
plugin/consensus/raft/listener.go
+1
-1
raft_test.go
plugin/consensus/raft/raft_test.go
+26
-157
No files found.
plugin/consensus/raft/chain33.test.toml
View file @
461958b4
...
@@ -80,6 +80,7 @@ poolCacheSize=10240
...
@@ -80,6 +80,7 @@ poolCacheSize=10240
# 共识驱动名,支持solo/raft/ticket/tendermint/pbft
# 共识驱动名,支持solo/raft/ticket/tendermint/pbft
name
=
"raft"
name
=
"raft"
minerstart
=
false
minerstart
=
false
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
[mver.consensus]
[mver.consensus]
fundKeyAddr
=
"1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
fundKeyAddr
=
"1BQXS6TxaYYG5mADaWij4AxhZZUTpw95a5"
...
@@ -127,7 +128,7 @@ enableMVCC=false
...
@@ -127,7 +128,7 @@ enableMVCC=false
[wallet]
[wallet]
minFee
=
100000
minFee
=
100000
driver
=
"
level
db"
driver
=
"
mem
db"
dbPath
=
"wallet"
dbPath
=
"wallet"
dbCache
=
16
dbCache
=
16
signType
=
"secp256k1"
signType
=
"secp256k1"
...
@@ -135,6 +136,8 @@ signType="secp256k1"
...
@@ -135,6 +136,8 @@ signType="secp256k1"
[wallet.sub.ticket]
[wallet.sub.ticket]
minerdisable
=
false
minerdisable
=
false
minerwhitelist
=
["*"]
minerwhitelist
=
["*"]
minerWaitTime
=
"1s"
[exec]
[exec]
isFree
=
false
isFree
=
false
...
@@ -144,6 +147,9 @@ enableMVCC=false
...
@@ -144,6 +147,9 @@ enableMVCC=false
alias
=
["token1:token","token2:token","token3:token"]
alias
=
["token1:token","token2:token","token3:token"]
saveTokenTxList
=
false
saveTokenTxList
=
false
[exec.sub.relay]
genesis
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
[exec.sub.cert]
[exec.sub.cert]
# 是否启用证书验证和签名
# 是否启用证书验证和签名
enable
=
false
enable
=
false
...
@@ -151,3 +157,14 @@ enable=false
...
@@ -151,3 +157,14 @@ enable=false
cryptoPath
=
"authdir/crypto"
cryptoPath
=
"authdir/crypto"
# 带证书签名类型,支持"auth_ecdsa", "auth_sm2"
# 带证书签名类型,支持"auth_ecdsa", "auth_sm2"
signType
=
"auth_ecdsa"
signType
=
"auth_ecdsa"
[exec.sub.manage]
superManager
=[
"1Bsg9j6gW83sShoee1fZAt9TkUjcrCgA9S"
,
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
,
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
]
[exec.sub.autonomy]
total
=
"16htvcBNSEA7fZhAdLJphDwQRQJaHpyHTp"
useBalance
=
false
\ No newline at end of file
plugin/consensus/raft/listener.go
View file @
461958b4
...
@@ -18,7 +18,7 @@ type stoppableListener struct {
...
@@ -18,7 +18,7 @@ type stoppableListener struct {
}
}
// 监听tcp连接
// 监听tcp连接
func
newStoppableListener
(
ctx
context
.
Context
,
addr
string
)
(
*
stoppableListener
,
error
)
{
func
newStoppableListener
(
ctx
context
.
Context
,
addr
string
)
(
*
stoppableListener
,
error
)
{
ln
,
err
:=
net
.
Listen
(
"tcp"
,
addr
)
ln
,
err
:=
net
.
Listen
(
"tcp"
,
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
...
plugin/consensus/raft/raft_test.go
View file @
461958b4
...
@@ -5,179 +5,47 @@
...
@@ -5,179 +5,47 @@
package
raft
package
raft
import
(
import
(
"encoding/binary"
"flag"
"fmt"
"fmt"
"math/rand"
"os"
"os"
"testing"
"testing"
"time"
"time"
"github.com/33cn/chain33/blockchain"
//加载系统内置store, 不要依赖plugin
"github.com/33cn/chain33/common"
_
"github.com/33cn/chain33/system/dapp/init"
"github.com/33cn/chain33/common/address"
_
"github.com/33cn/chain33/system/mempool/init"
"github.com/33cn/chain33/common/crypto"
_
"github.com/33cn/chain33/system/store/init"
"github.com/33cn/chain33/common/limits"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/common/log"
"github.com/33cn/chain33/util/testnode"
"github.com/33cn/chain33/executor"
"github.com/33cn/chain33/mempool"
"github.com/33cn/chain33/p2p"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/store"
"github.com/33cn/chain33/types"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/plugin/plugin/dapp/init"
_
"github.com/33cn/plugin/plugin/dapp/init"
pty
"github.com/33cn/plugin/plugin/dapp/norm/types"
_
"github.com/33cn/plugin/plugin/store/init"
_
"github.com/33cn/plugin/plugin/store/init"
)
)
var
(
// 执行: go test -cover
random
*
rand
.
Rand
func
TestRaft
(
t
*
testing
.
T
)
{
txNumber
=
10
mock33
:=
testnode
.
New
(
"chain33.test.toml"
,
nil
)
loopCount
=
10
defer
mock33
.
Close
()
)
mock33
.
Listen
(
)
t
.
Log
(
mock33
.
GetGenesisAddress
())
func
init
()
{
time
.
Sleep
(
10
*
time
.
Second
)
err
:=
limits
.
SetLimits
(
)
txs
:=
util
.
GenNoneTxs
(
mock33
.
GetGenesisKey
(),
10
)
if
err
!=
nil
{
for
i
:=
0
;
i
<
len
(
txs
);
i
++
{
panic
(
err
)
mock33
.
GetAPI
()
.
SendTx
(
txs
[
i
]
)
}
}
random
=
rand
.
New
(
rand
.
NewSource
(
types
.
Now
()
.
UnixNano
())
)
mock33
.
WaitHeight
(
1
)
log
.
SetLogLevel
(
"info"
)
txs
=
util
.
GenNoneTxs
(
mock33
.
GetGenesisKey
(),
10
)
}
for
i
:=
0
;
i
<
len
(
txs
);
i
++
{
func
TestRaftPerf
(
t
*
testing
.
T
)
{
mock33
.
GetAPI
()
.
SendTx
(
txs
[
i
])
RaftPerf
()
}
fmt
.
Println
(
"=======start clear test data!======="
)
mock33
.
WaitHeight
(
2
)
clearTestData
()
clearTestData
()
}
}
func
RaftPerf
()
{
q
,
chain
,
s
,
mem
,
exec
,
cs
,
p2p
:=
initEnvRaft
()
defer
q
.
Close
()
defer
s
.
Close
()
defer
p2p
.
Close
()
defer
mem
.
Close
()
defer
exec
.
Close
()
defer
chain
.
Close
()
defer
cs
.
Close
()
sendReplyList
(
q
)
}
func
initEnvRaft
()
(
queue
.
Queue
,
*
blockchain
.
BlockChain
,
queue
.
Module
,
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
)
s
:=
store
.
New
(
cfg
.
Store
,
sub
.
Store
)
s
.
SetQueueClient
(
q
.
Client
())
chain
:=
blockchain
.
New
(
cfg
.
BlockChain
)
chain
.
SetQueueClient
(
q
.
Client
())
exec
:=
executor
.
New
(
cfg
.
Exec
,
sub
.
Exec
)
exec
.
SetQueueClient
(
q
.
Client
())
types
.
SetMinFee
(
0
)
mem
:=
mempool
.
New
(
cfg
.
Mempool
,
nil
)
mem
.
SetQueueClient
(
q
.
Client
())
cs
:=
NewRaftCluster
(
cfg
.
Consensus
,
sub
.
Consensus
[
"raft"
])
cs
.
SetQueueClient
(
q
.
Client
())
network
:=
p2p
.
New
(
cfg
.
P2P
)
network
.
SetQueueClient
(
q
.
Client
())
return
q
,
chain
,
s
,
mem
,
exec
,
cs
,
network
}
func
generateKey
(
i
,
valI
int
)
string
{
key
:=
make
([]
byte
,
valI
)
binary
.
PutUvarint
(
key
[
:
10
],
uint64
(
valI
))
binary
.
PutUvarint
(
key
[
12
:
24
],
uint64
(
i
))
if
_
,
err
:=
rand
.
Read
(
key
[
24
:
]);
err
!=
nil
{
os
.
Exit
(
1
)
}
return
string
(
key
)
}
func
generateValue
(
i
,
valI
int
)
string
{
value
:=
make
([]
byte
,
valI
)
binary
.
PutUvarint
(
value
[
:
16
],
uint64
(
i
))
binary
.
PutUvarint
(
value
[
32
:
128
],
uint64
(
i
))
if
_
,
err
:=
rand
.
Read
(
value
[
128
:
]);
err
!=
nil
{
os
.
Exit
(
1
)
}
return
string
(
value
)
}
func
getprivkey
(
key
string
)
crypto
.
PrivKey
{
cr
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
if
err
!=
nil
{
panic
(
err
)
}
bkey
,
err
:=
common
.
FromHex
(
key
)
if
err
!=
nil
{
panic
(
err
)
}
priv
,
err
:=
cr
.
PrivKeyFromBytes
(
bkey
)
if
err
!=
nil
{
panic
(
err
)
}
return
priv
}
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
)}))
if
count
>=
loopCount
{
time
.
Sleep
(
4
*
time
.
Second
)
break
}
}
}
}
func
prepareTxList
()
*
types
.
Transaction
{
var
key
string
var
value
string
var
i
int
key
=
generateKey
(
i
,
32
)
value
=
generateValue
(
i
,
180
)
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
:
0
}
tx
.
To
=
address
.
ExecAddress
(
"norm"
)
tx
.
Nonce
=
random
.
Int63
()
tx
.
Sign
(
types
.
SECP256K1
,
getprivkey
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
))
return
tx
}
func
getReplyList
(
n
int
)
(
txs
[]
*
types
.
Transaction
)
{
for
i
:=
0
;
i
<
n
;
i
++
{
txs
=
append
(
txs
,
prepareTxList
())
}
return
txs
}
func
clearTestData
()
{
func
clearTestData
()
{
err
:=
os
.
RemoveAll
(
"datadir"
)
err
:=
os
.
RemoveAll
(
"chain33_raft-1"
)
if
err
!=
nil
{
fmt
.
Println
(
"delete datadir have a err:"
,
err
.
Error
())
}
err
=
os
.
RemoveAll
(
"chain33_raft-1"
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"delete chain33_raft dir have a err:"
,
err
.
Error
())
fmt
.
Println
(
"delete chain33_raft dir have a err:"
,
err
.
Error
())
}
}
fmt
.
Println
(
"test data clear successfully!"
)
fmt
.
Println
(
"test data clear successfully!"
)
}
}
\ No newline at end of file
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