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
b39ff34f
Commit
b39ff34f
authored
Oct 11, 2019
by
张振华
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into dpos-v2
parents
0cb36107
1958740a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
244 additions
and
1 deletion
+244
-1
round_state.go
plugin/consensus/tendermint/types/round_state.go
+1
-1
pokerbull_test.go
plugin/dapp/pokerbull/executor/pokerbull_test.go
+230
-0
jrpc_channel_test.go
plugin/dapp/pokerbull/rpc/jrpc_channel_test.go
+13
-0
No files found.
plugin/consensus/tendermint/types/round_state.go
View file @
b39ff34f
...
...
@@ -39,7 +39,7 @@ const (
ProposalPOLID
=
byte
(
0x05
)
VoteID
=
byte
(
0x06
)
HasVoteID
=
byte
(
0x07
)
VoteSetMaj23ID
=
byte
(
0
X
08
)
VoteSetMaj23ID
=
byte
(
0
x
08
)
VoteSetBitsID
=
byte
(
0x09
)
ProposalHeartbeatID
=
byte
(
0x0a
)
ProposalBlockID
=
byte
(
0x0b
)
...
...
plugin/dapp/pokerbull/executor/pokerbull_test.go
0 → 100644
View file @
b39ff34f
package
executor
import
(
"testing"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
pkt
"github.com/33cn/plugin/plugin/dapp/pokerbull/types"
"github.com/stretchr/testify/assert"
)
type
execEnv
struct
{
blockTime
int64
blockHeight
int64
difficulty
uint64
}
var
(
PrivKeyA
=
"0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
// 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
PrivKeyB
=
"0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4"
// 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
Nodes
=
[][]
byte
{
[]
byte
(
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
),
[]
byte
(
"1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"
),
}
)
func
TestPokerbull
(
t
*
testing
.
T
)
{
types
.
SetTitleOnlyForTest
(
"chain33"
)
total
:=
1000
*
types
.
Coin
accountA
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
0
]),
}
accountB
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
1
]),
}
execAddr
:=
dapp
.
ExecAddress
(
pkt
.
PokerBullX
)
stateDB
,
_
:=
dbm
.
NewGoMemDB
(
"1"
,
"2"
,
100
)
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
accA
:=
account
.
NewCoinsAccount
()
accA
.
SetDB
(
stateDB
)
accA
.
SaveExecAccount
(
execAddr
,
&
accountA
)
accB
:=
account
.
NewCoinsAccount
()
accB
.
SetDB
(
stateDB
)
accB
.
SaveExecAccount
(
execAddr
,
&
accountB
)
env
:=
execEnv
{
10
,
types
.
GetDappFork
(
pkt
.
PokerBullX
,
"Enable"
),
1539918074
,
}
// start game
p1
:=
&
pkt
.
PBGameStart
{
Value
:
5
*
types
.
Coin
,
PlayerNum
:
2
,
}
createTx
,
err
:=
types
.
CallCreateTransaction
(
pkt
.
PokerBullX
,
"Start"
,
p1
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
pkt
.
ExecerPokerBull
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
:=
newPBGame
()
exec
.
SetStateDB
(
stateDB
)
assert
.
Equal
(
t
,
exec
.
GetCoinsAccount
()
.
LoadExecAccount
(
string
(
Nodes
[
0
]),
execAddr
)
.
GetBalance
(),
total
)
exec
.
SetLocalDB
(
kvdb
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
:=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
:=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
gameID
:=
createTx
.
Hash
()
// start game p2
createTx
,
err
=
types
.
CallCreateTransaction
(
pkt
.
PokerBullX
,
"Start"
,
p1
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
pkt
.
ExecerPokerBull
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// continue game
p2
:=
&
pkt
.
PBGameContinue
{
GameId
:
common
.
ToHex
(
gameID
),
}
createTx
,
err
=
types
.
CallCreateTransaction
(
pkt
.
PokerBullX
,
"Continue"
,
p2
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
pkt
.
ExecerPokerBull
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// quit game
p3
:=
&
pkt
.
PBGameQuit
{
GameId
:
common
.
ToHex
(
gameID
),
}
createTx
,
err
=
types
.
CallCreateTransaction
(
pkt
.
PokerBullX
,
"Quit"
,
p3
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
pkt
.
ExecerPokerBull
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
2
,
env
.
blockTime
+
2
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
stateDB
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query
res
,
err
:=
exec
.
Query
(
pkt
.
FuncNameQueryGameByID
,
types
.
Encode
(
&
pkt
.
QueryPBGameInfo
{
GameId
:
common
.
ToHex
(
gameID
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
pkt
.
FuncNameQueryGameByAddr
,
types
.
Encode
(
&
pkt
.
QueryPBGameInfo
{
Addr
:
string
(
Nodes
[
0
])}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
pkt
.
FuncNameQueryGameByStatus
,
types
.
Encode
(
&
pkt
.
QueryPBGameInfo
{
Status
:
pkt
.
PBGameActionQuit
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
pkt
.
FuncNameQueryGameByRound
,
types
.
Encode
(
&
pkt
.
QueryPBGameByRound
{
GameId
:
common
.
ToHex
(
gameID
),
Round
:
int32
(
1
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
var
gameIDsS
[]
string
gameIDsS
=
append
(
gameIDsS
,
common
.
ToHex
(
gameID
))
res
,
err
=
exec
.
Query
(
pkt
.
FuncNameQueryGameListByIDs
,
types
.
Encode
(
&
pkt
.
QueryPBGameInfos
{
GameIds
:
gameIDsS
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
signType
:=
types
.
SECP256K1
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
pkt
.
PokerBullX
,
signType
))
if
err
!=
nil
{
return
tx
,
err
}
bytes
,
err
:=
common
.
FromHex
(
hexPrivKey
[
:
])
if
err
!=
nil
{
return
tx
,
err
}
privKey
,
err
:=
c
.
PrivKeyFromBytes
(
bytes
)
if
err
!=
nil
{
return
tx
,
err
}
tx
.
Sign
(
int32
(
signType
),
privKey
)
return
tx
,
nil
}
plugin/dapp/pokerbull/rpc/jrpc_channel_test.go
View file @
b39ff34f
...
...
@@ -41,7 +41,9 @@ func TestJRPCChannel(t *testing.T) {
{
fn
:
testStartRawTxCmd
},
{
fn
:
testContinueRawTxCmd
},
{
fn
:
testQuitRawTxCmd
},
{
fn
:
testPlayRawTxCmd
},
}
for
_
,
testCase
:=
range
testCases
{
err
:=
testCase
.
fn
(
t
,
jrpcClient
)
assert
.
Nil
(
t
,
err
)
...
...
@@ -93,6 +95,17 @@ func testContinueRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testPlayRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGamePlay
{
GameId
:
"123"
,
Round
:
1
,
Value
:
5
,
Address
:
[]
string
{
"a"
,
"b"
}}
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pty
.
PokerBullX
),
ActionName
:
pty
.
CreatePlayTx
,
Payload
:
types
.
MustPBToJSON
(
payload
),
}
var
res
string
return
jrpc
.
Call
(
"Chain33.CreateTransaction"
,
params
,
&
res
)
}
func
testQuitRawTxCmd
(
t
*
testing
.
T
,
jrpc
*
jsonclient
.
JSONClient
)
error
{
payload
:=
&
pty
.
PBGameQuit
{
GameId
:
"123"
}
params
:=
&
rpctypes
.
CreateTxIn
{
...
...
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