@@ -31,6 +31,7 @@ import (
31
31
"github.com/hyperledger/fabric/protos/common"
32
32
pb "github.com/hyperledger/fabric/protos/peer"
33
33
putils "github.com/hyperledger/fabric/protos/utils"
34
+ "github.com/stretchr/testify/assert"
34
35
)
35
36
36
37
func TestInit (t * testing.T ) {
@@ -49,8 +50,10 @@ func TestInvoke(t *testing.T) {
49
50
stub := shim .NewMockStub ("endorseronevalidsignature" , e )
50
51
successResponse := & pb.Response {Status : 200 , Payload : []byte ("payload" )}
51
52
failResponse := & pb.Response {Status : 500 , Message : "error" }
53
+ ccFailResponse := & pb.Response {Status : 400 , Message : "chaincode error" }
52
54
successRes , _ := putils .GetBytesResponse (successResponse )
53
55
failRes , _ := putils .GetBytesResponse (failResponse )
56
+ ccFailRes , _ := putils .GetBytesResponse (ccFailResponse )
54
57
ccid := & pb.ChaincodeID {Name : "foo" , Version : "v1" }
55
58
ccidBytes , err := proto .Marshal (ccid )
56
59
if err != nil {
@@ -152,12 +155,17 @@ func TestInvoke(t *testing.T) {
152
155
t .Fatalf ("escc invoke should have failed with a null action struct. args: %v" , args )
153
156
}
154
157
155
- // Failed path: status code >= 500
158
+ // Failed path: status code = 500
156
159
args = [][]byte {[]byte ("test" ), []byte ("test" ), []byte ("test" ), ccidBytes , failRes , []byte ("test" )}
157
- if res := stub .MockInvoke ("1" , args ); res .Status == shim .OK {
158
- fmt .Println ("Invoke" , args , "failed" , string (res .Message ))
159
- t .Fatalf ("escc invoke should have failed with a null response. args: %v" , args )
160
- }
160
+ res := stub .MockInvoke ("1" , args )
161
+ assert .NotEqual (t , res .Status , shim .OK , "Invoke should have failed with status code: %d" , ccFailResponse .Status )
162
+ assert .Contains (t , res .Message , fmt .Sprintf ("Status code less than %d will be endorsed" , shim .ERRORTHRESHOLD ))
163
+
164
+ // Failed path: status code = 400
165
+ args = [][]byte {[]byte ("test" ), []byte ("test" ), []byte ("test" ), ccidBytes , ccFailRes , []byte ("test" )}
166
+ res = stub .MockInvoke ("1" , args )
167
+ assert .NotEqual (t , res .Status , shim .OK , "Invoke should have failed with status code: %d" , ccFailResponse .Status )
168
+ assert .Contains (t , res .Message , fmt .Sprintf ("Status code less than %d will be endorsed" , shim .ERRORTHRESHOLD ))
161
169
162
170
// Successful path - create a proposal
163
171
cs := & pb.ChaincodeSpec {
@@ -199,7 +207,7 @@ func TestInvoke(t *testing.T) {
199
207
200
208
// success test 1: invocation with mandatory args only
201
209
args = [][]byte {[]byte ("" ), proposal .Header , proposal .Payload , ccidBytes , successRes , simRes }
202
- res : = stub .MockInvoke ("1" , args )
210
+ res = stub .MockInvoke ("1" , args )
203
211
if res .Status != shim .OK {
204
212
t .Fail ()
205
213
t .Fatalf ("escc invoke failed with: %s" , res .Message )
0 commit comments