Skip to content

Commit

Permalink
v2 implementation based on fabric-chaincode-go/v2
Browse files Browse the repository at this point in the history
The v2 implementation retains wire-level compatibility with Fabric but
does include the following breaking changes:

- Chaincode implementations that make direct use of fabric-protos-go
  will experience protocol buffer namespace conflicts (as described in
  https://protobuf.dev/reference/go/faq/). Any use of fabric-protos-go
  must be replaced by fabric-protos-go-apiv2.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday committed Jun 19, 2024
1 parent 66f7b67 commit 8abc5ce
Show file tree
Hide file tree
Showing 81 changed files with 17,056 additions and 109 deletions.
94 changes: 6 additions & 88 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,93 +8,11 @@ on:
workflow_call:

jobs:
license_check:
name: License check
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: "https://npm.pkg.github.com"
- name: install Tools
run: |
npm install -g license-check-and-add@4.0.5
- name: Check Licenses
run: license-check-and-add check -f ci/license-config.json
checks:
uses: ./.github/workflows/check.yml

tutorial:
name: Check tutorial
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Check tutorial contents
run: ci/scripts/tutorial-checks.sh
test-v1:
uses: ./.github/workflows/test-v1.yml

lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Staticcheck
run: make staticcheck
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest

unit_test:
name: Unit test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Run tests (excluding fv)
run: make unit-test

functional_test:
name: Functional test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Run functional tests
run: make functional-test

integration_test:
name: Integration test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: "https://npm.pkg.github.com"
- name: Run the integration tests
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker build . --file integrationtest/Dockerfile --tag hyperledger/fabric-contract-api-go-integrationtest
ci/scripts/setup-integration-chaincode.sh
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- samples binary docker
export TEST_NETWORK_DIR=$(pwd)/fabric-samples/test-network
cd ./integrationtest
npm ci
npx fabric-chaincode-integration run
test-v2:
uses: ./.github/workflows/test-v2.yml
34 changes: 34 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: Checks

on:
workflow_call:

jobs:
license_check:
name: License check
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: "https://npm.pkg.github.com"
- name: install Tools
run: |
npm install -g license-check-and-add@4.0.5
- name: Check Licenses
run: license-check-and-add check -f ci/license-config.json

tutorial:
name: Check tutorial
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Check tutorial contents
run: ci/scripts/tutorial-checks.sh
73 changes: 73 additions & 0 deletions .github/workflows/test-v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: Test (v1)

on:
workflow_call:

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Staticcheck
run: make -f Makefile.v1 staticcheck
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest

unit_test:
name: Unit test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Run tests (excluding fv)
run: make -f Makefile.v1 unit-test

functional_test:
name: Functional test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Run functional tests
run: make -f Makefile.v1 functional-test

integration_test:
name: Integration test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: "https://npm.pkg.github.com"
- name: Run the integration tests
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker build . --file integrationtest/Dockerfile --tag hyperledger/fabric-contract-api-go-integrationtest
ci/scripts/setup-integration-chaincode.sh
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- samples binary docker
export TEST_NETWORK_DIR=$(pwd)/fabric-samples/test-network
cd ./integrationtest
npm ci
npx fabric-chaincode-integration run
74 changes: 74 additions & 0 deletions .github/workflows/test-v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

name: Test (v2)

on:
workflow_call:

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Staticcheck
run: make staticcheck
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: v2

unit_test:
name: Unit test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Run tests (excluding fv)
run: make unit-test

functional_test:
name: Functional test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Run functional tests
run: make functional-test

integration_test:
name: Integration test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: "https://npm.pkg.github.com"
- name: Run the integration tests
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker build . --file integrationtest/Dockerfile --tag hyperledger/fabric-contract-api-go-integrationtest
ci/scripts/setup-integration-chaincode.sh
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- samples binary docker
export TEST_NETWORK_DIR=$(pwd)/fabric-samples/test-network
cd ./integrationtest
npm ci
npx fabric-chaincode-integration run
28 changes: 24 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

base_dir := $(patsubst %/,%,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
base_dir := $(patsubst %/,%,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))/v2
functional_dir := $(base_dir)/internal/functionaltests
go_bin_dir := $(shell go env GOPATH)/bin

mockery_version := 2.43.2
kernel_name := $(shell uname -s)
machine_hardware := $(shell uname -m)

.PHONY: test
test: generate lint unit-test functional-test

.PHONY: lint
lint: staticcheck golangci-lint

.PHONY: staticcheck
staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck -f stylish './...'
cd '$(base_dir)' && staticcheck -f stylish './...'

.PHONY: install-golangci-lint
install-golangci-lint:
Expand All @@ -24,9 +31,22 @@ $(go_bin_dir)/golangci-lint:
golangci-lint: $(go_bin_dir)/golangci-lint
golangci-lint run

.PHONY: install-mockery
install-mockery:
curl --fail --location \
'https://github.com/vektra/mockery/releases/download/v$(mockery_version)/mockery_$(mockery_version)_$(kernel_name)_$(machine_hardware).tar.gz' \
| tar -C '$(go_bin_dir)' -xzf - mockery

$(go_bin_dir)/mockery:
$(MAKE) install-mockery

.PHONY: generate
generate: $(go_bin_dir)/mockery
cd '$(base_dir)' && mockery

.PHONY: unit-test
unit-test:
go test -race $$(go list '$(base_dir)/...' | grep -v functionaltests)
cd '$(base_dir)' && go test -race $$(go list ./... | grep -v functionaltests)

.PHONY: functional-test
functional-test:
Expand All @@ -36,4 +56,4 @@ functional-test:
.PHONY: scan
scan:
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck '$(base_dir)/...'
cd '$(base_dir)' && govulncheck ./...
42 changes: 42 additions & 0 deletions Makefile.v1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright the Hyperledger Fabric contributors. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

base_dir := $(patsubst %/,%,$(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
functional_dir := $(base_dir)/internal/functionaltests
go_bin_dir := $(shell go env GOPATH)/bin

.PHONY: test
test: lint unit-test functional-test

.PHONY: lint
lint: staticcheck golangci-lint

.PHONY: staticcheck
staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@latest
cd '$(base_dir)' && staticcheck -f stylish './...'

.PHONY: install-golangci-lint
install-golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b '$(go_bin_dir)'

$(go_bin_dir)/golangci-lint:
$(MAKE) install-golangci-lint

.PHONY: golangci-lint
golangci-lint: $(go_bin_dir)/golangci-lint
cd '$(base_dir)' && golangci-lint run

.PHONY: unit-test
unit-test:
cd '$(base_dir)' && go test -race $$(go list ./... | grep -v functionaltests)

.PHONY: functional-test
functional-test:
go install github.com/cucumber/godog/cmd/godog@v0.12
cd '$(functional_dir)' && godog run features/*

.PHONY: scan
scan:
go install golang.org/x/vuln/cmd/govulncheck@latest
cd '$(base_dir)' && govulncheck ./...
Loading

0 comments on commit 8abc5ce

Please sign in to comment.