Skip to content

Commit

Permalink
test(plugin-htlc-coordinator-besu): use Jest error assert in refund.test
Browse files Browse the repository at this point in the history
Primary Changes
----------------
1. Refactored try-catch scenario in refund.test.ts

Fixes #3457

Signed-off-by: adrianbatuto <adrian.batuto@accenture.com>
  • Loading branch information
adrianbatuto committed Jan 24, 2025
1 parent 6af5fda commit 426cf6e
Showing 1 changed file with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 426cf6e

Please sign in to comment.