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
8150a333
Commit
8150a333
authored
Oct 16, 2019
by
liuyuhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify dapp test and para test
parent
ae9234f1
Show whitespace changes
Inline
Side-by-side
Showing
39 changed files
with
372 additions
and
191 deletions
+372
-191
para_test.go
plugin/consensus/para/para_test.go
+5
-1
parasync_test.go
plugin/consensus/para/parasync_test.go
+3
-0
paratxrequest_test.go
plugin/consensus/para/paratxrequest_test.go
+29
-9
ticket_test.go
plugin/consensus/ticket/ticket_test.go
+8
-6
assettransfer_test.go
plugin/dapp/paracross/executor/assettransfer_test.go
+16
-15
assetwithdraw_test.go
plugin/dapp/paracross/executor/assetwithdraw_test.go
+11
-9
paracross_test.go
plugin/dapp/paracross/executor/paracross_test.go
+22
-18
superaccount_test.go
plugin/dapp/paracross/executor/superaccount_test.go
+13
-16
rpc_test.go
plugin/dapp/paracross/rpc/rpc_test.go
+30
-9
para_test.go
plugin/dapp/paracross/testnode/para_test.go
+3
-2
paranode.go
plugin/dapp/paracross/testnode/paranode.go
+2
-1
para_test.go
plugin/dapp/paracross/wallet/para_test.go
+3
-2
main.go
plugin/dapp/relay/cmd/relayd/main.go
+5
-0
config.go
plugin/dapp/relay/cmd/relayd/relayd/config.go
+1
-0
relayd.go
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
+5
-1
relay_test.go
plugin/dapp/relay/executor/relay_test.go
+9
-5
relaydb_test.go
plugin/dapp/relay/executor/relaydb_test.go
+19
-6
retrieve_unit_test.go
plugin/dapp/retrieve/executor/retrieve_unit_test.go
+11
-5
ticket_test.go
plugin/dapp/ticket/executor/ticket_test.go
+15
-12
jrpc_channel_test.go
plugin/dapp/ticket/rpc/jrpc_channel_test.go
+3
-3
rpc.go
plugin/dapp/ticket/rpc/rpc.go
+0
-0
rpc_test.go
plugin/dapp/ticket/rpc/rpc_test.go
+14
-7
ticket_test.go
plugin/dapp/ticket/testnode/ticket_test.go
+3
-3
types_test.go
plugin/dapp/ticket/types/types_test.go
+4
-0
ticket_test.go
plugin/dapp/ticket/wallet/ticket_test.go
+23
-10
signatory.go
...in/dapp/token/cmd/signatory-server/signatory/signatory.go
+2
-2
token_new_test.go
plugin/dapp/token/executor/token_new_test.go
+5
-4
token_test.go
plugin/dapp/token/executor/token_test.go
+10
-2
rpc_real_test.go
plugin/dapp/token/rpc/rpc_real_test.go
+2
-1
rpc_test.go
plugin/dapp/token/rpc/rpc_test.go
+9
-2
types_test.go
plugin/dapp/token/types/types_test.go
+4
-0
exec_test.go
plugin/dapp/trade/executor/exec_test.go
+35
-18
trade_test.go
plugin/dapp/trade/executor/trade_test.go
+1
-1
jrpc_test.go
plugin/dapp/trade/rpc/jrpc_test.go
+14
-12
rpc_test.go
plugin/dapp/trade/rpc/rpc_test.go
+6
-1
trade_test.go
plugin/dapp/trade/types/trade_test.go
+7
-3
exec_test.go
plugin/dapp/unfreeze/executor/exec_test.go
+13
-2
means_test.go
plugin/dapp/unfreeze/executor/means_test.go
+1
-3
rpc_test.go
plugin/dapp/valnode/rpc/rpc_test.go
+6
-0
No files found.
plugin/consensus/para/para_test.go
View file @
8150a333
...
...
@@ -169,7 +169,11 @@ func TestAddMinerTx(t *testing.T) {
MainHeight
:
10
,
MainHash
:
[]
byte
(
"mainhash"
),
Txs
:
filterTxs
}
para
:=
new
(
client
)
api
:=
new
(
apimocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
para
:=
&
client
{
BaseClient
:&
drivers
.
BaseClient
{}}
para
.
SetAPI
(
api
)
para
.
subCfg
=
new
(
subConfig
)
para
.
privateKey
=
priKey
para
.
commitMsgClient
=
new
(
commitMsgClient
)
...
...
plugin/consensus/para/parasync_test.go
View file @
8150a333
...
...
@@ -19,6 +19,7 @@ import (
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
)
const
(
...
...
@@ -428,7 +429,9 @@ func execTest(t *testing.T, para *client, testLoopCount int32) {
//测试入口
func
TestSyncBlocks
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
testnode
.
DefaultConfig
)
q
:=
queue
.
New
(
"channel"
)
q
.
SetConfig
(
cfg
)
defer
q
.
Close
()
para
:=
createParaTestInstance
(
t
,
q
)
go
q
.
Start
()
...
...
plugin/consensus/para/paratxrequest_test.go
View file @
8150a333
...
...
@@ -20,6 +20,8 @@ import (
typesmocks
"github.com/33cn/chain33/types/mocks"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/assert"
drivers
"github.com/33cn/chain33/system/consensus"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
)
func
init
()
{
...
...
@@ -40,7 +42,12 @@ func getPrivKey(t *testing.T) crypto.PrivKey {
}
func
TestCalcCommitMsgTxs
(
t
*
testing
.
T
)
{
para
:=
new
(
client
)
cfg
:=
types
.
NewChain33Config
(
testnode
.
DefaultConfig
)
api
:=
new
(
apimocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
para
:=
&
client
{
BaseClient
:&
drivers
.
BaseClient
{}}
para
.
SetAPI
(
api
)
para
.
subCfg
=
new
(
subConfig
)
priKey
:=
getPrivKey
(
t
)
...
...
@@ -76,13 +83,22 @@ func TestCalcCommitMsgTxs(t *testing.T) {
}
func
TestGetConsensusStatus
(
t
*
testing
.
T
)
{
para
:=
new
(
client
)
chain33Cfg
:=
types
.
NewChain33Config
(
testnode
.
DefaultConfig
)
api
:=
new
(
apimocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33Cfg
,
nil
)
para
:=
&
client
{
BaseClient
:&
drivers
.
BaseClient
{}}
para
.
subCfg
=
new
(
subConfig
)
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
//grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
para
.
grpcClient
=
grpcClient
commitCli
:=
new
(
commitMsgClient
)
commitCli
.
paraClient
=
para
client
:=
&
commitMsgClient
{
paraClient
:
para
,
}
para
.
commitMsgClient
=
client
block
:=
&
types
.
Block
{
Height
:
1
,
...
...
@@ -90,9 +106,6 @@ func TestGetConsensusStatus(t *testing.T) {
}
getMockLastBlock
(
para
,
block
)
api
:=
&
apimocks
.
QueueProtocolAPI
{}
para
.
SetAPI
(
api
)
status
:=
&
pt
.
ParacrossStatus
{
Height
:
1
,
}
...
...
@@ -102,14 +115,21 @@ func TestGetConsensusStatus(t *testing.T) {
details
:=
&
types
.
BlockDetails
{
Items
:
[]
*
types
.
BlockDetail
{
detail
}}
api
.
On
(
"GetBlocks"
,
mock
.
Anything
)
.
Return
(
details
,
nil
)
.
Once
()
ret
,
err
:=
commitCli
.
getSelfConsensusStatus
()
para
.
SetAPI
(
api
)
ret
,
err
:=
client
.
getSelfConsensusStatus
()
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
1
),
ret
.
Height
)
}
func
TestSendCommitMsg
(
t
*
testing
.
T
)
{
para
:=
new
(
client
)
cfg
:=
types
.
NewChain33Config
(
testnode
.
DefaultConfig
)
api
:=
new
(
apimocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
para
:=
&
client
{
BaseClient
:&
drivers
.
BaseClient
{}}
para
.
SetAPI
(
api
)
grpcClient
:=
&
typesmocks
.
Chain33Client
{}
//grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
para
.
grpcClient
=
grpcClient
...
...
plugin/consensus/ticket/ticket_test.go
View file @
8150a333
...
...
@@ -24,6 +24,9 @@ import (
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/plugin/plugin/dapp/init"
_
"github.com/33cn/plugin/plugin/store/init"
"github.com/stretchr/testify/mock"
apimocks
"github.com/33cn/chain33/client/mocks"
drivers
"github.com/33cn/chain33/system/consensus"
)
func
TestTicket
(
t
*
testing
.
T
)
{
...
...
@@ -170,13 +173,12 @@ func Test_genPrivHash(t *testing.T) {
func
Test_getNextRequiredDifficulty
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
ReadFile
(
"testdata/chain33.cfg.toml"
))
mcfg
:=
cfg
.
GetModuleConfig
()
.
Consensus
var
q
=
queue
.
New
(
"channel"
)
q
.
SetConfig
(
cfg
)
clt
:=
New
(
mcfg
,
nil
)
clt
.
SetQueueClient
(
q
.
Client
())
c
:=
clt
.
(
*
Client
)
api
:=
new
(
apimocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
c
:=
&
Client
{
BaseClient
:&
drivers
.
BaseClient
{}}
c
.
SetAPI
(
api
)
bits
,
bt
,
err
:=
c
.
getNextRequiredDifficulty
(
nil
,
1
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
bt
,
defaultModify
)
...
...
plugin/dapp/paracross/executor/assettransfer_test.go
View file @
8150a333
...
...
@@ -17,8 +17,8 @@ import (
dbm
"github.com/33cn/chain33/common/db"
dbmock
"github.com/33cn/chain33/common/db/mocks"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/mock"
)
// para-exec addr on main 1HPkPopVe3ERfvaAgedDtJQ792taZFEHCe
...
...
@@ -28,10 +28,10 @@ var (
Amount
=
types
.
Coin
)
func
para_init
(
title
string
)
{
cfg
,
_
:=
types
.
InitCfgString
(
testnode
.
DefaultConfig
)
types
.
Init
(
title
,
cfg
)
}
//
func para_init(title string) {
//
cfg, _ := types.InitCfgString(testnode.DefaultConfig)
//
types.Init(title, cfg)
//
}
// 构建跨链交易, 用1个节点即可, 不测试共识
// assetTransfer
...
...
@@ -56,19 +56,20 @@ func (suite *AssetTransferTestSuite) SetupTest() {
//suite.localDB, _ = dbm.NewGoMemDB("local", "local", 1024)
suite
.
localDB
=
new
(
dbmock
.
KVDB
)
suite
.
api
=
new
(
apimock
.
QueueProtocolAPI
)
suite
.
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
enableParacrossTransfer
=
true
// setup block
blockDetail
:=
&
types
.
BlockDetail
{
Block
:
&
types
.
Block
{},
}
MainBlockHash10
=
blockDetail
.
Block
.
Hash
()
MainBlockHash10
=
blockDetail
.
Block
.
Hash
(
chain33TestCfg
)
// setup title nodes : len = 1
nodeConfigKey
:=
calcManageConfigNodesKey
(
Title
)
...
...
@@ -99,7 +100,7 @@ func (suite *AssetTransferTestSuite) SetupTest() {
}
func
(
suite
*
AssetTransferTestSuite
)
TestExecTransferNobalance
()
{
types
.
Init
(
"test"
,
nil
)
//
types.Init("test", nil)
toB
:=
Nodes
[
1
]
tx
,
err
:=
createAssetTransferTx
(
suite
.
Suite
,
PrivKeyD
,
toB
)
if
err
!=
nil
{
...
...
@@ -115,7 +116,7 @@ func (suite *AssetTransferTestSuite) TestExecTransferNobalance() {
}
func
(
suite
*
AssetTransferTestSuite
)
TestExecTransfer
()
{
types
.
Init
(
"test"
,
nil
)
//
types.Init("test", nil)
toB
:=
Nodes
[
1
]
total
:=
1000
*
types
.
Coin
...
...
@@ -124,7 +125,7 @@ func (suite *AssetTransferTestSuite) TestExecTransfer() {
Frozen
:
0
,
Addr
:
string
(
Nodes
[
0
]),
}
acc
:=
account
.
NewCoinsAccount
()
acc
:=
account
.
NewCoinsAccount
(
chain33TestCfg
)
acc
.
SetDB
(
suite
.
stateDB
)
addrMain
:=
address
.
ExecAddress
(
pt
.
ParaX
)
addrPara
:=
address
.
ExecAddress
(
Title
+
pt
.
ParaX
)
...
...
@@ -162,7 +163,7 @@ func (suite *AssetTransferTestSuite) TestExecTransfer() {
}
func
(
suite
*
AssetTransferTestSuite
)
TestExecTransferInPara
()
{
para_init
(
Title
)
//
para_init(Title)
toB
:=
Nodes
[
1
]
tx
,
err
:=
createAssetTransferTx
(
suite
.
Suite
,
PrivKeyA
,
toB
)
...
...
@@ -202,7 +203,7 @@ func createAssetTransferTx(s suite.Suite, privFrom string, to []byte) (*types.Tr
TokenSymbol
:
""
,
ExecName
:
Title
+
pt
.
ParaX
,
}
tx
,
err
:=
pt
.
CreateRawAssetTransferTx
(
&
param
)
tx
,
err
:=
pt
.
CreateRawAssetTransferTx
(
chain33TestCfg
,
&
param
)
assert
.
Nil
(
s
.
T
(),
err
,
"create asset transfer failed"
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -220,7 +221,7 @@ func createAssetTransferTx(s suite.Suite, privFrom string, to []byte) (*types.Tr
const
TestSymbol
=
"TEST"
func
(
suite
*
AssetTransferTestSuite
)
TestExecTransferToken
()
{
types
.
Init
(
"test"
,
nil
)
//
types.Init("test", nil)
toB
:=
Nodes
[
1
]
total
:=
1000
*
types
.
Coin
...
...
@@ -266,7 +267,7 @@ func (suite *AssetTransferTestSuite) TestExecTransferToken() {
}
func
(
suite
*
AssetTransferTestSuite
)
TestExecTransferTokenInPara
()
{
para_init
(
Title
)
//
para_init(Title)
toB
:=
Nodes
[
1
]
tx
,
err
:=
createAssetTransferTokenTx
(
suite
.
Suite
,
PrivKeyA
,
toB
)
...
...
@@ -306,7 +307,7 @@ func createAssetTransferTokenTx(s suite.Suite, privFrom string, to []byte) (*typ
TokenSymbol
:
TestSymbol
,
ExecName
:
Title
+
pt
.
ParaX
,
}
tx
,
err
:=
pt
.
CreateRawAssetTransferTx
(
&
param
)
tx
,
err
:=
pt
.
CreateRawAssetTransferTx
(
chain33TestCfg
,
&
param
)
assert
.
Nil
(
s
.
T
(),
err
,
"create asset transfer failed"
)
if
err
!=
nil
{
return
nil
,
err
...
...
plugin/dapp/paracross/executor/assetwithdraw_test.go
View file @
8150a333
...
...
@@ -18,6 +18,7 @@ import (
dbmock
"github.com/33cn/chain33/common/db/mocks"
"github.com/33cn/chain33/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/mock"
)
// 构建跨链交易, 依然使用1个节点
...
...
@@ -45,19 +46,20 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
//suite.localDB, _ = dbm.NewGoMemDB("local", "local", 1024)
suite
.
localDB
=
new
(
dbmock
.
KVDB
)
suite
.
api
=
new
(
apimock
.
QueueProtocolAPI
)
suite
.
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
enableParacrossTransfer
=
true
// setup block
blockDetail
:=
&
types
.
BlockDetail
{
Block
:
&
types
.
Block
{},
}
MainBlockHash10
=
blockDetail
.
Block
.
Hash
()
MainBlockHash10
=
blockDetail
.
Block
.
Hash
(
chain33TestCfg
)
// setup title nodes : len = 1
nodeConfigKey
:=
calcManageConfigNodesKey
(
Title
)
...
...
@@ -89,7 +91,7 @@ func (suite *AssetWithdrawTestSuite) SetupTest() {
// 主链先不执行
func
(
suite
*
AssetWithdrawTestSuite
)
TestExecAssetWithdrawOnMainChain
()
{
types
.
Init
(
"test"
,
nil
)
//
types.Init("test", nil)
tx
,
err
:=
createAssetWithdrawTx
(
suite
.
Suite
,
PrivKeyA
,
Nodes
[
1
])
if
err
!=
nil
{
suite
.
T
()
.
Error
(
"createAssetWithdrawTx"
,
"err"
,
err
)
...
...
@@ -106,7 +108,7 @@ func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawOnMainChain() {
// 平行链执行
func
(
suite
*
AssetWithdrawTestSuite
)
TestExecAssetWithdrawOnParaChain
()
{
para_init
(
Title
)
//
para_init(Title)
// make coins for transfer
total
:=
1000
*
types
.
Coin
...
...
@@ -144,9 +146,9 @@ func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawOnParaChain() {
// 主链在平行链执行成功后执行
func
(
suite
*
AssetWithdrawTestSuite
)
TestExecAssetWithdrawAfterPara
()
{
types
.
Init
(
"test"
,
nil
)
//
types.Init("test", nil)
// make coins for transfer
acc
:=
account
.
NewCoinsAccount
()
acc
:=
account
.
NewCoinsAccount
(
chain33TestCfg
)
acc
.
SetDB
(
suite
.
stateDB
)
total
:=
10
*
types
.
Coin
...
...
@@ -212,9 +214,9 @@ func (suite *AssetWithdrawTestSuite) TestExecAssetWithdrawAfterPara() {
}
func
(
suite
*
AssetWithdrawTestSuite
)
TestExecWithdrawFailedOnPara
()
{
para_init
(
Title
)
//
para_init(Title)
// make coins for transfer
acc
:=
account
.
NewCoinsAccount
()
acc
:=
account
.
NewCoinsAccount
(
chain33TestCfg
)
acc
.
SetDB
(
suite
.
stateDB
)
addrPara
:=
address
.
ExecAddress
(
Title
+
pt
.
ParaX
)
...
...
@@ -258,7 +260,7 @@ func createAssetWithdrawTx(s suite.Suite, privFrom string, to []byte) (*types.Tr
TokenSymbol
:
""
,
ExecName
:
Title
+
pt
.
ParaX
,
}
tx
,
err
:=
pt
.
CreateRawAssetTransferTx
(
&
param
)
tx
,
err
:=
pt
.
CreateRawAssetTransferTx
(
chain33TestCfg
,
&
param
)
assert
.
Nil
(
s
.
T
(),
err
,
"create asset Withdraw failed"
)
if
err
!=
nil
{
return
nil
,
err
...
...
plugin/dapp/paracross/executor/paracross_test.go
View file @
8150a333
...
...
@@ -20,6 +20,9 @@ import (
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/mock"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
"strings"
)
// 构造一个4个节点的平行链数据, 进行测试
...
...
@@ -52,6 +55,8 @@ var (
TokenSymbol
=
"X"
MainBlockHeightForTransfer
=
int64
(
9
)
tempTitle
=
""
chain33TestCfg
=
types
.
NewChain33Config
(
strings
.
Replace
(
testnode
.
DefaultConfig
,
"Title=
\"
user.p.guodun.
\"
"
,
"Title=
\"
user.p.test.
\"
"
,
1
))
//chain33TestCfg = types.NewChain33Config(testnode.DefaultConfig)
)
type
CommitTestSuite
struct
{
...
...
@@ -83,7 +88,7 @@ func makeNodeInfo(key, addr string, cnt int) *types.ConfigItem {
func
init
()
{
log
.
SetFileLog
(
nil
)
log
.
SetLogLevel
(
"debug"
)
Init
(
pt
.
ParaX
,
nil
)
Init
(
pt
.
ParaX
,
chain33TestCfg
,
nil
)
}
func
(
suite
*
CommitTestSuite
)
SetupSuite
()
{
...
...
@@ -93,12 +98,13 @@ func (suite *CommitTestSuite) SetupSuite() {
//suite.localDB, _ = dbm.NewGoMemDB("local", "local", 1024)
suite
.
localDB
=
new
(
dbmock
.
KVDB
)
suite
.
api
=
new
(
apimock
.
QueueProtocolAPI
)
suite
.
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
enableParacrossTransfer
=
false
// TODO, more fields
...
...
@@ -106,7 +112,7 @@ func (suite *CommitTestSuite) SetupSuite() {
blockDetail
:=
&
types
.
BlockDetail
{
Block
:
&
types
.
Block
{},
}
MainBlockHash10
=
blockDetail
.
Block
.
Hash
()
MainBlockHash10
=
blockDetail
.
Block
.
Hash
(
chain33TestCfg
)
blockDetail
.
Block
.
MainHash
=
MainBlockHash10
// setup title nodes : len = 4
...
...
@@ -167,7 +173,7 @@ func fillRawCommitTx(suite suite.Suite) (*types.Transaction, error) {
CrossTxResult
:
[]
byte
(
"abc"
),
CrossTxHashs
:
[][]
byte
{},
}
tx
,
err
:=
pt
.
CreateRawCommitTx4MainChain
(
&
st1
,
pt
.
GetExecName
(
),
0
)
tx
,
err
:=
pt
.
CreateRawCommitTx4MainChain
(
chain33TestCfg
,
&
st1
,
pt
.
GetExecName
(
chain33TestCfg
),
0
)
if
err
!=
nil
{
suite
.
T
()
.
Error
(
"TestExec"
,
"create tx failed"
,
err
)
}
...
...
@@ -260,8 +266,8 @@ func checkCommitReceipt(suite *CommitTestSuite, receipt *types.Receipt, commitCn
func
checkDoneReceipt
(
suite
suite
.
Suite
,
receipt
*
types
.
Receipt
,
commitCnt
int
)
{
assert
.
Equal
(
suite
.
T
(),
receipt
.
Ty
,
int32
(
types
.
ExecOk
))
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
2
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
2
)
assert
.
Len
(
suite
.
T
(),
receipt
.
KV
,
6
)
assert
.
Len
(
suite
.
T
(),
receipt
.
Logs
,
6
)
key
:=
calcTitleHeightKey
(
Title
,
TitleHeight
)
suite
.
T
()
.
Log
(
"title height key"
,
string
(
key
))
...
...
@@ -331,12 +337,7 @@ func (suite *CommitTestSuite) TestExec() {
}
func
TestCommitSuite
(
t
*
testing
.
T
)
{
tempTitle
=
types
.
GetTitle
()
types
.
SetTitleOnlyForTest
(
Title
)
suite
.
Run
(
t
,
new
(
CommitTestSuite
))
types
.
SetTitleOnlyForTest
(
tempTitle
)
}
func
TestGetTitle
(
t
*
testing
.
T
)
{
...
...
@@ -455,8 +456,11 @@ type VoteTestSuite struct {
}
func
(
s
*
VoteTestSuite
)
SetupSuite
()
{
para_init
(
Title
)
//
para_init(Title)
s
.
exec
=
newParacross
()
.
(
*
Paracross
)
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
s
.
exec
.
SetAPI
(
api
)
}
func
(
s
*
VoteTestSuite
)
TestVoteTx
()
{
...
...
@@ -636,7 +640,7 @@ func (s *VoteTestSuite) TestVoteTxFork() {
}
func
(
s
*
VoteTestSuite
)
createVoteTx
(
status
*
pt
.
ParacrossNodeStatus
,
privFrom
string
)
(
*
types
.
Transaction
,
error
)
{
tx
,
err
:=
pt
.
CreateRawMinerTx
(
&
pt
.
ParacrossMinerAction
{
Status
:
status
})
tx
,
err
:=
pt
.
CreateRawMinerTx
(
chain33TestCfg
,
&
pt
.
ParacrossMinerAction
{
Status
:
status
})
assert
.
Nil
(
s
.
T
(),
err
,
"create asset transfer failed"
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -662,7 +666,7 @@ func createCrossParaTx(s suite.Suite, to []byte) (*types.Transaction, error) {
TokenSymbol
:
""
,
ExecName
:
Title
+
pt
.
ParaX
,
}
tx
,
err
:=
pt
.
CreateRawAssetTransferTx
(
&
param
)
tx
,
err
:=
pt
.
CreateRawAssetTransferTx
(
chain33TestCfg
,
&
param
)
assert
.
Nil
(
s
.
T
(),
err
,
"create asset transfer failed"
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -680,7 +684,7 @@ func createCrossParaTx(s suite.Suite, to []byte) (*types.Transaction, error) {
func
createCrossCommitTx
(
s
suite
.
Suite
)
(
*
types
.
Transaction
,
error
)
{
status
:=
&
pt
.
ParacrossNodeStatus
{
MainBlockHash
:
[]
byte
(
"hash"
),
MainBlockHeight
:
0
,
Title
:
Title
}
tx
,
err
:=
pt
.
CreateRawCommitTx4MainChain
(
status
,
Title
+
pt
.
ParaX
,
0
)
tx
,
err
:=
pt
.
CreateRawCommitTx4MainChain
(
chain33TestCfg
,
status
,
Title
+
pt
.
ParaX
,
0
)
assert
.
Nil
(
s
.
T
(),
err
,
"create asset transfer failed"
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -696,11 +700,11 @@ func createCrossCommitTx(s suite.Suite) (*types.Transaction, error) {
}
func
createTxsGroup
(
s
suite
.
Suite
,
txs
[]
*
types
.
Transaction
)
([]
*
types
.
Transaction
,
error
)
{
group
,
err
:=
types
.
CreateTxGroup
(
txs
,
types
.
GInt
(
"MinFee"
))
group
,
err
:=
types
.
CreateTxGroup
(
txs
,
chain33TestCfg
.
GInt
(
"MinFee"
))
if
err
!=
nil
{
return
nil
,
err
}
err
=
group
.
Check
(
0
,
types
.
GInt
(
"MinFee"
),
types
.
GInt
(
"MaxFee"
))
err
=
group
.
Check
(
chain33TestCfg
,
0
,
chain33TestCfg
.
GInt
(
"MinFee"
),
chain33TestCfg
.
GInt
(
"MaxFee"
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -732,7 +736,7 @@ func createParaNormalTx(s suite.Suite, privFrom string, to []byte) (*types.Trans
To
:
address
.
ExecAddress
(
param
.
GetExecName
()),
Fee
:
param
.
Fee
,
}
tx
,
err
:=
types
.
FormatTx
(
param
.
GetExecName
(),
tx
)
tx
,
err
:=
types
.
FormatTx
(
chain33TestCfg
,
param
.
GetExecName
(),
tx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/dapp/paracross/executor/superaccount_test.go
View file @
8150a333
...
...
@@ -17,6 +17,7 @@ import (
"github.com/33cn/chain33/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/mock"
)
var
(
...
...
@@ -46,13 +47,14 @@ func (suite *NodeManageTestSuite) SetupSuite() {
//suite.localDB, _ = dbm.NewGoMemDB("local", "local", 1024)
suite
.
localDB
=
new
(
dbmock
.
KVDB
)
suite
.
api
=
new
(
apimock
.
QueueProtocolAPI
)
suite
.
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
suite
.
exec
=
newParacross
()
.
(
*
Paracross
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
suite
.
exec
.
SetLocalDB
(
suite
.
localDB
)
suite
.
exec
.
SetStateDB
(
suite
.
stateDB
)
suite
.
exec
.
SetEnv
(
0
,
0
,
0
)
suite
.
exec
.
SetBlockInfo
([]
byte
(
""
),
[]
byte
(
""
),
3
)
suite
.
exec
.
SetAPI
(
suite
.
api
)
enableParacrossTransfer
=
false
//forkHeight := types.GetDappFork(pt.ParaX, pt.ForkCommitTx)
...
...
@@ -61,15 +63,15 @@ func (suite *NodeManageTestSuite) SetupSuite() {
//
//}
types
.
S
(
"config.consensus.sub.para.MainForkParacrossCommitTx"
,
int64
(
1
))
types
.
S
(
"config.exec.sub.manage.superManager"
,
[]
interface
{}{
Account12Q
})
chain33TestCfg
.
S
(
"config.consensus.sub.para.MainForkParacrossCommitTx"
,
int64
(
1
))
chain33TestCfg
.
S
(
"config.exec.sub.manage.superManager"
,
[]
interface
{}{
Account12Q
})
// TODO, more fields
// setup block
blockDetail
:=
&
types
.
BlockDetail
{
Block
:
&
types
.
Block
{},
}
MainBlockHash10
=
blockDetail
.
Block
.
Hash
()
MainBlockHash10
=
blockDetail
.
Block
.
Hash
(
chain33TestCfg
)
}
...
...
@@ -179,7 +181,7 @@ func voteTest(suite *NodeManageTestSuite, id string, join bool) {
Id
:
id
,
Value
:
pt
.
ParaNodeVoteYes
,
}
tx
,
err
:=
pt
.
CreateRawNodeConfigTx
(
config
)
tx
,
err
:=
pt
.
CreateRawNodeConfigTx
(
c
hain33TestCfg
,
c
onfig
)
suite
.
Nil
(
err
)
count
++
...
...
@@ -206,7 +208,7 @@ func (suite *NodeManageTestSuite) testNodeGroupConfigQuit() {
Addrs
:
applyAddrs
,
Op
:
pt
.
ParacrossNodeGroupApply
,
}
tx
,
err
:=
pt
.
CreateRawNodeGroupApplyTx
(
config
)
tx
,
err
:=
pt
.
CreateRawNodeGroupApplyTx
(
c
hain33TestCfg
,
c
onfig
)
suite
.
Nil
(
err
)
receipt
:=
nodeCommit
(
suite
,
PrivKeyB
,
tx
)
...
...
@@ -221,7 +223,7 @@ func (suite *NodeManageTestSuite) testNodeGroupConfigQuit() {
Id
:
g
.
Current
.
Id
,
Op
:
pt
.
ParacrossNodeGroupQuit
,
}
tx
,
err
=
pt
.
CreateRawNodeGroupApplyTx
(
config
)
tx
,
err
=
pt
.
CreateRawNodeGroupApplyTx
(
c
hain33TestCfg
,
c
onfig
)
suite
.
Nil
(
err
)
nodeCommit
(
suite
,
PrivKeyB
,
tx
)
...
...
@@ -236,7 +238,7 @@ func (suite *NodeManageTestSuite) testNodeGroupConfig() {
Addrs
:
applyAddrs
,
Op
:
pt
.
ParacrossNodeGroupApply
,
}
tx
,
err
:=
pt
.
CreateRawNodeGroupApplyTx
(
config
)
tx
,
err
:=
pt
.
CreateRawNodeGroupApplyTx
(
c
hain33TestCfg
,
c
onfig
)
suite
.
Nil
(
err
)
receipt
:=
nodeCommit
(
suite
,
PrivKeyB
,
tx
)
...
...
@@ -251,7 +253,7 @@ func (suite *NodeManageTestSuite) testNodeGroupConfig() {
Id
:
g
.
Current
.
Id
,
Op
:
pt
.
ParacrossNodeGroupApprove
,
}
tx
,
err
=
pt
.
CreateRawNodeGroupApplyTx
(
config
)
tx
,
err
=
pt
.
CreateRawNodeGroupApplyTx
(
c
hain33TestCfg
,
c
onfig
)
suite
.
Nil
(
err
)
receipt
=
nodeCommit
(
suite
,
PrivKey12Q
,
tx
)
...
...
@@ -265,7 +267,7 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
Op
:
pt
.
ParaNodeJoin
,
Addr
:
Account14K
,
}
tx
,
err
:=
pt
.
CreateRawNodeConfigTx
(
config
)
tx
,
err
:=
pt
.
CreateRawNodeConfigTx
(
c
hain33TestCfg
,
c
onfig
)
suite
.
Nil
(
err
)
receipt
:=
nodeCommit
(
suite
,
PrivKey14K
,
tx
)
...
...
@@ -284,7 +286,7 @@ func (suite *NodeManageTestSuite) testNodeConfig() {
Op
:
pt
.
ParaNodeQuit
,
Addr
:
Account14K
,
}
tx
,
err
=
pt
.
CreateRawNodeConfigTx
(
config
)
tx
,
err
=
pt
.
CreateRawNodeConfigTx
(
c
hain33TestCfg
,
c
onfig
)
suite
.
Nil
(
err
)
receipt
=
nodeCommit
(
suite
,
PrivKeyD
,
tx
)
checkQuitReceipt
(
suite
,
receipt
)
...
...
@@ -304,12 +306,7 @@ func (suite *NodeManageTestSuite) TestExec() {
}
func
TestNodeManageSuite
(
t
*
testing
.
T
)
{
tempTitle
=
types
.
GetTitle
()
types
.
SetTitleOnlyForTest
(
Title
)
suite
.
Run
(
t
,
new
(
NodeManageTestSuite
))
types
.
SetTitleOnlyForTest
(
tempTitle
)
}
func
(
suite
*
NodeManageTestSuite
)
TearDownSuite
()
{
...
...
plugin/dapp/paracross/rpc/rpc_test.go
View file @
8150a333
...
...
@@ -18,6 +18,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"golang.org/x/net/context"
ptestNode
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
)
func
newGrpc
(
api
client
.
QueueProtocolAPI
)
*
channelClient
{
...
...
@@ -31,22 +32,26 @@ func newJrpc(api client.QueueProtocolAPI) *Jrpc {
}
func
TestChannelClient_GetTitle
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqString
{
Data
:
"xxxxxxxxxxx"
}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetTitle"
,
req
)
.
Return
(
&
pt
.
ParacrossStatus
{},
nil
)
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"GetTitle"
,
req
)
.
Return
(
&
pt
.
ParacrossStatus
{},
nil
)
api
.
On
(
"GetLastHeader"
,
mock
.
Anything
)
.
Return
(
&
types
.
Header
{},
nil
)
.
Once
()
_
,
err
:=
client
.
GetTitle
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_GetTitle
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
j
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqString
{
Data
:
"xxxxxxxxxxx"
}
var
result
interface
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetTitle"
,
req
)
.
Return
(
&
pt
.
ParacrossStatus
{
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"GetTitle"
,
req
)
.
Return
(
&
pt
.
ParacrossStatus
{
Title
:
"user.p.para"
,
Height
:
int64
(
64
),
BlockHash
:
[]
byte
{
177
,
17
,
9
,
106
,
247
,
117
,
90
,
242
,
221
,
160
,
157
,
31
,
33
,
51
,
10
,
99
,
77
,
47
,
245
,
223
,
59
,
64
,
121
,
121
,
215
,
167
,
152
,
17
,
223
,
218
,
173
,
83
}},
nil
)
api
.
On
(
"GetLastHeader"
,
mock
.
Anything
)
.
Return
(
&
types
.
Header
{},
nil
)
.
Once
()
err
:=
j
.
GetHeight
(
req
,
&
result
)
...
...
@@ -54,77 +59,93 @@ func TestJrpc_GetTitle(t *testing.T) {
}
func
TestChannelClient_ListTitles
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqNil
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"ListTitles"
,
req
)
.
Return
(
&
pt
.
RespParacrossTitles
{},
nil
)
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"ListTitles"
,
req
)
.
Return
(
&
pt
.
RespParacrossTitles
{},
nil
)
_
,
err
:=
client
.
ListTitles
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_ListTitles
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
j
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqNil
{}
var
result
interface
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"ListTitles"
,
req
)
.
Return
(
&
pt
.
RespParacrossTitles
{},
nil
)
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"ListTitles"
,
req
)
.
Return
(
&
pt
.
RespParacrossTitles
{},
nil
)
err
:=
j
.
ListTitles
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
}
func
TestChannelClient_GetTitleHeight
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
pt
.
ReqParacrossTitleHeight
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetTitleHeight"
,
req
)
.
Return
(
&
pt
.
ParacrossHeightStatusRsp
{},
nil
)
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"GetTitleHeight"
,
req
)
.
Return
(
&
pt
.
ParacrossHeightStatusRsp
{},
nil
)
_
,
err
:=
client
.
GetTitleHeight
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestChannelClient_GetTitleDoneHeight
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
pt
.
ReqParacrossTitleHeight
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetDoneTitleHeight"
,
req
)
.
Return
(
&
pt
.
RespParacrossDone
{},
nil
)
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"GetDoneTitleHeight"
,
req
)
.
Return
(
&
pt
.
RespParacrossDone
{},
nil
)
_
,
err
:=
client
.
GetDoneTitleHeight
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_GetTitleHeight
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
j
:=
newJrpc
(
api
)
req
:=
&
pt
.
ReqParacrossTitleHeight
{}
var
result
interface
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetTitleHeight"
,
req
)
.
Return
(
&
pt
.
ParacrossHeightStatusRsp
{},
nil
)
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"GetTitleHeight"
,
req
)
.
Return
(
&
pt
.
ParacrossHeightStatusRsp
{},
nil
)
err
:=
j
.
GetTitleHeight
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
}
func
TestChannelClient_GetAssetTxResult
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqHash
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetAssetTxResult"
,
req
)
.
Return
(
&
pt
.
ParacrossAsset
{},
nil
)
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"GetAssetTxResult"
,
req
)
.
Return
(
&
pt
.
ParacrossAsset
{},
nil
)
_
,
err
:=
client
.
GetAssetTxResult
(
context
.
Background
(),
req
)
assert
.
Nil
(
t
,
err
)
}
func
TestJrpc_GetAssetTxResult
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
j
:=
newJrpc
(
api
)
req
:=
&
types
.
ReqHash
{}
var
result
interface
{}
api
.
On
(
"Query"
,
pt
.
GetExecName
(),
"GetAssetTxResult"
,
req
)
.
Return
(
&
pt
.
ParacrossAsset
{},
nil
)
api
.
On
(
"Query"
,
pt
.
GetExecName
(
cfg
),
"GetAssetTxResult"
,
req
)
.
Return
(
&
pt
.
ParacrossAsset
{},
nil
)
err
:=
j
.
GetAssetTxResult
(
req
,
&
result
)
assert
.
Nil
(
t
,
err
)
}
func
TestChannelClient_IsSync
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
ptestNode
.
DefaultConfig
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"paracross"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqNil
{}
...
...
plugin/dapp/paracross/testnode/para_test.go
View file @
8150a333
...
...
@@ -11,12 +11,13 @@ import (
func
TestParaNode
(
t
*
testing
.
T
)
{
para
:=
NewParaNode
(
nil
,
nil
)
paraCfg
:=
para
.
Para
.
GetAPI
()
.
GetConfig
()
defer
para
.
Close
()
//通过rpc 发生信息
tx
:=
util
.
CreateTxWithExecer
(
para
.
Para
.
GetGenesisKey
(),
"user.p.guodun.none"
)
tx
:=
util
.
CreateTxWithExecer
(
para
Cfg
,
para
.
Para
.
GetGenesisKey
(),
"user.p.guodun.none"
)
para
.
Para
.
SendTxRPC
(
tx
)
para
.
Para
.
WaitHeight
(
1
)
tx
=
util
.
CreateTxWithExecer
(
para
.
Para
.
GetGenesisKey
(),
"user.p.guodun.none"
)
tx
=
util
.
CreateTxWithExecer
(
para
Cfg
,
para
.
Para
.
GetGenesisKey
(),
"user.p.guodun.none"
)
para
.
Para
.
SendTxRPC
(
tx
)
para
.
Para
.
WaitHeight
(
2
)
}
plugin/dapp/paracross/testnode/paranode.go
View file @
8150a333
...
...
@@ -3,6 +3,7 @@ package testnode
import
(
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
"strings"
)
/*
...
...
@@ -23,7 +24,7 @@ func NewParaNode(main *testnode.Chain33Mock, para *testnode.Chain33Mock) *ParaNo
main
.
Listen
()
}
if
para
==
nil
{
cfg
:=
types
.
NewChain33Config
(
DefaultConfig
)
cfg
:=
types
.
NewChain33Config
(
strings
.
Replace
(
DefaultConfig
,
"Title=
\"
user.p.guodun.
\"
"
,
"Title=
\"
user.p.test.
\"
"
,
1
)
)
testnode
.
ModifyParaClient
(
cfg
,
main
.
GetCfg
()
.
RPC
.
GrpcBindAddr
)
para
=
testnode
.
NewWithConfig
(
cfg
,
nil
)
para
.
Listen
()
...
...
plugin/dapp/paracross/wallet/para_test.go
View file @
8150a333
...
...
@@ -17,6 +17,7 @@ import (
func
TestParaQuery
(
t
*
testing
.
T
)
{
para
:=
node
.
NewParaNode
(
nil
,
nil
)
paraCfg
:=
para
.
Para
.
GetAPI
()
.
GetConfig
()
defer
para
.
Close
()
var
param
types
.
ReqWalletImportPrivkey
...
...
@@ -31,10 +32,10 @@ func TestParaQuery(t *testing.T) {
para
.
Para
.
GetAPI
()
.
WalletLock
()
//通过rpc 发生信息
tx
:=
util
.
CreateTxWithExecer
(
para
.
Para
.
GetGenesisKey
(),
"user.p.guodun.none"
)
tx
:=
util
.
CreateTxWithExecer
(
para
Cfg
,
para
.
Para
.
GetGenesisKey
(),
"user.p.guodun.none"
)
para
.
Para
.
SendTxRPC
(
tx
)
para
.
Para
.
WaitHeight
(
1
)
tx
=
util
.
CreateTxWithExecer
(
para
.
Para
.
GetGenesisKey
(),
"user.p.guodun.none"
)
tx
=
util
.
CreateTxWithExecer
(
para
Cfg
,
para
.
Para
.
GetGenesisKey
(),
"user.p.guodun.none"
)
para
.
Para
.
SendTxRPC
(
tx
)
para
.
Para
.
WaitHeight
(
2
)
...
...
plugin/dapp/relay/cmd/relayd/main.go
View file @
8150a333
...
...
@@ -17,11 +17,13 @@ import (
clog
"github.com/33cn/chain33/common/log"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/plugin/plugin/dapp/relay/cmd/relayd/relayd"
"github.com/33cn/chain33/types"
)
var
(
cpuNum
=
runtime
.
NumCPU
()
configPath
=
flag
.
String
(
"f"
,
"relayd.toml"
,
"configfile"
)
chain33ConfigPath
=
flag
.
String
(
"chain33flie"
,
""
,
"chain33configfile"
)
)
func
main
()
{
...
...
@@ -40,6 +42,9 @@ func main() {
flag
.
Parse
()
cfg
:=
relayd
.
NewConfig
(
*
configPath
)
clog
.
SetFileLog
(
&
cfg
.
Log
)
if
*
chain33ConfigPath
!=
""
{
cfg
.
Chain33Cfg
=
types
.
NewChain33Config
(
types
.
ReadFile
(
*
chain33ConfigPath
))
}
if
cfg
.
Watch
{
// set watching
...
...
plugin/dapp/relay/cmd/relayd/relayd/config.go
View file @
8150a333
...
...
@@ -27,6 +27,7 @@ type Config struct {
Btcd
Btcd
Log
types
.
Log
Auth
Auth
Chain33Cfg
*
types
.
Chain33Config
}
// Btcd adapt to btcd
...
...
plugin/dapp/relay/cmd/relayd/relayd/relayd.go
View file @
8150a333
...
...
@@ -325,7 +325,11 @@ func (r *Relayd) transaction(payload []byte) *types.Transaction {
To
:
address
.
ExecAddress
(
ty
.
RelayX
),
}
fee
,
_
:=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
))
minFee
:=
types
.
DefaultMinFee
if
r
.
config
.
Chain33Cfg
!=
nil
{
minFee
=
r
.
config
.
Chain33Cfg
.
GInt
(
"MinFee"
)
}
fee
,
_
:=
tx
.
GetRealFee
(
minFee
)
tx
.
Fee
=
fee
tx
.
Sign
(
types
.
SECP256K1
,
r
.
privateKey
)
log
.
Info
(
"transaction"
,
"fee : "
,
fee
)
...
...
plugin/dapp/relay/executor/relay_test.go
View file @
8150a333
...
...
@@ -20,9 +20,12 @@ import (
_
"github.com/33cn/chain33/system"
)
var
chainTestCfg
=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
func
init
()
{
//init some config param
testnode
.
New
(
""
,
nil
)
Init
(
ty
.
RelayX
,
chainTestCfg
,
nil
)
}
type
suiteRelay
struct
{
...
...
@@ -67,18 +70,17 @@ func (s *suiteRelay) accountSetup() {
}
func
(
s
*
suiteRelay
)
SetupSuite
()
{
chainTestCfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
//s.db = new(mocks.KV)
s
.
kvdb
=
new
(
mocks
.
KVDB
)
accDb
,
_
:=
db
.
NewGoMemDB
(
"relayTestDb"
,
"test"
,
128
)
relay
:=
&
relay
{}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetIsFree
(
false
)
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetChild
(
relay
)
relay
.
SetExecutorType
(
types
.
LoadExecutorType
(
driverName
))
s
.
relay
=
relay
...
...
@@ -408,11 +410,13 @@ func (s *suiteBtcHeader) SetupSuite() {
s
.
kvdb
=
new
(
mocks
.
KVDB
)
//accDb, _ := db.NewGoMemDB("relayTestDb", "test", 128)
relay
:=
&
relay
{}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetStateDB
(
s
.
db
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
relay
.
SetExecutorType
(
types
.
LoadExecutorType
(
driverName
))
s
.
relay
=
relay
...
...
plugin/dapp/relay/executor/relaydb_test.go
View file @
8150a333
...
...
@@ -17,6 +17,7 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
apimock
"github.com/33cn/chain33/client/mocks"
)
type
suiteRelayLog
struct
{
...
...
@@ -150,11 +151,13 @@ func (s *suiteRelayDB) SetupSuite() {
s
.
kvdb
=
new
(
mocks
.
KVDB
)
accDb
,
_
:=
db
.
NewGoMemDB
(
"relayTestDb"
,
"test"
,
128
)
relay
:=
&
relay
{}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
s
.
relay
=
relay
...
...
@@ -337,11 +340,13 @@ func (s *suiteAccept) SetupSuite() {
s
.
kvdb
=
new
(
mocks
.
KVDB
)
accDb
,
_
:=
db
.
NewGoMemDB
(
"relayTestAccept"
,
"test"
,
128
)
relay
:=
&
relay
{}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
s
.
relay
=
relay
...
...
@@ -540,11 +545,13 @@ func (s *suiteConfirm) SetupSuite() {
s
.
kvdb
=
new
(
mocks
.
KVDB
)
accDb
,
_
:=
db
.
NewGoMemDB
(
"relayTestAccept"
,
"test"
,
128
)
relay
:=
&
relay
{}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
s
.
relay
=
relay
...
...
@@ -837,11 +844,13 @@ func (s *suiteVerify) SetupSuite() {
s
.
kvdb
=
new
(
mocks
.
KVDB
)
accDb
,
_
:=
db
.
NewGoMemDB
(
"relayTestAccept"
,
"test"
,
128
)
relay
:=
&
relay
{}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
s
.
relay
=
relay
...
...
@@ -1072,11 +1081,13 @@ func (s *suiteVerifyCli) SetupSuite() {
s
.
kvdb
=
new
(
mocks
.
KVDB
)
accDb
,
_
:=
db
.
NewGoMemDB
(
"relayTestAccept"
,
"test"
,
128
)
relay
:=
&
relay
{}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetStateDB
(
accDb
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
s
.
relay
=
relay
...
...
@@ -1148,11 +1159,13 @@ func (s *suiteSaveBtcHeader) SetupSuite() {
s
.
db
=
new
(
mocks
.
KV
)
s
.
kvdb
=
new
(
mocks
.
KVDB
)
relay
:=
&
relay
{}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chainTestCfg
,
nil
)
relay
.
SetAPI
(
api
)
relay
.
SetStateDB
(
s
.
db
)
relay
.
SetLocalDB
(
s
.
kvdb
)
relay
.
SetEnv
(
10
,
100
,
1
)
relay
.
SetIsFree
(
false
)
relay
.
SetAPI
(
nil
)
relay
.
SetChild
(
relay
)
s
.
relay
=
relay
...
...
plugin/dapp/retrieve/executor/retrieve_unit_test.go
View file @
8150a333
...
...
@@ -13,12 +13,13 @@ import (
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/executor"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
rt
"github.com/33cn/plugin/plugin/dapp/retrieve/types"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/client"
"strings"
)
var
(
...
...
@@ -49,9 +50,7 @@ func init() {
retrieve
=
constructRetrieveInstance
()
}
func
NewTestDB
()
db
.
KV
{
return
executor
.
NewStateDB
(
nil
,
nil
,
nil
,
&
executor
.
StateDBOption
{
Height
:
types
.
GetFork
(
"ForkExecRollback"
)})
}
func
TestExecBackup
(
t
*
testing
.
T
)
{
var
targetReceipt
types
.
Receipt
var
targetErr
error
...
...
@@ -249,8 +248,15 @@ func TestExecDelLocalBackup(t *testing.T) {
}
func
constructRetrieveInstance
()
drivers
.
Driver
{
cfgstring
:=
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
)
chainTestCfg
:=
types
.
NewChain33Config
(
cfgstring
)
Init
(
rt
.
RetrieveX
,
chainTestCfg
,
nil
)
q
:=
queue
.
New
(
"channel"
)
q
.
SetConfig
(
chainTestCfg
)
api
,
_
:=
client
.
New
(
q
.
Client
(),
nil
)
r
:=
newRetrieve
()
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
r
.
SetAPI
(
api
)
r
.
SetStateDB
(
kvdb
)
r
.
SetLocalDB
(
kvdb
)
return
r
...
...
plugin/dapp/ticket/executor/ticket_test.go
View file @
8150a333
...
...
@@ -31,32 +31,35 @@ func TestMain(m *testing.M) {
}
func
TestTicketPrice
(
t
*
testing
.
T
)
{
cfg
:=
mock33
.
GetAPI
()
.
GetConfig
()
//test price
ti
:=
&
executor
.
DB
{}
assert
.
Equal
(
t
,
ti
.
GetRealPrice
(),
10000
*
types
.
Coin
)
assert
.
Equal
(
t
,
ti
.
GetRealPrice
(
cfg
),
10000
*
types
.
Coin
)
ti
=
&
executor
.
DB
{}
ti
.
Price
=
10
assert
.
Equal
(
t
,
ti
.
GetRealPrice
(),
int64
(
10
))
assert
.
Equal
(
t
,
ti
.
GetRealPrice
(
cfg
),
int64
(
10
))
}
func
TestCheckFork
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
int64
(
1
),
types
.
GetFork
(
"ForkChainParamV2"
))
p1
:=
ty
.
GetTicketMinerParam
(
0
)
cfg
:=
mock33
.
GetAPI
()
.
GetConfig
()
assert
.
Equal
(
t
,
int64
(
1
),
cfg
.
GetFork
(
"ForkChainParamV2"
))
p1
:=
ty
.
GetTicketMinerParam
(
cfg
,
0
)
assert
.
Equal
(
t
,
10000
*
types
.
Coin
,
p1
.
TicketPrice
)
p1
=
ty
.
GetTicketMinerParam
(
1
)
p1
=
ty
.
GetTicketMinerParam
(
cfg
,
1
)
assert
.
Equal
(
t
,
3000
*
types
.
Coin
,
p1
.
TicketPrice
)
p1
=
ty
.
GetTicketMinerParam
(
2
)
p1
=
ty
.
GetTicketMinerParam
(
cfg
,
2
)
assert
.
Equal
(
t
,
3000
*
types
.
Coin
,
p1
.
TicketPrice
)
p1
=
ty
.
GetTicketMinerParam
(
3
)
p1
=
ty
.
GetTicketMinerParam
(
cfg
,
3
)
assert
.
Equal
(
t
,
3000
*
types
.
Coin
,
p1
.
TicketPrice
)
}
func
TestTicket
(
t
*
testing
.
T
)
{
cfg
:=
mock33
.
GetAPI
()
.
GetConfig
()
reply
,
err
:=
mock33
.
GetAPI
()
.
ExecWalletFunc
(
"ticket"
,
"WalletAutoMiner"
,
&
ty
.
MinerFlag
{
Flag
:
1
})
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
true
,
reply
.
(
*
types
.
Reply
)
.
IsOk
)
acc
:=
account
.
NewCoinsAccount
()
acc
:=
account
.
NewCoinsAccount
(
cfg
)
addr
:=
mock33
.
GetGenesisAddress
()
accounts
,
err
:=
acc
.
GetBalance
(
mock33
.
GetAPI
(),
&
types
.
ReqBalance
{
Execer
:
"ticket"
,
Addresses
:
[]
string
{
addr
}})
assert
.
Nil
(
t
,
err
)
...
...
@@ -66,11 +69,11 @@ func TestTicket(t *testing.T) {
assert
.
Nil
(
t
,
err
)
//assert.Equal(t, accounts[0].Balance, int64(1000000000000))
//send to address
tx
:=
util
.
CreateCoinsTx
(
mock33
.
GetHotKey
(),
mock33
.
GetGenesisAddress
(),
types
.
Coin
/
100
)
tx
:=
util
.
CreateCoinsTx
(
cfg
,
mock33
.
GetHotKey
(),
mock33
.
GetGenesisAddress
(),
types
.
Coin
/
100
)
mock33
.
SendTx
(
tx
)
mock33
.
Wait
()
//bind miner
tx
=
createBindMiner
(
t
,
hotaddr
,
addr
,
mock33
.
GetGenesisKey
())
tx
=
createBindMiner
(
t
,
cfg
,
hotaddr
,
addr
,
mock33
.
GetGenesisKey
())
hash
:=
mock33
.
SendTx
(
tx
)
detail
,
err
:=
mock33
.
WaitTx
(
hash
)
assert
.
Nil
(
t
,
err
)
...
...
@@ -122,11 +125,11 @@ func TestTicket(t *testing.T) {
t
.
Error
(
"wait 100 , open and close not happened"
)
}
func
createBindMiner
(
t
*
testing
.
T
,
m
,
r
string
,
priv
crypto
.
PrivKey
)
*
types
.
Transaction
{
func
createBindMiner
(
t
*
testing
.
T
,
cfg
*
types
.
Chain33Config
,
m
,
r
string
,
priv
crypto
.
PrivKey
)
*
types
.
Transaction
{
ety
:=
types
.
LoadExecutorType
(
"ticket"
)
tx
,
err
:=
ety
.
Create
(
"Tbind"
,
&
ty
.
TicketBind
{
MinerAddress
:
m
,
ReturnAddress
:
r
})
assert
.
Nil
(
t
,
err
)
tx
,
err
=
types
.
FormatTx
(
"ticket"
,
tx
)
tx
,
err
=
types
.
FormatTx
(
cfg
,
"ticket"
,
tx
)
assert
.
Nil
(
t
,
err
)
tx
.
Sign
(
types
.
SECP256K1
,
priv
)
return
tx
...
...
plugin/dapp/ticket/rpc/jrpc_channel_test.go
View file @
8150a333
...
...
@@ -20,9 +20,9 @@ import (
var
mocker
*
testnode
.
Chain33Mock
func
TestMain
(
m
*
testing
.
M
)
{
cfg
,
sub
:=
testnode
.
GetDefaultConfig
(
)
cfg
.
Consensus
.
Name
=
"ticket"
mocker
=
testnode
.
NewWithConfig
(
cfg
,
sub
,
nil
)
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
()
)
cfg
.
GetModuleConfig
()
.
Consensus
.
Name
=
"ticket"
mocker
=
testnode
.
NewWithConfig
(
cfg
,
nil
)
mocker
.
Listen
()
m
.
Run
()
mocker
.
Close
()
...
...
plugin/dapp/ticket/rpc/rpc.go
View file @
8150a333
plugin/dapp/ticket/rpc/rpc_test.go
View file @
8150a333
...
...
@@ -116,7 +116,10 @@ func newJrpc(api client.QueueProtocolAPI) *Jrpc {
}
func
TestChannelClient_BindMiner
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
.
SetTitleOnlyForTest
(
"test"
)
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"ticket"
,
nil
,
nil
,
nil
)
head
:=
&
types
.
Header
{
Height
:
2
,
StateHash
:
[]
byte
(
"sdfadasds"
)}
...
...
@@ -128,9 +131,9 @@ func TestChannelClient_BindMiner(t *testing.T) {
storevalue
.
Values
=
append
(
storevalue
.
Values
,
accv
)
api
.
On
(
"StoreGet"
,
mock
.
Anything
)
.
Return
(
storevalue
,
nil
)
.
Twice
()
types
.
SetTitleOnlyForTest
(
"test"
)
cfg
,
_
:=
types
.
InitCfgString
(
cfgstring
)
types
.
Init
(
"test"
,
cfg
)
//
cfg, _ := types.InitCfgString(cfgstring)
//
types.Init("test", cfg)
//var addrs = make([]string, 1)
//addrs = append(addrs, "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt")
...
...
@@ -155,7 +158,9 @@ func TestChannelClient_BindMiner(t *testing.T) {
}
func
testGetTicketCountOK
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
api
:=
&
mocks
.
QueueProtocolAPI
{}
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
g
:=
newGrpc
(
api
)
api
.
On
(
"QueryConsensusFunc"
,
"ticket"
,
"GetTicketCount"
,
mock
.
Anything
)
.
Return
(
&
types
.
Int64
{},
nil
)
data
,
err
:=
g
.
GetTicketCount
(
context
.
Background
(),
nil
)
...
...
@@ -222,11 +227,13 @@ func TestJrpc_GetTicketCount(t *testing.T) {
}
func
TestRPC_CallTestNode
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
cfg
,
sub
:=
testnode
.
GetDefaultConfig
()
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
// 测试环境下,默认配置的共识为solo,需要修改
cfg
.
Consensus
.
Name
=
"ticket"
mock33
:=
testnode
.
NewWithConfig
(
cfg
,
sub
,
api
)
cfg
.
GetModuleConfig
()
.
Consensus
.
Name
=
"ticket"
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
mock33
:=
testnode
.
NewWithConfig
(
cfg
,
api
)
defer
func
()
{
mock33
.
Close
()
mock
.
AssertExpectationsForObjects
(
t
,
api
)
...
...
plugin/dapp/ticket/testnode/ticket_test.go
View file @
8150a333
...
...
@@ -22,9 +22,9 @@ func TestWalletTicket(t *testing.T) {
minerAddr
:=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
t
.
Log
(
"Begin wallet ticket test"
)
cfg
,
sub
:=
testnode
.
GetDefaultConfig
(
)
cfg
.
Consensus
.
Name
=
"ticket"
mock33
:=
testnode
.
NewWithConfig
(
cfg
,
sub
,
nil
)
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
()
)
cfg
.
GetModuleConfig
()
.
Consensus
.
Name
=
"ticket"
mock33
:=
testnode
.
NewWithConfig
(
cfg
,
nil
)
defer
mock33
.
Close
()
err
:=
mock33
.
WaitHeight
(
0
)
assert
.
Nil
(
t
,
err
)
...
...
plugin/dapp/ticket/types/types_test.go
View file @
8150a333
...
...
@@ -13,6 +13,10 @@ import (
"github.com/stretchr/testify/assert"
)
func
init
()
{
InitExecutor
(
nil
)
}
func
TestDecodeLogNewTicket
(
t
*
testing
.
T
)
{
var
logTmp
=
&
ReceiptTicket
{}
...
...
plugin/dapp/ticket/wallet/ticket_test.go
View file @
8150a333
...
...
@@ -12,7 +12,6 @@ import (
"github.com/stretchr/testify/mock"
"github.com/33cn/chain33/util/testnode"
wcom
"github.com/33cn/chain33/wallet/common"
ty
"github.com/33cn/plugin/plugin/dapp/ticket/types"
"github.com/stretchr/testify/assert"
...
...
@@ -30,17 +29,17 @@ const (
sendhash
=
"sendhash"
)
func
TestMain
(
m
*
testing
.
M
)
{
cfg
,
_
:=
testnode
.
GetDefaultConfig
()
cfg
.
Consensus
.
Name
=
"ticket"
types
.
Init
(
cfg
.
Title
,
cfg
)
m
.
Run
()
}
func
TestForceCloseTicketList
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
.
GetModuleConfig
()
.
Consensus
.
Name
=
"ticket"
ticket
:=
&
ticketPolicy
{
mtx
:
&
sync
.
Mutex
{}}
ticket
.
walletOperate
=
new
(
walletOperateMock
)
wallet
:=
new
(
walletOperateMock
)
qapi
:=
new
(
mocks
.
QueueProtocolAPI
)
qapi
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
wallet
.
api
=
qapi
ticket
.
walletOperate
=
wallet
t1
:=
&
ty
.
Ticket
{
Status
:
1
,
IsGenesis
:
false
}
t2
:=
&
ty
.
Ticket
{
Status
:
2
,
IsGenesis
:
false
}
t3
:=
&
ty
.
Ticket
{
Status
:
3
,
IsGenesis
:
false
}
...
...
@@ -53,6 +52,9 @@ func TestForceCloseTicketList(t *testing.T) {
}
func
TestCloseTicketsByAddr
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
.
GetModuleConfig
()
.
Consensus
.
Name
=
"ticket"
pk
,
err
:=
hex
.
DecodeString
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
)
assert
.
Nil
(
t
,
err
)
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
...
...
@@ -63,6 +65,7 @@ func TestCloseTicketsByAddr(t *testing.T) {
ticket
:=
&
ticketPolicy
{
mtx
:
&
sync
.
Mutex
{}}
wallet
:=
new
(
walletOperateMock
)
qapi
:=
new
(
mocks
.
QueueProtocolAPI
)
qapi
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
wallet
.
api
=
qapi
ticket
.
walletOperate
=
wallet
...
...
@@ -80,9 +83,15 @@ func TestCloseTicketsByAddr(t *testing.T) {
}
func
TestBuyTicketOne
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
.
GetModuleConfig
()
.
Consensus
.
Name
=
"ticket"
ticket
:=
&
ticketPolicy
{
mtx
:
&
sync
.
Mutex
{}}
ticket
.
walletOperate
=
new
(
walletOperateMock
)
wallet
:=
new
(
walletOperateMock
)
qapi
:=
new
(
mocks
.
QueueProtocolAPI
)
qapi
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
wallet
.
api
=
qapi
ticket
.
walletOperate
=
wallet
pk
,
err
:=
hex
.
DecodeString
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
)
assert
.
Nil
(
t
,
err
)
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
...
...
@@ -97,6 +106,9 @@ func TestBuyTicketOne(t *testing.T) {
}
func
TestBuyMinerAddrTicketOne
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
.
GetModuleConfig
()
.
Consensus
.
Name
=
"ticket"
pk
,
err
:=
hex
.
DecodeString
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
)
assert
.
Nil
(
t
,
err
)
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
...
...
@@ -109,6 +121,7 @@ func TestBuyMinerAddrTicketOne(t *testing.T) {
ticket
.
initMinerWhiteList
(
nil
)
wallet
:=
new
(
walletOperateMock
)
qapi
:=
new
(
mocks
.
QueueProtocolAPI
)
qapi
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
wallet
.
api
=
qapi
ticket
.
walletOperate
=
wallet
...
...
plugin/dapp/token/cmd/signatory-server/signatory/signatory.go
View file @
8150a333
...
...
@@ -63,7 +63,7 @@ func (signatory *Signatory) SignApprove(in *TokenFinish, out *interface{}) error
}
var
err
error
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
)
)
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
DefaultMinFee
)
if
err
!=
nil
{
log
.
Error
(
"SignApprove"
,
"calc fee failed"
,
err
)
return
err
...
...
@@ -104,7 +104,7 @@ func (signatory *Signatory) SignTransfer(in *string, out *interface{}) error {
}
var
err
error
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
GInt
(
"MinFee"
)
)
tx
.
Fee
,
err
=
tx
.
GetRealFee
(
types
.
DefaultMinFee
)
if
err
!=
nil
{
log
.
Error
(
"SignTranfer"
,
"calc fee failed"
,
err
)
return
err
...
...
plugin/dapp/token/executor/token_new_test.go
View file @
8150a333
...
...
@@ -20,6 +20,7 @@ import (
pty
"github.com/33cn/plugin/plugin/dapp/token/types"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"strings"
)
var
(
...
...
@@ -422,9 +423,9 @@ func getprivkey(key string) crypto.PrivKey {
}
func
TestToken_validSymbolWithHeight
(
t
*
testing
.
T
)
{
types
.
SetTitleOnlyForTest
(
"chain33"
)
forkBadTokenSymbol
:=
types
.
GetDappFork
(
pty
.
TokenX
,
pty
.
ForkBadTokenSymbolX
)
forkTokenSymbolWithNumber
:=
types
.
GetDappFork
(
pty
.
TokenX
,
pty
.
ForkTokenSymbolWithNumberX
)
cfg
:=
types
.
NewChain33Config
(
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
)
)
forkBadTokenSymbol
:=
cfg
.
GetDappFork
(
pty
.
TokenX
,
pty
.
ForkBadTokenSymbolX
)
forkTokenSymbolWithNumber
:=
cfg
.
GetDappFork
(
pty
.
TokenX
,
pty
.
ForkTokenSymbolWithNumberX
)
t
.
Log
(
"x"
,
"1"
,
forkBadTokenSymbol
,
"2"
,
forkTokenSymbolWithNumber
)
assert
.
Equal
(
t
,
true
,
(
forkTokenSymbolWithNumber
>=
forkBadTokenSymbol
))
...
...
@@ -451,7 +452,7 @@ func TestToken_validSymbolWithHeight(t *testing.T) {
for
_
,
c
:=
range
cases
{
c
:=
c
t
.
Run
(
"validSymbol"
,
func
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
c
.
expect
,
validSymbolWithHeight
(
c
.
symbol
,
c
.
height
))
assert
.
Equal
(
t
,
c
.
expect
,
validSymbolWithHeight
(
c
fg
,
c
.
symbol
,
c
.
height
))
})
}
}
plugin/dapp/token/executor/token_test.go
View file @
8150a333
...
...
@@ -14,6 +14,9 @@ import (
pty
"github.com/33cn/plugin/plugin/dapp/token/types"
"github.com/stretchr/testify/assert"
//"github.com/33cn/chain33/types/jsonpb"
"strings"
"github.com/stretchr/testify/mock"
apimock
"github.com/33cn/chain33/client/mocks"
)
type
execEnv
struct
{
...
...
@@ -40,7 +43,8 @@ var (
)
func
TestToken
(
t
*
testing
.
T
)
{
types
.
SetTitleOnlyForTest
(
"chain33"
)
cfg
:=
types
.
NewChain33Config
(
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
))
Init
(
pty
.
TokenX
,
cfg
,
nil
)
tokenTotal
:=
int64
(
10000
*
1e8
)
tokenBurn
:=
int64
(
10
*
1e8
)
tokenMint
:=
int64
(
20
*
1e8
)
...
...
@@ -68,7 +72,7 @@ func TestToken(t *testing.T) {
env
:=
execEnv
{
10
,
types
.
GetDappFork
(
pty
.
TokenX
,
pty
.
ForkTokenCheckX
),
cfg
.
GetDappFork
(
pty
.
TokenX
,
pty
.
ForkTokenCheckX
),
1539918074
,
}
...
...
@@ -111,6 +115,9 @@ func TestToken(t *testing.T) {
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
:=
newToken
()
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
exec
.
SetAPI
(
api
)
exec
.
SetStateDB
(
stateDB
)
exec
.
SetLocalDB
(
kvdb
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
...
...
@@ -137,6 +144,7 @@ func TestToken(t *testing.T) {
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
=
newToken
()
exec
.
SetAPI
(
api
)
exec
.
SetStateDB
(
stateDB
)
exec
.
SetLocalDB
(
kvdb
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
...
...
plugin/dapp/token/rpc/rpc_real_test.go
View file @
8150a333
...
...
@@ -19,6 +19,7 @@ import (
func
TestRPCTokenPreCreate
(
t
*
testing
.
T
)
{
// 启动RPCmocker
mock33
:=
testnode
.
New
(
""
,
nil
)
cfg
:=
mock33
.
GetAPI
()
.
GetConfig
()
defer
mock33
.
Close
()
mock33
.
Listen
()
//precreate
...
...
@@ -30,7 +31,7 @@ func TestRPCTokenPreCreate(t *testing.T) {
acc
=
mock33
.
GetAccount
(
block
.
StateHash
,
mock33
.
GetHotAddress
())
assert
.
Equal
(
t
,
acc
.
Balance
,
10000
*
types
.
Coin
)
tx
:=
util
.
CreateManageTx
(
mock33
.
GetHotKey
(),
"token-blacklist"
,
"add"
,
"BTY"
)
tx
:=
util
.
CreateManageTx
(
cfg
,
mock33
.
GetHotKey
(),
"token-blacklist"
,
"add"
,
"BTY"
)
reply
,
err
:=
mock33
.
GetAPI
()
.
SendTx
(
tx
)
assert
.
Nil
(
t
,
err
)
detail
,
err
:=
mock33
.
WaitTx
(
reply
.
GetMsg
())
...
...
plugin/dapp/token/rpc/rpc_test.go
View file @
8150a333
...
...
@@ -17,7 +17,9 @@ import (
)
func
newTestChannelClient
()
*
channelClient
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
api
:=
&
mocks
.
QueueProtocolAPI
{}
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
)
return
&
channelClient
{
ChannelClient
:
rpctypes
.
ChannelClient
{
QueueProtocolAPI
:
api
},
}
...
...
@@ -28,7 +30,9 @@ func newTestJrpcClient() *Jrpc {
}
func
testChannelClientGetTokenBalanceToken
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
)
client
:=
&
channelClient
{
ChannelClient
:
rpctypes
.
ChannelClient
{
QueueProtocolAPI
:
api
},
...
...
@@ -46,7 +50,7 @@ func testChannelClientGetTokenBalanceToken(t *testing.T) {
var
addrs
=
make
([]
string
,
1
)
addrs
=
append
(
addrs
,
"1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt"
)
var
in
=
&
tokenty
.
ReqTokenBalance
{
Execer
:
types
.
ExecName
(
tokenty
.
TokenX
),
Execer
:
cfg
.
ExecName
(
tokenty
.
TokenX
),
Addresses
:
addrs
,
TokenSymbol
:
"xxx"
,
}
...
...
@@ -58,7 +62,10 @@ func testChannelClientGetTokenBalanceToken(t *testing.T) {
}
func
testChannelClientGetTokenBalanceOther
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
)
client
:=
&
channelClient
{
ChannelClient
:
rpctypes
.
ChannelClient
{
QueueProtocolAPI
:
api
},
}
...
...
@@ -75,7 +82,7 @@ func testChannelClientGetTokenBalanceOther(t *testing.T) {
var
addrs
=
make
([]
string
,
1
)
addrs
=
append
(
addrs
,
"1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt"
)
var
in
=
&
tokenty
.
ReqTokenBalance
{
Execer
:
types
.
ExecName
(
"trade"
),
Execer
:
cfg
.
ExecName
(
"trade"
),
Addresses
:
addrs
,
TokenSymbol
:
"xxx"
,
}
...
...
plugin/dapp/token/types/types_test.go
View file @
8150a333
...
...
@@ -14,6 +14,10 @@ import (
rpctypes
"github.com/33cn/chain33/rpc/types"
)
func
init
()
{
InitExecutor
(
nil
)
}
func
TestDecodeLogTokenTransfer
(
t
*
testing
.
T
)
{
var
logTmp
=
&
types
.
ReceiptAccountTransfer
{}
dec
:=
types
.
Encode
(
logTmp
)
...
...
plugin/dapp/trade/executor/exec_test.go
View file @
8150a333
...
...
@@ -16,6 +16,9 @@ import (
"github.com/33cn/chain33/util"
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
apimock
"github.com/33cn/chain33/client/mocks"
"strings"
)
type
execEnv
struct
{
...
...
@@ -50,8 +53,13 @@ var (
[]
byte
(
"1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"
),
[]
byte
(
"1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"
),
}
chain33TestCfg
=
types
.
NewChain33Config
(
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
))
)
func
init
()
{
Init
(
pty
.
TradeX
,
chain33TestCfg
,
nil
)
}
func
TestTrade_Exec_SellLimit
(
t
*
testing
.
T
)
{
sellArgs
:=
&
orderArgs
{
100
,
2
,
2
,
100
}
buyArgs
:=
&
orderArgs
{
total
:
5
}
...
...
@@ -71,21 +79,24 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
env
:=
execEnv
{
1539918074
,
types
.
GetDappFork
(
"trade"
,
pty
.
ForkTradePriceX
),
chain33TestCfg
.
GetDappFork
(
"trade"
,
pty
.
ForkTradePriceX
),
2
,
1539918074
,
"hash"
,
}
_
,
ldb
,
kvdb
:=
util
.
CreateTestDB
()
accB
:=
account
.
NewCoinsAccount
()
accB
:=
account
.
NewCoinsAccount
(
chain33TestCfg
)
accB
.
SetDB
(
kvdb
)
accB
.
SaveExecAccount
(
address
.
ExecAddress
(
"trade"
),
&
accountB
)
accA
,
_
:=
account
.
NewAccountDB
(
AssetExecToken
,
Symbol
,
kvdb
)
accA
.
SaveExecAccount
(
address
.
ExecAddress
(
"trade"
),
&
accountA
)
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
driver
:=
newTrade
()
driver
.
SetAPI
(
api
)
driver
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
driver
.
SetStateDB
(
kvdb
)
driver
.
SetLocalDB
(
kvdb
)
...
...
@@ -101,7 +112,7 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
PriceExec
:
"coins"
,
PriceSymbol
:
"bty"
,
}
tx
,
_
:=
pty
.
CreateRawTradeSellTx
(
sell
)
tx
,
_
:=
pty
.
CreateRawTradeSellTx
(
chain33TestCfg
,
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
receipt
,
err
:=
driver
.
Exec
(
tx
,
env
.
index
)
...
...
@@ -142,7 +153,7 @@ func TestTrade_Exec_SellLimit(t *testing.T) {
BoardlotCnt
:
buyArgs
.
total
,
Fee
:
0
,
}
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
buy
)
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
chain33TestCfg
,
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
receipt
,
err
=
driver
.
Exec
(
tx
,
env
.
index
)
if
err
!=
nil
{
...
...
@@ -212,7 +223,7 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
env
:=
execEnv
{
1539918074
,
types
.
GetDappFork
(
"trade"
,
pty
.
ForkTradeAssetX
)
,
-
1
,
2
,
1539918074
,
"hash"
,
...
...
@@ -228,7 +239,10 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
accA
,
_
:=
account
.
NewAccountDB
(
AssetExecPara
,
Symbol
,
stateDB
)
accA
.
SaveExecAccount
(
address
.
ExecAddress
(
"trade"
),
&
accountA
)
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
driver
:=
newTrade
()
driver
.
SetAPI
(
api
)
driver
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
driver
.
SetStateDB
(
stateDB
)
driver
.
SetLocalDB
(
kvdb
)
...
...
@@ -244,7 +258,7 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
PriceExec
:
AssetExecToken
,
PriceSymbol
:
SymbolA
,
}
tx
,
_
:=
pty
.
CreateRawTradeBuyLimitTx
(
buy
)
tx
,
_
:=
pty
.
CreateRawTradeBuyLimitTx
(
chain33TestCfg
,
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
receipt
,
err
:=
driver
.
Exec
(
tx
,
env
.
index
)
...
...
@@ -284,7 +298,7 @@ func TestTrade_Exec_BuyLimit(t *testing.T) {
BoardlotCnt
:
sellArgs
.
total
,
Fee
:
0
,
}
tx
,
_
=
pty
.
CreateRawTradeSellMarketTx
(
sell
)
tx
,
_
=
pty
.
CreateRawTradeSellMarketTx
(
chain33TestCfg
,
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
receipt
,
err
=
driver
.
Exec
(
tx
,
env
.
index
)
if
err
!=
nil
{
...
...
@@ -345,10 +359,10 @@ func signTx(tx *types.Transaction, hexPrivKey string) (*types.Transaction, error
}
func
TestTradeSellFixAssetDB
(
t
*
testing
.
T
)
{
types
.
SetDappFork
(
types
.
GetTitle
(),
pty
.
TradeX
,
pty
.
ForkTradeAssetX
,
int64
(
10
))
types
.
SetDappFork
(
types
.
GetTitle
(),
pty
.
TradeX
,
pty
.
ForkTradeIDX
,
int64
(
10
))
types
.
SetDappFork
(
types
.
GetTitle
(),
pty
.
TradeX
,
pty
.
ForkTradeFixAssetDBX
,
int64
(
20
))
types
.
SetDappFork
(
types
.
GetTitle
(),
pty
.
TradeX
,
pty
.
ForkTradePriceX
,
int64
(
30
))
chain33TestCfg
.
SetDappFork
(
pty
.
TradeX
,
pty
.
ForkTradeAssetX
,
int64
(
10
))
chain33TestCfg
.
SetDappFork
(
pty
.
TradeX
,
pty
.
ForkTradeIDX
,
int64
(
10
))
chain33TestCfg
.
SetDappFork
(
pty
.
TradeX
,
pty
.
ForkTradeFixAssetDBX
,
int64
(
20
))
chain33TestCfg
.
SetDappFork
(
pty
.
TradeX
,
pty
.
ForkTradePriceX
,
int64
(
30
))
sellArgs
:=
&
orderArgs
{
100
,
2
,
2
,
100
}
buyArgs
:=
&
orderArgs
{
total
:
5
}
...
...
@@ -368,7 +382,7 @@ func TestTradeSellFixAssetDB(t *testing.T) {
envA
:=
execEnv
{
1539918074
,
types
.
GetDappFork
(
"trade"
,
pty
.
ForkTradeAssetX
)
-
1
,
chain33TestCfg
.
GetDappFork
(
"trade"
,
pty
.
ForkTradeAssetX
)
-
1
,
2
,
1539918074
,
"hash"
,
...
...
@@ -376,7 +390,7 @@ func TestTradeSellFixAssetDB(t *testing.T) {
envB
:=
execEnv
{
1539918074
,
types
.
GetDappFork
(
"trade"
,
pty
.
ForkTradeFixAssetDBX
)
-
1
,
chain33TestCfg
.
GetDappFork
(
"trade"
,
pty
.
ForkTradeFixAssetDBX
)
-
1
,
2
,
1539918074
,
"hash"
,
...
...
@@ -384,21 +398,24 @@ func TestTradeSellFixAssetDB(t *testing.T) {
envC
:=
execEnv
{
1539918074
,
types
.
GetDappFork
(
"trade"
,
pty
.
ForkTradeFixAssetDBX
),
chain33TestCfg
.
GetDappFork
(
"trade"
,
pty
.
ForkTradeFixAssetDBX
),
2
,
1539918074
,
"hash"
,
}
_
,
ldb
,
kvdb
:=
util
.
CreateTestDB
()
accB
:=
account
.
NewCoinsAccount
()
accB
:=
account
.
NewCoinsAccount
(
chain33TestCfg
)
accB
.
SetDB
(
kvdb
)
accB
.
SaveExecAccount
(
address
.
ExecAddress
(
"trade"
),
&
accountB
)
accA
,
_
:=
account
.
NewAccountDB
(
AssetExecToken
,
Symbol
,
kvdb
)
accA
.
SaveExecAccount
(
address
.
ExecAddress
(
"trade"
),
&
accountA
)
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
driver
:=
newTrade
()
driver
.
SetAPI
(
api
)
driver
.
SetEnv
(
envA
.
blockHeight
,
envA
.
blockTime
,
envA
.
difficulty
)
driver
.
SetStateDB
(
kvdb
)
driver
.
SetLocalDB
(
kvdb
)
...
...
@@ -412,7 +429,7 @@ func TestTradeSellFixAssetDB(t *testing.T) {
Fee
:
0
,
//AssetExec: AssetExecToken,
}
tx
,
_
:=
pty
.
CreateRawTradeSellTx
(
sell
)
tx
,
_
:=
pty
.
CreateRawTradeSellTx
(
chain33TestCfg
,
sell
)
tx
,
_
=
signTx
(
tx
,
PrivKeyA
)
receipt
,
err
:=
driver
.
Exec
(
tx
,
envA
.
index
)
...
...
@@ -454,7 +471,7 @@ func TestTradeSellFixAssetDB(t *testing.T) {
BoardlotCnt
:
buyArgs
.
total
,
Fee
:
0
,
}
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
buyB
)
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
chain33TestCfg
,
buyB
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
receipt
,
err
=
driver
.
Exec
(
tx
,
envB
.
index
)
assert
.
Equal
(
t
,
types
.
ErrNoBalance
,
err
)
...
...
@@ -465,7 +482,7 @@ func TestTradeSellFixAssetDB(t *testing.T) {
BoardlotCnt
:
buyArgs
.
total
,
Fee
:
0
,
}
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
buy
)
tx
,
_
=
pty
.
CreateRawTradeBuyTx
(
chain33TestCfg
,
buy
)
tx
,
_
=
signTx
(
tx
,
PrivKeyB
)
receipt
,
err
=
driver
.
Exec
(
tx
,
envC
.
index
)
if
err
!=
nil
{
...
...
plugin/dapp/trade/executor/trade_test.go
View file @
8150a333
...
...
@@ -128,6 +128,6 @@ func TestPriceCheck(t *testing.T) {
}
for
_
,
c
:=
range
cases
{
assert
.
Equal
(
t
,
c
.
result
,
checkPrice
(
types
.
GetDappFork
(
pty
.
TradeX
,
pty
.
ForkTradePriceX
),
c
.
exec
,
c
.
symbol
))
assert
.
Equal
(
t
,
c
.
result
,
checkPrice
(
chain33TestCfg
,
chain33TestCfg
.
GetDappFork
(
pty
.
TradeX
,
pty
.
ForkTradePriceX
),
c
.
exec
,
c
.
symbol
))
}
}
plugin/dapp/trade/rpc/jrpc_test.go
View file @
8150a333
...
...
@@ -8,7 +8,6 @@ import (
"encoding/hex"
"testing"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client/mocks"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
...
...
@@ -17,17 +16,20 @@ import (
"github.com/stretchr/testify/mock"
)
func
newTestChain33
(
api
client
.
QueueProtocolAPI
)
*
Jrpc
{
func
newTestChain33
()
(
*
mocks
.
QueueProtocolAPI
,
*
Jrpc
)
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
cli
:=
&
channelClient
{
ChannelClient
:
rpctypes
.
ChannelClient
{
QueueProtocolAPI
:
api
,
},
}
return
&
Jrpc
{
cli
:
cli
}
return
api
,
&
Jrpc
{
cli
:
cli
}
}
func
TestChain33_CreateRawTradeSellTx
(
t
*
testing
.
T
)
{
client
:=
newTestChain33
(
nil
)
_
,
client
:=
newTestChain33
(
)
var
testResult
interface
{}
err
:=
client
.
CreateRawTradeSellTx
(
nil
,
&
testResult
)
assert
.
NotNil
(
t
,
err
)
...
...
@@ -48,7 +50,7 @@ func TestChain33_CreateRawTradeSellTx(t *testing.T) {
}
func
TestChain33_CreateRawTradeBuyTx
(
t
*
testing
.
T
)
{
client
:=
newTestChain33
(
nil
)
_
,
client
:=
newTestChain33
(
)
var
testResult
interface
{}
err
:=
client
.
CreateRawTradeBuyTx
(
nil
,
&
testResult
)
assert
.
NotNil
(
t
,
err
)
...
...
@@ -66,7 +68,7 @@ func TestChain33_CreateRawTradeBuyTx(t *testing.T) {
}
func
TestChain33_CreateRawTradeRevokeTx
(
t
*
testing
.
T
)
{
client
:=
newTestChain33
(
nil
)
_
,
client
:=
newTestChain33
(
)
var
testResult
interface
{}
err
:=
client
.
CreateRawTradeRevokeTx
(
nil
,
&
testResult
)
assert
.
NotNil
(
t
,
err
)
...
...
@@ -84,7 +86,7 @@ func TestChain33_CreateRawTradeRevokeTx(t *testing.T) {
}
func
TestChain33_CreateRawTradeBuyLimitTx
(
t
*
testing
.
T
)
{
client
:=
newTestChain33
(
nil
)
_
,
client
:=
newTestChain33
(
)
var
testResult
interface
{}
err
:=
client
.
CreateRawTradeBuyLimitTx
(
nil
,
&
testResult
)
assert
.
NotNil
(
t
,
err
)
...
...
@@ -106,7 +108,7 @@ func TestChain33_CreateRawTradeBuyLimitTx(t *testing.T) {
}
func
TestChain33_CreateRawTradeSellMarketTx
(
t
*
testing
.
T
)
{
client
:=
newTestChain33
(
nil
)
_
,
client
:=
newTestChain33
(
)
var
testResult
interface
{}
err
:=
client
.
CreateRawTradeSellMarketTx
(
nil
,
&
testResult
)
assert
.
NotNil
(
t
,
err
)
...
...
@@ -125,7 +127,7 @@ func TestChain33_CreateRawTradeSellMarketTx(t *testing.T) {
}
func
TestChain33_CreateRawTradeRevokeBuyTx
(
t
*
testing
.
T
)
{
client
:=
newTestChain33
(
nil
)
_
,
client
:=
newTestChain33
(
)
var
testResult
interface
{}
err
:=
client
.
CreateRawTradeRevokeBuyTx
(
nil
,
&
testResult
)
assert
.
NotNil
(
t
,
err
)
...
...
@@ -274,14 +276,14 @@ func TestDecodeLogTradeBuyMarket(t *testing.T) {
}
func
TestChain33_GetLastMemPoolOk
(
t
*
testing
.
T
)
{
api
:=
new
(
mocks
.
QueueProtocolAPI
)
testChain33
:=
newTestChain33
(
api
)
api
,
testChain33
:=
newTestChain33
(
)
cfg
:=
api
.
GetConfig
(
)
var
txlist
types
.
ReplyTxList
var
action
pty
.
Trade
act
:=
types
.
Encode
(
&
action
)
var
tx
=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
pty
.
TradeX
)),
Execer
:
[]
byte
(
cfg
.
ExecName
(
pty
.
TradeX
)),
Payload
:
act
,
To
:
"to"
,
}
...
...
plugin/dapp/trade/rpc/rpc_test.go
View file @
8150a333
...
...
@@ -12,12 +12,17 @@ import (
rpctypes
"github.com/33cn/chain33/rpc/types"
ptypes
"github.com/33cn/plugin/plugin/dapp/trade/types"
"github.com/stretchr/testify/assert"
"github.com/33cn/chain33/types"
"github.com/stretchr/testify/mock"
)
func
newTestChannelClient
()
*
Grpc
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
cli
:=
&
channelClient
{
ChannelClient
:
rpctypes
.
ChannelClient
{
QueueProtocolAPI
:
&
mocks
.
QueueProtocolAPI
{}
,
QueueProtocolAPI
:
api
,
},
}
return
&
Grpc
{
channelClient
:
cli
}
...
...
plugin/dapp/trade/types/trade_test.go
View file @
8150a333
...
...
@@ -8,22 +8,26 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/33cn/chain33/types"
)
func
TestTradeType_GetName
(
t
*
testing
.
T
)
{
tp
:=
NewType
()
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
tp
:=
NewType
(
cfg
)
assert
.
Equal
(
t
,
TradeX
,
tp
.
GetName
())
}
func
TestTradeType_GetTypeMap
(
t
*
testing
.
T
)
{
tp
:=
NewType
()
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
tp
:=
NewType
(
cfg
)
actoins
:=
tp
.
GetTypeMap
()
assert
.
NotNil
(
t
,
actoins
)
assert
.
NotEqual
(
t
,
0
,
len
(
actoins
))
}
func
TestTradeType_GetLogMap
(
t
*
testing
.
T
)
{
tp
:=
NewType
()
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
tp
:=
NewType
(
cfg
)
l
:=
tp
.
GetLogMap
()
assert
.
NotNil
(
t
,
l
)
assert
.
NotEqual
(
t
,
0
,
len
(
l
))
...
...
plugin/dapp/unfreeze/executor/exec_test.go
View file @
8150a333
...
...
@@ -19,6 +19,9 @@ import (
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
pty
"github.com/33cn/plugin/plugin/dapp/unfreeze/types"
"strings"
"github.com/stretchr/testify/mock"
apimock
"github.com/33cn/chain33/client/mocks"
)
type
execEnv
struct
{
...
...
@@ -42,10 +45,14 @@ var (
[]
byte
(
"1NLHPEcbTWWxxU3dGUZBhayjrCHD3psX7k"
),
[]
byte
(
"1MCftFynyvG2F4ED5mdHYgziDxx6vDrScs"
),
}
chain33TestCfg
=
types
.
NewChain33Config
(
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
))
)
func
init
()
{
Init
(
pty
.
UnfreezeX
,
chain33TestCfg
,
nil
)
}
func
TestUnfreeze
(
t
*
testing
.
T
)
{
types
.
SetTitleOnlyForTest
(
"chain33"
)
total
:=
int64
(
100000
)
accountA
:=
types
.
Account
{
Balance
:
total
,
...
...
@@ -70,10 +77,11 @@ func TestUnfreeze(t *testing.T) {
env
:=
execEnv
{
10
,
types
.
GetDappFork
(
pty
.
UnfreezeX
,
pty
.
ForkUnfreezeIDX
),
chain33TestCfg
.
GetDappFork
(
pty
.
UnfreezeX
,
pty
.
ForkUnfreezeIDX
),
1539918074
,
}
ty
:=
pty
.
UnfreezeType
{}
ty
.
SetConfig
(
chain33TestCfg
)
// 创建
opt
:=
&
pty
.
FixAmount
{
Period
:
10
,
Amount
:
2
}
...
...
@@ -94,7 +102,10 @@ func TestUnfreeze(t *testing.T) {
if
err
!=
nil
{
t
.
Error
(
"RPC_UnfreezeCreateTx sign"
,
"err"
,
err
)
}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
chain33TestCfg
,
nil
)
exec
:=
newUnfreeze
()
exec
.
SetAPI
(
api
)
exec
.
SetStateDB
(
stateDB
)
exec
.
SetLocalDB
(
kvdb
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
...
...
plugin/dapp/unfreeze/executor/means_test.go
View file @
8150a333
...
...
@@ -5,13 +5,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/unfreeze/types"
)
func
TestCalcFrozen
(
t
*
testing
.
T
)
{
types
.
SetTitleOnlyForTest
(
"chain33"
)
m
,
err
:=
newMeans
(
"LeftProportion"
,
15000000
)
m
,
err
:=
newMeans
(
chain33TestCfg
,
"LeftProportion"
,
15000000
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
m
)
...
...
plugin/dapp/valnode/rpc/rpc_test.go
View file @
8150a333
...
...
@@ -18,6 +18,8 @@ import (
vt
"github.com/33cn/plugin/plugin/dapp/valnode/types"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
"strings"
"github.com/stretchr/testify/mock"
)
func
newGrpc
(
api
client
.
QueueProtocolAPI
)
*
channelClient
{
...
...
@@ -31,7 +33,9 @@ func newJrpc(api client.QueueProtocolAPI) *Jrpc {
}
func
TestChannelClient_IsSync
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
))
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"valnode"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqNil
{}
...
...
@@ -53,7 +57,9 @@ func TestJrpc_IsSync(t *testing.T) {
}
func
TestChannelClient_GetNodeInfo
(
t
*
testing
.
T
)
{
cfg
:=
types
.
NewChain33Config
(
strings
.
Replace
(
types
.
GetDefaultCfgstring
(),
"Title=
\"
local
\"
"
,
"Title=
\"
chain33
\"
"
,
1
))
api
:=
new
(
mocks
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
client
:=
newGrpc
(
api
)
client
.
Init
(
"valnode"
,
nil
,
nil
,
nil
)
req
:=
&
types
.
ReqNil
{}
...
...
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