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

Fix TransactionInfoAPI type #6539

12 changes: 6 additions & 6 deletions packages/web3-eth/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
TransactionForAccessList,
AccessListResult,
Eip712TypedData,
TransactionWithSenderAPI,
} from 'web3-types';
import { Web3Context, Web3PromiEvent } from 'web3-core';
import { format, hexToBytes, bytesToUint8Array, numberToHex } from 'web3-utils';
Expand Down Expand Up @@ -523,7 +524,7 @@
let wallet: Web3BaseWalletAccount | undefined;

if (web3Context.wallet && !isNullish(transactionFormatted.from)) {
wallet = web3Context.wallet.get(

Check warning on line 527 in packages/web3-eth/src/rpc_method_wrappers.ts

View check run for this annotation

Codecov / codecov/patch

packages/web3-eth/src/rpc_method_wrappers.ts#L527

Added line #L527 was not covered by tests
(transactionFormatted as Transaction).from as string,
);
}
Expand Down Expand Up @@ -567,7 +568,7 @@
transactionHash,
});
} catch (error) {
reject(

Check warning on line 571 in packages/web3-eth/src/rpc_method_wrappers.ts

View check run for this annotation

Codecov / codecov/patch

packages/web3-eth/src/rpc_method_wrappers.ts#L571

Added line #L571 was not covered by tests
await sendTxHelper.handleError({
error,
tx: transactionFormatted as TransactionCall,
Expand Down Expand Up @@ -627,9 +628,8 @@
};

try {
const { v , r , s,
...txWithoutSigParams} = unSerializedTransactionWithFrom;

const { v, r, s, ...txWithoutSigParams } = unSerializedTransactionWithFrom;

await sendTxHelper.checkRevertBeforeSending(
txWithoutSigParams as TransactionCall,
);
Expand Down Expand Up @@ -681,7 +681,7 @@
transactionHash,
});
} catch (error) {
reject(

Check warning on line 684 in packages/web3-eth/src/rpc_method_wrappers.ts

View check run for this annotation

Codecov / codecov/patch

packages/web3-eth/src/rpc_method_wrappers.ts#L684

Added line #L684 was not covered by tests
await sendTxHelper.handleError({
error,
tx: unSerializedTransactionWithFrom as TransactionCall,
Expand Down Expand Up @@ -740,7 +740,7 @@
) {
const response = await ethRpcMethods.signTransaction(
web3Context.requestManager,
formatTransaction(transaction, ETH_DATA_FORMAT),
formatTransaction(transaction as TransactionWithSenderAPI, ETH_DATA_FORMAT),
avkos marked this conversation as resolved.
Show resolved Hide resolved
);
// Some clients only return the encoded signed transaction (e.g. Ganache)
// while clients such as Geth return the desired SignedTransactionInfoAPI object
Expand Down Expand Up @@ -803,7 +803,7 @@

const response = await ethRpcMethods.estimateGas(
web3Context.requestManager,
transactionFormatted,
transactionFormatted as TransactionWithSenderAPI,
blockNumberFormatted,
);

Expand Down Expand Up @@ -951,7 +951,7 @@

const response = (await ethRpcMethods.createAccessList(
web3Context.requestManager,
formatTransaction(transaction, ETH_DATA_FORMAT),
formatTransaction(transaction as TransactionWithSenderAPI, ETH_DATA_FORMAT),
blockNumberFormatted,
)) as unknown as AccessListResult;

Expand Down
1 change: 0 additions & 1 deletion packages/web3-eth/test/fixtures/rpc_methods_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const transactionWithSender: TransactionWithSenderAPI = {
maxFeePerGas: '0x1475505aab',
maxPriorityFeePerGas: '0x7f324180',
accessList: [],
gasPrice: '0x4a817c800',
from: '0x407d73d8a49eeb85d32cf465507dd71d507100c1',
chainId: '0x1',
};
Expand Down
81 changes: 81 additions & 0 deletions packages/web3-eth/test/integration/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,87 @@ describe('rpc', () => {
validateTransaction(res as TransactionInfo);
expect(res?.hash).toBe(receipt.transactionHash);
});
it('check get transaction fields', async () => {
avkos marked this conversation as resolved.
Show resolved Hide resolved
const receipt0 = await web3Eth.sendTransaction({
from: tempAcc.address,
value: '0x1',
to: tempAcc2.address,
type: BigInt(0),
});
const res0 = await web3Eth.getTransaction(receipt0.transactionHash);

expect(res0.type).toBeDefined();
expect(res0.hash).toBeDefined();
expect(res0.nonce).toBeDefined();
expect(res0.blockHash).toBeDefined();
expect(res0.blockNumber).toBeDefined();
expect(res0.transactionIndex).toBeDefined();
expect(res0.from).toBeDefined();
expect(res0.to).toBeDefined();
expect(res0.value).toBeDefined();
expect(res0.gas).toBeDefined();
expect(res0.input).toBeDefined();
expect(res0.r).toBeDefined();
expect(res0.s).toBeDefined();
expect(res0.v).toBeDefined();
expect(res0.data).toBeDefined();
expect(res0?.hash).toBe(receipt0.transactionHash);
expect(res0.gasPrice).toBeDefined();

const receipt1 = await web3Eth.sendTransaction({
from: tempAcc.address,
value: '0x1',
maxPriorityFeePerGas: BigInt(500000000),
maxFeePerGas: BigInt(500000000),
to: tempAcc2.address,
type: BigInt(1),
});
const res1 = await web3Eth.getTransaction(receipt1.transactionHash);
expect(res1.type).toBeDefined();
expect(res1.hash).toBeDefined();
expect(res1.nonce).toBeDefined();
expect(res1.blockHash).toBeDefined();
expect(res1.blockNumber).toBeDefined();
expect(res1.transactionIndex).toBeDefined();
expect(res1.from).toBeDefined();
expect(res1.to).toBeDefined();
expect(res1.value).toBeDefined();
expect(res1.gas).toBeDefined();
expect(res1.input).toBeDefined();
expect(res1.r).toBeDefined();
expect(res1.s).toBeDefined();
expect(res1.data).toBeDefined();
expect(res1?.hash).toBe(receipt1.transactionHash);
expect(res1.gasPrice).toBeDefined();
expect(res1.accessList).toBeDefined();

const receipt2 = await web3Eth.sendTransaction({
from: tempAcc.address,
value: '0x1',
to: tempAcc2.address,
type: BigInt(2),
});
const res2 = await web3Eth.getTransaction(receipt2.transactionHash);

expect(res2.type).toBeDefined();
expect(res2.hash).toBeDefined();
expect(res2.nonce).toBeDefined();
expect(res2.blockHash).toBeDefined();
expect(res2.blockNumber).toBeDefined();
expect(res2.transactionIndex).toBeDefined();
expect(res2.from).toBeDefined();
expect(res2.to).toBeDefined();
expect(res2.value).toBeDefined();
expect(res2.gas).toBeDefined();
expect(res2.input).toBeDefined();
expect(res2.r).toBeDefined();
expect(res2.s).toBeDefined();
expect(res2.data).toBeDefined();
expect(res2?.hash).toBe(receipt2.transactionHash);
expect(res2.maxFeePerGas).toBeDefined();
expect(res2.maxPriorityFeePerGas).toBeDefined();
expect(res2.accessList).toBeDefined();
});

itIf(getSystemTestBackend() !== 'ganache')('getPendingTransactions', async () => {
const tx = web3Eth.sendTransaction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import { ethRpcMethods } from 'web3-rpc-methods';

import { TransactionInfoAPI } from 'web3-types';
import Web3Eth from '../../src/index';
import * as rpcMethodWrappers from '../../src/rpc_method_wrappers';
import {
Expand Down Expand Up @@ -52,7 +53,7 @@ import { testData as createAccessListTestData } from './rpc_method_wrappers/fixt
jest.mock('web3-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, 'getTransaction').mockResolvedValue(tx as TransactionInfoAPI);
jest.spyOn(rpcMethodWrappers, 'getTransactionReceipt').mockResolvedValue(txReceipt);

describe('web3_eth_methods_with_parameters', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const transaction: Partial<TransactionWithSenderAPI> = {
to: '0x3535353535353535353535353535353535353535',
value: '0x174876e800',
gas: '0x5208',
gasPrice: '0x4a817c800',
type: '0x0',
maxFeePerGas: '0x1229298c00',
maxPriorityFeePerGas: '0x49504f80',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const transaction: Partial<TransactionWithSenderAPI> = {
to: '0x3535353535353535353535353535353535353535',
value: '0x174876e800',
gas: '0x5208',
gasPrice: '0x4a817c800',
type: '0x0',
maxFeePerGas: '0x1229298c00',
maxPriorityFeePerGas: '0x49504f80',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const transaction: Partial<TransactionWithSenderAPI> = {
to: '0x3535353535353535353535353535353535353535',
value: '0x174876e800',
gas: '0x5208',
gasPrice: '0x4a817c800',
type: '0x0',
maxFeePerGas: '0x1229298c00',
maxPriorityFeePerGas: '0x49504f80',
Expand Down
8 changes: 8 additions & 0 deletions packages/web3-types/src/apis/eth_execution_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,35 @@ export interface Transaction1559UnsignedAPI extends BaseTransactionAPI {
readonly maxFeePerGas: Uint;
readonly maxPriorityFeePerGas: Uint;
readonly accessList: AccessList;
readonly gasPrice?: never;
}

export interface Transaction1559SignedAPI extends Transaction1559UnsignedAPI {
readonly yParity: Uint;
readonly r: Uint;
readonly s: Uint;
readonly v?: never;
}

export interface Transaction2930UnsignedAPI extends BaseTransactionAPI {
readonly gasPrice: Uint;
readonly accessList: AccessList;
readonly maxFeePerGas?: never;
readonly maxPriorityFeePerGas?: never;
}

export interface Transaction2930SignedAPI extends Transaction2930UnsignedAPI {
readonly yParity: Uint;
readonly r: Uint;
readonly s: Uint;
readonly v?: never;
}

export interface TransactionLegacyUnsignedAPI extends BaseTransactionAPI {
readonly gasPrice: Uint;
readonly accessList?: never;
readonly maxFeePerGas?: never;
readonly maxPriorityFeePerGas?: never;
}

export interface TransactionLegacySignedAPI extends TransactionLegacyUnsignedAPI {
Expand Down
Loading