@@ -20,6 +20,7 @@ import (
20
20
"github.com/hyperledger/fabric/core/common/ccprovider"
21
21
"github.com/hyperledger/fabric/core/common/sysccprovider"
22
22
"github.com/hyperledger/fabric/core/container/ccintf"
23
+ "github.com/hyperledger/fabric/core/scc"
23
24
pb "github.com/hyperledger/fabric/protos/peer"
24
25
. "github.com/onsi/ginkgo"
25
26
. "github.com/onsi/ginkgo/extensions/table"
@@ -32,7 +33,7 @@ var _ = Describe("Handler", func() {
32
33
fakeTransactionRegistry * mock.TransactionRegistry
33
34
fakeContextRegistry * fake.ContextRegistry
34
35
fakeChatStream * mock.ChaincodeStream
35
- fakeSystemCCProvider * mock. SystemCCProvider
36
+ builtinSCCs scc. BuiltinSCCs
36
37
fakeTxSimulator * mock.TxSimulator
37
38
fakeHistoryQueryExecutor * mock.HistoryQueryExecutor
38
39
fakeQueryResponseBuilder * fake.QueryResponseBuilder
@@ -61,7 +62,6 @@ var _ = Describe("Handler", func() {
61
62
fakeTransactionRegistry .AddReturns (true )
62
63
63
64
fakeChatStream = & mock.ChaincodeStream {}
64
- fakeSystemCCProvider = & mock.SystemCCProvider {}
65
65
66
66
fakeTxSimulator = & mock.TxSimulator {}
67
67
fakeHistoryQueryExecutor = & mock.HistoryQueryExecutor {}
@@ -106,6 +106,8 @@ var _ = Describe("Handler", func() {
106
106
fakeExecuteTimeouts = & metricsfakes.Counter {}
107
107
fakeExecuteTimeouts .WithReturns (fakeExecuteTimeouts )
108
108
109
+ builtinSCCs = map [string ]struct {}{}
110
+
109
111
chaincodeMetrics := & chaincode.HandlerMetrics {
110
112
ShimRequestsReceived : fakeShimRequestsReceived ,
111
113
ShimRequestsCompleted : fakeShimRequestsCompleted ,
@@ -122,7 +124,7 @@ var _ = Describe("Handler", func() {
122
124
InstantiationPolicyChecker : fakeInstantiationPolicyChecker ,
123
125
QueryResponseBuilder : fakeQueryResponseBuilder ,
124
126
Registry : fakeHandlerRegistry ,
125
- SystemCCProvider : fakeSystemCCProvider ,
127
+ BuiltinSCCs : builtinSCCs ,
126
128
SystemCCVersion : "system-cc-version" ,
127
129
TXContexts : fakeContextRegistry ,
128
130
UUIDGenerator : chaincode .UUIDGeneratorFunc (func () string {
@@ -416,60 +418,46 @@ var _ = Describe("Handler", func() {
416
418
incomingMessage .ChannelId = ""
417
419
})
418
420
419
- It ("checks if the target is system chaincode" , func () {
421
+ It ("validates the transaction context" , func () {
422
+ txContext .TXSimulator = nil
420
423
handler .HandleTransaction (incomingMessage , fakeMessageHandler .Handle )
421
424
422
- Expect (fakeSystemCCProvider .IsSysCCCallCount ()).To (Equal (1 ))
423
- name := fakeSystemCCProvider .IsSysCCArgsForCall (0 )
424
- Expect (name ).To (Equal ("target-chaincode-name" ))
425
+ Eventually (fakeChatStream .SendCallCount ).Should (Equal (1 ))
426
+ msg := fakeChatStream .SendArgsForCall (0 )
427
+ Expect (msg ).To (Equal (& pb.ChaincodeMessage {
428
+ Type : pb .ChaincodeMessage_ERROR ,
429
+ Payload : []byte ("INVOKE_CHAINCODE failed: transaction ID: tx-id: could not get valid transaction" ),
430
+ Txid : "tx-id" ,
431
+ }))
425
432
})
426
433
427
- Context ("when the target chaincode is not system chaincode" , func () {
434
+ Context ("when the target is system chaincode" , func () {
428
435
BeforeEach (func () {
429
- fakeSystemCCProvider . IsSysCCReturns ( false )
436
+ builtinSCCs [ "target-chaincode-name" ] = struct {}{}
430
437
})
431
438
432
- It ("validates the transaction context" , func () {
439
+ It ("gets the transaction context without validation " , func () {
433
440
txContext .TXSimulator = nil
434
441
handler .HandleTransaction (incomingMessage , fakeMessageHandler .Handle )
435
442
443
+ Expect (fakeContextRegistry .GetCallCount ()).To (Equal (1 ))
436
444
Eventually (fakeChatStream .SendCallCount ).Should (Equal (1 ))
437
445
msg := fakeChatStream .SendArgsForCall (0 )
438
- Expect (msg ).To (Equal (& pb.ChaincodeMessage {
439
- Type : pb .ChaincodeMessage_ERROR ,
440
- Payload : []byte ("INVOKE_CHAINCODE failed: transaction ID: tx-id: could not get valid transaction" ),
441
- Txid : "tx-id" ,
442
- }))
446
+ Expect (msg ).To (Equal (expectedResponse ))
443
447
})
444
448
445
- Context ("when the target is system chaincode" , func () {
446
- BeforeEach (func () {
447
- fakeSystemCCProvider .IsSysCCReturns (true )
448
- })
449
-
450
- It ("gets the transaction context without validation" , func () {
451
- txContext .TXSimulator = nil
449
+ Context ("and the transaction context is missing" , func () {
450
+ It ("returns an error" , func () {
451
+ fakeContextRegistry .GetReturns (nil )
452
452
handler .HandleTransaction (incomingMessage , fakeMessageHandler .Handle )
453
453
454
- Expect (fakeContextRegistry .GetCallCount ()).To (Equal (1 ))
455
454
Eventually (fakeChatStream .SendCallCount ).Should (Equal (1 ))
456
455
msg := fakeChatStream .SendArgsForCall (0 )
457
- Expect (msg ).To (Equal (expectedResponse ))
458
- })
459
-
460
- Context ("and the transaction context is missing" , func () {
461
- It ("returns an error" , func () {
462
- fakeContextRegistry .GetReturns (nil )
463
- handler .HandleTransaction (incomingMessage , fakeMessageHandler .Handle )
464
-
465
- Eventually (fakeChatStream .SendCallCount ).Should (Equal (1 ))
466
- msg := fakeChatStream .SendArgsForCall (0 )
467
- Expect (msg ).To (Equal (& pb.ChaincodeMessage {
468
- Type : pb .ChaincodeMessage_ERROR ,
469
- Payload : []byte ("INVOKE_CHAINCODE failed: transaction ID: tx-id: failed to get transaction context" ),
470
- Txid : "tx-id" ,
471
- }))
472
- })
456
+ Expect (msg ).To (Equal (& pb.ChaincodeMessage {
457
+ Type : pb .ChaincodeMessage_ERROR ,
458
+ Payload : []byte ("INVOKE_CHAINCODE failed: transaction ID: tx-id: failed to get transaction context" ),
459
+ Txid : "tx-id" ,
460
+ }))
473
461
})
474
462
})
475
463
})
@@ -2197,15 +2185,6 @@ var _ = Describe("Handler", func() {
2197
2185
fakeInvoker .InvokeReturns (responseMessage , nil )
2198
2186
})
2199
2187
2200
- It ("checks if the target is a system chaincode" , func () {
2201
- _ , err := handler .HandleInvokeChaincode (incomingMessage , txContext )
2202
- Expect (err ).NotTo (HaveOccurred ())
2203
-
2204
- Expect (fakeSystemCCProvider .IsSysCCCallCount () >= 1 ).To (BeTrue ())
2205
- name := fakeSystemCCProvider .IsSysCCArgsForCall (0 )
2206
- Expect (name ).To (Equal ("target-chaincode-name" ))
2207
- })
2208
-
2209
2188
It ("evaluates the access control policy" , func () {
2210
2189
_ , err := handler .HandleInvokeChaincode (incomingMessage , txContext )
2211
2190
Expect (err ).NotTo (HaveOccurred ())
@@ -2331,7 +2310,7 @@ var _ = Describe("Handler", func() {
2331
2310
2332
2311
Context ("when the target is a system chaincode" , func () {
2333
2312
BeforeEach (func () {
2334
- fakeSystemCCProvider . IsSysCCReturns ( true )
2313
+ builtinSCCs [ "target-chaincode-name" ] = struct {}{}
2335
2314
})
2336
2315
2337
2316
It ("does not perform acl checks" , func () {
@@ -2352,10 +2331,6 @@ var _ = Describe("Handler", func() {
2352
2331
})
2353
2332
2354
2333
Context ("when the target is not a system chaincode" , func () {
2355
- BeforeEach (func () {
2356
- fakeSystemCCProvider .IsSysCCReturns (false )
2357
- })
2358
-
2359
2334
It ("gets the chaincode definition" , func () {
2360
2335
_ , err := handler .HandleInvokeChaincode (incomingMessage , txContext )
2361
2336
Expect (err ).NotTo (HaveOccurred ())
0 commit comments