Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit f34cc66

Browse files
authored
[FABG 998]Integration tests (#136)
* 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 <[email protected]>
1 parent bdbc9bd commit f34cc66

32 files changed

+1661
-337
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ FABRIC_CRYPTOCONFIG_VER ?= v$(FABRIC_PREV_VERSION_MAJOR)
108108
FABRIC_CODELEVEL_UNITTEST_TAG ?= $(FABRIC_STABLE_CODELEVEL_TAG)
109109
FABRIC_CODELEVEL_UNITTEST_VER ?= $(FABRIC_STABLE_CODELEVEL_VER)
110110

111+
# CC_MODE
112+
CC_MODE_LIFECYCLE = lifecycle
113+
CC_MODE_LSCC = lscc
114+
111115
# Local variables used by makefile
112116
PROJECT_NAME := fabric-sdk-go
113117
ARCH := $(shell uname -m)
@@ -317,7 +321,7 @@ integration-tests-stable: clean-tests depend-noforce populate-noforce
317321
cd $(FIXTURE_DOCKERENV_PATH) && \
318322
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) \
319323
FABRIC_FIXTURE_VERSION=v$(FABRIC_STABLE_VERSION_MINOR) FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) \
320-
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" \
324+
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" CC_MODE="$(CC_MODE_LIFECYCLE)"\
321325
$(DOCKER_COMPOSE_CMD) $(BASE_DOCKER_COMPOSE_FILES) -f docker-compose-nopkcs11-test.yaml up $(DOCKER_COMPOSE_UP_TEST_FLAGS)
322326
@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"
323327

@@ -328,7 +332,7 @@ integration-tests-prev: clean-tests depend-noforce populate-fixtures-prev-noforc
328332
cd $(FIXTURE_DOCKERENV_PATH) && \
329333
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) \
330334
FABRIC_FIXTURE_VERSION=v$(FABRIC_PREV_VERSION_MINOR) FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) \
331-
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" \
335+
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" CC_MODE="$(CC_MODE_LSCC)" \
332336
$(DOCKER_COMPOSE_CMD) $(BASE_DOCKER_COMPOSE_FILES) -f docker-compose-nopkcs11-test.yaml up $(DOCKER_COMPOSE_UP_TEST_FLAGS)
333337
@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"
334338

@@ -363,7 +367,7 @@ integration-tests-stable-negative: clean-tests depend-noforce populate-noforce
363367
cd $(FIXTURE_DOCKERENV_PATH) && \
364368
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) \
365369
FABRIC_FIXTURE_VERSION=v$(FABRIC_STABLE_VERSION_MINOR) FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) \
366-
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" \
370+
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" CC_MODE="$(CC_MODE_LIFECYCLE)"\
367371
$(DOCKER_COMPOSE_CMD) $(BASE_DOCKER_COMPOSE_FILES) -f docker-compose-negative.yaml up $(DOCKER_COMPOSE_UP_TEST_FLAGS)
368372
@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"
369373

@@ -374,7 +378,7 @@ integration-tests-stable-pkcs11: clean-tests depend-noforce populate-noforce
374378
cd $(FIXTURE_DOCKERENV_PATH) && \
375379
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) \
376380
FABRIC_FIXTURE_VERSION=v$(FABRIC_STABLE_VERSION_MINOR) FABRIC_CRYPTOCONFIG_VERSION=$(FABRIC_CRYPTOCONFIG_VER) \
377-
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" \
381+
GO_TESTFLAGS="$(GO_TESTFLAGS_INTEGRATION)" CC_MODE="$(CC_MODE_LIFECYCLE)"\
378382
$(DOCKER_COMPOSE_CMD) $(BASE_DOCKER_COMPOSE_FILES) -f docker-compose-pkcs11-test.yaml up $(DOCKER_COMPOSE_UP_TEST_FLAGS)
379383
@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"
380384

pkg/client/channel/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Request struct {
5050
// The invoked chaincode (specified by ChaincodeID) may optionally be added to the invocation
5151
// chain along with any collections, otherwise it may be omitted.
5252
InvocationChain []*fab.ChaincodeCall
53+
IsInit bool
5354
}
5455

5556
//Response contains response parameters for query and execute an invocation transaction

pkg/client/channel/invoke/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Request struct {
5050
// The invoked chaincode (specified by ChaincodeID) may optionally be added to the invocation
5151
// chain along with any collections, otherwise it may be omitted.
5252
InvocationChain []*fab.ChaincodeCall
53+
IsInit bool
5354
}
5455

5556
//Response contains response parameters for query and execute transaction

pkg/client/channel/invoke/txnhandler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ func createAndSendTransactionProposal(transactor fab.ProposalSender, chrequest *
281281
Fcn: chrequest.Fcn,
282282
Args: chrequest.Args,
283283
TransientMap: chrequest.TransientMap,
284+
IsInit: chrequest.IsInit,
284285
}
285286

286287
txh, err := transactor.CreateTransactionHeader(opts...)

pkg/common/providers/fab/proposer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ type TransactionHeader interface {
6464
}
6565

6666
// ChaincodeInvokeRequest contains the parameters for sending a transaction proposal.
67+
// nolint: maligned
6768
type ChaincodeInvokeRequest struct {
6869
ChaincodeID string
6970
Lang pb.ChaincodeSpec_Type
7071
TransientMap map[string][]byte
7172
Fcn string
7273
Args [][]byte
74+
IsInit bool
7375
}
7476

7577
// TransactionProposal contains a marashalled transaction proposal.

pkg/fab/txn/proposal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func CreateChaincodeInvokeProposal(txh fab.TransactionHeader, request fab.Chainc
4242
// create invocation spec to target a chaincode with arguments
4343
ccis := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{
4444
Type: request.Lang, ChaincodeId: &pb.ChaincodeID{Name: request.ChaincodeID},
45-
Input: &pb.ChaincodeInput{Args: argsArray}}}
45+
Input: &pb.ChaincodeInput{Args: argsArray, IsInit: request.IsInit}}}
4646

