Commit fddd06f8 authored by vipwzw's avatar vipwzw

hello

parent de416732
......@@ -64,14 +64,14 @@ func Key(id string) (key []byte) {
func readGame(db dbm.KV, id string) (*pkt.PokerBull, error) {
data, err := db.Get(Key(id))
if err != nil {
logger.Error("query data have err:", err.Error())
logger.Error("query data have err:", "err", err)
return nil, err
}
var game pkt.PokerBull
//decode
err = types.Decode(data, &game)
if err != nil {
logger.Error("decode game have err:", err.Error())
logger.Error("decode game have err:", "err", err)
return nil, err
}
return &game, nil
......@@ -102,7 +102,6 @@ func getGameListByAddr(db dbm.Lister, addr string, index int64) (types.Message,
if err != nil {
return nil, err
}
var gameIds []*pkt.PBGameRecord
for _, value := range values {
var record pkt.PBGameRecord
......@@ -112,7 +111,9 @@ func getGameListByAddr(db dbm.Lister, addr string, index int64) (types.Message,
}
gameIds = append(gameIds, &record)
}
if len(gameIds) == 0 {
return nil, types.ErrNotFound
}
return &pkt.PBGameRecords{Records: gameIds}, nil
}
......
......@@ -29,7 +29,6 @@ func (g *PokerBull) Query_QueryGameByAddr(in *pkt.QueryPBGameInfo) (types.Messag
if err != nil {
return nil, err
}
return gameIds, nil
}
......
......@@ -5,7 +5,7 @@
package rpc_test
import (
"strings"
"fmt"
"testing"
commonlog "github.com/33cn/chain33/common/log"
......@@ -41,51 +41,65 @@ func TestJRPCChannel(t *testing.T) {
{fn: testStartRawTxCmd},
{fn: testContinueRawTxCmd},
{fn: testQuitRawTxCmd},
}
for _, testCase := range testCases {
err := testCase.fn(t, jrpcClient)
assert.Nil(t, err)
}
testCases = []struct {
fn func(*testing.T, *jsonclient.JSONClient) error
}{
{fn: testQueryGameByID},
{fn: testQueryGameByAddr},
{fn: testQueryGameByIDs},
{fn: testQueryGameByStatus},
{fn: testQueryGameByRound},
}
for index, testCase := range testCases {
err := testCase.fn(t, jrpcClient)
if err == nil {
continue
}
assert.NotEqualf(t, err, types.ErrActionNotSupport, "test index %d", index)
if strings.Contains(err.Error(), "rpc: can't find") {
assert.FailNowf(t, err.Error(), "test index %d", index)
}
assert.Equal(t, err, types.ErrNotFound, fmt.Sprint(index))
}
testCases = []struct {
fn func(*testing.T, *jsonclient.JSONClient) error
}{
{fn: testQueryGameByIDs},
}
for index, testCase := range testCases {
err := testCase.fn(t, jrpcClient)
assert.Equal(t, err, nil, fmt.Sprint(index))
}
}
func testStartRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
payload := &pty.PBGameStart{Value: 123}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pty.PokerBullX),
ActionName: pty.CreateStartTx,
Payload: []byte(""),
Payload: types.MustPBToJSON(payload),
}
var res string
return jrpc.Call("Chain33.CreateTransaction", params, &res)
}
func testContinueRawTxCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
payload := &pty.PBGameContinue{GameId: "123"}
params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pty.PokerBullX),
ActionName: pty.CreateContinueTx,
Payload: []byte(""),
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{
Execer: types.ExecName(pty.PokerBullX),
ActionName: pty.CreatequitTx,
Payload: []byte(""),
Payload: types.MustPBToJSON(payload),
}
var res string
return jrpc.Call("Chain33.CreateTransaction", params, &res)
}
......
......@@ -53,11 +53,11 @@ const (
// FuncNameQueryGameByRound 查询某一回合游戏结果
FuncNameQueryGameByRound = "QueryGameByRound"
// CreateStartTx 创建开始交易
CreateStartTx = "CreateStartTx"
CreateStartTx = "Start"
// CreateContinueTx 创建继续交易
CreateContinueTx = "CreateContinueTx"
CreateContinueTx = "Continue"
// CreatequitTx 创建退出交易
CreatequitTx = "CreatequitTx"
CreatequitTx = "Quit"
)
const (
......
......@@ -7,9 +7,6 @@ package types
import (
"reflect"
"encoding/json"
"errors"
log "github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
......@@ -66,79 +63,3 @@ func (t *PokerBullType) GetLogMap() map[int64]*types.LogInfo {
TyLogPBGameQuery: {Ty: reflect.TypeOf(ReceiptPBGame{}), Name: "TyLogPBGameQuery"},
}
}
// CreateTx method
func (t *PokerBullType) CreateTx(action string, message json.RawMessage) (*types.Transaction, error) {
llog.Debug("pokerbull.CreateTx", "action", action)
if action == CreateStartTx {
var param PBGameStart
err := json.Unmarshal(message, &param)
if err != nil {
llog.Error("CreateTx", "Error", err)
return nil, types.ErrInvalidParam
}
return CreateRawPBStartTx(&param)
} else if action == CreateContinueTx {
var param PBGameContinue
err := json.Unmarshal(message, &param)
if err != nil {
llog.Error("CreateTx", "Error", err)
return nil, types.ErrInvalidParam
}
return CreateRawPBContinueTx(&param)
} else if action == CreatequitTx {
var param PBGameQuit
err := json.Unmarshal(message, &param)
if err != nil {
llog.Error("CreateTx", "Error", err)
return nil, types.ErrInvalidParam
}
return CreateRawPBQuitTx(&param)
}
return nil, types.ErrNotSupport
}
// CreateRawPBStartTx method
func CreateRawPBStartTx(head *PBGameStart) (*types.Transaction, error) {
if head.PlayerNum > MaxPlayerNum {
return nil, errors.New("Player number should be maximum 5")
}
val := &PBGameAction{
Ty: PBGameActionStart,
Value: &PBGameAction_Start{Start: head},
}
tx, err := types.CreateFormatTx(types.ExecName(PokerBullX), types.Encode(val))
if err != nil {
return nil, err
}
return tx, nil
}
// CreateRawPBContinueTx method
func CreateRawPBContinueTx(head *PBGameContinue) (*types.Transaction, error) {
val := &PBGameAction{
Ty: PBGameActionContinue,
Value: &PBGameAction_Continue{Continue: head},
}
tx, err := types.CreateFormatTx(types.ExecName(PokerBullX), types.Encode(val))
if err != nil {
return nil, err
}
return tx, nil
}
// CreateRawPBQuitTx method
func CreateRawPBQuitTx(head *PBGameQuit) (*types.Transaction, error) {
val := &PBGameAction{
Ty: PBGameActionQuit,
Value: &PBGameAction_Quit{Quit: head},
}
tx, err := types.CreateFormatTx(types.ExecName(PokerBullX), types.Encode(val))
if err != nil {
return nil, err
}
return tx, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment