Skip to content

Commit

Permalink
test(connector-fabric): move integration tests to use Fabric v2.5.6 AIO
Browse files Browse the repository at this point in the history
1. This fixes many flakes that we were suffering from before with the
older versions of the AIO image.
2. There could still be other flakes lurking around, but their numbers
should definitely be going down with this change due to the increased
stability of the new AIO image.

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Mar 12, 2024
1 parent e4a8a66 commit a2e5da7
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
//////////////////////////////////

// Ledger settings
const imageName = "ghcr.io/hyperledger/cactus-fabric2-all-in-one";
const imageVersion = "2021-09-02--fix-876-supervisord-retries";
const fabricEnvVersion = "2.2.0";
const fabricEnvCAVersion = "1.4.9";
const ledgerChannelName = "mychannel";
const assetTradeContractName = "copyAssetTrade";
Expand Down Expand Up @@ -47,6 +44,9 @@ import { PluginRegistry } from "@hyperledger/cactus-core";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
import {
Containers,
DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
FABRIC_25_LTS_AIO_FABRIC_VERSION,
FABRIC_25_LTS_AIO_IMAGE_VERSION,
FabricTestLedgerV1,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
Expand Down Expand Up @@ -97,15 +97,20 @@ describe("Delegated signing tests", () => {

// Start Ledger
log.info("Start FabricTestLedgerV1...");
log.debug("Version:", fabricEnvVersion, "CA Version:", fabricEnvCAVersion);
log.debug(
"Fabric Version:",
FABRIC_25_LTS_AIO_FABRIC_VERSION,
"CA Version:",
fabricEnvCAVersion,
);
ledger = new FabricTestLedgerV1({
emitContainerLogs: false,
publishAllPorts: true,
logLevel: testLogLevel,
imageName,
imageVersion,
imageName: DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION,
envVars: new Map([
["FABRIC_VERSION", fabricEnvVersion],
["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION],
["CA_VERSION", fabricEnvCAVersion],
["CACTUS_FABRIC_TEST_LOOSE_MEMBERSHIP", "1"],
]),
Expand Down Expand Up @@ -336,7 +341,7 @@ describe("Delegated signing tests", () => {
expect(initQueryResponse.status).toEqual(200);
const initQueryOutput = JSON.parse(initQueryResponse.data.functionOutput);
expect(initQueryOutput["ID"]).toEqual("asset1");
expect(initQueryOutput["owner"]).not.toEqual(newAssetOwner);
expect(initQueryOutput["Owner"]).not.toEqual(newAssetOwner);

// Transfer ownership
const sendResponse = await apiClient.runTransactionV1({
Expand Down Expand Up @@ -367,7 +372,7 @@ describe("Delegated signing tests", () => {
expect(queryResponse.status).toEqual(200);
const queryOutput = JSON.parse(queryResponse.data.functionOutput);
expect(queryOutput["ID"]).toEqual("asset1");
expect(queryOutput["owner"]).toEqual(newAssetOwner);
expect(queryOutput["Owner"]).toEqual(newAssetOwner);
},
testTimeout,
);
Expand All @@ -392,7 +397,7 @@ describe("Delegated signing tests", () => {
expect(initQueryResponse.status).toEqual(200);
const initQueryOutput = JSON.parse(initQueryResponse.data.functionOutput);
expect(initQueryOutput["ID"]).toEqual("asset1");
expect(initQueryOutput["owner"]).not.toEqual(newAssetOwner);
expect(initQueryOutput["Owner"]).not.toEqual(newAssetOwner);
checkMockSigningCallbacksAndClear(initQueryId, 2);

// Transfer ownership
Expand Down Expand Up @@ -433,7 +438,7 @@ describe("Delegated signing tests", () => {
expect(queryResponse.status).toEqual(200);
const queryOutput = JSON.parse(queryResponse.data.functionOutput);
expect(queryOutput["ID"]).toEqual("asset1");
expect(queryOutput["owner"]).toEqual(newAssetOwner);
expect(queryOutput["Owner"]).toEqual(newAssetOwner);
checkMockSigningCallbacksAndClear(finalQueryId, 2);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
DEFAULT_FABRIC_2_AIO_FABRIC_VERSION,
DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
FabricTestLedgerV1,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
Expand Down Expand Up @@ -42,7 +44,7 @@ import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory

const testCase = "deploys Fabric 2.x contract from go source";
describe(testCase, () => {
const logLevel: LogLevelDesc = "TRACE";
const logLevel: LogLevelDesc = "INFO";
const expressApp = express();
expressApp.use(bodyParser.json({ limit: "250mb" }));
const server = http.createServer(expressApp);
Expand Down Expand Up @@ -134,50 +136,13 @@ describe(testCase, () => {
asLocalhost: true,
};

// This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image)
// const orgCfgDir = "/fabric-samples/test-network/organizations/";
const orgCfgDir =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/";

// these below mirror how the fabric-samples sets up the configuration
const org1Env = {
CORE_LOGGING_LEVEL: "debug",
FABRIC_LOGGING_SPEC: "debug",
CORE_PEER_LOCALMSPID: "Org1MSP",

ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,

FABRIC_CFG_PATH: "/etc/hyperledger/fabric",
CORE_PEER_TLS_ENABLED: "true",
CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`,
CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/[email protected]/msp`,
CORE_PEER_ADDRESS: "peer0.org1.example.com:7051",
ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
};

// these below mirror how the fabric-samples sets up the configuration
const org2Env = {
CORE_LOGGING_LEVEL: "debug",
FABRIC_LOGGING_SPEC: "debug",
CORE_PEER_LOCALMSPID: "Org2MSP",

FABRIC_CFG_PATH: "/etc/hyperledger/fabric",
CORE_PEER_TLS_ENABLED: "true",
ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,

CORE_PEER_ADDRESS: "peer0.org2.example.com:9051",
CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/[email protected]/msp`,
CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`,
ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
};

const pluginOptions: IPluginLedgerConnectorFabricOptions = {
instanceId: uuidv4(),
dockerBinary: "/usr/local/bin/docker",
peerBinary: "/fabric-samples/bin/peer",
goBinary: "/usr/local/go/bin/go",
pluginRegistry,
cliContainerEnv: org1Env,
cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
sshConfig,
logLevel,
connectionProfile,
Expand Down Expand Up @@ -259,8 +224,12 @@ describe(testCase, () => {
],
collectionsConfigFile: privateDataCollectionName,
ccName: contractName,
targetOrganizations: [org1Env, org2Env],
caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
targetOrganizations: [
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
],
caFile:
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE,
ccLabel: "basic-asset-transfer-2",
ccLang: ChainCodeProgrammingLanguage.Golang,
ccSequence: 1,
Expand Down Expand Up @@ -306,13 +275,6 @@ describe(testCase, () => {
Checks.truthy(packaging, `packaging truthy OK`);
Checks.truthy(queryCommitted, `queryCommitted truthy OK`);

// FIXME - without this wait it randomly fails with an error claiming that
// the endorsement was impossible to be obtained. The fabric-samples script
// does the same thing, it just waits 10 seconds for good measure so there
// might not be a way for us to avoid doing this, but if there is a way we
// absolutely should not have timeouts like this, anywhere...
await new Promise((resolve) => setTimeout(resolve, 10000));

const assetId = uuidv4();
const assetType = "asset";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import bodyParser from "body-parser";

import {
Containers,
DEFAULT_FABRIC_2_AIO_FABRIC_VERSION,
DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
FABRIC_25_LTS_AIO_FABRIC_VERSION,
FABRIC_25_LTS_AIO_IMAGE_VERSION,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
FabricTestLedgerV1,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
Expand Down Expand Up @@ -42,7 +44,7 @@ import { Configuration } from "@hyperledger/cactus-core-api";
import { DEFAULT_FABRIC_2_AIO_IMAGE_NAME } from "@hyperledger/cactus-test-tooling";

const testCase = "deploys Fabric 2.x contract from go source";
const logLevel: LogLevelDesc = "TRACE";
const logLevel: LogLevelDesc = "INFO";

test("BEFORE " + testCase, async (t: Test) => {
const pruning = pruneDockerAllIfGithubAction({ logLevel });
Expand All @@ -62,8 +64,8 @@ test(testCase, async (t: Test) => {
emitContainerLogs: true,
publishAllPorts: true,
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]]),
imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION,
envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]),
logLevel,
});

Expand Down Expand Up @@ -106,50 +108,13 @@ test(testCase, async (t: Test) => {
asLocalhost: true,
};

// This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image)
// const orgCfgDir = "/fabric-samples/test-network/organizations/";
const orgCfgDir =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/";

// these below mirror how the fabric-samples sets up the configuration
const org1Env = {
CORE_LOGGING_LEVEL: "debug",
FABRIC_LOGGING_SPEC: "debug",
CORE_PEER_LOCALMSPID: "Org1MSP",

ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,

FABRIC_CFG_PATH: "/etc/hyperledger/fabric",
CORE_PEER_TLS_ENABLED: "true",
CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`,
CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/[email protected]/msp`,
CORE_PEER_ADDRESS: "peer0.org1.example.com:7051",
ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
};

// these below mirror how the fabric-samples sets up the configuration
const org2Env = {
CORE_LOGGING_LEVEL: "debug",
FABRIC_LOGGING_SPEC: "debug",
CORE_PEER_LOCALMSPID: "Org2MSP",

FABRIC_CFG_PATH: "/etc/hyperledger/fabric",
CORE_PEER_TLS_ENABLED: "true",
ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,

CORE_PEER_ADDRESS: "peer0.org2.example.com:9051",
CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/[email protected]/msp`,
CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`,
ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
};

const pluginOptions: IPluginLedgerConnectorFabricOptions = {
instanceId: uuidv4(),
dockerBinary: "/usr/local/bin/docker",
peerBinary: "/fabric-samples/bin/peer",
goBinary: "/usr/local/go/bin/go",
pluginRegistry,
cliContainerEnv: org1Env,
cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
sshConfig,
logLevel,
connectionProfile,
Expand Down Expand Up @@ -225,8 +190,12 @@ test(testCase, async (t: Test) => {
// constructorArgs: { Args: ["john", "99"] },
sourceFiles: [assetTransferGo, smartContractGo, goMod, goSum],
ccName: contractName,
targetOrganizations: [org1Env, org2Env],
caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
targetOrganizations: [
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
],
caFile:
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE,
ccLabel: "basic-asset-transfer-2",
ccLang: ChainCodeProgrammingLanguage.Golang,
ccSequence: 1,
Expand Down Expand Up @@ -273,13 +242,6 @@ test(testCase, async (t: Test) => {
Checks.truthy(packaging, `packaging truthy OK`);
Checks.truthy(queryCommitted, `queryCommitted truthy OK`);

// FIXME - without this wait it randomly fails with an error claiming that
// the endorsement was impossible to be obtained. The fabric-samples script
// does the same thing, it just waits 10 seconds for good measure so there
// might not be a way for us to avoid doing this, but if there is a way we
// absolutely should not have timeouts like this, anywhere...
await new Promise((resolve) => setTimeout(resolve, 10000));

const assetId = uuidv4();
const assetOwner = uuidv4();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import bodyParser from "body-parser";

import {
Containers,
DEFAULT_FABRIC_2_AIO_FABRIC_VERSION,
DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
FABRIC_25_LTS_AIO_FABRIC_VERSION,
FABRIC_25_LTS_AIO_IMAGE_VERSION,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
FabricTestLedgerV1,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
Expand Down Expand Up @@ -65,8 +67,8 @@ test(testCase, async (t: Test) => {
emitContainerLogs: true,
publishAllPorts: true,
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]]),
imageVersion: FABRIC_25_LTS_AIO_IMAGE_VERSION,
envVars: new Map([["FABRIC_VERSION", FABRIC_25_LTS_AIO_FABRIC_VERSION]]),
logLevel,
});
const tearDown = async () => {
Expand Down Expand Up @@ -108,50 +110,13 @@ test(testCase, async (t: Test) => {
asLocalhost: true,
};

// This is the directory structure of the Fabirc 2.x CLI container (fabric-tools image)
// const orgCfgDir = "/fabric-samples/test-network/organizations/";
const orgCfgDir =
"/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/";

// these below mirror how the fabric-samples sets up the configuration
const org1Env = {
CORE_LOGGING_LEVEL: "debug",
FABRIC_LOGGING_SPEC: "debug",
CORE_PEER_LOCALMSPID: "Org1MSP",

ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,

FABRIC_CFG_PATH: "/etc/hyperledger/fabric",
CORE_PEER_TLS_ENABLED: "true",
CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt`,
CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org1.example.com/users/[email protected]/msp`,
CORE_PEER_ADDRESS: "peer0.org1.example.com:7051",
ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
};

// these below mirror how the fabric-samples sets up the configuration
const org2Env = {
CORE_LOGGING_LEVEL: "debug",
FABRIC_LOGGING_SPEC: "debug",
CORE_PEER_LOCALMSPID: "Org2MSP",

FABRIC_CFG_PATH: "/etc/hyperledger/fabric",
CORE_PEER_TLS_ENABLED: "true",
ORDERER_CA: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,

CORE_PEER_ADDRESS: "peer0.org2.example.com:9051",
CORE_PEER_MSPCONFIGPATH: `${orgCfgDir}peerOrganizations/org2.example.com/users/[email protected]/msp`,
CORE_PEER_TLS_ROOTCERT_FILE: `${orgCfgDir}peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt`,
ORDERER_TLS_ROOTCERT_FILE: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
};

const pluginOptions: IPluginLedgerConnectorFabricOptions = {
instanceId: uuidv4(),
dockerBinary: "/usr/local/bin/docker",
peerBinary: "/fabric-samples/bin/peer",
goBinary: "/usr/local/go/bin/go",
pluginRegistry,
cliContainerEnv: org1Env,
cliContainerEnv: FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
sshConfig,
logLevel,
connectionProfile,
Expand Down Expand Up @@ -235,8 +200,12 @@ test(testCase, async (t: Test) => {
// constructorArgs: { Args: ["john", "99"] },
sourceFiles,
ccName: contractName,
targetOrganizations: [org1Env, org2Env],
caFile: `${orgCfgDir}ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem`,
targetOrganizations: [
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1,
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_2,
],
caFile:
FABRIC_25_LTS_FABRIC_SAMPLES_ENV_INFO_ORG_1.ORDERER_TLS_ROOTCERT_FILE,
ccLabel: "basic-asset-transfer-2",
ccLang: ChainCodeProgrammingLanguage.Javascript,
ccSequence: 1,
Expand Down Expand Up @@ -282,13 +251,6 @@ test(testCase, async (t: Test) => {
Checks.truthy(packaging, `packaging truthy OK`);
Checks.truthy(queryCommitted, `queryCommitted truthy OK`);

// FIXME - without this wait it randomly fails with an error claiming that
// the endorsement was impossible to be obtained. The fabric-samples script
// does the same thing, it just waits 10 seconds for good measure so there
// might not be a way for us to avoid doing this, but if there is a way we
// absolutely should not have timeouts like this, anywhere...
await new Promise((resolve) => setTimeout(resolve, 30000));

const assetId = uuidv4();
const assetOwner = uuidv4();

Expand Down
Loading

0 comments on commit a2e5da7

Please sign in to comment.