Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 5555d8a

Browse files
authored
Gw service refactoring (#81)
cc service refactoring
1 parent 820c5a0 commit 5555d8a

49 files changed

Lines changed: 4705 additions & 2670 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/cpaper_asservice/bin/api/mock/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/s7techlab/cckit/examples/cpaper_asservice"
1313
cpaperservice "github.com/s7techlab/cckit/examples/cpaper_asservice/service"
1414
"github.com/s7techlab/cckit/gateway"
15-
servicemock "github.com/s7techlab/cckit/gateway/service/mock"
15+
gwmock "github.com/s7techlab/cckit/gateway/mock"
1616
"github.com/s7techlab/cckit/testing"
1717
"google.golang.org/grpc"
1818
)
@@ -42,7 +42,7 @@ func main() {
4242
cpaperMock := testing.NewMockStub(chaincodeName, cc)
4343

4444
// Chaincode invocation service mock. For real network you can use example with hlf-sdk-go
45-
cpaperMockService := servicemock.New(testing.NewPeer().WithChannel(channelName, cpaperMock))
45+
cpaperMockService := gwmock.New(testing.NewPeer().WithChannel(channelName, cpaperMock))
4646

4747
// default identity for signing requests to peeer (mocked)
4848
apiIdentity, err := testing.IdentityFromFile(`MSP`, `../../../testdata/admin.pem`, ioutil.ReadFile)

examples/cpaper_asservice/chaincode_test.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/golang/protobuf/ptypes"
1313
"github.com/golang/protobuf/ptypes/empty"
14-
"github.com/hyperledger/fabric-protos-go/peer"
1514
"github.com/hyperledger/fabric/msp"
1615
"github.com/s7techlab/cckit/examples/cpaper_asservice"
1716
"github.com/s7techlab/cckit/examples/cpaper_asservice/schema"
@@ -89,10 +88,8 @@ var _ = Describe(`CommercialPaper`, func() {
8988
expectcc.ResponseOk(cc.Invoke(s.CPaperChaincode_Issue, issuePayload))
9089

9190
// Validate event has been emitted with the transaction data
92-
Expect(<-cc.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
93-
EventName: `IssueCommercialPaper`,
94-
Payload: testcc.MustProtoMarshal(issuePayload),
95-
}))
91+
expectcc.EventStringerEqual(<-cc.ChaincodeEventsChannel,
92+
`IssueCommercialPaper`, issuePayload)
9693

9794
// Clear events channel after a test case that emits an event
9895
cc.ClearEvents()
@@ -161,11 +158,8 @@ var _ = Describe(`CommercialPaper`, func() {
161158
Expect(paper.Owner).To(Equal(BuyerName))
162159
Expect(paper.State).To(Equal(schema.CommercialPaper_TRADING))
163160

164-
Expect(<-cc.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
165-
EventName: `BuyCommercialPaper`,
166-
Payload: testcc.MustProtoMarshal(buyTransactionData),
167-
}))
168-
161+
expectcc.EventStringerEqual(<-cc.ChaincodeEventsChannel,
162+
`BuyCommercialPaper`, buyTransactionData)
169163
cc.ClearEvents()
170164
})
171165

@@ -188,10 +182,8 @@ var _ = Describe(`CommercialPaper`, func() {
188182
Expect(paper.Owner).To(Equal(IssuerName))
189183
Expect(paper.State).To(Equal(schema.CommercialPaper_REDEEMED))
190184

191-
Expect(<-cc.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
192-
EventName: `RedeemCommercialPaper`,
193-
Payload: testcc.MustProtoMarshal(redeemTransactionData),
194-
}))
185+
expectcc.EventStringerEqual(<-cc.ChaincodeEventsChannel,
186+
`RedeemCommercialPaper`, redeemTransactionData)
195187

