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

4811/investigate eslint errors in web3 eth #4893

Merged
merged 57 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8e0f3e0
WIP Web3Eth.sendTransaction tests
spacesailor24 Mar 17, 2022
98100a4
Merge branch '4.x' into wyatt/4.x/4810-web3-eth-promievent-tests
spacesailor24 Mar 17, 2022
b0c4448
Update use of ReceiptInfo and TransactionReceipt to ReceiptInfoFormatted
spacesailor24 Mar 21, 2022
a8e7858
Add optional data field to BaseTransaction
spacesailor24 Mar 21, 2022
32731f8
Init sendTransaction test and fixture
spacesailor24 Mar 21, 2022
b0099ac
Remove old sendTransactionValidData
spacesailor24 Mar 21, 2022
f2b59bb
Remove no longer needed imports
spacesailor24 Mar 21, 2022
55409e9
Remove errornous sendTransaction test
spacesailor24 Mar 21, 2022
467fc9f
Init getGasPricing tests for sendTransaction
spacesailor24 Mar 22, 2022
d879b70
Init wait_for_transaction_receipt.ts
spacesailor24 Mar 22, 2022
0bba805
Init watch_transaction_for_confirmations.ts
spacesailor24 Mar 22, 2022
9863c0f
Import waitForTransactionReceipt and watchTransactionForConfirmations…
spacesailor24 Mar 22, 2022
9788911
Init waitForTransactionReceipt and watchTransactionForConfirmations t…
spacesailor24 Mar 22, 2022
e66361f
Fix promiEvent bug with sendSignedTransaction
spacesailor24 Mar 22, 2022
bd7ff72
Use HexString for expectedTransactionHash instead of string
spacesailor24 Mar 22, 2022
ae0d00b
Remove jest.useRealTimers
spacesailor24 Mar 22, 2022
9314e6f
Init sendSignedTransaction tests
spacesailor24 Mar 22, 2022
d5bc84e
Update use of ReceiptInfo to ReceiptInfoFormatted for sendSignedTrans…
spacesailor24 Mar 22, 2022
d603378
Merge branch '4.x' into wyatt/4.x/4810-web3-eth-promievent-tests
spacesailor24 Mar 22, 2022
a09482b
Remove unused import ReceiptInfo
spacesailor24 Mar 22, 2022
6c6d829
Update SendSignedTransactionEvents to include only unique properties
spacesailor24 Mar 22, 2022
175c6d6
Add transactionHash to TransactionMissingReceiptOrBlockHashError
spacesailor24 Mar 22, 2022
722ca97
Merge branch '4.x' into wyatt/4.x/4810-web3-eth-promievent-tests
spacesailor24 Mar 22, 2022
027398c
Update packages/web3-eth/src/errors.ts
spacesailor24 Mar 22, 2022
465218f
Possible solution without disabling linter for line
nikoulai Mar 24, 2022
0a62614
Add effectiveGasPrice to sendSignedTransaction and sendTransaction fi…
spacesailor24 Mar 25, 2022
8f0146c
Add expectedTransactionHash to watchTransactionForConfirmationsSpy tests
spacesailor24 Mar 25, 2022
d8fb230
Update names of files to match existing casings
spacesailor24 Mar 25, 2022
ddc6dd5
Merge with #4859
spacesailor24 Mar 25, 2022
5d388dc
Merge branch '4.x' into wyatt/4.x/4810-web3-eth-promievent-tests
spacesailor24 Mar 25, 2022
7bd8a22
Merge to wyatt/4.x/4810-web3-eth-promievent-tests
nikoulai Mar 27, 2022
79d6ab4
Make first small change
nikoulai Mar 27, 2022
93f4fe1
Add more changes
nikoulai Mar 27, 2022
6fe1655
Add effectiveGasPrice in tests
nikoulai Mar 27, 2022
ccc3f2d
Possible solution without disabling linter for line
nikoulai Mar 24, 2022
4eacda2
Make first small change
nikoulai Mar 27, 2022
60250aa
Add more changes
nikoulai Mar 27, 2022
396a075
Add effectiveGasPrice in tests
nikoulai Mar 27, 2022
691f32d
Add all changes
nikoulai Mar 28, 2022
1d36eb3
Merge remote-tracking branch 'refs/remotes/origin/4811/investigate-es…
nikoulai Mar 28, 2022
9fdcbb5
Merge branch '4811-temp' into 4811/investigate-eslint-errors-in-web3-eth
nikoulai Mar 28, 2022
66901a1
Remove duplicate effectiveGasPrice entry
nikoulai Mar 28, 2022
55fa573
Merge branch '4.x' into wyatt/4.x/4810-web3-eth-promievent-tests
Mar 28, 2022
1c6c352
Merge branch '4.x' into 4811/investigate-eslint-errors-in-web3-eth
nikoulai Mar 29, 2022
5b85a6b
Test commig signing
nikoulai Mar 29, 2022
3626900
Undo previous commit
nikoulai Mar 29, 2022
f4747ee
Update import for ReceiptInfo
spacesailor24 Mar 31, 2022
cef590d
Add effectiveGasPrice to transactionSchema
spacesailor24 Mar 31, 2022
c6dac10
Update SendTransactionEvents and SendSignedTransactionEvents types
spacesailor24 Mar 31, 2022
96f02c4
Add transaction receipt formatting
spacesailor24 Mar 31, 2022
a15e419
Merge branch 'wyatt/4.x/4810-web3-eth-promievent-tests' of github.com…
spacesailor24 Mar 31, 2022
4681e83
Solve merge conflicts
spacesailor24 Mar 31, 2022
af1e4a5
Merge branch 'wyatt/4.x/4810-web3-eth-promievent-tests' into 4811/inv…
nikoulai Apr 6, 2022
b32fc4d
Solve merge conflicts
spacesailor24 Apr 8, 2022
5388337
Resolve merge
nikoulai Apr 11, 2022
582e425
Resolve merge
nikoulai Apr 11, 2022
ff75a8c
Merge branch '4811/investigate-eslint-errors-in-web3-eth' of https://…
nikoulai Apr 11, 2022
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
Empty file.
Binary file added .github/geth/data/geth/triecache/data.0.bin
Binary file not shown.
Binary file added .github/geth/data/geth/triecache/metadata.bin
Binary file not shown.
266 changes: 134 additions & 132 deletions packages/web3-eth/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,100 +355,101 @@ export function sendTransaction<ReturnFormat extends DataFormat>(
let transactionFormatted = formatTransaction(transaction, DEFAULT_RETURN_FORMAT);

const promiEvent = new PromiEvent<ReceiptInfo, SendTransactionEvents>(resolve => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setImmediate(async () => {
if (
!options?.ignoreGasPricing &&
transaction.gasPrice === undefined &&
(transaction.maxPriorityFeePerGas === undefined ||
transaction.maxFeePerGas === undefined)
) {
transactionFormatted = {
...transactionFormatted,
...(await getTransactionGasPricing(
transactionFormatted,
web3Context,
DEFAULT_RETURN_FORMAT,
)),
};
}

if (promiEvent.listenerCount('sending') > 0) {
promiEvent.emit('sending', transactionFormatted);
}

let transactionHash: HexString;

if (
web3Context.wallet &&
transaction.from &&
web3Context.wallet.get(transaction.from)
) {
const wallet = web3Context.wallet.get(transaction.from);

const signedTransaction = wallet.signTransaction(
transactionFormatted as Record<string, unknown>,
);

await rpcMethods.sendRawTransaction(
web3Context.requestManager,
signedTransaction.rawTransaction,
);

transactionHash = signedTransaction.transactionHash;
} else {
transactionHash = await rpcMethods.sendTransaction(
web3Context.requestManager,
transactionFormatted as Partial<TransactionWithSender>,
setImmediate(() => {
(async () => {
if (
!options?.ignoreGasPricing &&
transaction.gasPrice === undefined &&
(transaction.maxPriorityFeePerGas === undefined ||
transaction.maxFeePerGas === undefined)
) {
transactionFormatted = {
...transactionFormatted,
...(await getTransactionGasPricing(
transactionFormatted,
web3Context,
DEFAULT_RETURN_FORMAT,
)),
};
}

if (promiEvent.listenerCount('sending') > 0) {
promiEvent.emit('sending', transactionFormatted);
}

let transactionHash: HexString;

if (
web3Context.wallet &&
transaction.from &&
web3Context.wallet.get(transaction.from)
) {
const wallet = web3Context.wallet.get(transaction.from);

const signedTransaction = wallet.signTransaction(
transactionFormatted as Record<string, unknown>,
);

await rpcMethods.sendRawTransaction(
web3Context.requestManager,
signedTransaction.rawTransaction,
);

transactionHash = signedTransaction.transactionHash;
} else {
transactionHash = await rpcMethods.sendTransaction(
web3Context.requestManager,
transactionFormatted as Partial<TransactionWithSender>,
);
}

const transactionHashFormatted = format(
{ eth: 'bytes32' },
transactionHash,
returnFormat,
);
}

const transactionHashFormatted = format(
{ eth: 'bytes32' },
transactionHash,
returnFormat,
);

if (promiEvent.listenerCount('sent') > 0) {
promiEvent.emit('sent', transactionFormatted);
}
if (promiEvent.listenerCount('sent') > 0) {
promiEvent.emit('sent', transactionFormatted);
}

if (promiEvent.listenerCount('transactionHash') > 0) {
promiEvent.emit('transactionHash', transactionHashFormatted);
}
if (promiEvent.listenerCount('transactionHash') > 0) {
promiEvent.emit('transactionHash', transactionHashFormatted);
}

let transactionReceipt = await getTransactionReceipt(
web3Context,
transactionHash,
returnFormat,
);

// Transaction hasn't been included in a block yet
if (transactionReceipt === null)
transactionReceipt = await waitForTransactionReceipt(
let transactionReceipt = await getTransactionReceipt(
web3Context,
transactionHash,
returnFormat,
);

const transactionReceiptFormatted = format(
receiptInfoSchema,
transactionReceipt,
returnFormat,
);

promiEvent.emit('receipt', transactionReceiptFormatted as ReceiptInfo);
resolve(transactionReceiptFormatted as ReceiptInfo);
// Transaction hasn't been included in a block yet
if (transactionReceipt === null)
transactionReceipt = await waitForTransactionReceipt(
web3Context,
transactionHash,
returnFormat,
);

if (promiEvent.listenerCount('confirmation') > 0) {
watchTransactionForConfirmations<SendTransactionEvents, ReturnFormat>(
web3Context,
promiEvent,
transactionReceiptFormatted as ReceiptInfo,
transactionHash,
const transactionReceiptFormatted = format(
receiptInfoSchema,
transactionReceipt,
returnFormat,
);
}

promiEvent.emit('receipt', transactionReceiptFormatted as ReceiptInfo);
resolve(transactionReceiptFormatted as ReceiptInfo);

if (promiEvent.listenerCount('confirmation') > 0) {
watchTransactionForConfirmations<SendTransactionEvents, ReturnFormat>(
web3Context,
promiEvent,
transactionReceiptFormatted as ReceiptInfo,
transactionHash,
returnFormat,
);
}
})() as unknown;
});
});

Expand All @@ -463,66 +464,67 @@ export function sendSignedTransaction<ReturnFormat extends DataFormat>(
// TODO - Promise returned in function argument where a void return was expected
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const promiEvent = new PromiEvent<ReceiptInfo, SendSignedTransactionEvents>(resolve => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setImmediate(async () => {
// Formatting signedTransaction as per returnFormat to be returned to user
const signedTransactionFormatted = format(
{ eth: 'bytes' },
signedTransaction,
returnFormat,
);

promiEvent.emit('sending', signedTransactionFormatted);

// Formatting signedTransaction to be send to RPC endpoint
const signedTransactionFormattedHex = format(
{ eth: 'bytes' },
signedTransaction,
DEFAULT_RETURN_FORMAT,
);
const transactionHash = await rpcMethods.sendRawTransaction(
web3Context.requestManager,
signedTransactionFormattedHex,
);
const transactionHashFormatted = format(
{ eth: 'bytes32' },
transactionHash,
returnFormat,
);
setImmediate(() => {
(async () => {
// Formatting signedTransaction as per returnFormat to be returned to user
const signedTransactionFormatted = format(
{ eth: 'bytes' },
signedTransaction,
returnFormat,
);

promiEvent.emit('sent', signedTransactionFormatted);
promiEvent.emit('transactionHash', transactionHashFormatted);
promiEvent.emit('sending', signedTransactionFormatted);

let transactionReceipt = await getTransactionReceipt(
web3Context,
transactionHash,
returnFormat,
);
// Formatting signedTransaction to be send to RPC endpoint
const signedTransactionFormattedHex = format(
{ eth: 'bytes' },
signedTransaction,
DEFAULT_RETURN_FORMAT,
);
const transactionHash = await rpcMethods.sendRawTransaction(
web3Context.requestManager,
signedTransactionFormattedHex,
);
const transactionHashFormatted = format(
{ eth: 'bytes32' },
transactionHash,
returnFormat,
);

promiEvent.emit('sent', signedTransactionFormatted);
promiEvent.emit('transactionHash', transactionHashFormatted);

// Transaction hasn't been included in a block yet
if (transactionReceipt === null)
transactionReceipt = await waitForTransactionReceipt(
let transactionReceipt = await getTransactionReceipt(
web3Context,
transactionHash,
returnFormat,
);

const transactionReceiptFormatted = format(
receiptInfoSchema,
transactionReceipt,
returnFormat,
);
// Transaction hasn't been included in a block yet
if (transactionReceipt === null)
transactionReceipt = await waitForTransactionReceipt(
web3Context,
transactionHash,
returnFormat,
);

promiEvent.emit('receipt', transactionReceiptFormatted);
resolve(transactionReceiptFormatted);
const transactionReceiptFormatted = format(
receiptInfoSchema,
transactionReceipt,
returnFormat,
);

watchTransactionForConfirmations<SendSignedTransactionEvents, ReturnFormat>(
web3Context,
promiEvent,
transactionReceiptFormatted,
transactionHash,
returnFormat,
);
promiEvent.emit('receipt', transactionReceiptFormatted);
resolve(transactionReceiptFormatted);

watchTransactionForConfirmations<SendSignedTransactionEvents, ReturnFormat>(
web3Context,
promiEvent,
transactionReceiptFormatted,
transactionHash,
returnFormat,
);
})() as unknown;
});
});

Expand Down
44 changes: 22 additions & 22 deletions packages/web3-eth/src/utils/wait_for_transaction_receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ export async function waitForTransactionReceipt<ReturnFormat extends DataFormat>
): Promise<ReceiptInfo> {
return new Promise(resolve => {
let transactionPollingDuration = 0;
// TODO - Promise returned in function argument where a void return was expected
// eslint-disable-next-line @typescript-eslint/no-misused-promises
const intervalId = setInterval(async () => {
transactionPollingDuration +=
web3Context.transactionReceiptPollingInterval ??
web3Context.transactionPollingInterval;
const intervalId = setInterval(() => {
(async () => {
transactionPollingDuration +=
web3Context.transactionReceiptPollingInterval ??
web3Context.transactionPollingInterval;

if (transactionPollingDuration >= web3Context.transactionPollingTimeout) {
clearInterval(intervalId);
throw new TransactionPollingTimeoutError({
numberOfSeconds: web3Context.transactionPollingTimeout / 1000,
transactionHash,
});
}
if (transactionPollingDuration >= web3Context.transactionPollingTimeout) {
clearInterval(intervalId);
throw new TransactionPollingTimeoutError({
numberOfSeconds: web3Context.transactionPollingTimeout / 1000,
transactionHash,
});
}

const response = await getTransactionReceipt(
web3Context,
transactionHash,
returnFormat,
);
const response = await getTransactionReceipt(
web3Context,
transactionHash,
returnFormat,
);

if (response !== null) {
clearInterval(intervalId);
resolve(response);
}
if (response !== null) {
clearInterval(intervalId);
resolve(response);
}
})() as unknown;
}, web3Context.transactionReceiptPollingInterval ?? web3Context.transactionPollingInterval);
});
}
Loading