Commit 9eac9d7d authored by mdj33's avatar mdj33 Committed by 33cn

ut modify

parent 1515e456
...@@ -7,7 +7,6 @@ package para ...@@ -7,7 +7,6 @@ package para
import ( import (
"math/rand" "math/rand"
"testing" "testing"
"time"
"github.com/33cn/chain33/blockchain" "github.com/33cn/chain33/blockchain"
"github.com/33cn/chain33/common/log" "github.com/33cn/chain33/common/log"
...@@ -73,17 +72,10 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu ...@@ -73,17 +72,10 @@ func (s *suiteParaCommitMsg) initEnv(cfg *types.Config, sub *types.ConfigSubModu
s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client) s.para = New(cfg.Consensus, sub.Consensus["para"]).(*client)
s.grpcCli = &typesmocks.Chain33Client{} s.grpcCli = &typesmocks.Chain33Client{}
block := &types.Block{} // GetBlockBySeq return error to stop create's for cycle to request tx
blockSeq := &types.BlockSeq{ s.grpcCli.On("GetBlockBySeq", mock.Anything, mock.Anything).Return(nil, errors.New("quit create"))
Seq: &types.BlockSequence{
Hash: []byte("1"),
Type: 1,
},
Detail: &types.BlockDetail{Block: block},
}
s.grpcCli.On("GetBlockBySeq", mock.Anything, mock.Anything).Return(blockSeq, errors.New("nil"))
//data := &types.Int64{1} //data := &types.Int64{1}
s.grpcCli.On("GetLastBlockSequence", mock.Anything, mock.Anything).Return(nil, errors.New("nil")) s.grpcCli.On("GetLastBlockSequence", mock.Anything, mock.Anything).Return(nil, errors.New("nil")).Maybe()
reply := &types.Reply{IsOk: true} reply := &types.Reply{IsOk: true}
s.grpcCli.On("IsSync", mock.Anything, mock.Anything).Return(reply, nil) s.grpcCli.On("IsSync", mock.Anything, mock.Anything).Return(reply, nil)
result := &pt.ParacrossStatus{Height: -1} result := &pt.ParacrossStatus{Height: -1}
...@@ -131,45 +123,28 @@ func (s *suiteParaCommitMsg) SetupSuite() { ...@@ -131,45 +123,28 @@ func (s *suiteParaCommitMsg) SetupSuite() {
s.initEnv(initConfigFile()) s.initEnv(initConfigFile())
} }
func (s *suiteParaCommitMsg) TestRun_1() { func (s *suiteParaCommitMsg) createBlock() {
//s.testGetBlock() var i int64
lastBlock, err := s.para.RequestLastBlock() for i = 0; i < 3; i++ {
if err != nil { lastBlock, err := s.para.RequestLastBlock()
plog.Error("para test", "err", err.Error()) if err != nil {
} plog.Error("para test", "err", err.Error())
plog.Info("para test---------", "last height", lastBlock.Height) }
s.para.createBlock(lastBlock, nil, 0, getMainBlock(1, lastBlock.BlockTime+1)) s.Equal(int64(i), lastBlock.Height)
lastBlock, err = s.para.RequestLastBlock() s.para.createBlock(lastBlock, nil, i, getMainBlock(i+1, lastBlock.BlockTime+1))
if err != nil {
plog.Error("para test--2", "err", err.Error())
} }
plog.Info("para test---------", "last height", lastBlock.Height) }
s.Equal(int64(1), lastBlock.Height)
s.para.createBlock(lastBlock, nil, 1, getMainBlock(2, lastBlock.BlockTime+1))
time.Sleep(time.Second * 1)
lastBlock, err = s.para.RequestLastBlock() func (s *suiteParaCommitMsg) TestRun_1() {
if err != nil { s.createBlock()
plog.Error("para test--2", "err", err.Error())
}
plog.Info("para test---------", "last height", lastBlock.Height)
s.Equal(int64(2), lastBlock.Height)
s.para.createBlock(lastBlock, nil, 2, getMainBlock(3, lastBlock.BlockTime+1))
time.Sleep(time.Second * 1)
lastBlock, err = s.para.RequestLastBlock()
if err != nil {
plog.Error("para test--3", "err", err.Error())
}
s.Equal(int64(3), lastBlock.Height)
s.testRunGetMinerTxInfo() s.testRunGetMinerTxInfo()
s.testRunRmvBlock() s.testRunRmvBlock()
time.Sleep(time.Second * 1) lastBlock, _ := s.para.RequestLastBlock()
lastBlock, err = s.para.RequestLastBlock()
if lastBlock.Height > 0 { if lastBlock.Height > 0 {
s.para.DelBlock(lastBlock, 2) s.para.DelBlock(lastBlock, 1)
time.Sleep(time.Second * 1)
} }
} }
......
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