Commit 5bd7a99c authored by mdj33's avatar mdj33 Committed by vipwzw

add ut

parent a15cd2a7
......@@ -20,6 +20,11 @@ import (
paraexec "github.com/33cn/plugin/plugin/dapp/paracross/executor"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/mock"
qmocks "github.com/33cn/chain33/queue/mocks"
drivers "github.com/33cn/chain33/system/consensus"
"github.com/33cn/chain33/queue"
apimocks "github.com/33cn/chain33/client/mocks"
)
var (
......@@ -220,3 +225,43 @@ func TestAddMinerTx(t *testing.T) {
assert.False(t, ret)
}
func initBlock(){
println("initblock")
}
func TestGetLastBlockInfo(t *testing.T){
para := new(client)
baseCli := drivers.NewBaseClient(&types.Consensus{Name:"name"})
para.BaseClient=baseCli
grpcClient := &typesmocks.Chain33Client{}
qClient := &qmocks.Client{}
para.InitClient(qClient,initBlock)
api := &apimocks.QueueProtocolAPI{}
para.SetAPI(api)
para.grpcClient = grpcClient
block:=&types.Block{Height:0}
msg := queue.NewMessage(0, "", 1, block)
qClient.On("NewMessage", mock.Anything, mock.Anything, mock.Anything).Return(msg)
qClient.On("Send", mock.Anything, mock.Anything).Return(nil)
qClient.On("Wait", mock.Anything).Return(msg,nil)
api.On("GetSequenceByHash",mock.Anything).Return(&types.Int64{Data:int64(1)},nil)
mainBlock := &types.Block{ParentHash:[]byte("phash")}
mainDetail := &types.BlockDetail{Block:mainBlock}
blocks:=&types.BlockDetails{}
blocks.Items = append(blocks.Items,mainDetail)
grpcClient.On("GetBlockByHashes",mock.Anything, mock.Anything).Return(blocks,nil)
grpcClient.On("GetSequenceByHash",mock.Anything, mock.Anything).Return(&types.Int64{Data:int64(10)},nil)
mainSeq,hash,err:=para.getLastBlockMainInfo()
assert.NoError(t,err)
assert.Equal(t,int64(9),mainSeq)
assert.Equal(t,[]byte("phash"),hash)
}
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