Skip to content

Commit

Permalink
[FAB-17268] Move fabcar sample to test network
Browse files Browse the repository at this point in the history
Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com>
  • Loading branch information
NIKHIL E GUPTA committed Jan 20, 2020
1 parent b3b5267 commit 608b5ef
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 260 deletions.
4 changes: 2 additions & 2 deletions fabcar/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fabcar-java</groupId>
<artifactId>fabcar-java</artifactId>
<version>1.4.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -53,4 +53,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
5 changes: 2 additions & 3 deletions fabcar/java/src/main/java/org/example/ClientApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ public static void main(String[] args) throws Exception {
// Load a file system based wallet for managing identities.
Path walletPath = Paths.get("wallet");
Wallet wallet = Wallet.createFileSystemWallet(walletPath);

// load a CCP
Path networkConfigPath = Paths.get("..", "..", "first-network", "connection-org1.yaml");
Path networkConfigPath = Paths.get("..", "..", "test-network", "organizations", "peerOrganizations", "org1.example.com", "connection-org1.yaml");

Gateway.Builder builder = Gateway.createBuilder();
builder.identity(wallet, "user1").networkConfig(networkConfigPath).discovery(true);
builder.identity(wallet, "appUser").networkConfig(networkConfigPath).discovery(true);

// create a gateway connection
try (Gateway gateway = builder.connect()) {
Expand Down
2 changes: 1 addition & 1 deletion fabcar/java/src/main/java/org/example/EnrollAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void main(String[] args) throws Exception {
// Create a CA client for interacting with the CA.
Properties props = new Properties();
props.put("pemFile",
"../../first-network/crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem");
"../../test-network/organizations/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem");
props.put("allowAllHostNames", "true");
HFCAClient caClient = HFCAClient.createNewInstance("https://localhost:7054", props);
CryptoSuite cryptoSuite = CryptoSuiteFactory.getDefault().getCryptoSuite();
Expand Down
16 changes: 8 additions & 8 deletions fabcar/java/src/main/java/org/example/RegisterUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main(String[] args) throws Exception {
// Create a CA client for interacting with the CA.
Properties props = new Properties();
props.put("pemFile",
"../../first-network/crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem");
"../../test-network/organizations/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem");
props.put("allowAllHostNames", "true");
HFCAClient caClient = HFCAClient.createNewInstance("https://localhost:7054", props);
CryptoSuite cryptoSuite = CryptoSuiteFactory.getDefault().getCryptoSuite();
Expand All @@ -39,9 +39,9 @@ public static void main(String[] args) throws Exception {
Wallet wallet = Wallet.createFileSystemWallet(Paths.get("wallet"));

// Check to see if we've already enrolled the user.
boolean userExists = wallet.exists("user1");
boolean userExists = wallet.exists("appUser");
if (userExists) {
System.out.println("An identity for the user \"user1\" already exists in the wallet");
System.out.println("An identity for the user \"appUser\" already exists in the wallet");
return;
}

Expand Down Expand Up @@ -98,14 +98,14 @@ public String getMspId() {
};

// Register the user, enroll the user, and import the new identity into the wallet.
RegistrationRequest registrationRequest = new RegistrationRequest("user1");
RegistrationRequest registrationRequest = new RegistrationRequest("appUser");
registrationRequest.setAffiliation("org1.department1");
registrationRequest.setEnrollmentID("user1");
registrationRequest.setEnrollmentID("appUser");
String enrollmentSecret = caClient.register(registrationRequest, admin);
Enrollment enrollment = caClient.enroll("user1", enrollmentSecret);
Enrollment enrollment = caClient.enroll("appUser", enrollmentSecret);
Identity user = Identity.createIdentity("Org1MSP", enrollment.getCert(), enrollment.getKey());
wallet.put("user1", user);
System.out.println("Successfully enrolled user \"user1\" and imported it into the wallet");
wallet.put("appUser", user);
System.out.println("Successfully enrolled user \"appUser\" and imported it into the wallet");
}

}
3 changes: 2 additions & 1 deletion fabcar/javascript/enrollAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const { Wallets } = require('fabric-network');
const fs = require('fs');
const path = require('path');

const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
//const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
const ccpPath = path.resolve(__dirname, '..', '..', 'test-network', 'organizations', 'peerOrganizations', 'org1.example.com', 'connection-org1.json');
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
const ccp = JSON.parse(ccpJSON);

Expand Down
8 changes: 4 additions & 4 deletions fabcar/javascript/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const { Gateway, Wallets } = require('fabric-network');
const path = require('path');

const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
const ccpPath = path.resolve(__dirname, '..', '..', 'test-network','organizations','peerOrganizations','org1.example.com', 'connection-org1.json');

async function main() {
try {
Expand All @@ -18,16 +18,16 @@ async function main() {
console.log(`Wallet path: ${walletPath}`);

// Check to see if we've already enrolled the user.
const identity = await wallet.get('user1');
const identity = await wallet.get('appUser');
if (!identity) {
console.log('An identity for the user "user1" does not exist in the wallet');
console.log('An identity for the user "appUser" does not exist in the wallet');
console.log('Run the registerUser.js application before retrying');
return;
}

// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
await gateway.connect(ccpPath, { wallet, identity: 'appUser', discovery: { enabled: true, asLocalhost: true } });

// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork('mychannel');
Expand Down
8 changes: 4 additions & 4 deletions fabcar/javascript/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const { Gateway, Wallets } = require('fabric-network');
const path = require('path');

const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
const ccpPath = path.resolve(__dirname, '..', '..', 'test-network','organizations','peerOrganizations','org1.example.com', 'connection-org1.json');

async function main() {
try {
Expand All @@ -18,16 +18,16 @@ async function main() {
console.log(`Wallet path: ${walletPath}`);

// Check to see if we've already enrolled the user.
const identity = await wallet.get('user1');
const identity = await wallet.get('appUser');
if (!identity) {
console.log('An identity for the user "user1" does not exist in the wallet');
console.log('An identity for the user "appUser" does not exist in the wallet');
console.log('Run the registerUser.js application before retrying');
return;
}

// Create a new gateway for connecting to our peer node.
const gateway = new Gateway();
await gateway.connect(ccpPath, { wallet, identity: 'user1', discovery: { enabled: true, asLocalhost: true } });
await gateway.connect(ccpPath, { wallet, identity: 'appUser', discovery: { enabled: true, asLocalhost: true } });

// Get the network (channel) our contract is deployed to.
const network = await gateway.getNetwork('mychannel');
Expand Down
16 changes: 8 additions & 8 deletions fabcar/javascript/registerUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const { Gateway, Wallets } = require('fabric-network');
const path = require('path');

const ccpPath = path.resolve(__dirname, '..', '..', 'first-network', 'connection-org1.json');
const ccpPath = path.resolve(__dirname, '..', '..', 'test-network','organizations','peerOrganizations','org1.example.com', 'connection-org1.json');

async function main() {
try {
Expand All @@ -18,9 +18,9 @@ async function main() {
console.log(`Wallet path: ${walletPath}`);

// Check to see if we've already enrolled the user.
const userIdentity = await wallet.get('user1');
const userIdentity = await wallet.get('appUser');
if (userIdentity) {
console.log('An identity for the user "user1" already exists in the wallet');
console.log('An identity for the user "appUser" already exists in the wallet');
return;
}

Expand All @@ -42,8 +42,8 @@ async function main() {
const adminUser = await client.getUserContext('admin', false);

// Register the user, enroll the user, and import the new identity into the wallet.
const secret = await ca.register({ affiliation: 'org1.department1', enrollmentID: 'user1', role: 'client' }, adminUser);
const enrollment = await ca.enroll({ enrollmentID: 'user1', enrollmentSecret: secret });
const secret = await ca.register({ affiliation: 'org1.department1', enrollmentID: 'appUser', role: 'client' }, adminUser);
const enrollment = await ca.enroll({ enrollmentID: 'appUser', enrollmentSecret: secret });
const x509Identity = {
credentials: {
certificate: enrollment.certificate,
Expand All @@ -52,11 +52,11 @@ async function main() {
mspId: 'Org1MSP',
type: 'X.509',
};
await wallet.put('user1', x509Identity);
console.log('Successfully registered and enrolled admin user "user1" and imported it into the wallet');
await wallet.put('appUser', x509Identity);
console.log('Successfully registered and enrolled admin user "appUser" and imported it into the wallet');

} catch (error) {
console.error(`Failed to register user "user1": ${error}`);
console.error(`Failed to register user "appUser": ${error}`);
process.exit(1);
}
}
Expand Down
18 changes: 18 additions & 0 deletions fabcar/networkDown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
#
# Copyright IBM Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#
# Exit on first error
set -ex

# Bring the test network down
pushd ../test-network
./network.sh down
popd

# clean out any old identites in the wallets
rm -rf javascript/wallet/*
rm -rf java/wallet/*
rm -rf typescript/wallet/*
Loading

0 comments on commit 608b5ef

Please sign in to comment.