diff --git a/examples/cactus-example-cbdc-bridging-backend/package.json b/examples/cactus-example-cbdc-bridging-backend/package.json index 4375d801a5c..3695a5092ab 100644 --- a/examples/cactus-example-cbdc-bridging-backend/package.json +++ b/examples/cactus-example-cbdc-bridging-backend/package.json @@ -86,7 +86,6 @@ "web3-utils": "1.5.2" }, "devDependencies": { - "@types/chai": "^4.3.1", "@types/crypto-js": "4.1.1", "@types/cucumber": "^4.0.4", "@types/express": "4.17.19", @@ -94,7 +93,6 @@ "@types/fs-extra": "9.0.13", "@types/node": "^10.17.60", "@types/uuid": "8.3.4", - "chai": "^4.1.2", "cucumber": "^5.0.3", "hardhat": "2.17.2", "http-status-codes": "2.1.4", diff --git a/examples/cactus-example-cbdc-bridging-backend/src/main/typescript/satp-extension/client-helper.ts b/examples/cactus-example-cbdc-bridging-backend/src/main/typescript/satp-extension/client-helper.ts index 0dec1036d95..675e8de6a18 100644 --- a/examples/cactus-example-cbdc-bridging-backend/src/main/typescript/satp-extension/client-helper.ts +++ b/examples/cactus-example-cbdc-bridging-backend/src/main/typescript/satp-extension/client-helper.ts @@ -119,7 +119,7 @@ export class ClientHelper extends ClientGatewayHelper { .isValidBridgeBackCBDC( sessionData.sourceLedgerAssetID, sessionData.assetProfile.keyInformationLink[0].toString(), // Amount - sessionData.assetProfile.keyInformationLink[2].toString(), // Amount + sessionData.assetProfile.keyInformationLink[2].toString(), // ethAddress ) .catch((err) => { throw new Error(`${err}`); diff --git a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/features/bridge-back.feature b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/features/bridge-back.feature index 1ee3af40a6e..09da8ebfd3b 100644 --- a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/features/bridge-back.feature +++ b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/features/bridge-back.feature @@ -50,38 +50,18 @@ Feature: Client successfully bridges back CBDC Given "bob" locks and deletes an asset reference with id "c5dfbd04-a71b-4848-92d1-78cd1fafaaf1" in the source chain Given "alice" with 500 CBDC available in the sidechain smart contract When "alice" escrows 500 CBDC and creates an asset reference with id "d25fbcbb-0895-4905-b8d5-502d5e83b122" in the sidechain - Then "alice" fails to initiate bridge back of 10000 CBDC referenced by id "d25fbcbb-0895-4905-b8d5-502d5e83b122" to "alice" address in the source chain - - @bridgeBack - @fabric - @besu - Scenario: Client fails to initiate bridge back of CBDC to another user address in the source chain but transfer - Given "alice" with 500 CBDC available in the source chain - Given "alice" escrows 500 CBDC and creates an asset reference with id "c5dfbd04-a71b-4848-92d1-78cd1fafaaf1" in the source chain - Given "bob" locks and deletes an asset reference with id "c5dfbd04-a71b-4848-92d1-78cd1fafaaf1" in the source chain - Given "alice" with 500 CBDC available in the sidechain smart contract - When "alice" escrows 500 CBDC and creates an asset reference with id "d25fbcbb-0895-4905-b8d5-502d5e83b122" in the sidechain - Then "alice" fails to initiate bridge back of 500 CBDC referenced by id "d25fbcbb-0895-4905-b8d5-502d5e83b122" to "charlie" address in the source chain - Then "alice" has 0 CBDC available in the source chain - Then "alice" has 0 CBDC available in the sidechain - Then "bob" has 500 CBDC available in the source chain - Then "bob" has 500 CBDC available in the sidechain - Then "charlie" has 0 CBDC available in the source chain - Then "charlie" has 0 CBDC available in the sidechain + Then "alice" fails to initiate bridge back of 10000 CBDC referenced by id "d25fbcbb-0895-4905-b8d5-502d5e83b122" @bridgeBack @fabric @besu Scenario: Impersonator fails to initiate bridge back of CBDC escrowed by another user address but transfer - Given "alice" with 500 CBDC available in the source chain - Given "alice" escrows 500 CBDC and creates an asset reference with id "c5dfbd04-a71b-4848-92d1-78cd1fafaaf1" in the source chain - Given "bob" locks and deletes an asset reference with id "c5dfbd04-a71b-4848-92d1-78cd1fafaaf1" in the source chain Given "alice" with 500 CBDC available in the sidechain smart contract When "alice" escrows 500 CBDC and creates an asset reference with id "d25fbcbb-0895-4905-b8d5-502d5e83b122" in the sidechain - Then "charlie" fails to initiate bridge back of 500 CBDC referenced by id "d25fbcbb-0895-4905-b8d5-502d5e83b122" to "alice" address in the source chain + Then "charlie" fails to initiate bridge back of 500 CBDC referenced by id "d25fbcbb-0895-4905-b8d5-502d5e83b122" Then "alice" has 0 CBDC available in the source chain Then "alice" has 0 CBDC available in the sidechain - Then "bob" has 500 CBDC available in the source chain + Then "bob" has 0 CBDC available in the source chain Then "bob" has 500 CBDC available in the sidechain Then "charlie" has 0 CBDC available in the source chain Then "charlie" has 0 CBDC available in the sidechain diff --git a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/besu-gateway.steps.ts b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/besu-gateway.steps.ts index 64f4270c156..8812efcd53c 100644 --- a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/besu-gateway.steps.ts +++ b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/besu-gateway.steps.ts @@ -1,5 +1,4 @@ import { Given, When, Then, Before, After } from "cucumber"; -import { expect } from "chai"; import axios from "axios"; import CryptoMaterial from "../../../../crypto-material/crypto-material.json"; import { @@ -10,7 +9,7 @@ import { } from "../besu-helper"; import AssetReferenceContractJson from "../../../../solidity/asset-reference-contract/AssetReferenceContract.json"; import CBDCcontractJson from "../../../../solidity/cbdc-erc-20/CBDCcontract.json"; -import { getEthAddress, getPrvKey } from "./common"; +import { getEthAddress, getPrvKey, assertEqual, assertStringContains } from "./common"; const BESU_CONTRACT_CBDC_ERC20_NAME = CBDCcontractJson.contractName; const BESU_CONTRACT_ASSET_REF_NAME = AssetReferenceContractJson.contractName; @@ -25,6 +24,7 @@ After({ timeout: 20 * 1000, tags: "@besu" }, async function () { Given( "{string} with {int} CBDC available in the sidechain smart contract", + { timeout: 10 * 1000 }, async function (user: string, amount: number) { await axios.post( "http://127.0.0.1:4100/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract", @@ -47,6 +47,7 @@ Given( When( "{string} escrows {int} CBDC and creates an asset reference with id {string} in the sidechain", + { timeout: 10 * 1000 }, async function (user: string, amount: number, assetRefID: string) { await axios.post( "http://127.0.0.1:4100/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract", @@ -69,6 +70,7 @@ When( When( "bob locks the asset reference with id {string} in the sidechain", + { timeout: 10 * 1000 }, async function (assetRefID: string) { await lockBesuAssetReference( getEthAddress("bob"), @@ -80,6 +82,7 @@ When( When( "bob deletes the asset reference with id {string} in the sidechain", + { timeout: 10 * 1000 }, async function (assetRefID: string) { await axios.post( "http://127.0.0.1:4100/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract", @@ -103,21 +106,21 @@ When( Then( "the asset reference smart contract has an asset reference with id {string}", async function (assetRefID: string) { - expect(await isBesuAssetReference(assetRefID)).to.be.true; + assertEqual(await isBesuAssetReference(assetRefID), true); }, ); Then( "the asset reference smart contract has no asset reference with id {string}", async function (assetRefID: string) { - expect(await isBesuAssetReference(assetRefID)).to.be.false; + assertEqual(await isBesuAssetReference(assetRefID), false); }, ); Then( "{string} has {int} CBDC available in the sidechain", async function (user: string, amount: number) { - expect(await getBesuBalance(getEthAddress(user))).to.equal(amount); + assertEqual(await getBesuBalance(getEthAddress(user)), amount); }, ); @@ -141,7 +144,7 @@ Then( }, ); - expect(response.data.callOutput).to.equal(true); + assertEqual(response.data.callOutput, true); }, ); @@ -153,7 +156,7 @@ Then( getPrvKey(user), assetRefID, ).catch((err) => { - expect(err.response.data.error).to.contain( + assertStringContains(err.response.data.error, `Transaction has been reverted by the EVM`, ); }); diff --git a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/bridge-back.steps.ts b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/bridge-back.steps.ts index fd0a713e822..ae3df86af41 100644 --- a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/bridge-back.steps.ts +++ b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/bridge-back.steps.ts @@ -1,8 +1,7 @@ import { Then } from "cucumber"; -import { expect } from "chai"; import axios from "axios"; import CryptoMaterial from "../../../../crypto-material/crypto-material.json"; -import { getFabricId, getEthAddress } from "./common"; +import { getFabricId, getEthAddress, assertEqual } from "./common"; const MAX_RETRIES = 5; const MAX_TIMEOUT = 5000; @@ -64,21 +63,20 @@ Then( }, ); - expect(response.status).to.equal(200); + assertEqual(response.status, 200); }, ); Then( - "{string} fails to initiate bridge back of {int} CBDC referenced by id {string} to {string} address in the source chain", + "{string} fails to initiate bridge back of {int} CBDC referenced by id {string}", { timeout: 60 * 1000 }, async function ( user: string, amount: number, assetRefID: string, - finalUser: string, ) { const address = getEthAddress(user); - const fabricID = getFabricId(finalUser); + const fabricID = getFabricId(user); const assetProfile = { expirationDate: new Date(2060, 11, 24).toString(), @@ -126,7 +124,7 @@ Then( }, ) .catch((err) => { - expect(err.response.status).to.equal(500); + assertEqual(err.response.status, 500); }); }, ); diff --git a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/bridge-out.steps.ts b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/bridge-out.steps.ts index ee3b907388a..0090b303409 100644 --- a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/bridge-out.steps.ts +++ b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/bridge-out.steps.ts @@ -1,8 +1,7 @@ import { When, Then } from "cucumber"; -import { expect } from "chai"; import axios from "axios"; import CryptoMaterial from "../../../../crypto-material/crypto-material.json"; -import { getUserFromPseudonim, getFabricId, getEthAddress } from "./common"; +import { getUserFromPseudonim, getFabricId, getEthAddress, assertEqual, assertStringContains } from "./common"; const MAX_RETRIES = 5; const MAX_TIMEOUT = 5000; @@ -28,7 +27,7 @@ Then( }, ); - expect(parseInt(response.data.functionOutput)).to.equal(amount); + assertEqual(parseInt(response.data.functionOutput), amount); }, ); @@ -88,8 +87,8 @@ When( recipientLedgerAssetID: "FABRIC_ASSET_ID", }, ); - - expect(response.status).to.equal(200); + + assertEqual(response.status, 200); }, ); @@ -152,7 +151,7 @@ Then( }, ) .catch((err) => { - expect(err.response.data.error).to.contain(failureReason); + assertStringContains(err.response.data.error, failureReason); }); }, ); diff --git a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/common.ts b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/common.ts index ff53bc0fce1..59515d9e542 100644 --- a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/common.ts +++ b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/common.ts @@ -1,4 +1,3 @@ -import { assert } from "chai"; import CryptoMaterial from "../../../../crypto-material/crypto-material.json"; export function getUserFromPseudonim(user: string): string { @@ -10,7 +9,7 @@ export function getUserFromPseudonim(user: string): string { case "bob": return "bridge"; default: - assert.fail(0, 1, "Invalid user provided"); + throw Error("Invalid user provided"); } } @@ -23,7 +22,7 @@ export function getFabricId(user: string): string { case "bridge": return CryptoMaterial.accounts["bridge"].fabricID; default: - assert.fail(0, 1, "Invalid user provided"); + throw Error("Invalid user provided"); } } @@ -36,7 +35,7 @@ export function getEthAddress(user: string): string { case "bridge": return CryptoMaterial.accounts["bridge"].ethAddress; default: - assert.fail(0, 1, "Invalid user provided"); + throw Error("Invalid user provided"); } } @@ -49,6 +48,32 @@ export function getPrvKey(user: string): string { case "bridge": return CryptoMaterial.accounts["bridge"].privateKey; default: - assert.fail(0, 1, "Invalid user provided"); + throw Error("Invalid user provided"); } } + +export function assertEqual( + value_1: unknown, + value_2: unknown, +) { + if (value_1 !== value_2) { + throw Error(`Expected ${value_1} to be equal to ${value_2}`); + } +} + +export function assertStringContains( + mainString: string, + subString: string, +): void { + if (!mainString.includes(subString)) { + throw new Error(`String "${mainString}" does not contain "${subString}"`); + } +} + +export function assertNonNullish( + value: TValue, +): asserts value is NonNullable { + if (value === null || value === undefined) { + throw Error(`${value} was expected to be non-null`); + } +} \ No newline at end of file diff --git a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/fabric-gateway.steps.ts b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/fabric-gateway.steps.ts index c69af0e57b8..d3a2c819c2c 100644 --- a/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/fabric-gateway.steps.ts +++ b/examples/cactus-example-cbdc-bridging-backend/src/test/typescript/cucumber/steps/fabric-gateway.steps.ts @@ -1,8 +1,14 @@ import { Given, When, Then, Before, After } from "cucumber"; -import { expect } from "chai"; import axios from "axios"; import CryptoMaterial from "../../../../crypto-material/crypto-material.json"; -import { getEthAddress, getFabricId, getUserFromPseudonim } from "./common"; +import { + getEthAddress, + getFabricId, + getUserFromPseudonim, + assertEqual, + assertNonNullish, + assertStringContains +} from "./common"; import { deleteFabricAssetReference, fabricAssetReferenceExists, @@ -27,6 +33,7 @@ After({ timeout: 20 * 1000, tags: "@fabric" }, async function () { Given( "{string} with {int} CBDC available in the source chain", + { timeout: 10 * 1000 }, async function (user: string, amount: number) { await axios.post( "http://127.0.0.1:4000/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/run-transaction", @@ -43,12 +50,13 @@ Given( }, ); - expect(await getFabricBalance(getFabricId(user))).to.equal(amount); + assertEqual(await getFabricBalance(getFabricId(user)), amount); }, ); When( "{string} escrows {int} CBDC and creates an asset reference with id {string} in the source chain", + { timeout: 10 * 1000 }, async function (user: string, amount: number, assetRefID: string) { await axios.post( "http://127.0.0.1:4000/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-fabric/run-transaction", @@ -69,6 +77,7 @@ When( When( "{string} locks the asset reference with id {string} in the source chain", + { timeout: 10 * 1000 }, async function (user: string, assetRefID: string) { await lockFabricAssetReference(user, assetRefID); }, @@ -85,6 +94,7 @@ When( When( "bob refunds {int} CBDC to {string} in the source chain", + { timeout: 10 * 1000 }, async function (amount: number, userTo: string) { const finalUserFabricID = getFabricId(userTo); const finalUserEthAddress = getEthAddress(userTo); @@ -95,6 +105,7 @@ When( Then( "{string} fails to lock the asset reference with id {string} in the source chain", + { timeout: 10 * 1000 }, async function (user: string, assetRefID: string) { return axios .post( @@ -112,15 +123,14 @@ Then( }, ) .catch((err) => { - expect(err.response.statusText).to.contain( - `client is not authorized to perform the operation`, - ); + assertStringContains(err.response.data.error, `client is not authorized to perform the operation`); }); }, ); Then( "{string} fails to transfer {int} CBDC to {string}", + { timeout: 10 * 1000 }, async function (userFrom: string, amount: number, userTo: string) { const recipient = getFabricId(userTo); @@ -140,37 +150,39 @@ Then( }, ) .catch((err) => { - expect(err.response.statusText).to.contain("has insufficient funds"); + assertStringContains(err.response.data.error, `has insufficient funds`); }); }, ); Then( "{string} has {int} CBDC available in the source chain", + { timeout: 10 * 1000 }, async function (user: string, amount: number) { - expect(await getFabricBalance(getFabricId(user))).to.equal(amount); + assertEqual((await getFabricBalance(getFabricId(user))), amount) }, ); Then( "the asset reference chaincode has an asset reference with id {string}", + { timeout: 10 * 1000 }, async function (assetRefID: string) { - expect(await readFabricAssetReference(assetRefID)).to.not.be.undefined; + assertNonNullish((await readFabricAssetReference(assetRefID))); }, ); Then( "the asset reference with id {string} is locked in the source chain", + { timeout: 10 * 1000 }, async function (assetRefID: string) { - expect((await readFabricAssetReference(assetRefID)).isLocked).to.equal( - true, - ); + assertEqual((await readFabricAssetReference(assetRefID)).isLocked, true) }, ); Then( "the asset reference chaincode has no asset reference with id {string}", + { timeout: 10 * 1000 }, async function (assetRefID: string) { - expect(await fabricAssetReferenceExists(assetRefID)).to.equal("false"); + assertEqual(await fabricAssetReferenceExists(assetRefID), "false") }, );