Skip to content

Commit

Permalink
feat(fabric-test-ledger): add support to enrolling users in different…
Browse files Browse the repository at this point in the history
… Orgs

Created new methods to avoid breaking changes in the API exported
New methods created:
* getConnectionProfileOrgX
* enrollAdminV2
* enrollUserV2
* createCaClientV2

closes #2248

Co-authored-by: Peter Somogyvari <peter.somogyvari@accenture.com>

Signed-off-by: André Augusto <andre.augusto@tecnico.ulisboa.pt>
Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
AndreAugusto11 authored and petermetz committed Aug 14, 2023
1 parent 3a58508 commit b910681
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 57 deletions.
Expand Up @@ -3,6 +3,9 @@
import test, { Test } from "tape-promise/tape";

import {
DEFAULT_FABRIC_2_AIO_FABRIC_VERSION,
DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
FabricTestLedgerV1,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
Expand All @@ -18,7 +21,6 @@ const testCase = "adds org4 to the network";
const logLevel: LogLevelDesc = "TRACE";

test.skip("BEFORE " + testCase, async (t: Test) => {
t.skip();
const pruning = pruneDockerAllIfGithubAction({ logLevel });
await t.doesNotReject(pruning, "Pruning did not throw OK");
t.end();
Expand All @@ -38,9 +40,10 @@ test.skip(testCase, async (t: Test) => {
const ledger = new FabricTestLedgerV1({
emitContainerLogs: true,
publishAllPorts: true,
logLevel: "debug",
imageName: "ghcr.io/hyperledger/cactus-fabric2-all-in-one",
envVars: new Map([["FABRIC_VERSION", "2.2.0"]]),
logLevel,
imageName: DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
imageVersion: DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
envVars: new Map([["FABRIC_VERSION", DEFAULT_FABRIC_2_AIO_FABRIC_VERSION]]),
extraOrgs: [extraOrg],
});

Expand Down Expand Up @@ -88,12 +91,9 @@ test.skip(testCase, async (t: Test) => {
);

//Should return error, as there is no org101 in the default deployment of Fabric AIO image nor it was added
const error = "/Error.*/";

const error = "/no such container - Could not find the file.*/";
await t.rejects(ledger.getConnectionProfileOrgX("org101"), error);

//Let us add org 3 and retrieve the connection profile

t.end();
});

Expand Down
Expand Up @@ -60,8 +60,8 @@ const ledgerChannelName = "mychannel";
const ledgerContractName = "basic";

// Log settings
const testLogLevel: LogLevelDesc = "info"; // default: info
const sutLogLevel: LogLevelDesc = "info"; // default: info
const testLogLevel: LogLevelDesc = "TRACE"; // default: info
const sutLogLevel: LogLevelDesc = "TRACE"; // default: info

// Logger setup
const log: Logger = LoggerProvider.getOrCreate({
Expand Down Expand Up @@ -108,12 +108,15 @@ describe("watchBlocksV1 of fabric connector tests", () => {
// Get connection profile
log.info("Get fabric connection profile for Org1...");
const connectionProfile = await ledger.getConnectionProfileOrg1();
log.debug("Fabric connection profile for Org1 OK: %o", connectionProfile);
expect(connectionProfile).toBeTruthy();

// Enroll admin and user
const enrollAdminOut = await ledger.enrollAdmin();
log.debug("Enrolled admin OK.");
const adminWallet = enrollAdminOut[1];
const [userIdentity] = await ledger.enrollUser(adminWallet);
log.debug("Enrolled user OK.");

// Create Keychain Plugin
const keychainId = uuidv4();
Expand Down
Expand Up @@ -15,13 +15,13 @@ import { LogLevelDesc } from "@hyperledger/cactus-common";
const testCase = "obtains configuration profiles from Fabric 2.x ledger";
const logLevel: LogLevelDesc = "TRACE";

test.skip("BEFORE " + testCase, async (t: Test) => {
test("BEFORE " + testCase, async (t: Test) => {
const pruning = pruneDockerAllIfGithubAction({ logLevel });
await t.doesNotReject(pruning, "Pruning did not throw OK");
t.end();
});

test.skip(testCase, async (t: Test) => {
test(testCase, async (t: Test) => {
const ledger = new FabricTestLedgerV1({
emitContainerLogs: true,
publishAllPorts: true,
Expand All @@ -42,10 +42,10 @@ test.skip(testCase, async (t: Test) => {

t.ok(connectionProfile, "getConnectionProfileOrg1() out truthy OK");

const connectionProfileOrg1 = await ledger.getConnectionProfileOrgX("1");
const connectionProfileOrg1 = await ledger.getConnectionProfileOrgX("org1");
t.isEquivalent(connectionProfile, connectionProfileOrg1);

const connectionProfileOrg2 = await ledger.getConnectionProfileOrgX("2");
const connectionProfileOrg2 = await ledger.getConnectionProfileOrgX("org2");
t.ok(connectionProfileOrg2, "getConnectionProfileOrg2() out truthy OK");

t.notDeepEqual(
Expand All @@ -55,13 +55,13 @@ test.skip(testCase, async (t: Test) => {
);

//Should return error, as there is no Org3 in the default deployment of Fabric AIO image
const error = "/Error.*/";
await t.rejects(ledger.getConnectionProfileOrgX("3"), error);
const error = "/no such container - Could not find the file.*/";
await t.rejects(ledger.getConnectionProfileOrgX("org3"), error);

t.end();
});

test.skip("AFTER " + testCase, async (t: Test) => {
test("AFTER " + testCase, async (t: Test) => {
const pruning = pruneDockerAllIfGithubAction({ logLevel });
await t.doesNotReject(pruning, "Pruning did not throw OK");
t.end();
Expand Down

0 comments on commit b910681

Please sign in to comment.