@@ -20,19 +20,17 @@ import (
20
20
"testing"
21
21
22
22
"github.com/golang/protobuf/proto"
23
-
24
23
"github.com/hyperledger/fabric/core/util"
25
- "github.com/hyperledger/fabric/msp"
26
24
"github.com/hyperledger/fabric/protos/common"
27
25
pb "github.com/hyperledger/fabric/protos/peer"
28
- putils "github.com/hyperledger/fabric/protos/utils "
26
+ ptestutils "github.com/hyperledger/fabric/protos/testutils "
29
27
)
30
28
31
29
// 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 {
33
31
envs := []* common.Envelope {}
34
32
for i := 0 ; i < len (simulationResults ); i ++ {
35
- env , err := ConstructTestTransaction (t , simulationResults [i ], signer )
33
+ env , err := ConstructTestTransaction (t , simulationResults [i ], sign )
36
34
if err != nil {
37
35
t .Fatalf ("ConstructTestTransaction failed, err %s" , err )
38
36
}
@@ -52,38 +50,22 @@ func ConstructTestBlocks(t *testing.T, numBlocks int) []*pb.Block2 {
52
50
53
51
// ConstructTestBlock constructs a block with 'numTx' number of transactions for testing
54
52
func ConstructTestBlock (t * testing.T , numTx int , txSize int , startingTxID int ) * pb.Block2 {
55
- txs := []* pb. Transaction {}
53
+ txEnvs := []* common. Envelope {}
56
54
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 )
59
57
}
60
- return newBlock ( txs )
58
+ return newBlockEnv ( txEnvs )
61
59
}
62
60
63
61
// 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 )
84
67
}
85
-
86
- return env , nil
68
+ return ptestutils .ConstructUnsingedTxEnv (txID , ccName , simulationResults , nil , nil )
87
69
}
88
70
89
71
// ComputeBlockHash computes the crypto-hash of a block
@@ -93,16 +75,6 @@ func ComputeBlockHash(t testing.TB, block *pb.Block2) []byte {
93
75
return serBlock .ComputeHash ()
94
76
}
95
77
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
-
106
78
func newBlockEnv (env []* common.Envelope ) * pb.Block2 {
107
79
block := & pb.Block2 {}
108
80
block .PreviousBlockHash = []byte {}
0 commit comments