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
8e085e1c
Commit
8e085e1c
authored
Oct 11, 2019
by
张振华
Committed by
vipwzw
Oct 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix
parent
1f65d2e8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
39 deletions
+38
-39
game_test.go
plugin/dapp/guess/commands/game_test.go
+2
-3
guess_test.go
plugin/dapp/guess/rpc/guess_test.go
+23
-23
const.go
plugin/dapp/guess/types/const.go
+13
-13
No files found.
plugin/dapp/guess/commands/game_test.go
View file @
8e085e1c
...
...
@@ -7,8 +7,6 @@ import (
"errors"
"flag"
"fmt"
"github.com/33cn/chain33/system/consensus/solo"
"github.com/spf13/cobra"
"io/ioutil"
"math/rand"
"os"
...
...
@@ -26,13 +24,14 @@ import (
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/rpc"
"github.com/33cn/chain33/store"
"github.com/33cn/chain33/system/consensus/solo"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
_
"github.com/33cn/chain33/system"
_
"github.com/33cn/chain33/system/consensus/solo"
_
"github.com/33cn/plugin/plugin/store/init"
cty
"github.com/33cn/chain33/system/dapp/coins/types"
...
...
plugin/dapp/guess/rpc/guess_test.go
View file @
8e085e1c
...
...
@@ -454,7 +454,7 @@ func testGuessImp(t *testing.T) {
strGameID1
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
reply
:=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusStart
)
fmt
.
Println
(
"=======start sendGuessBetTx!======="
)
ok
,
txid
:=
sendGuessBetTx
(
strGameID1
,
"A"
,
5e8
,
userAPriv
)
...
...
@@ -465,7 +465,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
8
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusBet
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
1
)
ok
,
txid
=
sendGuessBetTx
(
strGameID1
,
"B"
,
5e8
,
userBPriv
)
if
!
ok
{
...
...
@@ -475,7 +475,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
8
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusBet
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
fmt
.
Println
(
"=======start sendGuessStopTx failed!======="
)
ok
,
txid
=
sendGuessStopTx
(
strGameID1
,
userBPriv
)
...
...
@@ -486,7 +486,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
8
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusBet
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
fmt
.
Println
(
"=======start sendGuessStopTx!======="
)
ok
,
txid
=
sendGuessStopTx
(
strGameID1
,
adminPriv
)
...
...
@@ -497,7 +497,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
9
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusStopBet
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
fmt
.
Println
(
"=======start sendGuessBetTx failed!======="
)
ok
,
txid
=
sendGuessBetTx
(
strGameID1
,
"A"
,
5e8
,
userAPriv
)
...
...
@@ -508,7 +508,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
9
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusStopBet
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
fmt
.
Println
(
"=======start sendGuessPublishTx failed!======="
)
ok
,
txid
=
sendGuessPublishTx
(
strGameID1
,
"A"
,
userAPriv
)
...
...
@@ -519,7 +519,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
9
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusStopBet
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
fmt
.
Println
(
"=======start sendGuessPublishTx!======="
)
ok
,
txid
=
sendGuessPublishTx
(
strGameID1
,
"A"
,
adminPriv
)
...
...
@@ -530,7 +530,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
11
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusPublish
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
fmt
.
Println
(
"=======start sendGuessAbortTx!======="
)
ok
,
txid
=
sendGuessAbortTx
(
strGameID1
,
adminPriv
)
...
...
@@ -541,7 +541,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
11
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusPublish
&&
reply
.
Games
[
0
]
.
BetStat
.
TotalBetTimes
==
2
)
//再来一次,测试异常流程:start->abort->stop
fmt
.
Println
(
"=======start sendGuessStartTx!======="
)
...
...
@@ -556,7 +556,7 @@ func testGuessImp(t *testing.T) {
strGameID2
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
reply
=
queryGuessByIds
(
strGameID2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusStart
)
fmt
.
Println
(
"=======start sendGuessAbortTx!======="
)
ok
,
txid
=
sendGuessAbortTx
(
strGameID2
,
adminPriv
)
...
...
@@ -567,7 +567,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
10
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusAbort
)
fmt
.
Println
(
"=======start sendGuessStopTx failed!======="
)
ok
,
txid
=
sendGuessStopTx
(
strGameID2
,
adminPriv
)
...
...
@@ -578,7 +578,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID2
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
10
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusAbort
)
//再来一次,测试流程:start->stop->abort
fmt
.
Println
(
"=======start sendGuessStartTx!======="
)
...
...
@@ -592,7 +592,7 @@ func testGuessImp(t *testing.T) {
strGameID3
:=
"0x"
+
hex
.
EncodeToString
(
gameid
)
reply
=
queryGuessByIds
(
strGameID3
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
7
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusStart
)
fmt
.
Println
(
"=======start sendGuessStopTx!======="
)
ok
,
txid
=
sendGuessStopTx
(
strGameID3
,
adminPriv
)
...
...
@@ -603,7 +603,7 @@ func testGuessImp(t *testing.T) {
}
time
.
Sleep
(
2
*
time
.
Second
)
reply
=
queryGuessByIds
(
strGameID3
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
9
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusStopBet
)
fmt
.
Println
(
"=======start sendGuessAbortTx!======="
)
ok
,
txid
=
sendGuessAbortTx
(
strGameID3
,
adminPriv
)
...
...
@@ -617,11 +617,11 @@ func testGuessImp(t *testing.T) {
//以下测试查询接口
fmt
.
Println
(
"=======start queryGuessByIds!======="
)
reply
=
queryGuessByIds
(
strGameID3
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
10
)
assert
.
Equal
(
t
,
true
,
reply
.
Games
[
0
]
.
Status
==
gty
.
GuessGameStatusAbort
)
fmt
.
Println
(
"=======start queryGuessByID!======="
)
reply2
:=
queryGuessByID
(
strGameID1
)
assert
.
Equal
(
t
,
true
,
reply2
.
Game
.
Status
==
11
&&
reply2
.
Game
.
BetStat
.
TotalBetTimes
==
2
)
assert
.
Equal
(
t
,
true
,
reply2
.
Game
.
Status
==
gty
.
GuessGameStatusPublish
&&
reply2
.
Game
.
BetStat
.
TotalBetTimes
==
2
)
fmt
.
Println
(
"=======start queryGuessByAddr!======="
)
record
:=
queryGuessByAddr
(
userAAddr
)
...
...
@@ -629,10 +629,10 @@ func testGuessImp(t *testing.T) {
fmt
.
Println
(
"=======start queryGuessByStatus!======="
)
record
=
queryGuessByStatus
(
11
)
record
=
queryGuessByStatus
(
gty
.
GuessGameStatusPublish
)
assert
.
Equal
(
t
,
true
,
record
.
Records
[
0
]
.
GameID
==
strGameID1
)
record
=
queryGuessByStatus
(
10
)
record
=
queryGuessByStatus
(
gty
.
GuessGameStatusAbort
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
2
)
fmt
.
Println
(
"=======start queryGuessByAdminAddr!======="
)
...
...
@@ -640,23 +640,23 @@ func testGuessImp(t *testing.T) {
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
3
)
fmt
.
Println
(
"=======start queryGuessByAddrStatus!======="
)
record
=
queryGuessByAddrStatus
(
userBAddr
,
11
)
record
=
queryGuessByAddrStatus
(
userBAddr
,
gty
.
GuessGameStatusPublish
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
1
&&
record
.
Records
[
0
]
.
GameID
==
strGameID1
)
record
=
queryGuessByAddrStatus
(
userBAddr
,
10
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
0
)
fmt
.
Println
(
"=======start queryGuessByAdminAddrStatus!======="
)
record
=
queryGuessByAdminAddrStatus
(
adminAddr
,
10
)
record
=
queryGuessByAdminAddrStatus
(
adminAddr
,
gty
.
GuessGameStatusAbort
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
2
)
record
=
queryGuessByAdminAddrStatus
(
adminAddr
,
11
)
record
=
queryGuessByAdminAddrStatus
(
adminAddr
,
gty
.
GuessGameStatusPublish
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
1
)
fmt
.
Println
(
"=======start queryGuessByCategoryStatus!======="
)
record
=
queryGuessByCategoryStatus
(
"football"
,
11
)
record
=
queryGuessByCategoryStatus
(
"football"
,
gty
.
GuessGameStatusPublish
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
1
)
record
=
queryGuessByCategoryStatus
(
"football"
,
10
)
record
=
queryGuessByCategoryStatus
(
"football"
,
gty
.
GuessGameStatusAbort
)
assert
.
Equal
(
t
,
true
,
len
(
record
.
Records
)
==
2
)
time
.
Sleep
(
2
*
time
.
Second
)
...
...
plugin/dapp/guess/types/const.go
View file @
8e085e1c
...
...
@@ -6,19 +6,19 @@ package types
//game action ty
const
(
GuessGameActionStart
=
iota
+
1
GuessGameActionBet
GuessGameActionStopBet
GuessGameActionAbort
GuessGameActionPublish
GuessGameActionQuery
GuessGameStatusStart
=
iota
+
1
GuessGameStatusBet
GuessGameStatusStopBet
GuessGameStatusAbort
GuessGameStatusPublish
GuessGameStatusTimeOut
GuessGameActionStart
=
5
GuessGameActionBet
=
6
GuessGameActionStopBet
=
7
GuessGameActionAbort
=
8
GuessGameActionPublish
=
9
GuessGameActionQuery
=
10
GuessGameStatusStart
=
1
1
GuessGameStatusBet
=
12
GuessGameStatusStopBet
=
13
GuessGameStatusAbort
=
14
GuessGameStatusPublish
=
15
GuessGameStatusTimeOut
=
16
)
//game log ty
...
...
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