Skip to content

Commit

Permalink
web3-eth sendTransaction and sendSignedTransaction PromiEvent
Browse files Browse the repository at this point in the history
… tests #4810 (#4875)

* WIP Web3Eth.sendTransaction tests

* Update use of ReceiptInfo and TransactionReceipt to ReceiptInfoFormatted

* Add optional data field to BaseTransaction

* Init sendTransaction test and fixture

* Remove old sendTransactionValidData

* Remove no longer needed imports

* Remove errornous sendTransaction test

* Init getGasPricing tests for sendTransaction

* Init wait_for_transaction_receipt.ts

* Init watch_transaction_for_confirmations.ts

* Import waitForTransactionReceipt and watchTransactionForConfirmations from utils/

* Init waitForTransactionReceipt and watchTransactionForConfirmations tests

* Fix promiEvent bug with sendSignedTransaction

* Use HexString for expectedTransactionHash instead of string

* Remove jest.useRealTimers

* Init sendSignedTransaction tests

* Update use of ReceiptInfo to ReceiptInfoFormatted for sendSignedTransaction

* Remove unused import ReceiptInfo

* Update SendSignedTransactionEvents to include only unique properties

* Add transactionHash to TransactionMissingReceiptOrBlockHashError

* Update packages/web3-eth/src/errors.ts

* Add effectiveGasPrice to sendSignedTransaction and sendTransaction fixtures

* Add expectedTransactionHash to watchTransactionForConfirmationsSpy tests

* Update names of files to match existing casings

* Merge with #4859

* Update import for ReceiptInfo

* Add effectiveGasPrice to transactionSchema

* Update SendTransactionEvents and SendSignedTransactionEvents types

* Add transaction receipt formatting

Co-authored-by: Alex <alex.luu@mail.utoronto.ca>
  • Loading branch information
spacesailor24 and Alex authored Mar 31, 2022
1 parent 6db0f4a commit df60a2d
Show file tree
Hide file tree
Showing 14 changed files with 945 additions and 194 deletions.
3 changes: 2 additions & 1 deletion packages/web3-common/src/eth_execution_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export interface BaseTransaction {
readonly nonce: Uint;
readonly gas: Uint;
readonly value: Uint;
// TODO - Investigate if this should actually be data instead of input
// TODO - https://github.com/ethereum/execution-apis/pull/201
readonly input: HexStringBytes;
readonly data?: HexStringBytes;
readonly chainId?: Uint;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth-contract/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export class Contract<Abi extends ContractAbi>
contractOptions: contractOptions ?? this.options,
});

return sendTransaction(this, tx);
return sendTransaction(this, tx, DEFAULT_RETURN_FORMAT);
}

private async _contractMethodEstimateGas<
Expand Down
24 changes: 12 additions & 12 deletions packages/web3-eth-ens/src/ens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBlock } from 'web3-eth';
import { getBlock, ReceiptInfo } from 'web3-eth';
import { Web3Context, SupportedProviders, Web3ContextObject } from 'web3-core';
import { getId, Web3NetAPI } from 'web3-net';
import { Address } from 'web3-utils';
Expand All @@ -9,7 +9,7 @@ import {
ENSNetworkNotSyncedError,
DEFAULT_RETURN_FORMAT,
} from 'web3-common';
import { NonPayableCallOptions, TransactionReceipt, Contract } from 'web3-eth-contract';
import { NonPayableCallOptions, Contract } from 'web3-eth-contract';
import { RESOLVER } from './abi/resolver';
import { Registry } from './registry';
import { registryAddresses } from './config';
Expand Down Expand Up @@ -50,7 +50,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
name: string,
address: Address,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._registry.setResolver(name, address, txConfig);
}

Expand All @@ -64,7 +64,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
resolver: Address,
ttl: number,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._registry.setSubnodeRecord(name, label, owner, resolver, ttl, txConfig);
}

Expand All @@ -75,7 +75,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
operator: Address,
approved: boolean,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._registry.setApprovalForAll(operator, approved, txConfig);
}

Expand All @@ -101,7 +101,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
label: string,
address: Address,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._registry.setSubnodeOwner(name, label, address, txConfig);
}

Expand All @@ -119,7 +119,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
name: string,
ttl: number,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._registry.setTTL(name, ttl, txConfig);
}

Expand All @@ -137,7 +137,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
name: string,
address: Address,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._registry.setOwner(name, address, txConfig);
}

Expand All @@ -150,7 +150,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
resolver: Address,
ttl: number,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._registry.setRecord(name, owner, resolver, ttl, txConfig);
}

Expand All @@ -161,7 +161,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
name: string,
address: Address,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._resolver.setAddress(name, address, txConfig);
}

Expand All @@ -173,7 +173,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
x: string,
y: string,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._resolver.setPubkey(name, x, y, txConfig);
}

Expand All @@ -184,7 +184,7 @@ export class ENS extends Web3Context<EthExecutionAPI & Web3NetAPI> {
name: string,
hash: string,
txConfig: NonPayableCallOptions,
): Promise<TransactionReceipt | RevertInstructionError> {
): Promise<ReceiptInfo | RevertInstructionError> {
return this._resolver.setContenthash(name, hash, txConfig);
}

Expand Down
15 changes: 9 additions & 6 deletions packages/web3-eth/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import {
ERR_TX_POLLING_TIMEOUT,
ERR_TX_RECEIPT_MISSING_OR_BLOCKHASH_NULL,
ERR_TX_RECEIPT_MISSING_BLOCK_NUMBER,
ReceiptInfo,
} from 'web3-common';
import { HexString, HexString32Bytes, Numbers, Web3Error } from 'web3-utils';
import { Bytes, HexString, Numbers, Web3Error } from 'web3-utils';

import { ReceiptInfo } from './types';

export class InvalidTransactionWithSender extends Web3Error {
public code = ERR_TX_INVALID_SENDER;
Expand Down Expand Up @@ -249,9 +250,9 @@ export class TransactionDataAndInputError extends Web3Error {
export class TransactionPollingTimeoutError extends Web3Error {
public code = ERR_TX_POLLING_TIMEOUT;

public constructor(value: { numberOfSeconds: number; transactionHash: HexString32Bytes }) {
public constructor(value: { numberOfSeconds: number; transactionHash: Bytes }) {
super(
`transactionHash: ${value.transactionHash}`,
`transactionHash: ${value.transactionHash.toString()}`,
`Transaction was not mined within ${value.numberOfSeconds} seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!`,
);
}
Expand All @@ -260,9 +261,11 @@ export class TransactionPollingTimeoutError extends Web3Error {
export class TransactionMissingReceiptOrBlockHashError extends Web3Error {
public code = ERR_TX_RECEIPT_MISSING_OR_BLOCKHASH_NULL;

public constructor(value: { receipt: ReceiptInfo; blockHash: HexString32Bytes }) {
public constructor(value: { receipt: ReceiptInfo; blockHash: Bytes; transactionHash: Bytes }) {
super(
`receipt: ${JSON.stringify(value.receipt)}, blockHash: ${value.blockHash}`,
`receipt: ${JSON.stringify(
value.receipt,
)}, blockHash: ${value.blockHash.toString()}, transactionHash: ${value.transactionHash.toString()}`,
`Receipt missing or blockHash null`,
);
}
Expand Down
Loading

0 comments on commit df60a2d

Please sign in to comment.