-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(connector-fabric): combine 3 tests into connector-fabric-baseline
1. This is making the test case harder to read but shaves off easily 10 to 15 minutes from one of our slowest CI jobs which can take up to an hour to run when the GitHub runners are feeling lazy. 2. That above is my only justification for it. The test cases I'm consolidating are relatively stable at this point (took us years to get here but now they are passing with a high ratio and the false negatives have pretty much disappeared). 3. We are downloading and launching the fabirc AIO ledger 10+ times which is very resource intensive and this could help make a dent in it. Running this test right now looks like this on my machine: PASS packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/ integration/fabric-v2-2-x/connector-fabric-baseline.test.ts (277.062 s, 638 MB heap size) PluginLedgerConnectorFabric ✓ getBlockV1() -Get first block by it's number - decoded. (1216 ms) ✓ getBlockV1() - Get first block by it's number - encoded. (1084 ms) ✓ getBlockV1() - Get a block by transactionId it contains (4534 ms) ✓ getBlockV1() - Get a block by transactionId it contains - cacti transactions (4535 ms) ✓ getBlockV1() - Get a block by transactionId it contains - cacti full block (4559 ms) ✓ getBlockV1() - Get block by it's hash. (6727 ms) ✓ getBlockV1() - Reading block with invalid number returns an error. (1 ms) ✓ GetChainInfoV1() - Get test ledger chain info. (2134 ms) ✓ deployContractV1() - deploys Fabric 2.x contract from go source (38351 ms) ✓ deployContractV1() - deploys contract and performs transactions (40840 ms) Test Suites: 1 passed, 1 total Tests: 10 passed, 10 total Snapshots: 0 total Time: 277.117 s Signed-off-by: Peter Somogyvari <[email protected]>
- Loading branch information
Showing
8 changed files
with
996 additions
and
1,265 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
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 |
---|---|---|
|
@@ -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: | ||
|
@@ -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: | ||
|
93 changes: 93 additions & 0 deletions
93
packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/common/get-block.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,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); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...s-plugin-ledger-connector-fabric/src/test/typescript/common/send-transaction-on-fabric.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,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; | ||
} |
Oops, something went wrong.