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
277b2f9f
Commit
277b2f9f
authored
Sep 11, 2019
by
mdj33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ut
parent
060344b0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
234 additions
and
4 deletions
+234
-4
ticket_test.go
plugin/dapp/ticket/wallet/ticket_test.go
+234
-4
No files found.
plugin/dapp/ticket/wallet/ticket_test.go
View file @
277b2f9f
...
@@ -2,20 +2,28 @@
...
@@ -2,20 +2,28 @@
// Use of this source code is governed by a BSD-style
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// license that can be found in the LICENSE file.
package
wallet
_test
package
wallet
import
(
import
(
"encoding/hex"
"github.com/stretchr/testify/mock"
"math/rand"
"sync"
"testing"
"testing"
"github.com/33cn/chain33/util/testnode"
"github.com/33cn/chain33/util/testnode"
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"
ticketwallet
"github.com/33cn/plugin/plugin/dapp/ticket/wallet"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
_
"github.com/33cn/plugin/plugin"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/db"
)
)
func
Test_WalletTicket
(
t
*
testing
.
T
)
{
func
Test_WalletTicket
(
t
*
testing
.
T
)
{
...
@@ -33,7 +41,7 @@ func Test_WalletTicket(t *testing.T) {
...
@@ -33,7 +41,7 @@ func Test_WalletTicket(t *testing.T) {
ticketList
:=
msg
.
(
*
ty
.
ReplyTicketList
)
ticketList
:=
msg
.
(
*
ty
.
ReplyTicketList
)
assert
.
NotNil
(
t
,
ticketList
)
assert
.
NotNil
(
t
,
ticketList
)
//return
//return
ticketwallet
.
FlushTicket
(
mock33
.
GetAPI
())
FlushTicket
(
mock33
.
GetAPI
())
err
=
mock33
.
WaitHeight
(
2
)
err
=
mock33
.
WaitHeight
(
2
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
header
,
err
:=
mock33
.
GetAPI
()
.
GetLastHeader
()
header
,
err
:=
mock33
.
GetAPI
()
.
GetLastHeader
()
...
@@ -53,3 +61,224 @@ func Test_WalletTicket(t *testing.T) {
...
@@ -53,3 +61,224 @@ func Test_WalletTicket(t *testing.T) {
assert
.
NotNil
(
t
,
hashes
)
assert
.
NotNil
(
t
,
hashes
)
t
.
Log
(
"End wallet ticket test"
)
t
.
Log
(
"End wallet ticket test"
)
}
}
func
Test_ForceCloseTicketList
(
t
*
testing
.
T
)
{
ticket
:=
&
ticketPolicy
{
mtx
:&
sync
.
Mutex
{}}
ticket
.
walletOperate
=
new
(
walletOperateMock
)
t1
:=
&
ty
.
Ticket
{
Status
:
1
,
IsGenesis
:
false
}
t2
:=
&
ty
.
Ticket
{
Status
:
2
,
IsGenesis
:
false
}
t3
:=
&
ty
.
Ticket
{
Status
:
3
,
IsGenesis
:
false
}
tlist
:=
[]
*
ty
.
Ticket
{
t1
,
t2
,
t3
}
r1
,
r2
:=
ticket
.
forceCloseTicketList
(
0
,
nil
,
tlist
)
assert
.
Nil
(
t
,
r1
)
assert
.
Nil
(
t
,
r2
)
}
func
Test_CloseTicketsByAddr
(
t
*
testing
.
T
)
{
pk
,
err
:=
hex
.
DecodeString
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
)
assert
.
Nil
(
t
,
err
)
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
assert
.
Nil
(
t
,
err
)
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
assert
.
Nil
(
t
,
err
)
ticket
:=
&
ticketPolicy
{
mtx
:&
sync
.
Mutex
{}}
wallet
:=
new
(
walletOperateMock
)
qapi
:=
new
(
mocks
.
QueueProtocolAPI
)
wallet
.
api
=
qapi
ticket
.
walletOperate
=
wallet
t1
:=
&
ty
.
Ticket
{
Status
:
1
,
IsGenesis
:
false
}
t2
:=
&
ty
.
Ticket
{
Status
:
2
,
IsGenesis
:
false
}
t3
:=
&
ty
.
Ticket
{
Status
:
3
,
IsGenesis
:
false
}
tlist
:=
&
ty
.
ReplyTicketList
{
Tickets
:
[]
*
ty
.
Ticket
{
t1
,
t2
,
t3
}}
qapi
.
On
(
"Query"
,
ty
.
TicketX
,
"TicketList"
,
mock
.
Anything
)
.
Return
(
tlist
,
nil
)
ticket
.
closeTicketsByAddr
(
0
,
priKey
)
}
func
Test_BuyTicketOne
(
t
*
testing
.
T
)
{
ticket
:=
&
ticketPolicy
{
mtx
:&
sync
.
Mutex
{}}
ticket
.
walletOperate
=
new
(
walletOperateMock
)
pk
,
err
:=
hex
.
DecodeString
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
)
assert
.
Nil
(
t
,
err
)
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
assert
.
Nil
(
t
,
err
)
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
assert
.
Nil
(
t
,
err
)
ticket
.
buyTicketOne
(
0
,
priKey
)
}
func
Test_BuyMinerAddrTicketOne
(
t
*
testing
.
T
)
{
pk
,
err
:=
hex
.
DecodeString
(
"CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944"
)
assert
.
Nil
(
t
,
err
)
secp
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
""
,
types
.
SECP256K1
))
assert
.
Nil
(
t
,
err
)
priKey
,
err
:=
secp
.
PrivKeyFromBytes
(
pk
)
assert
.
Nil
(
t
,
err
)
ticket
:=
&
ticketPolicy
{
mtx
:&
sync
.
Mutex
{}}
wallet
:=
new
(
walletOperateMock
)
qapi
:=
new
(
mocks
.
QueueProtocolAPI
)
wallet
.
api
=
qapi
ticket
.
walletOperate
=
wallet
tlist
:=
&
types
.
ReplyStrings
{
Datas
:
[]
string
{
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
}}
qapi
.
On
(
"Query"
,
ty
.
TicketX
,
"MinerSourceList"
,
mock
.
Anything
)
.
Return
(
tlist
,
nil
)
ticket
.
buyMinerAddrTicketOne
(
0
,
priKey
)
}
type
walletOperateMock
struct
{
api
client
.
QueueProtocolAPI
}
func
(
_m
*
walletOperateMock
)
AddrInWallet
(
addr
string
)
bool
{
return
false
}
// CheckWalletStatus provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
CheckWalletStatus
()
(
bool
,
error
)
{
return
false
,
nil
}
// GetAPI provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetAPI
()
client
.
QueueProtocolAPI
{
return
_m
.
api
}
// GetAllPrivKeys provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetAllPrivKeys
()
([]
crypto
.
PrivKey
,
error
)
{
return
nil
,
nil
}
// 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
}
// GetBlockHeight provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetBlockHeight
()
int64
{
return
0
}
// GetConfig provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetConfig
()
*
types
.
Wallet
{
return
nil
}
// GetDBStore provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetDBStore
()
db
.
DB
{
return
nil
}
// GetLastHeader provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetLastHeader
()
*
types
.
Header
{
return
nil
}
// GetMutex provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetMutex
()
*
sync
.
Mutex
{
return
nil
}
// GetPassword provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetPassword
()
string
{
return
""
}
// GetPrivKeyByAddr provides a mock function with given fields: addr
func
(
_m
*
walletOperateMock
)
GetPrivKeyByAddr
(
addr
string
)
(
crypto
.
PrivKey
,
error
)
{
return
nil
,
nil
}
// GetRandom provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetRandom
()
*
rand
.
Rand
{
return
nil
}
// GetSignType provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetSignType
()
int
{
return
0
}
// GetTxDetailByHashs provides a mock function with given fields: ReqHashes
func
(
_m
*
walletOperateMock
)
GetTxDetailByHashs
(
ReqHashes
*
types
.
ReqHashes
)
{
return
}
// GetWaitGroup provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetWaitGroup
()
*
sync
.
WaitGroup
{
return
nil
}
// GetWalletAccounts provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetWalletAccounts
()
([]
*
types
.
WalletAccountStore
,
error
)
{
return
nil
,
nil
}
// GetWalletDone provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
GetWalletDone
()
chan
struct
{}
{
return
nil
}
// IsCaughtUp provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
IsCaughtUp
()
bool
{
return
false
}
// IsClose provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
IsClose
()
bool
{
return
false
}
// IsWalletLocked provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
IsWalletLocked
()
bool
{
return
true
}
// Nonce provides a mock function with given fields:
func
(
_m
*
walletOperateMock
)
Nonce
()
int64
{
return
0
}
// RegisterMineStatusReporter provides a mock function with given fields: reporter
func
(
_m
*
walletOperateMock
)
RegisterMineStatusReporter
(
reporter
wcom
.
MineStatusReport
)
error
{
return
nil
}
// 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
}
// 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
}
// WaitTx provides a mock function with given fields: hash
func
(
_m
*
walletOperateMock
)
WaitTx
(
hash
[]
byte
)
*
types
.
TransactionDetail
{
return
nil
}
// WaitTxs provides a mock function with given fields: hashes
func
(
_m
*
walletOperateMock
)
WaitTxs
(
hashes
[][]
byte
)
[]
*
types
.
TransactionDetail
{
return
nil
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment