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

Commit

Permalink
Merge 9a1164f into 820c5a0
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiko committed Dec 14, 2021
2 parents 820c5a0 + 9a1164f commit 1c7b0f1
Show file tree
Hide file tree
Showing 48 changed files with 4,631 additions and 2,597 deletions.
4 changes: 2 additions & 2 deletions examples/cpaper_asservice/bin/api/mock/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/s7techlab/cckit/examples/cpaper_asservice"
cpaperservice "github.com/s7techlab/cckit/examples/cpaper_asservice/service"
"github.com/s7techlab/cckit/gateway"
servicemock "github.com/s7techlab/cckit/gateway/service/mock"
gwmock "github.com/s7techlab/cckit/gateway/mock"
"github.com/s7techlab/cckit/testing"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ func main() {
cpaperMock := testing.NewMockStub(chaincodeName, cc)

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

// default identity for signing requests to peeer (mocked)
apiIdentity, err := testing.IdentityFromFile(`MSP`, `../../../testdata/admin.pem`, ioutil.ReadFile)
Expand Down
26 changes: 8 additions & 18 deletions examples/cpaper_asservice/chaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

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

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

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

Expect(<-cc.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
EventName: `BuyCommercialPaper`,
Payload: testcc.MustProtoMarshal(buyTransactionData),
}))

expectcc.EventStringerEqual(<-cc.ChaincodeEventsChannel,
`BuyCommercialPaper`, buyTransactionData)
cc.ClearEvents()
})

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

Expect(<-cc.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
EventName: `RedeemCommercialPaper`,
Payload: testcc.MustProtoMarshal(redeemTransactionData),
}))
expectcc.EventStringerEqual(<-cc.ChaincodeEventsChannel,
`RedeemCommercialPaper`, redeemTransactionData)

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

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

// Clear events channel after a test case that emits an event
cc.ClearEvents()
Expand Down
19 changes: 6 additions & 13 deletions examples/cpaper_extended/chaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
. "github.com/onsi/gomega"

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

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

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

Expect(<-paperChaincode.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
EventName: `BuyCommercialPaper`,
Payload: testcc.MustProtoMarshal(buyTransactionData),
}))
expectcc.EventStringerEqual(<-paperChaincode.ChaincodeEventsChannel,
`BuyCommercialPaper`, buyTransactionData)

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

Expect(<-paperChaincode.ChaincodeEventsChannel).To(BeEquivalentTo(&peer.ChaincodeEvent{
EventName: `RedeemCommercialPaper`,
Payload: testcc.MustProtoMarshal(redeemTransactionData),
}))
expectcc.EventStringerEqual(<-paperChaincode.ChaincodeEventsChannel,
`RedeemCommercialPaper`, redeemTransactionData)

paperChaincode.ClearEvents()
})
Expand Down
7 changes: 5 additions & 2 deletions extensions/encryption/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ var _ = Describe(`Router`, func() {
})
//
It("Allow to create payment providing key in encryptPaymentCC ", func(done Done) {
events := encryptPaymentCCWithEncStateContext.EventSubscription()
events, closer := encryptPaymentCCWithEncStateContext.EventSubscription()

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

//event name and payload is encrypted with key
Expect(<-events).To(BeEquivalentTo(encryption.MustEncryptEvent(encKey, &peer.ChaincodeEvent{
EventName: `PaymentEvent`,
ChaincodeId: encCCInvoker.MockStub.Name,
TxId: encCCInvoker.MockStub.LastTxID,
EventName: `PaymentEvent`,
Payload: testcc.MustProtoMarshal(&schema.PaymentEvent{
Type: pType,
Id: pID1,
Amount: pAmount3,
}),
})))

closer()
close(done)
}, 0.2)

Expand Down
14 changes: 14 additions & 0 deletions gateway/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.: generate

generate:
@echo "chaincode invoke service"
@protoc -I=. \
-I=../../ \
-I=../vendor \
-I=../third_party/googleapis \
-I=../third_party/hyperledger \
--grpc-gateway-b2bchain_out=paths=source_relative:. \
--go-b2bchain_out=paths=source_relative,plugins=grpc:. \
--govalidators-b2bchain_out=paths=source_relative:. \
--swagger-b2bchain_out=logtostderr=true:. \
chaincode.proto

0 comments on commit 1c7b0f1

Please sign in to comment.