mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
Move lint and test-network-basic tests from Azure to GHA - READY FOR MERGE (#862)
* Move Test Network Basic tests from Azure to GHA Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com> * Move linters from Azure to GHA Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com> * Apply review comments - pin java, node, and go runtimes Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com> Signed-off-by: Josh Kneubuhl <jkneubuh@us.ibm.com>
This commit is contained in:
parent
34734cfff2
commit
0ce94bbb9b
24 changed files with 702 additions and 242 deletions
64
.github/workflows/lint.yaml
vendored
Normal file
64
.github/workflows/lint.yaml
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
name: Lint
|
||||||
|
run-name: ${{ github.actor }} is linting fabric-samples
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
env:
|
||||||
|
GO_VER: 1.18.3
|
||||||
|
NODE_VER: 16.x
|
||||||
|
JAVA_VER: 11.x
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
go:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ${{ env.GO_VER }}
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: go install golang.org/x/tools/cmd/goimports@latest
|
||||||
|
- run: ci/scripts/lint-go.sh
|
||||||
|
|
||||||
|
typescript:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VER }}
|
||||||
|
- run: ci/scripts/lint-typescript.sh
|
||||||
|
|
||||||
|
javascript:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VER }}
|
||||||
|
- run: ci/scripts/lint-javascript.sh
|
||||||
|
|
||||||
|
java:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: ${{ env.JAVA_VER }}
|
||||||
|
- run: ci/scripts/lint-java.sh
|
||||||
|
|
||||||
|
shell:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: ci/scripts/lint-shell.sh
|
||||||
33
.github/workflows/test-fsat-appdev.yaml
vendored
33
.github/workflows/test-fsat-appdev.yaml
vendored
|
|
@ -9,34 +9,39 @@ on:
|
||||||
paths:
|
paths:
|
||||||
- "full-stack-asset-transfer-guide/**"
|
- "full-stack-asset-transfer-guide/**"
|
||||||
|
|
||||||
|
env:
|
||||||
|
GO_VER: 1.18.3
|
||||||
|
NODE_VER: 16.x
|
||||||
|
K9S_VERSION: v0.25.3
|
||||||
|
JUST_VERSION: 1.2.0
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-fsat-appdev:
|
appdev:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
|
- uses: actions/checkout@v3
|
||||||
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
|
|
||||||
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
|
|
||||||
|
|
||||||
- name: checkout
|
- uses: actions/setup-go@v3
|
||||||
uses: actions/checkout@v3
|
with:
|
||||||
|
go-version: ${{ env.GO_VER }}
|
||||||
|
|
||||||
- name: k9s
|
- uses: actions/setup-node@v3
|
||||||
env:
|
with:
|
||||||
K9S_VERSION: v0.25.3
|
node-version: ${{ env.NODE_VER }}
|
||||||
|
|
||||||
|
- name: Install k9s
|
||||||
run: |
|
run: |
|
||||||
curl --fail --silent --show-error -L https://github.com/derailed/k9s/releases/download/${K9S_VERSION}/k9s_Linux_x86_64.tar.gz -o /tmp/k9s_Linux_x86_64.tar.gz
|
curl --fail --silent --show-error -L https://github.com/derailed/k9s/releases/download/${K9S_VERSION}/k9s_Linux_x86_64.tar.gz -o /tmp/k9s_Linux_x86_64.tar.gz
|
||||||
tar -zxf /tmp/k9s_Linux_x86_64.tar.gz -C /usr/local/bin k9s
|
tar -zxf /tmp/k9s_Linux_x86_64.tar.gz -C /usr/local/bin k9s
|
||||||
sudo chown root /usr/local/bin/k9s
|
sudo chown root /usr/local/bin/k9s
|
||||||
sudo chmod 755 /usr/local/bin/k9s
|
sudo chmod 755 /usr/local/bin/k9s
|
||||||
|
|
||||||
- name: just
|
- name: Install just
|
||||||
env:
|
|
||||||
JUST_VERSION: 1.2.0
|
|
||||||
run: |
|
run: |
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --tag ${JUST_VERSION} --to /usr/local/bin
|
curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --tag ${JUST_VERSION} --to /usr/local/bin
|
||||||
|
|
||||||
- name: weft
|
- name: Install weft
|
||||||
run: |
|
run: |
|
||||||
npm install -g @hyperledger-labs/weft
|
npm install -g @hyperledger-labs/weft
|
||||||
|
|
||||||
|
|
|
||||||
45
.github/workflows/test-network-basic.yaml
vendored
Normal file
45
.github/workflows/test-network-basic.yaml
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
name: Test Network Basic
|
||||||
|
run-name: ${{ github.actor }} is running the test-network basic tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
basic:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
chaincode-language:
|
||||||
|
- go
|
||||||
|
- javascript
|
||||||
|
- typescript
|
||||||
|
- java
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install fabric CLI
|
||||||
|
run: |
|
||||||
|
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- binary
|
||||||
|
echo ${PWD}/bin >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Pull Fabric Docker Images
|
||||||
|
run: curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- docker
|
||||||
|
|
||||||
|
- name: Install retry CLI
|
||||||
|
run: curl -sSL https://raw.githubusercontent.com/kadwanev/retry/master/retry -o ./bin/retry && chmod +x ./bin/retry
|
||||||
|
|
||||||
|
- name: Run Test Network Basic
|
||||||
|
working-directory: test-network
|
||||||
|
env:
|
||||||
|
CHAINCODE_LANGUAGE: ${{ matrix.chaincode-language }}
|
||||||
|
run: ../ci/scripts/run-test-network-basic.sh
|
||||||
|
|
||||||
45
.github/workflows/test-network-gateway.yaml
vendored
Normal file
45
.github/workflows/test-network-gateway.yaml
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
name: Test Network Gateway
|
||||||
|
run-name: ${{ github.actor }} is running the test-network gateway tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
gateway:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
chaincode-language:
|
||||||
|
- go
|
||||||
|
- javascript
|
||||||
|
- typescript
|
||||||
|
- java
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install fabric CLI
|
||||||
|
run: |
|
||||||
|
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- binary
|
||||||
|
echo ${PWD}/bin >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Pull Fabric Docker Images
|
||||||
|
run: curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- docker
|
||||||
|
|
||||||
|
- name: Install retry CLI
|
||||||
|
run: curl -sSL https://raw.githubusercontent.com/kadwanev/retry/master/retry -o ./bin/retry && chmod +x ./bin/retry
|
||||||
|
|
||||||
|
- name: Run Test Network Off Chain
|
||||||
|
working-directory: test-network
|
||||||
|
env:
|
||||||
|
CHAINCODE_LANGUAGE: ${{ matrix.chaincode-language }}
|
||||||
|
run: ../ci/scripts/run-test-network-gateway.sh
|
||||||
|
|
||||||
54
.github/workflows/test-network-hsm.yaml
vendored
Normal file
54
.github/workflows/test-network-hsm.yaml
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
name: Test Network HSM
|
||||||
|
run-name: ${{ github.actor }} is running the test-network HSM tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
hsm:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
chaincode-language:
|
||||||
|
- go
|
||||||
|
- javascript
|
||||||
|
- typescript
|
||||||
|
- java
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install fabric CLI
|
||||||
|
run: |
|
||||||
|
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- binary
|
||||||
|
echo ${PWD}/bin >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Pull Fabric Docker Images
|
||||||
|
run: curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- docker
|
||||||
|
|
||||||
|
- name: Install retry CLI
|
||||||
|
run: curl -sSL https://raw.githubusercontent.com/kadwanev/retry/master/retry -o ./bin/retry && chmod +x ./bin/retry
|
||||||
|
|
||||||
|
- name: Install SoftHSM
|
||||||
|
run: sudo apt install -y softhsm2
|
||||||
|
|
||||||
|
- name: Set up SoftHSM
|
||||||
|
run: |
|
||||||
|
echo directories.tokendir = /tmp > $HOME/softhsm2.conf
|
||||||
|
export SOFTHSM2_CONF=$HOME/softhsm2.conf
|
||||||
|
softhsm2-util --init-token --slot 0 --label "ForFabric" --pin 98765432 --so-pin 1234
|
||||||
|
|
||||||
|
- name: Run Test Network HSM
|
||||||
|
working-directory: test-network
|
||||||
|
env:
|
||||||
|
CHAINCODE_LANGUAGE: ${{ matrix.chaincode-language }}
|
||||||
|
run: ../ci/scripts/run-test-network-hsm.sh
|
||||||
|
|
||||||
45
.github/workflows/test-network-off-chain-data.yaml
vendored
Normal file
45
.github/workflows/test-network-off-chain-data.yaml
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
name: Test Network Off Chain
|
||||||
|
run-name: ${{ github.actor }} is running the test-network off chain data tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
off-chain:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
chaincode-language:
|
||||||
|
- go
|
||||||
|
- javascript
|
||||||
|
- typescript
|
||||||
|
- java
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install fabric CLI
|
||||||
|
run: |
|
||||||
|
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- binary
|
||||||
|
echo ${PWD}/bin >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Pull Fabric Docker Images
|
||||||
|
run: curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/install-fabric.sh | bash -s -- docker
|
||||||
|
|
||||||
|
- name: Install retry CLI
|
||||||
|
run: curl -sSL https://raw.githubusercontent.com/kadwanev/retry/master/retry -o ./bin/retry && chmod +x ./bin/retry
|
||||||
|
|
||||||
|
- name: Run Test Network Off Chain
|
||||||
|
working-directory: test-network
|
||||||
|
env:
|
||||||
|
CHAINCODE_LANGUAGE: ${{ matrix.chaincode-language }}
|
||||||
|
run: ../ci/scripts/run-test-network-off-chain.sh
|
||||||
|
|
||||||
|
|
@ -34,8 +34,6 @@ const (
|
||||||
tlsCertPath = cryptoPath + "/peers/peer0.org1.example.com/tls/ca.crt"
|
tlsCertPath = cryptoPath + "/peers/peer0.org1.example.com/tls/ca.crt"
|
||||||
peerEndpoint = "localhost:7051"
|
peerEndpoint = "localhost:7051"
|
||||||
gatewayPeer = "peer0.org1.example.com"
|
gatewayPeer = "peer0.org1.example.com"
|
||||||
channelName = "mychannel"
|
|
||||||
chaincodeName = "basic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var now = time.Now()
|
var now = time.Now()
|
||||||
|
|
@ -67,6 +65,17 @@ func main() {
|
||||||
}
|
}
|
||||||
defer gw.Close()
|
defer gw.Close()
|
||||||
|
|
||||||
|
// Override default values for chaincode and channel name as they may differ in testing contexts.
|
||||||
|
chaincodeName := "basic"
|
||||||
|
if ccname := os.Getenv("CHAINCODE_NAME"); ccname != "" {
|
||||||
|
chaincodeName = ccname
|
||||||
|
}
|
||||||
|
|
||||||
|
channelName := "mychannel"
|
||||||
|
if cname := os.Getenv("CHANNEL_NAME"); cname != "" {
|
||||||
|
channelName = cname
|
||||||
|
}
|
||||||
|
|
||||||
network := gw.GetNetwork(channelName)
|
network := gw.GetNetwork(channelName)
|
||||||
contract := network.GetContract(chaincodeName)
|
contract := network.GetContract(chaincodeName)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,22 +34,22 @@ import java.time.Instant;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public final class App {
|
public final class App {
|
||||||
private static final String mspID = "Org1MSP";
|
private static final String MSP_ID = System.getenv().getOrDefault("MSP_ID", "Org1MSP");
|
||||||
private static final String channelName = "mychannel";
|
private static final String CHANNEL_NAME = System.getenv().getOrDefault("CHANNEL_NAME", "mychannel");
|
||||||
private static final String chaincodeName = "basic";
|
private static final String CHAINCODE_NAME = System.getenv().getOrDefault("CHAINCODE_NAME", "basic");
|
||||||
|
|
||||||
// Path to crypto materials.
|
// Path to crypto materials.
|
||||||
private static final Path cryptoPath = Paths.get("..", "..", "test-network", "organizations", "peerOrganizations", "org1.example.com");
|
private static final Path CRYPTO_PATH = Paths.get("../../test-network/organizations/peerOrganizations/org1.example.com");
|
||||||
// Path to user certificate.
|
// Path to user certificate.
|
||||||
private static final Path certPath = cryptoPath.resolve(Paths.get("users", "User1@org1.example.com", "msp", "signcerts", "cert.pem"));
|
private static final Path CERT_PATH = CRYPTO_PATH.resolve(Paths.get("users/User1@org1.example.com/msp/signcerts/cert.pem"));
|
||||||
// Path to user private key directory.
|
// Path to user private key directory.
|
||||||
private static final Path keyDirPath = cryptoPath.resolve(Paths.get("users", "User1@org1.example.com", "msp", "keystore"));
|
private static final Path KEY_DIR_PATH = CRYPTO_PATH.resolve(Paths.get("users/User1@org1.example.com/msp/keystore"));
|
||||||
// Path to peer tls certificate.
|
// Path to peer tls certificate.
|
||||||
private static final Path tlsCertPath = cryptoPath.resolve(Paths.get("peers", "peer0.org1.example.com", "tls", "ca.crt"));
|
private static final Path TLS_CERT_PATH = CRYPTO_PATH.resolve(Paths.get("peers/peer0.org1.example.com/tls/ca.crt"));
|
||||||
|
|
||||||
// Gateway peer end point.
|
// Gateway peer end point.
|
||||||
private static final String peerEndpoint = "localhost:7051";
|
private static final String PEER_ENDPOINT = "localhost:7051";
|
||||||
private static final String overrideAuth = "peer0.org1.example.com";
|
private static final String OVERRIDE_AUTH = "peer0.org1.example.com";
|
||||||
|
|
||||||
private final Contract contract;
|
private final Contract contract;
|
||||||
private final String assetId = "asset" + Instant.now().toEpochMilli();
|
private final String assetId = "asset" + Instant.now().toEpochMilli();
|
||||||
|
|
@ -75,19 +75,19 @@ public final class App {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ManagedChannel newGrpcConnection() throws IOException, CertificateException {
|
private static ManagedChannel newGrpcConnection() throws IOException, CertificateException {
|
||||||
var tlsCertReader = Files.newBufferedReader(tlsCertPath);
|
var tlsCertReader = Files.newBufferedReader(TLS_CERT_PATH);
|
||||||
var tlsCert = Identities.readX509Certificate(tlsCertReader);
|
var tlsCert = Identities.readX509Certificate(tlsCertReader);
|
||||||
|
|
||||||
return NettyChannelBuilder.forTarget(peerEndpoint)
|
return NettyChannelBuilder.forTarget(PEER_ENDPOINT)
|
||||||
.sslContext(GrpcSslContexts.forClient().trustManager(tlsCert).build()).overrideAuthority(overrideAuth)
|
.sslContext(GrpcSslContexts.forClient().trustManager(tlsCert).build()).overrideAuthority(OVERRIDE_AUTH)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Identity newIdentity() throws IOException, CertificateException {
|
private static Identity newIdentity() throws IOException, CertificateException {
|
||||||
var certReader = Files.newBufferedReader(certPath);
|
var certReader = Files.newBufferedReader(CERT_PATH);
|
||||||
var certificate = Identities.readX509Certificate(certReader);
|
var certificate = Identities.readX509Certificate(certReader);
|
||||||
|
|
||||||
return new X509Identity(mspID, certificate);
|
return new X509Identity(MSP_ID, certificate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Signer newSigner() throws IOException, InvalidKeyException {
|
private static Signer newSigner() throws IOException, InvalidKeyException {
|
||||||
|
|
@ -98,7 +98,7 @@ public final class App {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Path getPrivateKeyPath() throws IOException {
|
private static Path getPrivateKeyPath() throws IOException {
|
||||||
try (var keyFiles = Files.list(keyDirPath)) {
|
try (var keyFiles = Files.list(KEY_DIR_PATH)) {
|
||||||
return keyFiles.findFirst().orElseThrow();
|
return keyFiles.findFirst().orElseThrow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,10 +106,10 @@ public final class App {
|
||||||
public App(final Gateway gateway) {
|
public App(final Gateway gateway) {
|
||||||
// Get a network instance representing the channel where the smart contract is
|
// Get a network instance representing the channel where the smart contract is
|
||||||
// deployed.
|
// deployed.
|
||||||
var network = gateway.getNetwork(channelName);
|
var network = gateway.getNetwork(CHANNEL_NAME);
|
||||||
|
|
||||||
// Get the smart contract from the network.
|
// Get the smart contract from the network.
|
||||||
contract = network.getContract(chaincodeName);
|
contract = network.getContract(CHAINCODE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws GatewayException, CommitException {
|
public void run() throws GatewayException, CommitException {
|
||||||
|
|
|
||||||
|
|
@ -55,12 +55,24 @@ func main() {
|
||||||
}
|
}
|
||||||
defer gw.Close()
|
defer gw.Close()
|
||||||
|
|
||||||
network, err := gw.GetNetwork("mychannel")
|
channelName := "mychannel"
|
||||||
|
if cname := os.Getenv("CHANNEL_NAME"); cname != "" {
|
||||||
|
channelName = cname
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("--> Connecting to channel", channelName)
|
||||||
|
network, err := gw.GetNetwork(channelName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to get network: %v", err)
|
log.Fatalf("Failed to get network: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
contract := network.GetContract("basic")
|
chaincodeName := "basic"
|
||||||
|
if ccname := os.Getenv("CHAINCODE_NAME"); ccname != "" {
|
||||||
|
chaincodeName = ccname
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("--> Using chaincode", chaincodeName)
|
||||||
|
contract := network.GetContract(chaincodeName)
|
||||||
|
|
||||||
log.Println("--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger")
|
log.Println("--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger")
|
||||||
result, err := contract.SubmitTransaction("InitLedger")
|
result, err := contract.SubmitTransaction("InitLedger")
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,10 @@ import { enrollUserToWallet, registerUser, UserToEnroll, UserToRegister } from '
|
||||||
|
|
||||||
const walletPath = path.join(__dirname, 'wallet');
|
const walletPath = path.join(__dirname, 'wallet');
|
||||||
|
|
||||||
// define information about the channel and chaincode id that will be driven by this application
|
// define information about the channel and chaincode that will be driven by this application
|
||||||
const channelName = 'mychannel';
|
const channelName = envOrDefault('CHANNEL_NAME', 'mychannel');
|
||||||
const chaincodeId = 'basic';
|
const chaincodeName = envOrDefault('CHAINCODE_NAME', 'default-basic');
|
||||||
|
|
||||||
|
|
||||||
// define the CA Registrar
|
// define the CA Registrar
|
||||||
const mspOrg1 = 'Org1MSP';
|
const mspOrg1 = 'Org1MSP';
|
||||||
|
|
@ -192,7 +193,7 @@ async function main() {
|
||||||
const network = await gateway.getNetwork(channelName);
|
const network = await gateway.getNetwork(channelName);
|
||||||
|
|
||||||
// Get the contract from the network.
|
// Get the contract from the network.
|
||||||
const contract = network.getContract(chaincodeId);
|
const contract = network.getContract(chaincodeName);
|
||||||
|
|
||||||
// loop around all transactions to send, each one will be sent sequentially
|
// loop around all transactions to send, each one will be sent sequentially
|
||||||
// through the same gateway/network/contract as subsequent transations expect the
|
// through the same gateway/network/contract as subsequent transations expect the
|
||||||
|
|
@ -274,5 +275,12 @@ async function interactWithFabric(contract: Contract, transactionToPerform: Tran
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* envOrDefault() will return the value of an environment variable, or a default value if the variable is undefined.
|
||||||
|
*/
|
||||||
|
function envOrDefault(key: string, defaultValue: string): string {
|
||||||
|
return process.env[key] || defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
// execute the main function
|
// execute the main function
|
||||||
main();
|
main();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
rootProject.name = System.getenv('CHAINCODE_NAME') ?: 'basic'
|
||||||
rootProject.name = 'basic'
|
|
||||||
|
|
@ -23,6 +23,7 @@ variables:
|
||||||
- group: credentials
|
- group: credentials
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
- job: REST_Sample
|
- job: REST_Sample
|
||||||
displayName: REST Server Sample
|
displayName: REST Server Sample
|
||||||
pool:
|
pool:
|
||||||
|
|
@ -86,51 +87,6 @@ jobs:
|
||||||
- template: templates/install-deps.yml
|
- template: templates/install-deps.yml
|
||||||
- template: templates/fabcar/azure-pipelines-typescript.yml
|
- template: templates/fabcar/azure-pipelines-typescript.yml
|
||||||
|
|
||||||
- job: Lint
|
|
||||||
displayName: Lint
|
|
||||||
pool:
|
|
||||||
vmImage: ubuntu-20.04
|
|
||||||
steps:
|
|
||||||
- task: GoTool@0
|
|
||||||
inputs:
|
|
||||||
goBin: $(GO_BIN)
|
|
||||||
version: $(GO_VER)
|
|
||||||
displayName: Install GoLang
|
|
||||||
- task: NodeTool@0
|
|
||||||
inputs:
|
|
||||||
versionSpec: $(NODE_VER)
|
|
||||||
displayName: Install Node.js
|
|
||||||
- script: ./ci/scripts/shellcheck.sh
|
|
||||||
displayName: Lint Shell Scripts
|
|
||||||
- script: ./ci/scripts/lint.sh
|
|
||||||
displayName: Lint Code
|
|
||||||
|
|
||||||
- job: TestNetworkBasic
|
|
||||||
displayName: Test Network
|
|
||||||
pool:
|
|
||||||
vmImage: ubuntu-20.04
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
Basic-Go:
|
|
||||||
CHAINCODE_NAME: basic
|
|
||||||
CHAINCODE_LANGUAGE: go
|
|
||||||
Basic-Java:
|
|
||||||
CHAINCODE_NAME: basic
|
|
||||||
CHAINCODE_LANGUAGE: java
|
|
||||||
Basic-Javascript:
|
|
||||||
CHAINCODE_NAME: basic
|
|
||||||
CHAINCODE_LANGUAGE: javascript
|
|
||||||
Basic-Typescript:
|
|
||||||
CHAINCODE_NAME: basic
|
|
||||||
CHAINCODE_LANGUAGE: typescript
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- template: templates/install-deps.yml
|
|
||||||
- template: templates/install-deps-hsm.yml
|
|
||||||
- script: ../ci/scripts/run-test-network-basic.sh
|
|
||||||
workingDirectory: test-network
|
|
||||||
displayName: Run Test Network Basic Chaincode
|
|
||||||
|
|
||||||
- job: KubeTestNetworkBasic
|
- job: KubeTestNetworkBasic
|
||||||
displayName: Kube Test Network
|
displayName: Kube Test Network
|
||||||
pool:
|
pool:
|
||||||
|
|
|
||||||
34
ci/scripts/lint-go.sh
Executable file
34
ci/scripts/lint-go.sh
Executable file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs=("$(find . -name "*-go" -type d -not -path '*/.*')")
|
||||||
|
for dir in $dirs; do
|
||||||
|
print "Linting $dir"
|
||||||
|
pushd $dir
|
||||||
|
|
||||||
|
print "Running go vet"
|
||||||
|
go vet -tags pkcs11 ./...
|
||||||
|
|
||||||
|
print "Running gofmt"
|
||||||
|
output=$(gofmt -l -s $(go list -tags pkcs11 -f '{{.Dir}}' ./...))
|
||||||
|
if [[ "${output}" != "" ]]; then
|
||||||
|
print "The following files contain formatting errors, please run 'gofmt -l -w <path>' to fix these issues:"
|
||||||
|
echo "${output}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Running goimports"
|
||||||
|
output=$(goimports -l $(go list -tags pkcs11 -f '{{.Dir}}' ./...))
|
||||||
|
if [[ "${output}" != "" ]]; then
|
||||||
|
print "The following files contain import errors, please run 'goimports -l -w <path>' to fix these issues:"
|
||||||
|
echo "${output}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
popd
|
||||||
|
done
|
||||||
24
ci/scripts/lint-java.sh
Executable file
24
ci/scripts/lint-java.sh
Executable file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs=("$(find . -name "*-java" -type d -not -path '*/.*')")
|
||||||
|
for dir in $dirs; do
|
||||||
|
print "Linting $dir"
|
||||||
|
pushd $dir
|
||||||
|
|
||||||
|
if [[ -f "pom.xml" ]]; then
|
||||||
|
print "Running Maven Build"
|
||||||
|
mvn clean package
|
||||||
|
else
|
||||||
|
print "Running Gradle Build"
|
||||||
|
./gradlew build
|
||||||
|
fi
|
||||||
|
popd
|
||||||
|
done
|
||||||
22
ci/scripts/lint-javascript.sh
Executable file
22
ci/scripts/lint-javascript.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs=("$(find . -name "*-javascript" -type d -not -path '*/.*')")
|
||||||
|
for dir in $dirs; do
|
||||||
|
print "Linting $dir"
|
||||||
|
pushd $dir
|
||||||
|
|
||||||
|
print "Installing node modules"
|
||||||
|
npm install
|
||||||
|
print "Running Lint"
|
||||||
|
npm run lint
|
||||||
|
|
||||||
|
popd
|
||||||
|
done
|
||||||
22
ci/scripts/lint-typescript.sh
Executable file
22
ci/scripts/lint-typescript.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs=("$(find . -name "*-typescript" -type d -not -path '*/.*')")
|
||||||
|
for dir in $dirs; do
|
||||||
|
print "Linting $dir"
|
||||||
|
pushd $dir
|
||||||
|
|
||||||
|
print "Installing node modules"
|
||||||
|
npm install
|
||||||
|
print "Running Lint"
|
||||||
|
npm run lint
|
||||||
|
|
||||||
|
popd
|
||||||
|
done
|
||||||
|
|
@ -1,50 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
function print() {
|
cd "$(dirname "$0")/../.."
|
||||||
GREEN='\033[0;32m'
|
|
||||||
NC='\033[0m'
|
|
||||||
echo
|
|
||||||
echo -e "${GREEN}${1}${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
go install golang.org/x/tools/cmd/goimports@latest
|
ci/scripts/lint-go.sh
|
||||||
|
ci/scripts/lint-javascript.sh
|
||||||
dirs=("$(find . -name "*-go" -o -name "*-java" -o -name "*-javascript" -o -name "*-typescript" -not -path '*/.*')")
|
ci/scripts/lint-typescript.sh
|
||||||
for dir in $dirs; do
|
ci/scripts/lint-java.sh
|
||||||
if [[ -d $dir ]] && [[ ! $dir =~ node_modules ]]; then
|
ci/scripts/lint-shell.sh
|
||||||
print "Linting $dir"
|
|
||||||
pushd $dir
|
|
||||||
if [[ "$dir" =~ "-go" ]]; then
|
|
||||||
print "Running go vet"
|
|
||||||
go vet -tags pkcs11 ./...
|
|
||||||
print "Running gofmt"
|
|
||||||
output=$(gofmt -l -s $(go list -tags pkcs11 -f '{{.Dir}}' ./...))
|
|
||||||
if [[ "${output}" != "" ]]; then
|
|
||||||
print "The following files contain formatting errors, please run 'gofmt -l -w <path>' to fix these issues:"
|
|
||||||
echo "${output}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
print "Running goimports"
|
|
||||||
output=$(goimports -l $(go list -tags pkcs11 -f '{{.Dir}}' ./...))
|
|
||||||
if [[ "${output}" != "" ]]; then
|
|
||||||
print "The following files contain import errors, please run 'goimports -l -w <path>' to fix these issues:"
|
|
||||||
echo "${output}"
|
|
||||||
fi
|
|
||||||
elif [[ "$dir" =~ "-javascript" || "$dir" =~ "-typescript" ]]; then
|
|
||||||
print "Installing node modules"
|
|
||||||
npm install
|
|
||||||
print "Running Lint"
|
|
||||||
npm run lint
|
|
||||||
elif [[ "$dir" =~ "-java" ]]; then
|
|
||||||
if [[ -f "pom.xml" ]]; then
|
|
||||||
print "Running Maven Build"
|
|
||||||
mvn clean package
|
|
||||||
else
|
|
||||||
print "Running Gradle Build"
|
|
||||||
./gradlew build
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
popd
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
CHAINCODE_LANGUAGE=${CHAINCODE_LANGUAGE:-go}
|
CHAINCODE_LANGUAGE=${CHAINCODE_LANGUAGE:-go}
|
||||||
CHAINCODE_NAME=${CHAINCODE_NAME:-basic}
|
|
||||||
CHAINCODE_PATH=${CHAINCODE_PATH:-../asset-transfer-basic}
|
CHAINCODE_PATH=${CHAINCODE_PATH:-../asset-transfer-basic}
|
||||||
|
|
||||||
function print() {
|
function print() {
|
||||||
|
|
@ -17,6 +18,9 @@ function createNetwork() {
|
||||||
cd addOrg3
|
cd addOrg3
|
||||||
./addOrg3.sh up -ca -s couchdb
|
./addOrg3.sh up -ca -s couchdb
|
||||||
cd ..
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
|
function deployChaincode() {
|
||||||
print "Deploying ${CHAINCODE_NAME} chaincode"
|
print "Deploying ${CHAINCODE_NAME} chaincode"
|
||||||
./network.sh deployCC -ccn "${CHAINCODE_NAME}" -ccp "${CHAINCODE_PATH}/chaincode-${CHAINCODE_LANGUAGE}" -ccv 1 -ccs 1 -ccl "${CHAINCODE_LANGUAGE}"
|
./network.sh deployCC -ccn "${CHAINCODE_NAME}" -ccp "${CHAINCODE_PATH}/chaincode-${CHAINCODE_LANGUAGE}" -ccv 1 -ccs 1 -ccl "${CHAINCODE_LANGUAGE}"
|
||||||
}
|
}
|
||||||
|
|
@ -26,46 +30,43 @@ function stopNetwork() {
|
||||||
./network.sh down
|
./network.sh down
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run Go application
|
# Set up one test network to run each test scenario.
|
||||||
|
# Each test will create an independent scope by installing a new chaincode contract to the channel.
|
||||||
createNetwork
|
createNetwork
|
||||||
|
|
||||||
|
|
||||||
|
# Run Go application
|
||||||
print "Initializing Go application"
|
print "Initializing Go application"
|
||||||
|
export CHAINCODE_NAME=basic_go
|
||||||
|
deployChaincode
|
||||||
pushd ../asset-transfer-basic/application-go
|
pushd ../asset-transfer-basic/application-go
|
||||||
print "Executing AssetTransfer.go"
|
print "Executing AssetTransfer.go"
|
||||||
go run .
|
go run .
|
||||||
popd
|
popd
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run Java application
|
# Run Java application
|
||||||
createNetwork
|
|
||||||
print "Initializing Java application"
|
print "Initializing Java application"
|
||||||
|
export CHAINCODE_NAME=basic_java
|
||||||
|
deployChaincode
|
||||||
pushd ../asset-transfer-basic/application-java
|
pushd ../asset-transfer-basic/application-java
|
||||||
print "Executing Gradle Run"
|
print "Executing Gradle Run"
|
||||||
gradle run
|
gradle run
|
||||||
popd
|
popd
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run Java application using gateway
|
|
||||||
createNetwork
|
|
||||||
print "Initializing Java application"
|
|
||||||
pushd ../asset-transfer-basic/application-gateway-java
|
|
||||||
print "Executing Gradle Run"
|
|
||||||
./gradlew run
|
|
||||||
popd
|
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run Javascript application
|
# Run Javascript application
|
||||||
createNetwork
|
|
||||||
print "Initializing Javascript application"
|
print "Initializing Javascript application"
|
||||||
|
export CHAINCODE_NAME=basic_javascript
|
||||||
|
deployChaincode
|
||||||
pushd ../asset-transfer-basic/application-javascript
|
pushd ../asset-transfer-basic/application-javascript
|
||||||
npm install
|
npm install
|
||||||
print "Executing app.js"
|
print "Executing app.js"
|
||||||
node app.js
|
node app.js
|
||||||
popd
|
popd
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run typescript application
|
# Run typescript application
|
||||||
createNetwork
|
|
||||||
print "Initializing Typescript application"
|
print "Initializing Typescript application"
|
||||||
|
export CHAINCODE_NAME=basic_typescript
|
||||||
|
deployChaincode
|
||||||
pushd ../asset-transfer-basic/application-typescript
|
pushd ../asset-transfer-basic/application-typescript
|
||||||
npm install
|
npm install
|
||||||
print "Building app.ts"
|
print "Building app.ts"
|
||||||
|
|
@ -73,95 +74,6 @@ npm run build
|
||||||
print "Running the output app"
|
print "Running the output app"
|
||||||
node dist/app.js
|
node dist/app.js
|
||||||
popd
|
popd
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run gateway typescript application
|
|
||||||
createNetwork
|
|
||||||
print "Initializing Typescript gateway application"
|
|
||||||
pushd ../asset-transfer-basic/application-gateway-typescript
|
|
||||||
npm install
|
|
||||||
print "Building app.ts"
|
|
||||||
npm run build
|
|
||||||
print "Running the output app"
|
|
||||||
node dist/app.js
|
|
||||||
popd
|
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run typescript HSM application
|
|
||||||
createNetwork
|
|
||||||
print "Initializing Typescript HSM application"
|
|
||||||
pushd ../asset-transfer-basic/application-typescript-hsm
|
|
||||||
print "Setup SoftHSM"
|
|
||||||
export SOFTHSM2_CONF=$PWD/softhsm2.conf
|
|
||||||
print "install dependencies"
|
|
||||||
npm install
|
|
||||||
print "Building app.ts"
|
|
||||||
npm run build
|
|
||||||
print "Running the output app"
|
|
||||||
node dist/app.js
|
|
||||||
popd
|
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run Typescript HSM gateway application
|
|
||||||
echo 'Delete fabric-ca-client from samples bin'
|
|
||||||
rm ../bin/fabric-ca-client
|
|
||||||
echo 'go install pkcs11 enabled fabric-ca-client'
|
|
||||||
go install -tags pkcs11 github.com/hyperledger/fabric-ca/cmd/fabric-ca-client@latest
|
|
||||||
createNetwork
|
|
||||||
print "Initializing Typescript HSM gateway application"
|
|
||||||
pushd ../hardware-security-module/scripts/
|
|
||||||
print "Enroll and register User in HSM"
|
|
||||||
./generate-hsm-user.sh HSMUser
|
|
||||||
pushd ../application-typescript/
|
|
||||||
print "install dependencies and prepare for running"
|
|
||||||
npm install
|
|
||||||
print "Running the output app"
|
|
||||||
npm run start
|
|
||||||
popd
|
|
||||||
popd
|
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run Go HSM gateway application
|
|
||||||
createNetwork
|
|
||||||
print "Initializing Go HSM gateway application"
|
|
||||||
pushd ../hardware-security-module/scripts/
|
|
||||||
print "Register and enroll user in HSM"
|
|
||||||
./generate-hsm-user.sh HSMUser
|
|
||||||
pushd ../application-go
|
|
||||||
print "Running the output app"
|
|
||||||
go run -tags pkcs11 .
|
|
||||||
popd
|
|
||||||
popd
|
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run Go gateway application
|
|
||||||
createNetwork
|
|
||||||
print "Initializing Go gateway application"
|
|
||||||
pushd ../asset-transfer-basic/application-gateway-go
|
|
||||||
print "Executing AssetTransfer.go"
|
|
||||||
go run .
|
|
||||||
popd
|
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run off-chain data TypeScript application
|
|
||||||
createNetwork
|
|
||||||
print "Initializing Typescript off-chain data application"
|
|
||||||
pushd ../off_chain_data/application-typescript
|
|
||||||
rm -f checkpoint.json store.log
|
|
||||||
npm install
|
|
||||||
print "Running the output app"
|
|
||||||
SIMULATED_FAILURE_COUNT=1 npm start getAllAssets transact getAllAssets listen
|
|
||||||
SIMULATED_FAILURE_COUNT=1 npm start listen
|
|
||||||
popd
|
|
||||||
stopNetwork
|
|
||||||
|
|
||||||
# Run off-chain data Java application
|
|
||||||
createNetwork
|
|
||||||
print "Initializing Typescript off-chain data application"
|
|
||||||
pushd ../off_chain_data/application-java
|
|
||||||
rm -f app/checkpoint.json app/store.log
|
|
||||||
print "Running the output app"
|
|
||||||
SIMULATED_FAILURE_COUNT=1 ./gradlew run --quiet --args='getAllAssets transact getAllAssets listen'
|
|
||||||
SIMULATED_FAILURE_COUNT=1 ./gradlew run --quiet --args=listen
|
|
||||||
popd
|
|
||||||
stopNetwork
|
stopNetwork
|
||||||
|
|
|
||||||
71
ci/scripts/run-test-network-gateway.sh
Executable file
71
ci/scripts/run-test-network-gateway.sh
Executable file
|
|
@ -0,0 +1,71 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
CHAINCODE_LANGUAGE=${CHAINCODE_LANGUAGE:-go}
|
||||||
|
CHAINCODE_PATH=${CHAINCODE_PATH:-../asset-transfer-basic}
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNetwork() {
|
||||||
|
print "Creating 3 Org network"
|
||||||
|
./network.sh up createChannel -ca -s couchdb
|
||||||
|
cd addOrg3
|
||||||
|
./addOrg3.sh up -ca -s couchdb
|
||||||
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
|
function deployChaincode() {
|
||||||
|
print "Deploying ${CHAINCODE_NAME} chaincode"
|
||||||
|
./network.sh deployCC -ccn "${CHAINCODE_NAME}" -ccp "${CHAINCODE_PATH}/chaincode-${CHAINCODE_LANGUAGE}" -ccv 1 -ccs 1 -ccl "${CHAINCODE_LANGUAGE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopNetwork() {
|
||||||
|
print "Stopping network"
|
||||||
|
./network.sh down
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up one test network to run each test scenario.
|
||||||
|
# Each test will create an independent scope by installing a new chaincode contract to the channel.
|
||||||
|
createNetwork
|
||||||
|
|
||||||
|
|
||||||
|
# Run Go gateway application
|
||||||
|
print "Initializing Go gateway application"
|
||||||
|
export CHAINCODE_NAME=go_gateway
|
||||||
|
deployChaincode
|
||||||
|
pushd ../asset-transfer-basic/application-gateway-go
|
||||||
|
print "Executing AssetTransfer.go"
|
||||||
|
go run .
|
||||||
|
popd
|
||||||
|
|
||||||
|
|
||||||
|
# Run gateway typescript application
|
||||||
|
print "Initializing Typescript gateway application"
|
||||||
|
export CHAINCODE_NAME=typescript_gateway
|
||||||
|
deployChaincode
|
||||||
|
pushd ../asset-transfer-basic/application-gateway-typescript
|
||||||
|
npm install
|
||||||
|
print "Building app.ts"
|
||||||
|
npm run build
|
||||||
|
print "Running the output app"
|
||||||
|
node dist/app.js
|
||||||
|
popd
|
||||||
|
|
||||||
|
|
||||||
|
# Run Java application using gateway
|
||||||
|
print "Initializing Java application"
|
||||||
|
export CHAINCODE_NAME=java_gateway
|
||||||
|
deployChaincode
|
||||||
|
pushd ../asset-transfer-basic/application-gateway-java
|
||||||
|
print "Executing Gradle Run"
|
||||||
|
./gradlew run
|
||||||
|
popd
|
||||||
|
|
||||||
|
|
||||||
|
stopNetwork
|
||||||
89
ci/scripts/run-test-network-hsm.sh
Executable file
89
ci/scripts/run-test-network-hsm.sh
Executable file
|
|
@ -0,0 +1,89 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
CHAINCODE_LANGUAGE=${CHAINCODE_LANGUAGE:-go}
|
||||||
|
CHAINCODE_PATH=${CHAINCODE_PATH:-../asset-transfer-basic}
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNetwork() {
|
||||||
|
print "Creating 3 Org network"
|
||||||
|
./network.sh up createChannel -ca -s couchdb
|
||||||
|
cd addOrg3
|
||||||
|
./addOrg3.sh up -ca -s couchdb
|
||||||
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
|
function deployChaincode() {
|
||||||
|
print "Deploying ${CHAINCODE_NAME} chaincode"
|
||||||
|
./network.sh deployCC -ccn "${CHAINCODE_NAME}" -ccp "${CHAINCODE_PATH}/chaincode-${CHAINCODE_LANGUAGE}" -ccv 1 -ccs 1 -ccl "${CHAINCODE_LANGUAGE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopNetwork() {
|
||||||
|
print "Stopping network"
|
||||||
|
./network.sh down
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up one test network to run each test scenario.
|
||||||
|
# Each test will create an independent scope by installing a new chaincode contract to the channel.
|
||||||
|
createNetwork
|
||||||
|
|
||||||
|
|
||||||
|
# Run typescript HSM application
|
||||||
|
print "Initializing Typescript HSM application"
|
||||||
|
export CHAINCODE_NAME=typescript_hsm
|
||||||
|
deployChaincode
|
||||||
|
pushd ../asset-transfer-basic/application-typescript-hsm
|
||||||
|
print "Setup SoftHSM"
|
||||||
|
export SOFTHSM2_CONF=$PWD/softhsm2.conf
|
||||||
|
print "install dependencies"
|
||||||
|
npm install
|
||||||
|
print "Building app.ts"
|
||||||
|
npm run build
|
||||||
|
print "Running the output app"
|
||||||
|
node dist/app.js
|
||||||
|
popd
|
||||||
|
|
||||||
|
# Run Typescript HSM gateway application
|
||||||
|
print "Initializing Typescript HSM Gateway application"
|
||||||
|
export CHAINCODE_NAME=ts_hsm_gateway
|
||||||
|
deployChaincode
|
||||||
|
echo 'Delete fabric-ca-client from samples bin'
|
||||||
|
rm ../bin/fabric-ca-client
|
||||||
|
echo 'go install pkcs11 enabled fabric-ca-client'
|
||||||
|
GOBIN=${PWD}/../bin go install -tags pkcs11 github.com/hyperledger/fabric-ca/cmd/fabric-ca-client@latest
|
||||||
|
fabric-ca-client version
|
||||||
|
print "Initializing Typescript HSM gateway application"
|
||||||
|
pushd ../hardware-security-module/scripts/
|
||||||
|
print "Enroll and register User in HSM"
|
||||||
|
./generate-hsm-user.sh HSMUser
|
||||||
|
pushd ../application-typescript/
|
||||||
|
print "install dependencies and prepare for running"
|
||||||
|
npm install
|
||||||
|
print "Running the output app"
|
||||||
|
npm run start
|
||||||
|
popd
|
||||||
|
popd
|
||||||
|
|
||||||
|
# Run Go HSM gateway application
|
||||||
|
print "Initializing Go HSM gateway application"
|
||||||
|
export CHAINCODE_NAME=go_hsm
|
||||||
|
deployChaincode
|
||||||
|
pushd ../hardware-security-module/scripts/
|
||||||
|
print "Register and enroll user in HSM"
|
||||||
|
./generate-hsm-user.sh HSMUser
|
||||||
|
pushd ../application-go
|
||||||
|
print "Running the output app"
|
||||||
|
go run -tags pkcs11 .
|
||||||
|
popd
|
||||||
|
popd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
stopNetwork
|
||||||
61
ci/scripts/run-test-network-off-chain.sh
Executable file
61
ci/scripts/run-test-network-off-chain.sh
Executable file
|
|
@ -0,0 +1,61 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
CHAINCODE_LANGUAGE=${CHAINCODE_LANGUAGE:-go}
|
||||||
|
CHAINCODE_PATH=${CHAINCODE_PATH:-../asset-transfer-basic}
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function createNetwork() {
|
||||||
|
print "Creating 3 Org network"
|
||||||
|
./network.sh up createChannel -ca -s couchdb
|
||||||
|
cd addOrg3
|
||||||
|
./addOrg3.sh up -ca -s couchdb
|
||||||
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
|
function deployChaincode() {
|
||||||
|
print "Deploying ${CHAINCODE_NAME} chaincode"
|
||||||
|
./network.sh deployCC -ccn "${CHAINCODE_NAME}" -ccp "${CHAINCODE_PATH}/chaincode-${CHAINCODE_LANGUAGE}" -ccv 1 -ccs 1 -ccl "${CHAINCODE_LANGUAGE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopNetwork() {
|
||||||
|
print "Stopping network"
|
||||||
|
./network.sh down
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set up one test network to run each test scenario.
|
||||||
|
# Each test will create an independent scope by installing a new chaincode contract to the channel.
|
||||||
|
createNetwork
|
||||||
|
|
||||||
|
# Run off-chain data TypeScript application
|
||||||
|
export CHAINCODE_NAME=ts_off_chain_data
|
||||||
|
deployChaincode
|
||||||
|
print "Initializing Typescript off-chain data application"
|
||||||
|
pushd ../off_chain_data/application-typescript
|
||||||
|
rm -f checkpoint.json store.log
|
||||||
|
npm install
|
||||||
|
print "Running the output app"
|
||||||
|
SIMULATED_FAILURE_COUNT=1 npm start getAllAssets transact getAllAssets listen
|
||||||
|
SIMULATED_FAILURE_COUNT=1 npm start listen
|
||||||
|
popd
|
||||||
|
|
||||||
|
# Run off-chain data Java application
|
||||||
|
#createNetwork
|
||||||
|
export CHAINCODE_NAME=off_chain_data
|
||||||
|
deployChaincode
|
||||||
|
print "Initializing off-chain data application"
|
||||||
|
pushd ../off_chain_data/application-java
|
||||||
|
rm -f app/checkpoint.json app/store.log
|
||||||
|
print "Running the output app"
|
||||||
|
SIMULATED_FAILURE_COUNT=1 ./gradlew run --quiet --args='getAllAssets transact getAllAssets listen'
|
||||||
|
SIMULATED_FAILURE_COUNT=1 ./gradlew run --quiet --args=listen
|
||||||
|
popd
|
||||||
|
|
||||||
|
stopNetwork
|
||||||
|
|
@ -76,8 +76,20 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func exampleTransaction(gateway *client.Gateway) {
|
func exampleTransaction(gateway *client.Gateway) {
|
||||||
network := gateway.GetNetwork("mychannel")
|
|
||||||
contract := network.GetContract("basic")
|
// Override default values for chaincode and channel name as they may differ in testing contexts.
|
||||||
|
channelName := "mychannel"
|
||||||
|
if cname := os.Getenv("CHANNEL_NAME"); cname != "" {
|
||||||
|
channelName = cname
|
||||||
|
}
|
||||||
|
|
||||||
|
chaincodeName := "basic"
|
||||||
|
if ccname := os.Getenv("CHAINCODE_NAME"); ccname != "" {
|
||||||
|
chaincodeName = ccname
|
||||||
|
}
|
||||||
|
|
||||||
|
network := gateway.GetNetwork(channelName)
|
||||||
|
contract := network.GetContract(chaincodeName)
|
||||||
|
|
||||||
fmt.Printf("Submit Transaction: CreateAsset, creates new asset with ID, Color, Size, Owner and AppraisedValue arguments \n")
|
fmt.Printf("Submit Transaction: CreateAsset, creates new asset with ID, Color, Size, Owner and AppraisedValue arguments \n")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,12 @@ async function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exampleTransaction(gateway: Gateway):Promise<void> {
|
async function exampleTransaction(gateway: Gateway):Promise<void> {
|
||||||
const network = gateway.getNetwork('mychannel');
|
|
||||||
const contract = network.getContract('basic');
|
const channelName = envOrDefault('CHANNEL_NAME', 'mychannel');
|
||||||
|
const chaincodeName = envOrDefault('CHAINCODE_NAME', 'default-basic');
|
||||||
|
|
||||||
|
const network = gateway.getNetwork(channelName);
|
||||||
|
const contract = network.getContract(chaincodeName);
|
||||||
|
|
||||||
console.log('\n--> Submit Transaction: CreateAsset, creates new asset with ID, Color, Size, Owner and AppraisedValue arguments');
|
console.log('\n--> Submit Transaction: CreateAsset, creates new asset with ID, Color, Size, Owner and AppraisedValue arguments');
|
||||||
|
|
||||||
|
|
@ -154,4 +158,11 @@ function getUncompressedPointOnCurve(key: jsrsa.KJUR.crypto.ECDSA): Buffer {
|
||||||
return uncompressedPoint;
|
return uncompressedPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* envOrDefault() will return the value of an environment variable, or a default value if the variable is undefined.
|
||||||
|
*/
|
||||||
|
function envOrDefault(key: string, defaultValue: string): string {
|
||||||
|
return process.env[key] || defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
main().catch(console.error);
|
main().catch(console.error);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue