Skip to content

Commit

Permalink
Remove the need for gateway-enabled when binding to a fabric 2.2 SUT (#…
Browse files Browse the repository at this point in the history
…1255)

Signed-off-by: D <d_kelsey@uk.ibm.com>

Co-authored-by: D <d_kelsey@uk.ibm.com>
  • Loading branch information
davidkel and davidkel committed Mar 8, 2022
1 parent 5380af7 commit 5ee6aaa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
19 changes: 8 additions & 11 deletions packages/caliper-fabric/lib/FabricConnectorFactory.js
Expand Up @@ -40,11 +40,14 @@ const _determineInstalledNodeSDKVersion = () => {
}
};

const _loadAppropriateConnectorClass = (installedNodeSDKVersion, useGateway) => {
const _loadAppropriateConnectorClass = (installedNodeSDKVersion) => {
let connectorPath;
let walletFacadeFactoryPath;

if (semver.satisfies(installedNodeSDKVersion, '=1.x')) {
const useGateway = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Enabled, false);
Logger.info(`Initializing ${useGateway ? 'gateway' : 'standard' } connector compatible with installed SDK: ${installedNodeSDKVersion}`);

if (!useGateway) {
connectorPath = NEW_V1_NODE_CONNECTOR;
walletFacadeFactoryPath = NEW_V1_WALLET_FACADE_FACTORY;
Expand All @@ -58,12 +61,9 @@ const _loadAppropriateConnectorClass = (installedNodeSDKVersion, useGateway) =>
}
}
} else if (semver.satisfies(installedNodeSDKVersion, '=2.x')) {
if (!useGateway) {
throw new Error(`Caliper currently only supports gateway based operation using the ${installedNodeSDKVersion} Fabric-SDK. Please retry with the gateway flag`);
} else {
connectorPath = NEW_V2_GATEWAY_CONNECTOR;
walletFacadeFactoryPath = NEW_V2_WALLET_FACADE_FACTORY;
}
Logger.info(`Initializing gateway connector compatible with installed SDK: ${installedNodeSDKVersion}`);
connectorPath = NEW_V2_GATEWAY_CONNECTOR;
walletFacadeFactoryPath = NEW_V2_WALLET_FACADE_FACTORY;
} else {
throw new Error(`Installed SDK version ${installedNodeSDKVersion} did not match any compatible Fabric connectors`);
}
Expand Down Expand Up @@ -96,10 +96,7 @@ const connectorFactory = async (workerIndex) => {
}

const installedNodeSDKVersion = _determineInstalledNodeSDKVersion();
const useGateway = ConfigUtil.get(ConfigUtil.keys.Fabric.Gateway.Enabled, false);

Logger.info(`Initializing ${useGateway ? 'gateway' : 'standard' } connector compatible with installed SDK: ${installedNodeSDKVersion}`);
const {fabricConnectorClass, walletFacadeFactoryClass} = _loadAppropriateConnectorClass(installedNodeSDKVersion, useGateway);
const {fabricConnectorClass, walletFacadeFactoryClass} = _loadAppropriateConnectorClass(installedNodeSDKVersion);
const connectorConfiguration = await new ConnectorConfigurationFactory().create(connectorConfigurationFile, new walletFacadeFactoryClass());
const fabricConnector = new fabricConnectorClass(connectorConfiguration, workerIndex, 'fabric');

Expand Down
8 changes: 4 additions & 4 deletions packages/caliper-fabric/test/FabricConnectorFactory.js
Expand Up @@ -112,7 +112,7 @@ describe('A Fabric Connector Factory', () => {
mockery.deregisterAll();
});

it('should create a V1 Gateway connector when a 1.4 fabric library is bound, usegateway was specified', async () => {
it('should create a V1 Gateway connector when a 1.4 fabric library is bound and gateway is specified', async () => {
mockery.registerMock('fabric-network', {
DefaultEventHandlerStrategies,
DefaultQueryHandlerStrategies,
Expand All @@ -129,21 +129,21 @@ describe('A Fabric Connector Factory', () => {
mockery.deregisterAll();
});

it('should create a V2 Gateway connector when a 2.x fabric library is bound, usegateway was specified', async () => {
it('should create a V2 Gateway connector when a 2.x fabric library is bound', async () => {
mockery.registerMock('fabric-network', {
DefaultEventHandlerStrategies,
DefaultQueryHandlerStrategies,
Wallets: AlternativeWallets
});
mockery.registerMock('fabric-network/package', {version: '2.2.1'});
ConfigUtil.set(ConfigUtil.keys.NetworkConfig, path.resolve(__dirname, v2Config));
ConfigUtil.set(ConfigUtil.keys.Fabric.Gateway.Enabled, true);
ConfigUtil.set(ConfigUtil.keys.Fabric.Gateway.Enabled, false);
const connector = await ConnectorFactory(1);
connector.constructor.name.should.equal('V2FabricGateway');
mockery.deregisterAll();
});

it('should create a V1 Fabric connector if a 1.4 fabric library is bound and usegateway was not specified', async () => {
it('should create a V1 Fabric connector if a 1.4 fabric library is bound gateway not specified', async () => {
mockery.registerMock('fabric-network', {
DefaultEventHandlerStrategies,
DefaultQueryHandlerStrategies,
Expand Down
6 changes: 3 additions & 3 deletions packages/caliper-tests-integration/fabric_tests/run.sh
Expand Up @@ -38,7 +38,7 @@ export CALIPER_PROJECTCONFIG=../caliper.yaml

dispose () {
docker ps -a
${CALL_METHOD} launch manager --caliper-workspace phase7 --caliper-flow-only-end --caliper-fabric-gateway-enabled
${CALL_METHOD} launch manager --caliper-workspace phase7 --caliper-flow-only-end
}

# needed, since the peer looks for the latest, which is no longer on dockerhub
Expand Down Expand Up @@ -112,7 +112,7 @@ if [[ "${BIND_IN_PACKAGE_DIR}" = "true" ]]; then
fi

# PHASE 6: testing through the gateway API (v2 SDK)
${CALL_METHOD} launch manager --caliper-workspace phase6 --caliper-flow-only-test --caliper-fabric-gateway-enabled
${CALL_METHOD} launch manager --caliper-workspace phase6 --caliper-flow-only-test
rc=$?
if [[ ${rc} != 0 ]]; then
echo "Failed CI step 7";
Expand All @@ -121,7 +121,7 @@ if [[ ${rc} != 0 ]]; then
fi

# PHASE 7: just disposing of the network
${CALL_METHOD} launch manager --caliper-workspace phase7 --caliper-flow-only-end --caliper-fabric-gateway-enabled
${CALL_METHOD} launch manager --caliper-workspace phase7 --caliper-flow-only-end
rc=$?
if [[ ${rc} != 0 ]]; then
echo "Failed CI step 8";
Expand Down

0 comments on commit 5ee6aaa

Please sign in to comment.