Skip to content

Commit

Permalink
[FABG 998]Integration tests (#136)
Browse files Browse the repository at this point in the history
* Integration tests include: package cc, install cc, get installed cc package, query installed cc, approve cc, query approve cc, check commit readiness, commit cc, query committed cc

Signed-off-by: Jiehua Huang <huangjiehua@aisino.com>
  • Loading branch information
huangjiehua authored Aug 4, 2020
1 parent bdbc9bd commit f34cc66
Show file tree
Hide file tree
Showing 32 changed files with 1,661 additions and 337 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ FABRIC_CRYPTOCONFIG_VER ?= v$(FABRIC_PREV_VERSION_MAJOR)
FABRIC_CODELEVEL_UNITTEST_TAG ?= $(FABRIC_STABLE_CODELEVEL_TAG)
FABRIC_CODELEVEL_UNITTEST_VER ?= $(FABRIC_STABLE_CODELEVEL_VER)

# CC_MODE
CC_MODE_LIFECYCLE = lifecycle
CC_MODE_LSCC = lscc

# Local variables used by makefile
PROJECT_NAME := fabric-sdk-go
ARCH := $(shell uname -m)
Expand Down Expand Up @@ -317,7 +321,7 @@ integration-tests-stable: clean-tests depend-noforce populate-noforce
cd $(FIXTURE_DOCKERENV_PATH) && \
TEST_CHANGED_ONLY=$(FABRIC_SDKGO_TEST_CHANGED) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_STABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_STABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) \
FABRIC_FIXTURE_VERSION=v$(FABRIC_STABLE_VERSION_MINOR) FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) \
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" \
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" CC_MODE="$(CC_MODE_LIFECYCLE)"\
$(DOCKER_COMPOSE_CMD) $(BASE_DOCKER_COMPOSE_FILES) -f docker-compose-nopkcs11-test.yaml up $(DOCKER_COMPOSE_UP_TEST_FLAGS)
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "$(BASE_DOCKER_COMPOSE_FILES) -f ./docker-compose-nopkcs11-test.yaml"

Expand All @@ -328,7 +332,7 @@ integration-tests-prev: clean-tests depend-noforce populate-fixtures-prev-noforc
cd $(FIXTURE_DOCKERENV_PATH) && \
TEST_CHANGED_ONLY=$(FABRIC_SDKGO_TEST_CHANGED) E2E_ONLY="false" FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_PREV_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_PREV_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) \
FABRIC_FIXTURE_VERSION=v$(FABRIC_PREV_VERSION_MINOR) FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) \
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" \
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" CC_MODE="$(CC_MODE_LSCC)" \
$(DOCKER_COMPOSE_CMD) $(BASE_DOCKER_COMPOSE_FILES) -f docker-compose-nopkcs11-test.yaml up $(DOCKER_COMPOSE_UP_TEST_FLAGS)
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "$(BASE_DOCKER_COMPOSE_FILES) -f ./docker-compose-nopkcs11-test.yaml"

Expand Down Expand Up @@ -363,7 +367,7 @@ integration-tests-stable-negative: clean-tests depend-noforce populate-noforce
cd $(FIXTURE_DOCKERENV_PATH) && \
TEST_CHANGED_ONLY=$(FABRIC_SDKGO_TEST_CHANGED) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_STABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_STABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) \
FABRIC_FIXTURE_VERSION=v$(FABRIC_STABLE_VERSION_MINOR) FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) \
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" \
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" CC_MODE="$(CC_MODE_LIFECYCLE)"\
$(DOCKER_COMPOSE_CMD) $(BASE_DOCKER_COMPOSE_FILES) -f docker-compose-negative.yaml up $(DOCKER_COMPOSE_UP_TEST_FLAGS)
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "$(BASE_DOCKER_COMPOSE_FILES) -f ./docker-compose-negative.yaml"

Expand All @@ -374,7 +378,7 @@ integration-tests-stable-pkcs11: clean-tests depend-noforce populate-noforce
cd $(FIXTURE_DOCKERENV_PATH) && \
TEST_CHANGED_ONLY=$(FABRIC_SDKGO_TEST_CHANGED) FABRIC_SDKGO_CODELEVEL_VER=$(FABRIC_STABLE_CODELEVEL_VER) FABRIC_SDKGO_CODELEVEL_TAG=$(FABRIC_STABLE_CODELEVEL_TAG) FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) \
FABRIC_FIXTURE_VERSION=v$(FABRIC_STABLE_VERSION_MINOR) FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) \
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" \
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" CC_MODE="$(CC_MODE_LIFECYCLE)"\
$(DOCKER_COMPOSE_CMD) $(BASE_DOCKER_COMPOSE_FILES) -f docker-compose-pkcs11-test.yaml up $(DOCKER_COMPOSE_UP_TEST_FLAGS)
@cd $(FIXTURE_DOCKERENV_PATH) && FABRIC_DOCKER_REGISTRY=$(FABRIC_RELEASE_REGISTRY) $(FIXTURE_SCRIPTS_PATH)/check_status.sh "$(BASE_DOCKER_COMPOSE_FILES) -f ./docker-compose-pkcs11-test.yaml"

