@@ -20,19 +20,17 @@ import (
2020 "testing"
2121
2222 "github.com/golang/protobuf/proto"
23-
2423 "github.com/hyperledger/fabric/core/util"
25- "github.com/hyperledger/fabric/msp"
2624 "github.com/hyperledger/fabric/protos/common"
2725 pb "github.com/hyperledger/fabric/protos/peer"
28- putils "github.com/hyperledger/fabric/protos/utils "
26+ ptestutils "github.com/hyperledger/fabric/protos/testutils "
2927)
3028
3129// ConstructBlockForSimulationResults constructs a block that includes a number of transactions - one per simulationResults
32- func ConstructBlockForSimulationResults (t * testing.T , simulationResults [][]byte , signer msp. SigningIdentity ) * pb.Block2 {
30+ func ConstructBlockForSimulationResults (t * testing.T , simulationResults [][]byte , sign bool ) * pb.Block2 {
3331 envs := []* common.Envelope {}
3432 for i := 0 ; i < len (simulationResults ); i ++ {
35- env , err := ConstructTestTransaction (t , simulationResults [i ], signer )
33+ env , err := ConstructTestTransaction (t , simulationResults [i ], sign )
3634 if err != nil {
3735 t .Fatalf ("ConstructTestTransaction failed, err %s" , err )
3836 }
@@ -52,38 +50,22 @@ func ConstructTestBlocks(t *testing.T, numBlocks int) []*pb.Block2 {
5250
5351// ConstructTestBlock constructs a block with 'numTx' number of transactions for testing
5452func ConstructTestBlock (t * testing.T , numTx int , txSize int , startingTxID int ) * pb.Block2 {
55- txs := []* pb. Transaction {}
53+ txEnvs := []* common. Envelope {}
5654 for i := startingTxID ; i < numTx + startingTxID ; i ++ {
57- tx , _ := putils . CreateTx ( common . HeaderType_ENDORSER_TRANSACTION , [] byte {}, [] byte {}, ConstructRandomBytes (t , txSize ), [] * pb. Endorsement {} )
58- txs = append (txs , tx )
55+ txEnv , _ := ConstructTestTransaction ( t , ConstructRandomBytes (t , txSize ), false )
56+ txEnvs = append (txEnvs , txEnv )
5957 }
60- return newBlock ( txs )
58+ return newBlockEnv ( txEnvs )
6159}
6260
6361// ConstructTestTransaction constructs a transaction for testing
64- func ConstructTestTransaction (t * testing.T , simulationResults []byte , signer msp.SigningIdentity ) (* common.Envelope , error ) {
65- ss , err := signer .Serialize ()
66- if err != nil {
67- return nil , err
68- }
69-
70- uuid := util .GenerateUUID ()
71- prop , err := putils .CreateChaincodeProposal (uuid , & pb.ChaincodeInvocationSpec {ChaincodeSpec : & pb.ChaincodeSpec {ChaincodeID : & pb.ChaincodeID {Name : "foo" }}}, ss )
72- if err != nil {
73- return nil , err
74- }
75-
76- presp , err := putils .CreateProposalResponse (prop .Header , prop .Payload , simulationResults , nil , nil , signer )
77- if err != nil {
78- return nil , err
79- }
80-
81- env , err := putils .CreateSignedTx (prop , signer , presp )
82- if err != nil {
83- return nil , err
62+ func ConstructTestTransaction (t * testing.T , simulationResults []byte , sign bool ) (* common.Envelope , error ) {
63+ ccName := "foo"
64+ txID := util .GenerateUUID ()
65+ if sign {
66+ return ptestutils .ConstructSingedTxEnvWithDefaultSigner (txID , ccName , simulationResults , nil , nil )
8467 }
85-
86- return env , nil
68+ return ptestutils .ConstructUnsingedTxEnv (txID , ccName , simulationResults , nil , nil )
8769}
8870
8971// ComputeBlockHash computes the crypto-hash of a block
@@ -93,16 +75,6 @@ func ComputeBlockHash(t testing.TB, block *pb.Block2) []byte {
9375 return serBlock .ComputeHash ()
9476}
9577
96- func newBlock (txs []* pb.Transaction ) * pb.Block2 {
97- block := & pb.Block2 {}
98- block .PreviousBlockHash = []byte {}
99- for i := 0 ; i < len (txs ); i ++ {
100- txBytes , _ := proto .Marshal (txs [i ])
101- block .Transactions = append (block .Transactions , txBytes )
102- }
103- return block
104- }
105-
10678func newBlockEnv (env []* common.Envelope ) * pb.Block2 {
10779 block := & pb.Block2 {}
10880 block .PreviousBlockHash = []byte {}
0 commit comments