Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(connector-fabric): combine 3 tests into connector-fabric-baseline #3520

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
examples/cactus-example-carbon-accounting-frontend/www/
examples/cactus-example-supply-chain-frontend/www/
weaver/core/identity-management/iin-agent/out/
weaver/common/protos-js/build/

**/src/main/typescript/generated/proto/**
**/src/main/typescript/generated/wasm-pack/**
Expand Down
36 changes: 1 addition & 35 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1458,14 +1458,13 @@ jobs:
continue-on-error: false
env:
CACTI_NPM_PACKAGE_NAME: "@hyperledger/cactus-plugin-ledger-connector-fabric"
HFC_LOGGING: '{"debug":"console","info":"console","warn": "console","error":"console"}'
HFC_LOGGING: ''
FULL_BUILD_DISABLED: true
FREE_UP_GITHUB_RUNNER_DISK_SPACE_DISABLED: false
JEST_TEST_PATTERN: packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts
JEST_TEST_RUNNER_DISABLED: false
JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/plc-fabric-0
JEST_TEST_CODE_COVERAGE_ENABLED: true
TAPE_TEST_PATTERN: ""
TAPE_TEST_RUNNER_DISABLED: true
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -1557,39 +1556,6 @@ jobs:
- run: npm run configure
- run: yarn ts-node ./packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/deploy-cc-from-typescript-source.test.ts

plc-fabric-3:
needs:
- build-dev
- compute_changed_packages
if: needs.compute_changed_packages.outputs.plugin-ledger-connector-fabric-changed == 'true'
continue-on-error: false
env:
CACTI_NPM_PACKAGE_NAME: "@hyperledger/cactus-plugin-ledger-connector-fabric"
HFC_LOGGING: '{"debug":"console","info":"console","warn": "console","error":"console"}'
FULL_BUILD_DISABLED: true
JEST_TEST_PATTERN: packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts
JEST_TEST_RUNNER_DISABLED: true
TAPE_TEST_PATTERN: ""
TAPE_TEST_RUNNER_DISABLED: true
runs-on: ubuntu-22.04
steps:
- name: Use Node.js ${{ env.NODEJS_VERSION }}
uses: actions/[email protected]
with:
node-version: ${{ env.NODEJS_VERSION }}
- uses: actions/[email protected]

- id: yarn-cache
name: Restore Yarn Cache
uses: actions/[email protected]
with:
key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
path: ./.yarn/
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
- run: npm run configure
- run: yarn jest ./packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/integration/fabric-v2-2-x/deploy-lock-asset.test.ts

plc-fabric-4:
continue-on-error: false
needs:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Logger } from "@hyperledger/cactus-common";
import {
GatewayOptions,
GetBlockRequestV1Query,
GetBlockResponseTypeV1,
DefaultApi as FabricApi,
} from "../../../main/typescript/generated/openapi/typescript-axios/api";

/**
* Run get block endpoint using a query, do basic response checks.
* Can be reused throughout the tests.
*
* @param query how to find requested block
* @param responseType response type requested
*
* @returns block object / block buffer
*/
export async function getBlock(opts: {
readonly query: GetBlockRequestV1Query;
readonly responseType?: GetBlockResponseTypeV1;
readonly gatewayOptions: GatewayOptions;
readonly log: Logger;
readonly apiClient: FabricApi;
readonly ledgerChannelName: string;
}): Promise<any> {
const {
responseType = GetBlockResponseTypeV1.Full,
ledgerChannelName,
gatewayOptions,
query,
log,
apiClient,
} = opts;

const getBlockReq = {
channelName: ledgerChannelName,
gatewayOptions,
query,
responseType,
};

const getBlockResponse = await apiClient.getBlockV1(getBlockReq);
log.debug(
"getBlockResponse = ",
getBlockResponse.status,
getBlockResponse.data,
);

expect(getBlockResponse).toBeTruthy();
expect(getBlockResponse.status).toEqual(200);
expect(getBlockResponse.data).toBeTruthy();

switch (responseType) {
case GetBlockResponseTypeV1.Full:
if (!("decodedBlock" in getBlockResponse.data)) {
throw new Error(
`Wrong response received - expected decoded, got: ${getBlockResponse.data}`,
);
}
expect(getBlockResponse.data.decodedBlock).toBeTruthy();
return getBlockResponse.data.decodedBlock;
case GetBlockResponseTypeV1.Encoded:
if (!("encodedBlock" in getBlockResponse.data)) {
throw new Error(
`Wrong response received - expected encoded, got: ${getBlockResponse.data}`,
);
}
expect(getBlockResponse.data.encodedBlock).toBeTruthy();
return getBlockResponse.data.encodedBlock;
case GetBlockResponseTypeV1.CactiTransactions:
if (!("cactiTransactionsEvents" in getBlockResponse.data)) {
throw new Error(
`Wrong response received - expected CactiTransactions, got: ${getBlockResponse.data}`,
);
}
expect(getBlockResponse.data.cactiTransactionsEvents).toBeTruthy();
return getBlockResponse.data.cactiTransactionsEvents;
case GetBlockResponseTypeV1.CactiFullBlock:
if (!("cactiFullEvents" in getBlockResponse.data)) {
throw new Error(
`Wrong response received - expected CactiFullBlock, got: ${getBlockResponse.data}`,
);
}
expect(getBlockResponse.data.cactiFullEvents).toBeTruthy();
return getBlockResponse.data.cactiFullEvents;
default:
// Will not compile if any type was not handled by above switch.
const unknownType: never = responseType;
const validTypes = Object.keys(GetBlockResponseTypeV1).join(";");
const errorMessage = `Unknown get block response type '${unknownType}'. Accepted types for GetBlockResponseTypeV1 are: [${validTypes}]`;
throw new Error(errorMessage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Logger } from "@hyperledger/cactus-common";

import { FabricSigningCredential } from "../../../main/typescript/generated/openapi/typescript-axios/api";
import { FabricContractInvocationType } from "../../../main/typescript/generated/openapi/typescript-axios/api";
import { GatewayOptions } from "../../../main/typescript/generated/openapi/typescript-axios/api";
import { DefaultApi as FabricApi } from "../../../main/typescript/generated/openapi/typescript-axios/api";

/**
* Create new asset on the ledger to trigger new transaction creation.
*
* @param assetName unique asset name to create
* @returns committed transaction id.
*/
export async function sendTransactionOnFabric(opts: {
readonly gatewayOptions: GatewayOptions;
readonly log: Logger;
readonly apiClient: FabricApi;
readonly assetName: string;
readonly ledgerChannelName: string;
readonly ledgerContractName: string;
}) {
const fn = "sendTransactionOnFabric()";

if (!opts) {
throw new TypeError(`${fn} arg opts cannot be falsy.`);
}
const { log, apiClient, gatewayOptions, assetName } = opts;
const { ledgerContractName, ledgerChannelName } = opts;

if (!opts.gatewayOptions) {
throw new TypeError(`${fn} arg opts.gatewayOptions cannot be falsy.`);
}
if (!gatewayOptions.wallet) {
throw new TypeError(`${fn} arg opts.gatewayOptions.wallet cannot be falsy`);
}

const createAssetResponse = await apiClient.runTransactionV1({
signingCredential: gatewayOptions.wallet
.keychain as FabricSigningCredential,
channelName: ledgerChannelName,
invocationType: FabricContractInvocationType.Send,
contractName: ledgerContractName,
methodName: "CreateAsset",
params: [assetName, "green", "111", "someOwner", "299"],
});
expect(createAssetResponse).toBeTruthy();
expect(createAssetResponse.status).toEqual(200);
expect(createAssetResponse.data).toBeTruthy();
const txId = createAssetResponse.data.transactionId;
expect(txId).toBeTruthy();

log.debug("Crated new transaction, txId:", txId);
return txId;
}
Loading
Loading