Commit 715c73dd authored by vipwzw's avatar vipwzw

auto ci

parent 2ec44b30
...@@ -7,18 +7,19 @@ package para ...@@ -7,18 +7,19 @@ package para
import ( import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
//"github.com/stretchr/testify/mock" //"github.com/stretchr/testify/mock"
"encoding/hex"
"errors" "errors"
"math/rand"
"testing" "testing"
"time"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
typesmocks "github.com/33cn/chain33/types/mocks" typesmocks "github.com/33cn/chain33/types/mocks"
paraexec "github.com/33cn/plugin/plugin/dapp/paracross/executor" paraexec "github.com/33cn/plugin/plugin/dapp/paracross/executor"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"encoding/hex"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/address"
"math/rand"
"time"
) )
var ( var (
...@@ -30,7 +31,7 @@ var ( ...@@ -30,7 +31,7 @@ var (
func TestFilterTxsForPara(t *testing.T) { func TestFilterTxsForPara(t *testing.T) {
types.Init(Title, nil) types.Init(Title, nil)
detail,filterTxs,_ := createTestTxs(t) detail, filterTxs, _ := createTestTxs(t)
rst := paraexec.FilterTxsForPara(Title, detail) rst := paraexec.FilterTxsForPara(Title, detail)
assert.Equal(t, filterTxs, rst) assert.Equal(t, filterTxs, rst)
...@@ -124,7 +125,7 @@ func TestGetBlockHashForkHeightOnMainChain(t *testing.T) { ...@@ -124,7 +125,7 @@ func TestGetBlockHashForkHeightOnMainChain(t *testing.T) {
} }
func createTestTxs(t *testing.T) (*types.BlockDetail,[]*types.Transaction,[]*types.Transaction){ func createTestTxs(t *testing.T) (*types.BlockDetail, []*types.Transaction, []*types.Transaction) {
//all para tx group //all para tx group
tx5, err := createCrossParaTx("toB", 5) tx5, err := createCrossParaTx("toB", 5)
assert.Nil(t, err) assert.Nil(t, err)
...@@ -178,46 +179,43 @@ func createTestTxs(t *testing.T) (*types.BlockDetail,[]*types.Transaction,[]*typ ...@@ -178,46 +179,43 @@ func createTestTxs(t *testing.T) (*types.BlockDetail,[]*types.Transaction,[]*typ
recptD := &types.ReceiptData{Ty: types.ExecPack} recptD := &types.ReceiptData{Ty: types.ExecPack}
receipts := []*types.ReceiptData{recpt5, recpt6, recpt7, recpt8, recptB, recptC, recptD} receipts := []*types.ReceiptData{recpt5, recpt6, recpt7, recpt8, recptB, recptC, recptD}
block := &types.Block{Height:10, Txs: txs} block := &types.Block{Height: 10, Txs: txs}
detail := &types.BlockDetail{ detail := &types.BlockDetail{
Block: block, Block: block,
Receipts: receipts, Receipts: receipts,
} }
filterTxs := []*types.Transaction{tx5, tx6, txB, txC} filterTxs := []*types.Transaction{tx5, tx6, txB, txC}
return detail,filterTxs,txs return detail, filterTxs, txs
} }
func TestAddMinerTx(t *testing.T){ func TestAddMinerTx(t *testing.T) {
pk, err := hex.DecodeString(minerPrivateKey) pk, err := hex.DecodeString(minerPrivateKey)
assert.Nil(t,err) assert.Nil(t, err)
secp, err := crypto.New(types.GetSignName("", types.SECP256K1)) secp, err := crypto.New(types.GetSignName("", types.SECP256K1))
assert.Nil(t,err) assert.Nil(t, err)
priKey, err := secp.PrivKeyFromBytes(pk) priKey, err := secp.PrivKeyFromBytes(pk)
assert.Nil(t,err) assert.Nil(t, err)
mainForkParacrossCommitTx = 1 mainForkParacrossCommitTx = 1
block := &types.Block{} block := &types.Block{}
mainDetail, filterTxs, allTxs := createTestTxs(t) mainDetail, filterTxs, allTxs := createTestTxs(t)
mainBlock := &types.BlockSeq{ mainBlock := &types.BlockSeq{
Seq:&types.BlockSequence{}, Seq: &types.BlockSequence{},
Detail:mainDetail} Detail: mainDetail}
para := new(client) para := new(client)
para.privateKey = priKey para.privateKey = priKey
para.addMinerTx(nil, block,mainBlock,allTxs) para.addMinerTx(nil, block, mainBlock, allTxs)
ret := checkTxInMainBlock(filterTxs[0],mainDetail) ret := checkTxInMainBlock(filterTxs[0], mainDetail)
assert.True(t,ret) assert.True(t, ret)
tx2,_ := createCrossMainTx("toA") tx2, _ := createCrossMainTx("toA")
ret = checkTxInMainBlock(tx2,mainDetail) ret = checkTxInMainBlock(tx2, mainDetail)
assert.False(t,ret) assert.False(t, ret)
}
}
\ No newline at end of file
...@@ -18,6 +18,8 @@ import ( ...@@ -18,6 +18,8 @@ import (
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"time"
"github.com/33cn/chain33/queue" "github.com/33cn/chain33/queue"
"github.com/33cn/chain33/store" "github.com/33cn/chain33/store"
_ "github.com/33cn/chain33/system" _ "github.com/33cn/chain33/system"
...@@ -25,7 +27,6 @@ import ( ...@@ -25,7 +27,6 @@ import (
typesmocks "github.com/33cn/chain33/types/mocks" typesmocks "github.com/33cn/chain33/types/mocks"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types" pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"time"
) )
func init() { func init() {
...@@ -275,7 +276,7 @@ func TestGetConsensusStatus(t *testing.T) { ...@@ -275,7 +276,7 @@ func TestGetConsensusStatus(t *testing.T) {
assert.Equal(t, int64(1), ret.Height) assert.Equal(t, int64(1), ret.Height)
} }
func TestSendCommitMsg(t *testing.T){ func TestSendCommitMsg(t *testing.T) {
para := new(client) para := new(client)
grpcClient := &typesmocks.Chain33Client{} grpcClient := &typesmocks.Chain33Client{}
//grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once() //grpcClient.On("GetFork", mock.Anything, &types.ReqKey{Key: []byte("ForkBlockHash")}).Return(&types.Int64{Data: 1}, errors.New("err")).Once()
...@@ -292,13 +293,13 @@ func TestSendCommitMsg(t *testing.T){ ...@@ -292,13 +293,13 @@ func TestSendCommitMsg(t *testing.T){
// IsOk: true, // IsOk: true,
// Msg: types.Encode(status), // Msg: types.Encode(status),
//} //}
grpcClient.On("SendTransaction", mock.Anything, mock.Anything).Return(nil,types.ErrNotFound).Twice() grpcClient.On("SendTransaction", mock.Anything, mock.Anything).Return(nil, types.ErrNotFound).Twice()
tx := &types.Transaction{} tx := &types.Transaction{}
sendMsgCh <-tx sendMsgCh <- tx
time.Sleep(3*time.Second) time.Sleep(3 * time.Second)
//para.BaseClient.Close() //para.BaseClient.Close()
close(commitCli.quit) close(commitCli.quit)
} }
\ No newline at end of file
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