Expand Down
1 change: 1 addition & 0 deletions pkg/client/channel/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Request struct {
// The invoked chaincode (specified by ChaincodeID) may optionally be added to the invocation
// chain along with any collections, otherwise it may be omitted.
InvocationChain []*fab.ChaincodeCall
IsInit bool
}

//Response contains response parameters for query and execute an invocation transaction
Expand Down
1 change: 1 addition & 0 deletions pkg/client/channel/invoke/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Request struct {
// The invoked chaincode (specified by ChaincodeID) may optionally be added to the invocation
// chain along with any collections, otherwise it may be omitted.
InvocationChain []*fab.ChaincodeCall
IsInit bool
}

//Response contains response parameters for query and execute transaction
Expand Down
1 change: 1 addition & 0 deletions pkg/client/channel/invoke/txnhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func createAndSendTransactionProposal(transactor fab.ProposalSender, chrequest *
Fcn: chrequest.Fcn,
Args: chrequest.Args,
TransientMap: chrequest.TransientMap,
IsInit: chrequest.IsInit,
}

txh, err := transactor.CreateTransactionHeader(opts...)
Expand Down
2 changes: 2 additions & 0 deletions pkg/common/providers/fab/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ type TransactionHeader interface {
}

// ChaincodeInvokeRequest contains the parameters for sending a transaction proposal.
// nolint: maligned
type ChaincodeInvokeRequest struct {
ChaincodeID string
Lang pb.ChaincodeSpec_Type
TransientMap map[string][]byte
Fcn string
Args [][]byte
IsInit bool
}

// TransactionProposal contains a marashalled transaction proposal.
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/txn/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func CreateChaincodeInvokeProposal(txh fab.TransactionHeader, request fab.Chainc
// create invocation spec to target a chaincode with arguments
ccis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{
Type: request.Lang, ChaincodeId: &pb.ChaincodeID{Name: request.ChaincodeID},
Input: &pb.ChaincodeInput{Args: argsArray}}}
Input: &pb.ChaincodeInput{Args: argsArray, IsInit: request.IsInit}}}

proposal, _, err := protoutil.CreateChaincodeProposalWithTxIDNonceAndTransient(string(txh.TransactionID()), common.HeaderType_ENDORSER_TRANSACTION, txh.ChannelID(), ccis, txh.Nonce(), txh.Creator(), request.TransientMap)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/dockerenv/docker-compose-negative.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
- FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
- TEST_CHANGED_ONLY
- CORE_VM_ENDPOINT
- CC_MODE
volumes:
- ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
- ../../../:/opt/workspace/fabric-sdk-go
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/dockerenv/docker-compose-nopkcs11-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ services:
- E2E_ONLY
- TEST_CHANGED_ONLY
- CORE_VM_ENDPOINT
- CC_MODE
volumes:
- ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
- ../../../:/opt/workspace/fabric-sdk-go
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/dockerenv/docker-compose-pkcs11-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
- TEST_CHANGED_ONLY
- CORE_VM_ENDPOINT
- CC_MODE
volumes:
- ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
- ../../../:/opt/workspace/fabric-sdk-go
Expand Down
63 changes: 42 additions & 21 deletions test/fixtures/fabric/v2.2/config/configtx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,34 +147,41 @@ Organizations:
#
################################################################################
Capabilities:
# Global capabilities apply to both the orderers and the peers and must be
# supported by both. Set the value of the capability to true to require it.
# Channel capabilities apply to both the orderers and the peers and must be
# supported by both.
# Set the value of the capability to true to require it.
Channel: &ChannelCapabilities
# V1.1 for Global is a catchall flag for behavior which has been
# determined to be desired for all orderers and peers running v1.0.x,
# but the modification of which would cause imcompatibilities. Users
# should leave this flag set to true.
V1_1: true
# V2_0 capability ensures that orderers and peers behave according
# to v2.0 channel capabilities. Orderers and peers from
# prior releases would behave in an incompatible way, and are therefore
# not able to participate in channels at v2.0 capability.
# Prior to enabling V2.0 channel capabilities, ensure that all
# orderers and peers on a channel are at v2.0.0 or later.
V2_0: true

