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
c914326a
Commit
c914326a
authored
Sep 12, 2019
by
mdj33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ut
parent
3b91705f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
40 deletions
+78
-40
ticket_test.go
plugin/dapp/ticket/testnode/ticket_test.go
+55
-0
ticket_test.go
plugin/dapp/ticket/wallet/ticket_test.go
+23
-40
No files found.
plugin/dapp/ticket/testnode/ticket_test.go
0 → 100644
View file @
c914326a
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
testnode
import
(
"testing"
"github.com/33cn/chain33/util/testnode"
ty
"github.com/33cn/plugin/plugin/dapp/ticket/types"
ticketwallet
"github.com/33cn/plugin/plugin/dapp/ticket/wallet"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
_
"github.com/33cn/plugin/plugin"
)
func
Test_WalletTicket
(
t
*
testing
.
T
)
{
minerAddr
:=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
t
.
Log
(
"Begin wallet ticket test"
)
cfg
,
sub
:=
testnode
.
GetDefaultConfig
()
cfg
.
Consensus
.
Name
=
"ticket"
mock33
:=
testnode
.
NewWithConfig
(
cfg
,
sub
,
nil
)
defer
mock33
.
Close
()
err
:=
mock33
.
WaitHeight
(
0
)
assert
.
Nil
(
t
,
err
)
msg
,
err
:=
mock33
.
GetAPI
()
.
Query
(
ty
.
TicketX
,
"TicketList"
,
&
ty
.
TicketList
{
Addr
:
minerAddr
,
Status
:
1
})
assert
.
Nil
(
t
,
err
)
ticketList
:=
msg
.
(
*
ty
.
ReplyTicketList
)
assert
.
NotNil
(
t
,
ticketList
)
//return
ticketwallet
.
FlushTicket
(
mock33
.
GetAPI
())
err
=
mock33
.
WaitHeight
(
2
)
assert
.
Nil
(
t
,
err
)
header
,
err
:=
mock33
.
GetAPI
()
.
GetLastHeader
()
require
.
Equal
(
t
,
err
,
nil
)
require
.
Equal
(
t
,
header
.
Height
>=
2
,
true
)
in
:=
&
ty
.
TicketClose
{
MinerAddress
:
minerAddr
}
msg
,
err
=
mock33
.
GetAPI
()
.
ExecWalletFunc
(
ty
.
TicketX
,
"CloseTickets"
,
in
)
assert
.
Nil
(
t
,
err
)
hashes
:=
msg
.
(
*
types
.
ReplyHashes
)
assert
.
NotNil
(
t
,
hashes
)
in
=
&
ty
.
TicketClose
{}
msg
,
err
=
mock33
.
GetAPI
()
.
ExecWalletFunc
(
ty
.
TicketX
,
"CloseTickets"
,
in
)
assert
.
Nil
(
t
,
err
)
hashes
=
msg
.
(
*
types
.
ReplyHashes
)
assert
.
NotNil
(
t
,
hashes
)
t
.
Log
(
"End wallet ticket test"
)
}
plugin/dapp/ticket/wallet/ticket_test.go
View file @
c914326a
...
...
@@ -16,7 +16,6 @@ import (
wcom
"github.com/33cn/chain33/wallet/common"
ty
"github.com/33cn/plugin/plugin/dapp/ticket/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
...
...
@@ -27,40 +26,14 @@ import (
"github.com/33cn/chain33/common/db"
)
func
Test_WalletTicket
(
t
*
testing
.
T
)
{
minerAddr
:=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv
"
t
.
Log
(
"Begin wallet ticket test"
)
const
(
sendhash
=
"sendhash
"
)
cfg
,
sub
:=
testnode
.
GetDefaultConfig
()
func
init
()
{
cfg
,
_
:=
testnode
.
GetDefaultConfig
()
cfg
.
Consensus
.
Name
=
"ticket"
mock33
:=
testnode
.
NewWithConfig
(
cfg
,
sub
,
nil
)
defer
mock33
.
Close
()
err
:=
mock33
.
WaitHeight
(
0
)
assert
.
Nil
(
t
,
err
)
msg
,
err
:=
mock33
.
GetAPI
()
.
Query
(
ty
.
TicketX
,
"TicketList"
,
&
ty
.
TicketList
{
Addr
:
minerAddr
,
Status
:
1
})
assert
.
Nil
(
t
,
err
)
ticketList
:=
msg
.
(
*
ty
.
ReplyTicketList
)
assert
.
NotNil
(
t
,
ticketList
)
//return
FlushTicket
(
mock33
.
GetAPI
())
err
=
mock33
.
WaitHeight
(
2
)
assert
.
Nil
(
t
,
err
)
header
,
err
:=
mock33
.
GetAPI
()
.
GetLastHeader
()
require
.
Equal
(
t
,
err
,
nil
)
require
.
Equal
(
t
,
header
.
Height
>=
2
,
true
)
in
:=
&
ty
.
TicketClose
{
MinerAddress
:
minerAddr
}
msg
,
err
=
mock33
.
GetAPI
()
.
ExecWalletFunc
(
ty
.
TicketX
,
"CloseTickets"
,
in
)
assert
.
Nil
(
t
,
err
)
hashes
:=
msg
.
(
*
types
.
ReplyHashes
)
assert
.
NotNil
(
t
,
hashes
)
in
=
&
ty
.
TicketClose
{}
msg
,
err
=
mock33
.
GetAPI
()
.
ExecWalletFunc
(
ty
.
TicketX
,
"CloseTickets"
,
in
)
assert
.
Nil
(
t
,
err
)
hashes
=
msg
.
(
*
types
.
ReplyHashes
)
assert
.
NotNil
(
t
,
hashes
)
t
.
Log
(
"End wallet ticket test"
)
types
.
Init
(
cfg
.
Title
,
cfg
)
}
func
Test_ForceCloseTicketList
(
t
*
testing
.
T
)
{
...
...
@@ -73,7 +46,7 @@ func Test_ForceCloseTicketList(t *testing.T) {
tlist
:=
[]
*
ty
.
Ticket
{
t1
,
t2
,
t3
}
r1
,
r2
:=
ticket
.
forceCloseTicketList
(
0
,
nil
,
tlist
)
assert
.
Nil
(
t
,
r1
)
assert
.
Equal
(
t
,
[]
byte
(
sendhash
)
,
r1
)
assert
.
Nil
(
t
,
r2
)
}
...
...
@@ -99,7 +72,9 @@ func Test_CloseTicketsByAddr(t *testing.T) {
tlist
:=
&
ty
.
ReplyTicketList
{
Tickets
:
[]
*
ty
.
Ticket
{
t1
,
t2
,
t3
}}
qapi
.
On
(
"Query"
,
ty
.
TicketX
,
"TicketList"
,
mock
.
Anything
)
.
Return
(
tlist
,
nil
)
ticket
.
closeTicketsByAddr
(
0
,
priKey
)
r1
,
r2
:=
ticket
.
closeTicketsByAddr
(
0
,
priKey
)
assert
.
Equal
(
t
,
[]
byte
(
sendhash
),
r1
)
assert
.
Nil
(
t
,
r2
)
}
...
...
@@ -113,7 +88,10 @@ func Test_BuyTicketOne(t *testing.T) {
assert
.
Nil
(
t
,
err
)
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
assert
.
Nil
(
t
,
err
)
ticket
.
buyTicketOne
(
0
,
priKey
)
hash
,
r1
,
r2
:=
ticket
.
buyTicketOne
(
0
,
priKey
)
assert
.
Equal
(
t
,
[]
byte
(
sendhash
),
hash
)
assert
.
Equal
(
t
,
10
,
r1
)
assert
.
Nil
(
t
,
r2
)
}
...
...
@@ -126,6 +104,8 @@ func Test_BuyMinerAddrTicketOne(t *testing.T) {
assert
.
Nil
(
t
,
err
)
ticket
:=
&
ticketPolicy
{
mtx
:
&
sync
.
Mutex
{}}
ticket
.
cfg
=
&
subConfig
{}
ticket
.
initMinerWhiteList
(
nil
)
wallet
:=
new
(
walletOperateMock
)
qapi
:=
new
(
mocks
.
QueueProtocolAPI
)
wallet
.
api
=
qapi
...
...
@@ -134,7 +114,10 @@ func Test_BuyMinerAddrTicketOne(t *testing.T) {
tlist
:=
&
types
.
ReplyStrings
{
Datas
:
[]
string
{
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
}}
qapi
.
On
(
"Query"
,
ty
.
TicketX
,
"MinerSourceList"
,
mock
.
Anything
)
.
Return
(
tlist
,
nil
)
ticket
.
buyMinerAddrTicketOne
(
0
,
priKey
)
hashs
,
r2
,
r3
:=
ticket
.
buyMinerAddrTicketOne
(
0
,
priKey
)
assert
.
Equal
(
t
,
[][]
byte
{[]
byte
(
sendhash
)},
hashs
)
assert
.
Equal
(
t
,
10
,
r2
)
assert
.
Nil
(
t
,
r3
)
}
...
...
@@ -164,7 +147,7 @@ func (_m *walletOperateMock) GetAllPrivKeys() ([]crypto.PrivKey, error) {
// GetBalance provides a mock function with given fields: addr, execer
func
(
_m
*
walletOperateMock
)
GetBalance
(
addr
string
,
execer
string
)
(
*
types
.
Account
,
error
)
{
return
&
types
.
Account
{
Balance
:
10
},
nil
return
&
types
.
Account
{
Balance
:
10
000000000000
,
Addr
:
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
},
nil
}
// GetBlockHeight provides a mock function with given fields:
...
...
@@ -259,12 +242,12 @@ func (_m *walletOperateMock) RegisterMineStatusReporter(reporter wcom.MineStatus
// SendToAddress provides a mock function with given fields: priv, addrto, amount, note, Istoken, tokenSymbol
func
(
_m
*
walletOperateMock
)
SendToAddress
(
priv
crypto
.
PrivKey
,
addrto
string
,
amount
int64
,
note
string
,
Istoken
bool
,
tokenSymbol
string
)
(
*
types
.
ReplyHash
,
error
)
{
return
nil
,
nil
return
&
types
.
ReplyHash
{
Hash
:
[]
byte
(
sendhash
)}
,
nil
}
// SendTransaction provides a mock function with given fields: payload, execer, priv, to
func
(
_m
*
walletOperateMock
)
SendTransaction
(
payload
types
.
Message
,
execer
[]
byte
,
priv
crypto
.
PrivKey
,
to
string
)
([]
byte
,
error
)
{
return
nil
,
nil
return
[]
byte
(
sendhash
)
,
nil
}
// WaitTx provides a mock function with given fields: hash
...
...
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