Skip to content

Commit

Permalink
FAB-10977 Extract lifecycle to interface
Browse files Browse the repository at this point in the history
This is step two to remove lifecycle from the chaincode package,
replacing the explicit dependency in the tests on the lifecycle
implementation with a mocked implementation.

Change-Id: I4243d691d2de7dabac3af998c3b8b8354e80a602
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jul 10, 2018
1 parent 305c5ad commit b1dd84b
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 160 deletions.
11 changes: 5 additions & 6 deletions core/chaincode/chaincode_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package chaincode_test
import (
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/chaincode/lifecycle"
"github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/container/ccintf"
"github.com/hyperledger/fabric/core/ledger"
Expand Down Expand Up @@ -54,11 +53,6 @@ type processor interface {
chaincode.Processor
}

//go:generate counterfeiter -o mock/executor.go --fake-name Executor . executor
type executor interface {
lifecycle.Executor
}

//go:generate counterfeiter -o mock/invoker.go --fake-name Invoker . invoker
type invoker interface {
chaincode.Invoker
Expand All @@ -69,6 +63,11 @@ type packageProvider interface {
chaincode.PackageProvider
}

//go:generate counterfeiter -o mock/lifecycle.go --fake-name Lifecycle . lifecycle
type lifecycle interface {
chaincode.Lifecycle
}

//go:generate counterfeiter -o mock/cc_package.go --fake-name CCPackage . ccpackage
type ccpackage interface {
ccprovider.CCPackage
Expand Down
23 changes: 23 additions & 0 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ type Launcher interface {
LaunchInit(context context.Context, cccid *ccprovider.CCContext, spec *pb.ChaincodeDeploymentSpec) error
}

// Lifecycle provides a way to retrieve chaincode definitions and the packages necessary to run them
type Lifecycle interface {
// GetChaincodeDefinition returns the details for a chaincode by name
GetChaincodeDefinition(
ctx context.Context,
txid string,
signedProp *pb.SignedProposal,
prop *pb.Proposal,
chainID string,
chaincodeID string,
) (ccprovider.ChaincodeDefinition, error)

// GetChaincodeDeploymentSpec returns the package necessary to launch a chaincode
GetChaincodeDeploymentSpec(
ctx context.Context,
txid string,
signedProp *pb.SignedProposal,
prop *pb.Proposal,
chainID string,
chaincodeID string,
) (*pb.ChaincodeDeploymentSpec, error)
}

// ChaincodeSupport responsible for providing interfacing with chaincodes from the Peer.
type ChaincodeSupport struct {
Keepalive time.Duration
Expand Down
112 changes: 0 additions & 112 deletions core/chaincode/mock/executor.go

This file was deleted.

189 changes: 189 additions & 0 deletions core/chaincode/mock/lifecycle.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions core/chaincode/runtime_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package chaincode
import (
"time"

"github.com/hyperledger/fabric/core/chaincode/lifecycle"
"github.com/hyperledger/fabric/core/common/ccprovider"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/pkg/errors"
Expand All @@ -32,7 +31,7 @@ type RuntimeLauncher struct {
Runtime Runtime
Registry LaunchRegistry
PackageProvider PackageProvider
Lifecycle *lifecycle.Lifecycle
Lifecycle Lifecycle
StartupTimeout time.Duration
}

Expand Down
Loading

0 comments on commit b1dd84b

Please sign in to comment.