From 426cf6e1a6a4e677cdd4ecbf8f55432b739c5102 Mon Sep 17 00:00:00 2001 From: adrianbatuto Date: Fri, 24 Jan 2025 22:30:59 +0800 Subject: [PATCH] test(plugin-htlc-coordinator-besu): use Jest error assert in refund.test Primary Changes ---------------- 1. Refactored try-catch scenario in refund.test.ts Fixes #3457 Signed-off-by: adrianbatuto --- .../plugin-htlc-coordinator/refund.test.ts | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/extensions/cactus-plugin-htlc-coordinator-besu/src/test/typescript/integration/plugin-htlc-coordinator/refund.test.ts b/extensions/cactus-plugin-htlc-coordinator-besu/src/test/typescript/integration/plugin-htlc-coordinator/refund.test.ts index 5fda8a2095..431cc2becb 100644 --- a/extensions/cactus-plugin-htlc-coordinator-besu/src/test/typescript/integration/plugin-htlc-coordinator/refund.test.ts +++ b/extensions/cactus-plugin-htlc-coordinator-besu/src/test/typescript/integration/plugin-htlc-coordinator/refund.test.ts @@ -44,7 +44,6 @@ import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory import HashTimeLockJSON from "@hyperledger/cactus-plugin-htlc-eth-besu-erc20/src/main/solidity/contracts/HashedTimeLockContract.json"; import TestTokenJSON from "@hyperledger/cactus-test-plugin-htlc-eth-besu-erc20/src/test/solidity/token-erc20-contract/Test_Token.json"; import DemoHelperJSON from "@hyperledger/cactus-test-plugin-htlc-eth-besu-erc20/src/test/solidity/token-erc20-contract/DemoHelpers.json"; -import axios from "axios"; describe("HTLC Coordinator Besu", () => { const logLevel: LogLevelDesc = "DEBUG"; @@ -312,22 +311,22 @@ describe("HTLC Coordinator Besu", () => { gas: estimatedGas, }; - try { - await htlcCoordinatorBesuApiClient.withdrawCounterpartyV1( - withdrawCounterparty, - ); - } catch (exp: unknown) { - log.debug("Caught error as expected: %o", exp); - if (axios.isAxiosError(exp) && exp.response) { - log.debug("Caught response: %o", exp.response.data); - const revertReason = exp.response.data.cause.receipt.revertReason; - const regExp = new RegExp(/0e494e56414c49445f5345435245540/); - expect(revertReason).toMatch(regExp); - // t.match(revertReason, regExp, rejectMsg); - } else { - throw exp; - } - } + const withdrawCall = + htlcCoordinatorBesuApiClient.withdrawCounterpartyV1(withdrawCounterparty); + + await expect(withdrawCall).rejects.toMatchObject({ + response: expect.objectContaining({ + data: expect.objectContaining({ + cause: expect.objectContaining({ + receipt: expect.objectContaining({ + revertReason: expect.stringMatching( + /0e494e56414c49445f5345435245540/, + ), + }), + }), + }), + }), + }); const responseFinalBalanceReceiver = await connector.invokeContract({ contractName: TestTokenJSON.contractName,