Skip to content

Moved service registration in final SDK from base SDKs #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: f-remove-sp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
atsafsc,
iou,
iou-hsm,
newiou,
orioncars,
pingpong,
stoprestart,
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ testing-docker-images:
docker tag postgres:16.2-alpine fsc.itests/postgres:latest

INTEGRATION_TARGETS = integration-tests-iou
INTEGRATION_TARGETS = integration-tests-newiou
INTEGRATION_TARGETS += integration-tests-atsacc
INTEGRATION_TARGETS += integration-tests-chaincode-events
INTEGRATION_TARGETS += integration-tests-atsafsc
Expand All @@ -104,6 +105,10 @@ integration-tests: $(INTEGRATION_TARGETS)
integration-tests-iou:
cd ./integration/fabric/iou; export FAB_BINS=$(FAB_BINS); ginkgo $(GINKGO_TEST_OPTS) .

.PHONY: integration-tests-newiou
integration-tests-newiou:
cd ./integration/fabric/newiou; export FAB_BINS=$(FAB_BINS); ginkgo $(GINKGO_TEST_OPTS) .

.PHONY: integration-tests-iou-hsm
integration-tests-iou-hsm:
@echo "Setup SoftHSM"
Expand Down
24 changes: 24 additions & 0 deletions integration/fabric/newiou/iou_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright IBM Corp All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package newiou_test

import (
"testing"

"github.com/hyperledger-labs/fabric-smart-client/integration"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestEndToEnd(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "NewIOU Suite")
}

func StartPort() int {
return integration.NewIOUPort.StartPortForNode()
}
107 changes: 107 additions & 0 deletions integration/fabric/newiou/iou_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Copyright IBM Corp All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package newiou_test

import (
"github.com/hyperledger-labs/fabric-smart-client/integration"
iou "github.com/hyperledger-labs/fabric-smart-client/integration/fabric/iou"
"github.com/hyperledger-labs/fabric-smart-client/integration/fabric/newiou"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/postgres"
. "github.com/onsi/ginkgo/v2"
)

var _ = Describe("EndToEnd", func() {
Describe("IOU Life Cycle With LibP2P", func() {
s := NewTestSuite(fsc.LibP2P, integration.NoReplication, true)
BeforeEach(s.Setup)
AfterEach(s.TearDown)
It("succeeded", s.TestSucceeded)
})

Describe("IOU Life Cycle With Websockets", func() {
s := NewTestSuite(fsc.WebSocket, integration.NoReplication, true)
BeforeEach(s.Setup)
AfterEach(s.TearDown)
It("succeeded", s.TestSucceeded)
})

Describe("IOU Life Cycle With Websockets and no TLS", func() {
s := NewTestSuite(fsc.WebSocket, integration.NoReplication, false)
BeforeEach(s.Setup)
AfterEach(s.TearDown)
It("succeeded", s.TestSucceeded)
})

Describe("IOU Life Cycle With Websockets and replicas", func() {
s := NewTestSuite(
fsc.WebSocket,
&integration.ReplicationOptions{
ReplicationFactors: map[string]int{
"borrower": 3,
"lender": 2,
},
SQLConfigs: map[string]*postgres.ContainerConfig{
"borrower": postgres.DefaultConfig("borrower-db"),
"lender": postgres.DefaultConfig("lender-db"),
},
},
true,
)
BeforeEach(s.Setup)
AfterEach(s.TearDown)
It("succeeded", s.TestSucceededWithReplicas)
})
})

type TestSuite struct {
*integration.TestSuite
}

func NewTestSuite(commType fsc.P2PCommunicationType, nodeOpts *integration.ReplicationOptions, tlsEnabled bool) *TestSuite {
return &TestSuite{TestSuite: integration.NewTestSuite(func() (*integration.Infrastructure, error) {
return integration.Generate(StartPort(), true, newiou.Topology(&iou.Opts{
SDK: &newiou.SDK{},
CommType: commType,
ReplicationOpts: nodeOpts,
TLSEnabled: tlsEnabled,
})...)
})}
}

