Skip to content

Commit

Permalink
Merge pull request #1038 from starknet-io/fix-transaction-receipt-suc…
Browse files Browse the repository at this point in the history
…cess-guard

feat: add type guard to receipt response status methods
  • Loading branch information
tabaktoni authored Mar 25, 2024
2 parents 87147d5 + 587d9f6 commit 4b2398a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
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

0 comments on commit 4b2398a

Please sign in to comment.