Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type guard to receipt response status methods #1038

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions __tests__/utils/ethSigner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ describe('Ethereum signer', () => {
{ maxFee: 1 * 10 ** 16 }
);
const txR = await provider.waitForTransaction(respTransfer.transaction_hash);
expect(txR.execution_status).toBe('SUCCEEDED');

if (txR.isSuccess()) {
expect(txR.execution_status).toBe('SUCCEEDED');
} else {
fail('txR not success');
}
});

test('ETH account declaration V2', async () => {
Expand Down Expand Up @@ -279,7 +284,11 @@ describe('Ethereum signer', () => {
});

const txR = await provider.waitForTransaction(respTransfer.transaction_hash);
expect(txR.execution_status).toBe('SUCCEEDED');
if (txR.isSuccess()) {
expect(txR.execution_status).toBe('SUCCEEDED');
} else {
fail('txR not success');
}
});

test('ETH account declaration V3', async () => {
Expand Down
10 changes: 8 additions & 2 deletions src/provider/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ export class CustomError extends Error {
export class LibraryError extends CustomError {}

export class GatewayError extends LibraryError {
constructor(message: string, public errorCode: string) {
constructor(
message: string,
public errorCode: string
) {
super(message);
}
}

export class HttpError extends LibraryError {
constructor(message: string, public errorCode: number) {
constructor(
message: string,
public errorCode: number
) {
super(message);
}
}
6 changes: 3 additions & 3 deletions src/utils/transactionReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export class ReceiptTx implements TransactionReceiptUtilityInterface {
return (callbacks as TransactionReceiptCallbacksDefault)._();
}

isSuccess() {
isSuccess(): this is SuccessfulTransactionReceiptResponse {
return this.statusReceipt === 'success';
}

isReverted() {
isReverted(): this is RevertedTransactionReceiptResponse {
return this.statusReceipt === 'reverted';
}

isRejected() {
isRejected(): this is RejectedTransactionReceiptResponse {
return this.statusReceipt === 'rejected';
}

Expand Down
Loading