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

transaction integration tests #6071

Merged
merged 18 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
15 changes: 8 additions & 7 deletions packages/web3-core/src/web3_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,14 @@ export class Web3Context<
}

// To avoid cycle dependency declare this type in this file
export type TransactionBuilder<API extends Web3APISpec = unknown> = <
ReturnType = Transaction,
>(options: {
transaction: Transaction;
web3Context: Web3Context<API>;
privateKey?: HexString | Uint8Array;
}) => Promise<ReturnType>;
export type TransactionBuilder<API extends Web3APISpec = unknown> = <ReturnType = Transaction>(
options: {
transaction: Transaction;
web3Context: Web3Context<API>;
privateKey?: HexString | Uint8Array;
},
fillGasPrice: boolean,
jdevcs marked this conversation as resolved.
Show resolved Hide resolved
) => Promise<ReturnType>;

/**
* Extend this class when creating a plugin that either doesn't require {@link EthExecutionAPI},
Expand Down
4 changes: 4 additions & 0 deletions packages/web3-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fixed `ignoreGasPricing` bug with wallet in context (#6071)

### Changed

- `formatTransaction` no longer throws a `TransactionDataAndInputError` if it's passed a transaction object with both `data` and `input` properties set (as long as they are the same value) (#6064)
Expand Down
14 changes: 9 additions & 5 deletions packages/web3-eth/src/utils/prepare_transaction_for_signing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ export const prepareTransactionForSigning = async (
transaction: Transaction,
web3Context: Web3Context<EthExecutionAPI>,
privateKey?: HexString | Uint8Array,
fillGasPrice = false,
) => {
const populatedTransaction = (await transactionBuilder({
transaction,
web3Context,
privateKey,
})) as unknown as PopulatedUnsignedTransaction;
const populatedTransaction = (await transactionBuilder(
{
transaction,
web3Context,
privateKey,
},
fillGasPrice,
)) as unknown as PopulatedUnsignedTransaction;

const formattedTransaction = formatTransaction(
populatedTransaction,
Expand Down
58 changes: 34 additions & 24 deletions packages/web3-eth/src/utils/transaction_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ import { NUMBER_DATA_FORMAT } from '../constants';
// eslint-disable-next-line import/no-cycle
import { getChainId, getTransactionCount } from '../rpc_method_wrappers';
import { detectTransactionType } from './detect_transaction_type';
// eslint-disable-next-line import/no-cycle
import { getTransactionGasPricing } from './get_transaction_gas_pricing';
import { transactionSchema } from '../schemas';
import { InternalTransaction } from '../types';
// eslint-disable-next-line import/no-cycle
import { getTransactionGasPricing } from './get_transaction_gas_pricing';

export const getTransactionFromOrToAttr = (
attr: 'from' | 'to',
Expand Down Expand Up @@ -124,11 +124,14 @@ export const getTransactionType = (

// Keep in mind that the order the properties of populateTransaction get populated matters
// as some of the properties are dependent on others
export async function defaultTransactionBuilder<ReturnType = Transaction>(options: {
transaction: Transaction;
web3Context: Web3Context<EthExecutionAPI & Web3NetAPI>;
privateKey?: HexString | Uint8Array;
}): Promise<ReturnType> {
export async function defaultTransactionBuilder<ReturnType = Transaction>(
options: {
transaction: Transaction;
web3Context: Web3Context<EthExecutionAPI & Web3NetAPI>;
privateKey?: HexString | Uint8Array;
},
fillGasPrice = false,
): Promise<ReturnType> {
// let populatedTransaction = { ...options.transaction } as unknown as InternalTransaction;
let populatedTransaction = format(
transactionSchema,
Expand Down Expand Up @@ -228,25 +231,32 @@ export async function defaultTransactionBuilder<ReturnType = Transaction>(option
populatedTransaction.accessList = [];
}

populatedTransaction = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: #6063

Copy link
Contributor Author

@jdevcs jdevcs May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gas price is already assigned in sendTransaction and at this place its called again

...populatedTransaction,
...(await getTransactionGasPricing(
populatedTransaction,
options.web3Context,
ETH_DATA_FORMAT,
)),
};
if (fillGasPrice)
populatedTransaction = {
...populatedTransaction,
...(await getTransactionGasPricing(
populatedTransaction,
options.web3Context,
ETH_DATA_FORMAT,
)),
};

return populatedTransaction as ReturnType;
}

export const transactionBuilder = async <ReturnType = Transaction>(options: {
transaction: Transaction;
web3Context: Web3Context<EthExecutionAPI>;
privateKey?: HexString | Uint8Array;
export const transactionBuilder = async <ReturnType = Transaction>(
options: {
transaction: Transaction;
web3Context: Web3Context<EthExecutionAPI>;
privateKey?: HexString | Uint8Array;
},
fillGasPrice = false,
// eslint-disable-next-line @typescript-eslint/require-await
}) =>
(options.web3Context.transactionBuilder ?? defaultTransactionBuilder)({
...options,
transaction: options.transaction,
}) as unknown as ReturnType;
) =>
(options.web3Context.transactionBuilder ?? defaultTransactionBuilder)(
{
...options,
transaction: options.transaction,
},
fillGasPrice,
) as unknown as ReturnType;
Loading