Commit d48fa9c1 authored by vipwzw's avatar vipwzw

fix rpc ticket test

parent a2206aef
......@@ -20,6 +20,8 @@ require (
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/protobuf v1.3.2
github.com/hashicorp/golang-lru v0.5.0
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pkg/errors v0.8.0
github.com/prometheus/client_golang v1.1.0 // indirect
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d
......
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/33cn/chain33 v0.0.0-20191017025459-6d5c61c7d134 h1:uglc+qoZXRLxsLn9TdwLV5YDzjnRbLV0QjaxqvVFh4M=
github.com/33cn/chain33 v0.0.0-20191017025459-6d5c61c7d134/go.mod h1:4I8n+Zyf3t0UKM5jjpqJY627Tub62oXkLsdzIv4r6rQ=
github.com/33cn/chain33 v0.0.0-20191017084333-edce70d31ccc h1:ZE5zFLMdGTiHF7fZcVk+uOT16Q5gwmT4p01MSz/9ZBQ=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7 h1:PqzgE6kAMi81xWQA2QIVxjWkFHptGgC547vchpUbtFo=
github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
......
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc_test
import (
"strings"
"testing"
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types"
_ "github.com/33cn/chain33/system"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util/testnode"
_ "github.com/33cn/plugin/plugin"
"github.com/stretchr/testify/assert"
)
var mocker *testnode.Chain33Mock
func TestMain(m *testing.M) {
cfg, sub := testnode.GetDefaultConfig()
cfg.Consensus.Name = "ticket"
mocker = testnode.NewWithConfig(cfg, sub, nil)
mocker.Listen()
m.Run()
mocker.Close()
}
func TestJRPCChannel(t *testing.T) {
jrpcClient := mocker.GetJSONC()
testCases := []struct {
fn func(*testing.T, *jsonclient.JSONClient) error
}{
{fn: testCountTicketCmd},
{fn: testCloseTicketCmd},
{fn: testGetColdAddrByMinerCmd},
}
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)
}
t.Log(err.Error())
}
}
func testCountTicketCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var res int64
return jrpc.Call("ticket.GetTicketCount", nil, &res)
}
func testCloseTicketCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var res types.ReplyHashes
return jrpc.Call("ticket.CloseTickets", nil, &res)
}
func testGetColdAddrByMinerCmd(t *testing.T, jrpc *jsonclient.JSONClient) error {
var rep interface{}
var params rpctypes.Query4Jrpc
req := &types.ReqString{}
params.Execer = "ticket"
params.FuncName = "MinerSourceList"
params.Payload = types.MustPBToJSON(req)
rep = &types.ReplyStrings{}
return jrpc.Call("Chain33.Query", params, rep)
}
......@@ -42,6 +42,10 @@ func (g *channelClient) CreateBindMiner(ctx context.Context, in *ty.ReqBindMiner
if err != nil {
return nil, err
}
price := ty.GetTicketMinerParam(header.Height).TicketPrice
if price == 0 {
return nil, types.ErrInvalidParam
}
if in.Amount%ty.GetTicketMinerParam(header.Height).TicketPrice != 0 || in.Amount < 0 {
return nil, types.ErrAmount
}
......
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc_test
//only load all plugin and system
import (
"testing"
rpctypes "github.com/33cn/chain33/rpc/types"
_ "github.com/33cn/chain33/system"
_ "github.com/33cn/plugin/plugin"
ty "github.com/33cn/plugin/plugin/dapp/ticket/types"
"github.com/stretchr/testify/assert"
)
func TestNewTicket(t *testing.T) {
//选票(可以用hotwallet 关闭选票)
in := &ty.TicketClose{MinerAddress: mocker.GetHotAddress()}
var res rpctypes.ReplyHashes
err := mocker.GetJSONC().Call("ticket.CloseTickets", in, &res)
assert.Nil(t, err)
}
......@@ -128,30 +128,16 @@ func TestChannelClient_BindMiner(t *testing.T) {
storevalue.Values = append(storevalue.Values, accv)
api.On("StoreGet", mock.Anything).Return(storevalue, nil).Twice()
types.SetTitleOnlyForTest("test")
cfg, _ := types.InitCfgString(cfgstring)
types.Init("test", cfg)
//var addrs = make([]string, 1)
//addrs = append(addrs, "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt")
var in = &ty.ReqBindMiner{
BindAddr: "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt",
OriginAddr: "1Jn2qu84Z1SUUosWjySggBS9pKWdAP3tZt",
Amount: 10000 * types.Coin,
CheckBalance: true,
CheckBalance: false,
}
_, err := client.CreateBindMiner(context.Background(), in)
assert.Nil(t, err)
in.Amount = 200000 * types.Coin
_, err = client.CreateBindMiner(context.Background(), in)
assert.Equal(t, types.ErrNoBalance, err)
head.Height = 20 //ForkChainParamV2
api.On("GetLastHeader").Return(head, nil).Times(2)
_, err = client.CreateBindMiner(context.Background(), in)
assert.Equal(t, types.ErrAmount, err)
}
func testGetTicketCountOK(t *testing.T) {
......
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