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
5eef0b20
Commit
5eef0b20
authored
Jun 26, 2019
by
kingwang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test
parent
5c62f0d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletion
+64
-1
cache_test.go
plugin/mempool/price/cache_test.go
+54
-0
testnode.go
vendor/github.com/33cn/chain33/util/testnode/testnode.go
+10
-1
No files found.
plugin/mempool/price/cache_test.go
View file @
5eef0b20
package
price
import
(
"log"
"testing"
"github.com/33cn/chain33/common"
...
...
@@ -9,8 +10,12 @@ import (
cty
"github.com/33cn/chain33/system/dapp/coins/types"
drivers
"github.com/33cn/chain33/system/mempool"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/util/testnode"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
_
"github.com/33cn/chain33/system"
)
var
(
...
...
@@ -162,3 +167,52 @@ func TestGetProperFee(t *testing.T) {
txSize2
:=
proto
.
Size
(
item4
.
Value
)
assert
.
Equal
(
t
,
(
item1
.
Value
.
Fee
/
int64
(
txSize1
/
1000
+
1
)
+
item4
.
Value
.
Fee
/
int64
(
txSize2
/
1000
+
1
))
/
2
,
cache
.
GetProperFee
())
}
func
TestRealNodeMempool
(
t
*
testing
.
T
)
{
mock33
:=
testnode
.
New
(
"chain33.test.toml"
,
nil
)
defer
mock33
.
Close
()
mock33
.
Listen
()
mock33
.
WaitHeight
(
0
)
mock33
.
SendHot
()
mock33
.
WaitHeight
(
1
)
n
:=
300
done
:=
make
(
chan
struct
{},
n
)
keys
:=
make
([]
crypto
.
PrivKey
,
n
)
for
i
:=
0
;
i
<
n
;
i
++
{
addr
,
priv
:=
util
.
Genaddress
()
tx
:=
util
.
CreateCoinsTx
(
mock33
.
GetHotKey
(),
addr
,
10
*
types
.
Coin
)
mock33
.
SendTx
(
tx
)
keys
[
i
]
=
priv
}
mock33
.
Wait
()
for
i
:=
0
;
i
<
n
;
i
++
{
go
func
(
priv
crypto
.
PrivKey
)
{
for
i
:=
0
;
i
<
100
;
i
++
{
tx
:=
util
.
CreateCoinsTx
(
priv
,
mock33
.
GetGenesisAddress
(),
types
.
Coin
/
1000
)
reply
,
err
:=
mock33
.
GetAPI
()
.
SendTx
(
tx
)
if
err
!=
nil
{
log
.
Println
(
err
)
continue
}
mock33
.
SetLastSend
(
reply
.
GetMsg
())
}
done
<-
struct
{}{}
}(
keys
[
i
])
}
for
i
:=
0
;
i
<
n
;
i
++
{
<-
done
}
for
{
txs
,
err
:=
mock33
.
GetAPI
()
.
GetMempool
()
assert
.
Nil
(
t
,
err
)
if
len
(
txs
.
GetTxs
())
>
0
{
mock33
.
Wait
()
continue
}
break
}
peer
,
err
:=
mock33
.
GetAPI
()
.
PeerInfo
()
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
len
(
peer
.
Peers
),
1
)
assert
.
Equal
(
t
,
peer
.
Peers
[
0
]
.
MempoolSize
,
int32
(
0
))
}
vendor/github.com/33cn/chain33/util/testnode/testnode.go
View file @
5eef0b20
...
...
@@ -12,6 +12,7 @@ import (
"math/rand"
"os"
"strings"
"sync"
"time"
"github.com/33cn/chain33/account"
...
...
@@ -67,6 +68,7 @@ type Chain33Mock struct {
sub
*
types
.
ConfigSubModule
datadir
string
lastsend
[]
byte
mu
sync
.
Mutex
}
//GetDefaultConfig :
...
...
@@ -369,10 +371,17 @@ func (mock *Chain33Mock) SendTx(tx *types.Transaction) []byte {
if
err
!=
nil
{
panic
(
err
)
}
mock
.
lastsend
=
reply
.
GetMsg
(
)
mock
.
SetLastSend
(
reply
.
GetMsg
()
)
return
reply
.
GetMsg
()
}
//SetLastSend :
func
(
mock
*
Chain33Mock
)
SetLastSend
(
hash
[]
byte
)
{
mock
.
mu
.
Lock
()
mock
.
lastsend
=
hash
mock
.
mu
.
Unlock
()
}
//SendTxRPC :
func
(
mock
*
Chain33Mock
)
SendTxRPC
(
tx
*
types
.
Transaction
)
[]
byte
{
var
txhash
string
...
...
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