func (s *TestSuite) TestSucceeded() {
iou.InitApprover(s.II, "approver1")
iou.InitApprover(s.II, "approver2")
iouState := iou.CreateIOU(s.II, "", 10, "approver1")
iou.CheckState(s.II, "borrower", iouState, 10)
iou.CheckState(s.II, "lender", iouState, 10)
iou.UpdateIOU(s.II, iouState, 5, "approver2")
iou.CheckState(s.II, "borrower", iouState, 5)
iou.CheckState(s.II, "lender", iouState, 5)

iou.CheckLocalMetrics(s.II, "borrower", "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/endorser/CollectEndorsementsView")
iou.CheckPrometheusMetrics(s.II, "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/endorser/CollectEndorsementsView")
}

func (s *TestSuite) TestSucceededWithReplicas() {
iou.InitApprover(s.II, "approver1")
iou.InitApprover(s.II, "approver2")

iouState := iou.CreateIOUWithBorrower(s.II, "fsc.borrower.0", "", 10, "approver1")
iou.CheckState(s.II, "fsc.borrower.0", iouState, 10)
iou.CheckState(s.II, "fsc.borrower.1", iouState, 10)
iou.CheckState(s.II, "fsc.borrower.2", iouState, 10)
iou.CheckState(s.II, "fsc.lender.0", iouState, 10)
iou.CheckState(s.II, "fsc.lender.1", iouState, 10)

iou.UpdateIOUWithBorrower(s.II, "fsc.borrower.1", iouState, 5, "approver2")
iou.CheckState(s.II, "fsc.borrower.0", iouState, 5)
iou.CheckState(s.II, "fsc.borrower.1", iouState, 5)
iou.CheckState(s.II, "fsc.borrower.2", iouState, 5)
iou.CheckState(s.II, "fsc.lender.0", iouState, 5)
iou.CheckState(s.II, "fsc.lender.1", iouState, 5)
}
121 changes: 121 additions & 0 deletions integration/fabric/newiou/sdk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package newiou

import (
"errors"

"github.com/hyperledger-labs/fabric-smart-client/integration/fabric/newiou/views"
"github.com/hyperledger-labs/fabric-smart-client/pkg/node"
dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
sdk "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/sdk/dig"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/endorser"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/state"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/vfsdk"
)

type SDK struct {
dig2.SDK
}

func NewSDK(registry node.Registry) *SDK {
return NewFrom(sdk.NewFrom(vfsdk.NewSDK(registry)))
}

func NewFrom(sdk dig2.SDK) *SDK {
return &SDK{SDK: sdk}
}

func (p *SDK) Install() error {
err := errors.Join(
p.Container().Provide(endorser.NewEndorseViewFactory),
p.Container().Provide(endorser.NewCollectEndorsementsViewFactory),
p.Container().Provide(state.NewRespondExchangeRecipientIdentitiesViewFactory),
p.Container().Provide(state.NewExchangeRecipientIdentitiesViewFactory),
p.Container().Provide(endorser.NewOrderingAndFinalityViewFactory),
p.Container().Provide(state.NewReceiveTransactionViewFactory),
)
if err != nil {
return err
}

return p.SDK.Install()
}

func NewApproverSDK(registry node.Registry) *ApproverSDK {
return NewApproverSDKFrom(NewSDK(registry))
}

func NewApproverSDKFrom(sdk dig2.SDK) *ApproverSDK {
return &ApproverSDK{SDK: sdk}
}

type ApproverSDK struct {
dig2.SDK
}

func (p *ApproverSDK) Install() error {
err := errors.Join(
p.Container().Provide(views.NewApproverViewFactory, vfsdk.WithInitiators(&views.CreateIOUView{}, &views.UpdateIOUView{})),
p.Container().Provide(views.NewApproverInitViewFactory, vfsdk.WithFactoryId("init")),
p.Container().Provide(endorser.NewFinalityViewFactory, vfsdk.WithFactoryId("finality")),
)
if err != nil {
return err
}
return p.SDK.Install()
}

func NewBorrowerSDK(registry node.Registry) *BorrowerSDK {
return NewBorrowerSDKFrom(NewSDK(registry))
}

func NewBorrowerSDKFrom(sdk dig2.SDK) *BorrowerSDK {
return &BorrowerSDK{SDK: sdk}
}

type BorrowerSDK struct {
dig2.SDK
}

