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