Skip to content

Commit 3867c51

Browse files
committed
Improve error handling in createEscrow and createFundAndSetupEscrow tests
1 parent 36b5b90 commit 3867c51

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

packages/sdk/typescript/human-protocol-sdk/test/escrow.test.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
ErrorUnsupportedChainID,
4242
ErrorInvalidManifest,
4343
InvalidEthereumAddressError,
44+
ContractExecutionError,
4445
} from '../src/error';
4546
import { EscrowClient, EscrowUtils } from '../src/escrow';
4647
import {
@@ -238,13 +239,21 @@ describe('EscrowClient', () => {
238239
test('should throw an error if the create an escrow fails', async () => {
239240
const tokenAddress = ethers.ZeroAddress;
240241

242+
const mockedError = ethers.makeError(
243+
'Custom error',
244+
'CALL_EXCEPTION' as any
245+
);
246+
const expectedError = new ContractExecutionError(
247+
(mockedError as any).reason as string
248+
);
249+
241250
escrowClient.escrowFactoryContract.createEscrow.mockRejectedValueOnce(
242-
new Error()
251+
mockedError
243252
);
244253

245254
await expect(
246255
escrowClient.createEscrow(tokenAddress, jobRequesterId)
247-
).rejects.toThrow();
256+
).rejects.toEqual(expectedError);
248257

249258
expect(
250259
escrowClient.escrowFactoryContract.createEscrow
@@ -515,9 +524,16 @@ describe('EscrowClient', () => {
515524

516525
test('should throw an error if the createFundAndSetupEscrow fails', async () => {
517526
const jobRequesterId = 'job-requester';
527+
const mockedError = ethers.makeError(
528+
'Custom error',
529+
'CALL_EXCEPTION' as any
530+
);
531+
const expectedError = new ContractExecutionError(
532+
(mockedError as any).reason as string
533+
);
518534

519535
escrowClient.escrowFactoryContract.createFundAndSetupEscrow.mockRejectedValueOnce(
520-
new Error()
536+
mockedError
521537
);
522538

523539
await expect(
@@ -527,7 +543,7 @@ describe('EscrowClient', () => {
527543
jobRequesterId,
528544
escrowConfig
529545
)
530-
).rejects.toThrow();
546+
).rejects.toEqual(expectedError);
531547

532548
expect(
533549
escrowClient.escrowFactoryContract.createFundAndSetupEscrow

0 commit comments

Comments
 (0)