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
2bea5d2e
Commit
2bea5d2e
authored
Dec 24, 2018
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ut
parent
7e15e892
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
102 additions
and
38 deletions
+102
-38
jrpc_channel_test.go
plugin/dapp/guess/rpc/jrpc_channel_test.go
+102
-38
No files found.
plugin/dapp/guess/rpc/jrpc_channel_test.go
View file @
2bea5d2e
...
...
@@ -13,7 +13,7 @@ import (
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
pty
"github.com/33cn/plugin/plugin/dapp/
pokerbull
/types"
pty
"github.com/33cn/plugin/plugin/dapp/
guess
/types"
"github.com/stretchr/testify/assert"
_
"github.com/33cn/chain33/system"
...
...
@@ -39,8 +39,10 @@ func TestJRPCChannel(t *testing.T) {
fn
func
(
*
testing
.
T
,
*
jsonclient
.
JSONClient
)
error
}{
{
fn
:
testStartRawTxCmd
},
{
fn
:
testContinueRawTxCmd
},
{
fn
:
testQuitRawTxCmd
},
{
fn
:
testBetRawTxCmd
},
{
fn
:
testStopBetRawTxCmd
},
{
fn
:
testPublishRawTxCmd
},
{
fn
:
testAbortRawTxCmd
},
}
for
_
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
...
...
@@ -51,9 +53,12 @@ func TestJRPCChannel(t *testing.T) {
fn
func
(
*
testing
.
T
,
*
jsonclient
.
JSONClient
)
error
}{
{
fn
:
testQueryGameByID
},
{
fn
:
testQueryGameByAddr
},
{
fn
:
testQueryGameByStatus
},
{
fn
:
testQueryGameByRound
},
{
fn
:
testQueryGamesByAddr
},
{
fn
:
testQueryGamesByStatus
},
{
fn
:
testQueryGamesByAdminAddr
},
{
fn
:
testQueryGamesByAddrStatus
},
{
fn
:
testQueryGamesByAdminStatus
},
{
fn
:
testQueryGamesByCategoryStatus
},
}
for
index
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
...
...
@@ -63,7 +68,7 @@ func TestJRPCChannel(t *testing.T) {
testCases
=
[]
struct
{
fn
func
(
*
testing
.
T
,
*
jsonclient
.
JSONClient
)
error
}{
{
fn
:
testQueryGameByIDs
},
{
fn
:
testQueryGame
s
ByIDs
},
}
for
index
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
...
...
@@ -72,9 +77,9 @@ func TestJRPCChannel(t *testing.T) {
}
func
testStartRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGameStart
{
Value
:
123
}
payload
:=
&
pty
.
GuessGameStart
{
Topic
:
"WorldCup Final"
,
Options
:
"A:France;B:Claodia"
,
Category
:
"football"
,
MaxBetsOneTime
:
100e8
,
MaxBetsNumber
:
1000e8
,
DevFeeFactor
:
5
,
DevFeeAddr
:
"1D6RFZNp2rh6QdbcZ1d7RWuBUz61We6SD7"
,
PlatFeeFactor
:
5
,
PlatFeeAddr
:
"1PHtChNt3UcfssR7v7trKSk3WJtAWjKjjX"
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBull
X
),
Execer
:
types
.
ExecName
(
pty
.
Guess
X
),
ActionName
:
pty
.
CreateStartTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
...
...
@@ -82,79 +87,137 @@ func testStartRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
test
Continue
RawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGameContinue
{
GameId
:
"123"
}
func
test
Bet
RawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
GuessGameBet
{
GameID
:
"0x76dae82fcbe554d4b8df5ed1460d71dcac86a50864649a0df43e0c50b245f004"
,
Option
:
"A"
,
BetsNum
:
5e8
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBull
X
),
ActionName
:
pty
.
Create
Continue
Tx
,
Execer
:
types
.
ExecName
(
pty
.
Guess
X
),
ActionName
:
pty
.
Create
Bet
Tx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
test
Qui
tRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGameQuit
{
GameId
:
"123
"
}
func
test
StopBe
tRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
GuessGameStopBet
{
GameID
:
"0x76dae82fcbe554d4b8df5ed1460d71dcac86a50864649a0df43e0c50b245f004
"
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBull
X
),
ActionName
:
pty
.
Create
qui
tTx
,
Execer
:
types
.
ExecName
(
pty
.
Guess
X
),
ActionName
:
pty
.
Create
StopBe
tTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testPublishRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
GuessGamePublish
{
GameID
:
"0x76dae82fcbe554d4b8df5ed1460d71dcac86a50864649a0df43e0c50b245f004"
,
Result
:
"A"
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
GuessX
),
ActionName
:
pty
.
CreatePublishTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testAbortRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
GuessGameAbort
{
GameID
:
"0x76dae82fcbe554d4b8df5ed1460d71dcac86a50864649a0df43e0c50b245f004"
}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
GuessX
),
ActionName
:
pty
.
CreateAbortTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testQueryGameByID
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
Query
PB
GameInfo
{}
params
.
Execer
=
pty
.
PokerBull
X
req
:=
&
pty
.
Query
Guess
GameInfo
{}
params
.
Execer
=
pty
.
Guess
X
params
.
FuncName
=
pty
.
FuncNameQueryGameByID
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
Reply
PBGame
{}
rep
=
&
pty
.
Reply
GuessGameInfo
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGameByAddr
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
testQueryGame
s
ByAddr
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
Query
PB
GameInfo
{}
params
.
Execer
=
pty
.
PokerBull
X
req
:=
&
pty
.
Query
Guess
GameInfo
{}
params
.
Execer
=
pty
.
Guess
X
params
.
FuncName
=
pty
.
FuncNameQueryGameByAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
PB
GameRecords
{}
rep
=
&
pty
.
Guess
GameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGameByIDs
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
testQueryGame
s
ByIDs
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
Query
PB
GameInfos
{}
params
.
Execer
=
pty
.
PokerBull
X
params
.
FuncName
=
pty
.
FuncNameQueryGame
List
ByIDs
req
:=
&
pty
.
Query
Guess
GameInfos
{}
params
.
Execer
=
pty
.
Guess
X
params
.
FuncName
=
pty
.
FuncNameQueryGame
s
ByIDs
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
Reply
PBGameList
{}
rep
=
&
pty
.
Reply
GuessGameInfos
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGameByStatus
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
testQueryGame
s
ByStatus
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
Query
PB
GameInfo
{}
params
.
Execer
=
pty
.
PokerBull
X
req
:=
&
pty
.
Query
Guess
GameInfo
{}
params
.
Execer
=
pty
.
Guess
X
params
.
FuncName
=
pty
.
FuncNameQueryGameByStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
PBGameRecords
{}
rep
=
&
pty
.
GuessGameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGamesByAdminAddr
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryGuessGameInfo
{}
params
.
Execer
=
pty
.
GuessX
params
.
FuncName
=
pty
.
FuncNameQueryGameByAdminAddr
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
GuessGameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGamesByAddrStatus
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryGuessGameInfo
{}
params
.
Execer
=
pty
.
GuessX
params
.
FuncName
=
pty
.
FuncNameQueryGameByAddrStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
GuessGameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGamesByAdminStatus
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
QueryGuessGameInfo
{}
params
.
Execer
=
pty
.
GuessX
params
.
FuncName
=
pty
.
FuncNameQueryGameByAdminStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
GuessGameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
func
testQueryGame
ByRound
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
func
testQueryGame
sByCategoryStatus
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
var
rep
interface
{}
var
params
rpctypes
.
Query4Jrpc
req
:=
&
pty
.
Query
PBGameByRound
{}
params
.
Execer
=
pty
.
PokerBull
X
params
.
FuncName
=
pty
.
FuncNameQueryGameBy
Round
req
:=
&
pty
.
Query
GuessGameInfo
{}
params
.
Execer
=
pty
.
Guess
X
params
.
FuncName
=
pty
.
FuncNameQueryGameBy
CategoryStatus
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
rep
=
&
pty
.
PB
GameRecords
{}
rep
=
&
pty
.
Guess
GameRecords
{}
return
jrpc
.
Call
(
"Chain33.Query"
,
params
,
rep
)
}
\ 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