196188
cc.ClearEvents()
197189
})
@@ -216,10 +208,8 @@ var _ = Describe(`CommercialPaper`, func() {
216208
expectcc.ResponseOk(ccEncWrapped.Invoke(s.CPaperChaincode_Issue, issuePayload))
217209

218210
// Validate event has been emitted with the transaction data, and event name and payload is encrypted
219-
Expect(<-ccEnc.ChaincodeEventsChannel).To(BeEquivalentTo(encryption.MustEncryptEvent(encKey, &peer.ChaincodeEvent{
220-
EventName: `IssueCommercialPaper`,
221-
Payload: testcc.MustProtoMarshal(issuePayload),
222-
})))
211+
expectcc.EventStringerEqual(ccEncWrapped.LastEvent(),
212+
`IssueCommercialPaper`, issuePayload)
223213

224214
// Clear events channel after a test case that emits an event
225215
cc.ClearEvents()

examples/cpaper_extended/chaincode_test.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
. "github.com/onsi/gomega"
99

1010
"github.com/golang/protobuf/ptypes"
11-
"github.com/hyperledger/fabric-protos-go/peer"
1211
"github.com/s7techlab/cckit/examples/cpaper_extended"
1312
"github.com/s7techlab/cckit/examples/cpaper_extended/schema"
1413
"github.com/s7techlab/cckit/examples/cpaper_extended/testdata"
@@ -60,10 +59,8 @@ var _ = Describe(`CommercialPaper`, func() {
6059
paperChaincode.Invoke(`issue`, issueTransactionData))
6160

6261
// Validate event has been emitted with the transaction data
63-
Expect(<-paperChaincode.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
64-
EventName: `IssueCommercialPaper`,
65-
Payload: testcc.MustProtoMarshal(issueTransactionData),
66-
}))
62+
expectcc.EventStringerEqual(<-paperChaincode.ChaincodeEventsChannel,
63+
`IssueCommercialPaper`, issueTransactionData)
6764

6865
// Clear events channel after a test case that emits an event
6966
paperChaincode.ClearEvents()
@@ -133,10 +130,8 @@ var _ = Describe(`CommercialPaper`, func() {
133130
Expect(paper.Owner).To(Equal(BuyerName))
134131
Expect(paper.State).To(Equal(schema.CommercialPaper_TRADING))
135132

136-
Expect(<-paperChaincode.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
137-
EventName: `BuyCommercialPaper`,
138-
Payload: testcc.MustProtoMarshal(buyTransactionData),
139-
}))
133+
expectcc.EventStringerEqual(<-paperChaincode.ChaincodeEventsChannel,
134+
`BuyCommercialPaper`, buyTransactionData)
140135

141136
paperChaincode.ClearEvents()
142137
})
@@ -160,10 +155,8 @@ var _ = Describe(`CommercialPaper`, func() {
160155
Expect(paper.Owner).To(Equal(IssuerName))
161156
Expect(paper.State).To(Equal(schema.CommercialPaper_REDEEMED))
162157

163-
Expect(<-paperChaincode.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
164-
EventName: `RedeemCommercialPaper`,
165-
Payload: testcc.MustProtoMarshal(redeemTransactionData),
166-
}))
158+
expectcc.EventStringerEqual(<-paperChaincode.ChaincodeEventsChannel,
159+
`RedeemCommercialPaper`, redeemTransactionData)
167160

168161
paperChaincode.ClearEvents()
169162
})

extensions/encryption/encryption_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ var _ = Describe(`Router`, func() {
228228
})
229229
//
230230
It("Allow to create payment providing key in encryptPaymentCC ", func(done Done) {
231-
events := encryptPaymentCCWithEncStateContext.EventSubscription()
231+
events, closer := encryptPaymentCCWithEncStateContext.EventSubscription()
232232

233233
responsePayment := expectcc.PayloadIs(
234234
// encCCInvoker encrypts args before passing to cc invoke and pass key in transient map
@@ -242,14 +242,17 @@ var _ = Describe(`Router`, func() {
242242

243243
//event name and payload is encrypted with key
244244
Expect(<-events).To(BeEquivalentTo(encryption.MustEncryptEvent(encKey, &peer.ChaincodeEvent{
245-
EventName: `PaymentEvent`,
245+
ChaincodeId: encCCInvoker.MockStub.Name,
246+
TxId: encCCInvoker.MockStub.LastTxID,
247+
EventName: `PaymentEvent`,
246248
Payload: testcc.MustProtoMarshal(&schema.PaymentEvent{
247249
Type: pType,
248250
Id: pID1,
249251
Amount: pAmount3,
250252
}),
251253
})))
252254

255+
closer()
253256
close(done)
254257
}, 0.2)
255258

gateway/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.: generate
2+
3+
generate:
4+
@echo "chaincode invoke service"
5+
@protoc -I=. \
6+
-I=../../ \
7+
-I=../vendor \
8+
-I=../third_party/googleapis \
9+
-I=../third_party/hyperledger \
10+
--grpc-gateway-b2bchain_out=paths=source_relative:. \
11+
--go-b2bchain_out=paths=source_relative,plugins=grpc:. \
12+
--govalidators-b2bchain_out=paths=source_relative:. \
13+
--swagger-b2bchain_out=logtostderr=true:. \
14+
chaincode.proto

0 commit comments

Comments
 (0)