-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fabric): user defined fabric samples version
Primary Change -------------- 1. The fabric-all-in-one can now accept fabric versions as argument at runtime and corresponding code changes are incorporated. Minor refactorings that were also necessary to accomodate 1) ------------------------------------------------------------ 2. The interface IFabricTestLedgerV1ConstructorOptions in the class fabric-test-ledger-v1 is modified to incorporate new variable fabricVersion. Corresponding changes are made to the functions to include the same. 3. The client user name has been renamed from user1 to user2 as Hyperledger Fabric 2.xversions has user1 already registered. 4. Go has been manually setup in the Dockerfile located at tools/docker/fabric-all-in-one/Dockerfile to support Hyperledger Fabric 2.x versions, as Go isn't setup by default in v2.x 5. Check for existence has been put over the peer1.org{org_number}.example.com as peer1 is not setup for test-network. 6. fabricVersion has been removed from FabricTestLedgerV1, and instead envVars map<string,string> has been included to support more dynamic features for the fabric-all-in-one image like fabricVersion, caVersion 7. The healthcheck logic for the above mentioned Dockerfile has moved to the healthcheck.sh script to support Hyperledger Fabric 2.x versions. Changes are made for the run-fabric-network.sh script for the same. 8. The Readme for the Dockerfile mentioned in 4) has been updated 9. Created 2 seperate Dockerfile for 2.x and 1.4.x versions of Hyperledger Fabric 10. 2 sepearte integration tests corresponding to Fabric v1.4.x and v2.2.x Fixes #391 Signed-off-by: jagpreetsinghsasan <jagpreet.singh.sasan@accenture.com> Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
1 parent
f40bf9b
commit 8a60717
Showing
11 changed files
with
425 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
...-fabric/src/test/typescript/integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import http from "http"; | ||
import { AddressInfo } from "net"; | ||
|
||
import test, { Test } from "tape"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
import bodyParser from "body-parser"; | ||
import express from "express"; | ||
|
||
import { FabricTestLedgerV1 } from "@hyperledger/cactus-test-tooling"; | ||
import { PluginRegistry } from "@hyperledger/cactus-core"; | ||
|
||
import { | ||
IListenOptions, | ||
LogLevelDesc, | ||
Servers, | ||
} from "@hyperledger/cactus-common"; | ||
|
||
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; | ||
|
||
import { | ||
PluginLedgerConnectorFabric, | ||
DefaultApi as FabricApi, | ||
RunTransactionRequest, | ||
FabricContractInvocationType, | ||
DefaultEventHandlerStrategy, | ||
} from "../../../../main/typescript/public-api"; | ||
|
||
import { IPluginLedgerConnectorFabricOptions } from "../../../../main/typescript/plugin-ledger-connector-fabric"; | ||
import { DiscoveryOptions } from "fabric-network"; | ||
|
||
/** | ||
* Use this to debug issues with the fabric node SDK | ||
* ```sh | ||
* export HFC_LOGGING='{"debug":"console","info":"console"}' | ||
* ``` | ||
*/ | ||
|
||
test("runs tx on a Fabric v2.2.0 ledger", async (t: Test) => { | ||
const logLevel: LogLevelDesc = "TRACE"; | ||
|
||
const ledger = new FabricTestLedgerV1({ | ||
publishAllPorts: true, | ||
logLevel, | ||
imageName: "hyperledger/cactus-fabric-all-in-one", | ||
imageVersion: "2020-12-16-3ddfd8f-v2.2.0", | ||
envVars: new Map([ | ||
["FABRIC_VERSION", "2.2.0"], | ||
["CA_VERSION", "1.4.9"], | ||
]), | ||
}); | ||
|
||
await ledger.start(); | ||
|
||
const tearDownLedger = async () => { | ||
await ledger.stop(); | ||
await ledger.destroy(); | ||
}; | ||
test.onFinish(tearDownLedger); | ||
|
||
const [_, adminWallet] = await ledger.enrollAdmin(); | ||
const [userIdentity] = await ledger.enrollUser(adminWallet); | ||
|
||
const connectionProfile = await ledger.getConnectionProfileOrg1(); | ||
|
||
const sshConfig = await ledger.getSshConfig(); | ||
|
||
const keychainInstanceId = uuidv4(); | ||
const keychainId = uuidv4(); | ||
const keychainEntryKey = "user2"; | ||
const keychainEntryValue = JSON.stringify(userIdentity); | ||
|
||
const keychainPlugin = new PluginKeychainMemory({ | ||
instanceId: keychainInstanceId, | ||
keychainId, | ||
logLevel, | ||
backend: new Map([ | ||
[keychainEntryKey, keychainEntryValue], | ||
["some-other-entry-key", "some-other-entry-value"], | ||
]), | ||
}); | ||
|
||
const pluginRegistry = new PluginRegistry({ plugins: [keychainPlugin] }); | ||
|
||
const discoveryOptions: DiscoveryOptions = { | ||
enabled: true, | ||
asLocalhost: true, | ||
}; | ||
|
||
const pluginOptions: IPluginLedgerConnectorFabricOptions = { | ||
instanceId: uuidv4(), | ||
pluginRegistry, | ||
sshConfig, | ||
logLevel, | ||
connectionProfile, | ||
discoveryOptions, | ||
eventHandlerOptions: { | ||
strategy: DefaultEventHandlerStrategy.NETWORKSCOPEALLFORTX, | ||
}, | ||
}; | ||
const plugin = new PluginLedgerConnectorFabric(pluginOptions); | ||
|
||
const expressApp = express(); | ||
expressApp.use(bodyParser.json({ limit: "250mb" })); | ||
const server = http.createServer(expressApp); | ||
const listenOptions: IListenOptions = { | ||
hostname: "localhost", | ||
port: 0, | ||
server, | ||
}; | ||
const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; | ||
test.onFinish(async () => await Servers.shutdown(server)); | ||
const { address, port } = addressInfo; | ||
const apiHost = `http://${address}:${port}`; | ||
const apiClient = new FabricApi({ basePath: apiHost }); | ||
|
||
await plugin.installWebServices(expressApp); | ||
|
||
const carId = "CAR277"; | ||
const carOwner = uuidv4(); | ||
|
||
{ | ||
const res = await apiClient.runTransactionV1({ | ||
keychainId, | ||
keychainRef: keychainEntryKey, | ||
channelName: "mychannel", | ||
chainCodeId: "fabcar", | ||
invocationType: FabricContractInvocationType.CALL, | ||
functionName: "queryAllCars", | ||
functionArgs: [], | ||
} as RunTransactionRequest); | ||
t.ok(res); | ||
t.ok(res.data); | ||
t.equal(res.status, 200); | ||
const cars = JSON.parse(res.data.functionOutput); | ||
} | ||
|
||
{ | ||
const req: RunTransactionRequest = { | ||
keychainId, | ||
keychainRef: keychainEntryKey, | ||
channelName: "mychannel", | ||
invocationType: FabricContractInvocationType.SEND, | ||
chainCodeId: "fabcar", | ||
functionName: "createCar", | ||
functionArgs: [carId, "Trabant", "601", "Blue", carOwner], | ||
}; | ||
|
||
const res = await apiClient.runTransactionV1(req); | ||
t.ok(res); | ||
t.ok(res.data); | ||
t.equal(res.status, 200); | ||
} | ||
|
||
{ | ||
const res = await apiClient.runTransactionV1({ | ||
keychainId, | ||
keychainRef: keychainEntryKey, | ||
channelName: "mychannel", | ||
chainCodeId: "fabcar", | ||
invocationType: FabricContractInvocationType.CALL, | ||
functionName: "queryAllCars", | ||
functionArgs: [], | ||
} as RunTransactionRequest); | ||
t.ok(res); | ||
t.ok(res.data); | ||
t.equal(res.status, 200); | ||
const cars = JSON.parse(res.data.functionOutput); | ||
const car277 = cars.find((c: any) => c.Key === carId); | ||
t.ok(car277, "Located Car record by its ID OK"); | ||
t.ok(car277.Record, `Car object has "Record" property OK`); | ||
t.ok(car277.Record.owner, `Car object has "Record"."owner" property OK`); | ||
t.equal(car277.Record.owner, carOwner, `Car has expected owner OK`); | ||
} | ||
|
||
t.end(); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.