# Orderer capabilities apply only to the orderers, and may be safely
# manipulated without concern for upgrading peers. Set the value of the
# capability to true to require it.
# used with prior release peers.
# Set the value of the capability to true to require it.
Orderer: &OrdererCapabilities
# V1.1 for Order is a catchall flag for behavior which has been
# determined to be desired for all orderers running v1.0.x, but the
# modification of which would cause imcompatibilities. Users should
# leave this flag set to true.
V1_1: true
# V2_0 orderer capability ensures that orderers behave according
# to v2.0 orderer capabilities. Orderers from
# prior releases would behave in an incompatible way, and are therefore
# not able to participate in channels at v2.0 orderer capability.
# Prior to enabling V2.0 orderer capabilities, ensure that all
# orderers on channel are at v2.0.0 or later.
V2_0: true

# Application capabilities apply only to the peer network, and may be safely
# manipulated without concern for upgrading orderers. Set the value of the
# capability to true to require it.
# used with prior release orderers.
# Set the value of the capability to true to require it.
Application: &ApplicationCapabilities
# V1.1 for Application is a catchall flag for behavior which has been
# determined to be desired for all peers running v1.0.x, but the
# modification of which would cause incompatibilities. Users should
# leave this flag set to true.
V1_2: true
# V2_0 application capability ensures that peers behave according
# to v2.0 application capabilities. Peers from
# prior releases would behave in an incompatible way, and are therefore
# not able to participate in channels at v2.0 application capability.
# Prior to enabling V2.0 application capabilities, ensure that all
# peers on channel are at v2.0.0 or later.
V2_0: true


################################################################################
Expand Down Expand Up @@ -271,6 +278,20 @@ Application: &ApplicationDefaults
#User's can override these defaults with their own policy mapping by defining the
#mapping under ACLs in their channel definition

#---New Lifecycle System Chaincode (_lifecycle) function to policy mapping for access control--#

# ACL policy for _lifecycle's "CheckCommitReadiness" function
_lifecycle/CheckCommitReadiness: /Channel/Application/Writers

# ACL policy for _lifecycle's "CommitChaincodeDefinition" function
_lifecycle/CommitChaincodeDefinition: /Channel/Application/Writers

# ACL policy for _lifecycle's "QueryChaincodeDefinition" function
_lifecycle/QueryChaincodeDefinition: /Channel/Application/Readers

# ACL policy for _lifecycle's "QueryChaincodeDefinitions" function
_lifecycle/QueryChaincodeDefinitions: /Channel/Application/Readers

#---Lifecycle System Chaincode (lscc) function to policy mapping for access control---#

#ACL policy for lscc's "getid" function
Expand Down
22 changes: 22 additions & 0 deletions test/integration/base_test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,21 @@ func ExampleCCInitArgs() [][]byte {
return initArgs
}

//ExampleCCInitArgsLc returns example cc initialization args
func ExampleCCInitArgsLc() [][]byte {
return initArgs[1:]
}

//ExampleCCUpgradeArgs returns example cc upgrade args
func ExampleCCUpgradeArgs() [][]byte {
return upgradeArgs
}

//ExampleCCUpgradeArgsLc returns example cc upgrade args
func ExampleCCUpgradeArgsLc() [][]byte {
return upgradeArgs[1:]
}

// IsJoinedChannel returns true if the given peer has joined the given channel
func IsJoinedChannel(channelID string, resMgmtClient *resmgmt.Client, peer fabAPI.Peer) (bool, error) {
resp, err := resMgmtClient.QueryChannels(resmgmt.WithTargets(peer))
Expand Down Expand Up @@ -168,6 +178,18 @@ func GetDeployPath() string {
return filepath.Join(metadata.GetProjectPath(), ccPath)
}

// GetLcDeployPath returns the path to the chaincode fixtures
func GetLcDeployPath() string {
const ccPath = "test/fixtures/testdata/go/src/github.com/example_cc"
return filepath.Join(metadata.GetProjectPath(), ccPath)
}

// GetLcPvtDeployPath returns the path to the chaincode fixtures
func GetLcPvtDeployPath() string {
const ccPath = "test/fixtures/testdata/go/src/github.com/example_pvt_cc"
return filepath.Join(metadata.GetProjectPath(), ccPath)
}

// GetJavaDeployPath returns the path to the java chaincode fixtrues
func GetJavaDeployPath() string {
const ccPath = "test/fixtures/testdata/java"
Expand Down
Loading

0 comments on commit f34cc66

Please sign in to comment.