func (p *BorrowerSDK) Install() error {
err := errors.Join(
p.Container().Provide(views.NewCreateIOUViewFactory, vfsdk.WithFactoryId("create")),
p.Container().Provide(views.NewUpdateIOUViewFactory, vfsdk.WithFactoryId("update")),
p.Container().Provide(views.NewQueryViewFactory, vfsdk.WithFactoryId("query")),
p.Container().Provide(endorser.NewFinalityViewFactory, vfsdk.WithFactoryId("finality")),
)
if err != nil {
return err
}
return p.SDK.Install()
}

func NewLenderSDK(registry node.Registry) *LenderSDK {
return NewLenderSDKFrom(NewSDK(registry))
}

func NewLenderSDKFrom(sdk dig2.SDK) *LenderSDK {
return &LenderSDK{SDK: sdk}
}

type LenderSDK struct {
dig2.SDK
}

func (p *LenderSDK) Install() error {
err := errors.Join(
p.Container().Provide(views.NewCreateIOUResponderViewFactory, vfsdk.WithInitiators(&views.CreateIOUView{})),
p.Container().Provide(views.NewUpdateIOUResponderViewFactory, vfsdk.WithInitiators(&views.UpdateIOUView{})),
p.Container().Provide(views.NewQueryViewFactory, vfsdk.WithFactoryId("query")),
p.Container().Provide(endorser.NewFinalityViewFactory, vfsdk.WithFactoryId("finality")),
)
if err != nil {
return err
}
return p.SDK.Install()
}
75 changes: 75 additions & 0 deletions integration/fabric/newiou/topology.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package newiou

import (
"github.com/hyperledger-labs/fabric-smart-client/integration/fabric/iou"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/monitoring"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/tracing"
)

func Topology(opts *iou.Opts) []api.Topology {
// Define a Fabric topology with:
// 1. Three organization: Org1, Org2, and Org3
// 2. A namespace whose changes can be endorsed by Org1.
fabricTopology := fabric.NewDefaultTopology()
fabricTopology.AddOrganizationsByName("Org1", "Org2", "Org3")
fabricTopology.SetNamespaceApproverOrgs("Org1")
fabricTopology.AddNamespaceWithUnanimity("iou", "Org1")
fabricTopology.TLSEnabled = opts.TLSEnabled

// Define an FSC topology with 3 FCS nodes.
// One for the approver, one for the borrower, and one for the lender.
fscTopology := fsc.NewTopology()
fscTopology.P2PCommunicationType = opts.CommType
fscTopology.EnablePrometheusMetrics()

// fscTopology.SetLogging("debug", "")
fscTopology.EnableTracing(tracing.Otpl)

// Add the approver FSC node.
fscTopology.AddNodeByName("approver1").
// This option equips the approver's FSC node with an identity belonging to Org1.
// Therefore, the approver is an endorser of the Fabric namespace we defined above.
AddOptions(fabric.WithOrganization("Org1")).
AddOptions(opts.ReplicationOpts.For("approver1")...).
AddSDK(&ApproverSDK{})

// Add another approver as well
fscTopology.AddNodeByName("approver2").
// This option equips the approver's FSC node with an identity belonging to Org1.
// Therefore, the approver is an endorser of the Fabric namespace we defined above.
AddOptions(fabric.WithOrganization("Org1")).
AddOptions(opts.ReplicationOpts.For("approver2")...).
AddSDK(&ApproverSDK{})

// Add the borrower's FSC node
fscTopology.AddNodeByName("borrower").
AddOptions(fabric.WithOrganization("Org2")).
AddOptions(opts.ReplicationOpts.For("borrower")...).
AddSDK(&BorrowerSDK{})

// Add the lender's FSC node
fscTopology.AddNodeByName("lender").
AddOptions(fabric.WithOrganization("Org3")).
AddOptions(opts.ReplicationOpts.For("lender")...).
AddSDK(&LenderSDK{})

// Monitoring
monitoringTopology := monitoring.NewTopology()
monitoringTopology.EnablePrometheusGrafana()
monitoringTopology.EnableOPTL()

return []api.Topology{
fabricTopology,
fscTopology,
monitoringTopology,
}
}
Loading