4747
proposal, _, err := protoutil.CreateChaincodeProposalWithTxIDNonceAndTransient(string(txh.TransactionID()), common.HeaderType_ENDORSER_TRANSACTION, txh.ChannelID(), ccis, txh.Nonce(), txh.Creator(), request.TransientMap)
4848
if err != nil {

test/fixtures/dockerenv/docker-compose-negative.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ services:
2020
- FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
2121
- TEST_CHANGED_ONLY
2222
- CORE_VM_ENDPOINT
23+
- CC_MODE
2324
volumes:
2425
- ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
2526
- ../../../:/opt/workspace/fabric-sdk-go

test/fixtures/dockerenv/docker-compose-nopkcs11-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
- E2E_ONLY
2323
- TEST_CHANGED_ONLY
2424
- CORE_VM_ENDPOINT
25+
- CC_MODE
2526
volumes:
2627
- ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
2728
- ../../../:/opt/workspace/fabric-sdk-go

test/fixtures/dockerenv/docker-compose-pkcs11-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ services:
2121
- FABRIC_SDK_CLIENT_EVENTSERVICE_TYPE
2222
- TEST_CHANGED_ONLY
2323
- CORE_VM_ENDPOINT
24+
- CC_MODE
2425
volumes:
2526
- ${GOPATH}/pkg/mod:/opt/gopath/pkg/mod
2627
- ../../../:/opt/workspace/fabric-sdk-go

test/fixtures/fabric/v2.2/config/configtx.yaml

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,34 +147,41 @@ Organizations:
147147
#
148148
################################################################################
149149
Capabilities:
150-
# Global capabilities apply to both the orderers and the peers and must be
151-
# supported by both. Set the value of the capability to true to require it.
150+
# Channel capabilities apply to both the orderers and the peers and must be
151+
# supported by both.
152+
# Set the value of the capability to true to require it.
152153
Channel: &ChannelCapabilities
153-
# V1.1 for Global is a catchall flag for behavior which has been
154-
# determined to be desired for all orderers and peers running v1.0.x,
155-
# but the modification of which would cause imcompatibilities. Users
156-
# should leave this flag set to true.
157-
V1_1: true
154+
# V2_0 capability ensures that orderers and peers behave according
155+
# to v2.0 channel capabilities. Orderers and peers from
156+
# prior releases would behave in an incompatible way, and are therefore
157+
# not able to participate in channels at v2.0 capability.
158+
# Prior to enabling V2.0 channel capabilities, ensure that all
159+
# orderers and peers on a channel are at v2.0.0 or later.
160+
V2_0: true
158161

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

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

179186

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

281+
#---New Lifecycle System Chaincode (_lifecycle) function to policy mapping for access control--#
282+
283+
# ACL policy for _lifecycle's "CheckCommitReadiness" function
284+
_lifecycle/CheckCommitReadiness: /Channel/Application/Writers
285+
286+
# ACL policy for _lifecycle's "CommitChaincodeDefinition" function
287+
_lifecycle/CommitChaincodeDefinition: /Channel/Application/Writers
288+
289+
# ACL policy for _lifecycle's "QueryChaincodeDefinition" function
290+
_lifecycle/QueryChaincodeDefinition: /Channel/Application/Readers
291+
292+
# ACL policy for _lifecycle's "QueryChaincodeDefinitions" function
293+
_lifecycle/QueryChaincodeDefinitions: /Channel/Application/Readers
294+
274295
#---Lifecycle System Chaincode (lscc) function to policy mapping for access control---#
275296

276297
#ACL policy for lscc's "getid" function

test/integration/base_test_setup.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,21 @@ func ExampleCCInitArgs() [][]byte {
9595
return initArgs
9696
}
9797

98+
//ExampleCCInitArgsLc returns example cc initialization args
99+
func ExampleCCInitArgsLc() [][]byte {
100+
return initArgs[1:]
101+
}
102+
98103
//ExampleCCUpgradeArgs returns example cc upgrade args
99104
func ExampleCCUpgradeArgs() [][]byte {
100105
return upgradeArgs
101106
}
102107

108+
//ExampleCCUpgradeArgsLc returns example cc upgrade args
109+
func ExampleCCUpgradeArgsLc() [][]byte {
110+
return upgradeArgs[1:]
111+
}
112+
103113
// IsJoinedChannel returns true if the given peer has joined the given channel
104114
func IsJoinedChannel(channelID string, resMgmtClient *resmgmt.Client, peer fabAPI.Peer) (bool, error) {
105115
resp, err := resMgmtClient.QueryChannels(resmgmt.WithTargets(peer))
@@ -168,6 +178,18 @@ func GetDeployPath() string {
168178
return filepath.Join(metadata.GetProjectPath(), ccPath)
169179
}
170180

181+
// GetLcDeployPath returns the path to the chaincode fixtures
182+
func GetLcDeployPath() string {
183+
const ccPath = "test/fixtures/testdata/go/src/github.com/example_cc"
184+
return filepath.Join(metadata.GetProjectPath(), ccPath)
185+
}
186+
187+
// GetLcPvtDeployPath returns the path to the chaincode fixtures
188+
func GetLcPvtDeployPath() string {
189+
const ccPath = "test/fixtures/testdata/go/src/github.com/example_pvt_cc"
190+
return filepath.Join(metadata.GetProjectPath(), ccPath)
191+
}
192+
171193
// GetJavaDeployPath returns the path to the java chaincode fixtrues
172194
func GetJavaDeployPath() string {
173195
const ccPath = "test/fixtures/testdata/java"

0 commit comments

Comments
 (0)