Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
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
1 change: 1 addition & 0 deletions packages/web3-errors/src/error_codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const ERR_TX_RECEIPT_MISSING_BLOCK_NUMBER = 428;

export const ERR_TX_LOCAL_WALLET_NOT_AVAILABLE = 429;

export const ERR_TX_NOT_FOUND = 430;
// Connection error codes
export const ERR_CONN = 500;
export const ERR_CONN_INVALID = 501;
Expand Down
7 changes: 7 additions & 0 deletions packages/web3-errors/src/errors/transaction_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
ERR_TX_REVERT_INSTRUCTION,
ERR_TX_REVERT_TRANSACTION,
ERR_TX_REVERT_WITHOUT_REASON,
ERR_TX_NOT_FOUND,
} from '../error_codes';
import { ReceiptInfo } from '../types';
import { Web3Error } from '../web3_error_base';
Expand Down Expand Up @@ -125,3 +126,9 @@ export class UndefinedRawTransactionError extends TransactionError {
this.code = ERR_RAW_TX_UNDEFINED;
}
}
export class TransactionNotFound extends TransactionError {
public constructor() {
super('Transaction not found');
this.code = ERR_TX_NOT_FOUND;
}
}
21 changes: 19 additions & 2 deletions packages/web3-eth/src/web3_eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Web3Context,
Web3ContextInitOptions,
} from 'web3-core';
import { TransactionNotFound } from 'web3-errors';
import {
Address,
Bytes,
Expand Down Expand Up @@ -200,7 +201,15 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
transactionHash: Bytes,
returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat,
) {
return rpcMethodsWrappers.getTransaction(this, transactionHash, returnFormat);
const response = await rpcMethodsWrappers.getTransaction(
this,
transactionHash,
returnFormat,
);

if (!response) throw new TransactionNotFound();

return response;
}

public async getPendingTransactions<
Expand All @@ -227,7 +236,15 @@ export class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscrip
public async getTransactionReceipt<
ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT,
>(transactionHash: Bytes, returnFormat: ReturnFormat = DEFAULT_RETURN_FORMAT as ReturnFormat) {
return rpcMethodsWrappers.getTransactionReceipt(this, transactionHash, returnFormat);
const response = await rpcMethodsWrappers.getTransactionReceipt(
this,
transactionHash,
returnFormat,
);

if (!response) throw new TransactionNotFound();

return response;
}

public async getTransactionCount<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Uint256,
} from 'web3-utils';
import { transactionWithSender } from './rpc_methods_wrappers';
import { ReceiptInfo } from '../../src/types';

/**
* Array consists of:
Expand Down Expand Up @@ -1835,3 +1836,39 @@ export const getProofValidData: [
],
],
];

export const tx = {
blockHash: '0xb3a667f84f58c90ab87476073e06c5d1186a0f0b0b69aa3033bfe0e4df264350',
blockNumber: '123',
from: '0x01ada9d3470eb9eb3875d9e7948c674804ca43ae',
gas: '21000',
gasPrice: '10000',
hash: '0x84f44dffc3cd90a1b66ad0219a97680308e5e7a77299fbf1e2ebb572cf02cc2d',
input: '0x',
nonce: '61',
to: '0x0000000000000000000000000000000000000000',
transactionIndex: '0',
value: '1',
type: '0x01',
v: '2710',
r: '0xbefb00433ef79b2609dc560c28963c2e954370792671f71ab99665b8807b7feb',
s: '0x6bebe5e2c9f839d3ce0264dc5c7cc521f902e86705c69f5fddffaa3de5aac6d3',
};

export const txReceipt: ReceiptInfo = {
blockHash: '0xb3a667f84f58c90ab87476073e06c5d1186a0f0b0b69aa3033bfe0e4df264350',
blockNumber: BigInt(123),
cumulativeGasUsed: BigInt(21000),
effectiveGasPrice: BigInt(10000),
from: '0x01ada9d3470eb9eb3875d9e7948c674804ca43ae',
gasUsed: BigInt(21000),
logs: [],
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: BigInt(1),
to: '0x0000000000000000000000000000000000000000',
transactionHash: '0x84f44dffc3cd90a1b66ad0219a97680308e5e7a77299fbf1e2ebb572cf02cc2d',
transactionIndex: BigInt(0),
type: BigInt(0),
root: '',
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ import {
sendSignedTransactionValidData,
signValidData,
submitWorkValidData,
tx,
txReceipt,
} from '../fixtures/web3_eth_methods_with_parameters';

jest.mock('../../src/rpc_methods');
jest.mock('../../src/rpc_method_wrappers');
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
jest.spyOn(rpcMethodWrappers, 'getTransaction').mockResolvedValue(tx);
jest.spyOn(rpcMethodWrappers, 'getTransactionReceipt').mockResolvedValue(txReceipt);

describe('web3_eth_methods_with_parameters', () => {
let web3Eth: Web3Eth;
Expand Down