Skip to content

Commit

Permalink
Merge branch '4.x' into 6451
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Altabba committed Oct 16, 2023
2 parents 715cfe2 + 42502b6 commit e28bba7
Show file tree
Hide file tree
Showing 43 changed files with 1,286 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
days-before-stale: 60
days-before-close: 14
operations-per-run: 100
exempt-pr-labels: 'work-in-progress','4.x'
exempt-issue-labels: 'work-in-progress','4.x'
exempt-pr-labels: 'work-in-progress,4.x'
exempt-issue-labels: 'work-in-progress,4.x'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,7 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
#### web3-eth

- Ensure provider.supportsSubscriptions exists before watching by subscription (#6440)
- Fixed `withdrawalsSchema.address` property type `bytes32` to `address` (#6470)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/web3_providers_guide/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ Follow these steps to connect to the Ethereum network with MetaMask and web3.js,
</pre
>
<script src="https://cdnjs.cloudflare.com/ajax/libs/web3/4.0.1-alpha.5/web3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/web3/dist/web3.min.js"></script>
<script>
window.addEventListener('load', async function () {
// Check if web3 is available
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/guides/web3_providers_guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ As stated above, the injected provider should be in compliance with [EIP-1193](h
The web3.js 4.x Provider specifications are defined in [web3 base provider](https://github.com/ChainSafe/web3.js/blob/4.x/packages/web3-types/src/web3_base_provider.ts) for Injected Providers.

```html
<script src="https://cdn.jsdelivr.net/npm/web3@4.0.1-rc.1/dist/web3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/web3/dist/web3.min.js"></script>
<script>
window.addEventListener('load', function () {
// Check if web3 is available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ await web3.eth.getFeeHistory('0x1', 'latest', []);

#### sending

- In 1.x, the event listener would receive a `payload` object as an argument. In 4.x, just the sent transaction object is recieved
- In 1.x, the event listener would receive a `payload` object as an argument. In 4.x, just the sent transaction object is received

```typescript
// in 1.x
Expand Down Expand Up @@ -211,7 +211,7 @@ web3.eth.sendTransaction({ ... }).on('sending', (sendTransactionObject) => { ...

#### sent

- In 1.x, the event listener would receive a `payload` object as an argument. In 4.x just the sent transaction object is recieved
- In 1.x, the event listener would receive a `payload` object as an argument. In 4.x just the sent transaction object is received

```typescript
// in 1.x
Expand Down
2 changes: 1 addition & 1 deletion docs/src/theme/SearchBar/algolia.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.algolia-docsearch-suggestion--highlight {
color: #3a33d1;
}
/* Highligted search terms in the main category headers */
/* Highlighted search terms in the main category headers */
.algolia-docsearch-suggestion--category-header
.algolia-docsearch-suggestion--highlight {
background-color: #4d47d5;
Expand Down
6 changes: 3 additions & 3 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6222,9 +6222,9 @@ postcss-zindex@^5.1.0:
integrity sha512-fgFMf0OtVSBR1va1JNHYgMxYk73yhn/qb4uQDq1DLGYolz8gHCyr/sesEuGUaYs58E3ZJRcpoGuPVoB7Meiq9A==

postcss@^8.3.11, postcss@^8.4.14, postcss@^8.4.17, postcss@^8.4.21:
version "8.4.24"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.24.tgz#f714dba9b2284be3cc07dbd2fc57ee4dc972d2df"
integrity sha512-M0RzbcI0sO/XJNucsGjvWU9ERWxb/ytp1w6dKtxTKgixdtQDq4rmx/g8W1hnaheq9jgwL/oyEdH5Bc4WwJKMqg==
version "8.4.31"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d"
integrity sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==
dependencies:
nanoid "^3.3.6"
picocolors "^1.0.0"
Expand Down
5 changes: 5 additions & 0 deletions packages/web3-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,8 @@ Documentation:

- defaultTransactionType is now type 0x2 instead of 0x0 (#6282)
- Allows formatter to parse large base fee (#6456)
- The package now uses `EventEmitter` from `web3-utils` that works in node envrioment as well as in the browser. (#6398)

### Fixed

- Fix the issue: "Uncaught TypeError: Class extends value undefined is not a constructor or null #6371". (#6398)
2 changes: 1 addition & 1 deletion packages/web3-core/src/web3_event_emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

import { EventEmitter } from 'events';
import { EventEmitter } from 'web3-utils';

export type Web3EventMap = Record<string, unknown>;
export type Web3EventKey<T extends Web3EventMap> = string & keyof T;
Expand Down
6 changes: 5 additions & 1 deletion packages/web3-eth-abi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,8 @@ Documentation:

- Dependencies updated

## [Unreleased]
## [Unreleased]

### Fixed

- Fix issue with default config with babel (and React): "TypeError: Cannot convert a BigInt value to a number #6187" (#6506)
20 changes: 1 addition & 19 deletions packages/web3-eth-abi/src/coders/base/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { padLeft, toBigInt } from 'web3-utils';
import { utils } from 'web3-validator';
import { DecoderResult, EncoderResult } from '../types.js';
import { WORD_SIZE } from '../utils.js';
import { numberLimits } from './numbersLimits.js';

// eslint-disable-next-line no-bitwise
const mask = BigInt(1) << BigInt(256);
Expand All @@ -43,25 +44,6 @@ function uint8ArrayToBigInt(value: Uint8Array, max: bigint): bigint {
return result - mask;
}

const numberLimits = new Map<string, { min: bigint; max: bigint }>();

// precalculate all the limits
for (let i = 8; i <= 256; i += 8) {
numberLimits.set(`uint${i}`, {
min: BigInt(0),
max: BigInt(2) ** BigInt(i) - BigInt(1),
});
numberLimits.set(`int${i}`, {
min: -(BigInt(2) ** BigInt(i - 1)),
max: BigInt(2) ** BigInt(i - 1) - BigInt(1),
});
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
numberLimits.set(`int`, numberLimits.get('int256')!);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
numberLimits.set(`uint`, numberLimits.get('uint256')!);

export function encodeNumber(param: AbiParameter, input: unknown): EncoderResult {
let value;
try {
Expand Down
39 changes: 39 additions & 0 deletions packages/web3-eth-abi/src/coders/base/numbersLimits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* this variable contains the precalculated limits for all the numbers for uint and int types
*/
export const numberLimits = new Map<string, { min: bigint; max: bigint }>();

let base = BigInt(256); // 2 ^ 8 = 256
for (let i = 8; i <= 256; i += 8) {
numberLimits.set(`uint${i}`, {
min: BigInt(0),
max: base - BigInt(1),
});
numberLimits.set(`int${i}`, {
min: -base / BigInt(2),
max: base / BigInt(2) - BigInt(1),
});
base *= BigInt(256);
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
numberLimits.set(`int`, numberLimits.get('int256')!);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
numberLimits.set(`uint`, numberLimits.get('uint256')!);
3 changes: 1 addition & 2 deletions packages/web3-eth-accounts/src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
import pkg from 'crc-32';
import { EventEmitter } from 'events';
import { EventEmitter, bytesToHex, hexToBytes, uint8ArrayConcat } from 'web3-utils';
import type { Numbers } from 'web3-types';
import { bytesToHex, hexToBytes, uint8ArrayConcat } from 'web3-utils';
import { TypeOutput } from './types.js';
import { intToUint8Array, toType, parseGethGenesis } from './utils.js';
import goerli from './chains/goerli.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
import Web3 from 'web3';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Web3Account } from 'web3-eth-accounts';
import { EventLog } from 'web3-types';
import { Contract } from '../../../src';
import { ERC721TokenAbi, ERC721TokenBytecode } from '../../shared_fixtures/build/ERC721Token';
import { getSystemTestProvider, createLocalAccount } from '../../fixtures/system_test_utils';
Expand Down Expand Up @@ -80,8 +79,7 @@ describe('contract', () => {
tempAccount.address.toLowerCase(),
);

const logs = await contractDeployed.getPastEvents('Transfer');
const tokenId = (logs[0] as EventLog)?.returnValues?.tokenId as string;
const tokenId = awardReceipt.events?.Transfer.returnValues?.tokenId as string;

expect(
toUpperCaseHex(
Expand Down Expand Up @@ -113,8 +111,7 @@ describe('contract', () => {
tempAccount.address.toLowerCase(),
);

const logs = await contractDeployed.getPastEvents('Transfer');
const tokenId = (logs[0] as EventLog)?.returnValues?.tokenId as string;
const tokenId = awardReceipt.events?.Transfer.returnValues?.tokenId as string;
const transferFromReceipt = await contractDeployed.methods
.transferFrom(tempAccount.address, toAccount.address, tokenId)
.send({
Expand Down Expand Up @@ -186,8 +183,7 @@ describe('contract', () => {
tempAccount.address.toLowerCase(),
);

const logs = await contractDeployed.getPastEvents('Transfer');
const tokenId = (logs[0] as EventLog)?.returnValues?.tokenId as string;
const tokenId = awardReceipt.events?.Transfer.returnValues?.tokenId as string;

const approveReceipt = await contractDeployed.methods
.approve(toAccount.address, tokenId)
Expand Down
1 change: 1 addition & 0 deletions packages/web3-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ Documentation:
### Fixed

- Ensure provider.supportsSubscriptions exists before watching by subscription (#6440)
- Fixed param sent to `checkRevertBeforeSending` in `sendSignedTransaction`

### Added

Expand Down
5 changes: 4 additions & 1 deletion packages/web3-eth/src/rpc_method_wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,11 @@ export function sendSignedTransaction<
};

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

await sendTxHelper.checkRevertBeforeSending(
unSerializedTransactionWithFrom as TransactionCall,
txWithoutSigParams as TransactionCall,
);

sendTxHelper.emitSending(signedTransactionFormattedHex);
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-eth/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export const withdrawalsSchema = {
format: 'uint',
},
address: {
format: 'bytes32',
format: 'address',
},
amount: {
format: 'uint',
Expand Down
10 changes: 7 additions & 3 deletions packages/web3-eth/src/utils/wait_for_transaction_receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { TransactionPollingTimeoutError } from 'web3-errors';
import { EthExecutionAPI, Bytes, TransactionReceipt, DataFormat } from 'web3-types';

// eslint-disable-next-line import/no-cycle
import { pollTillDefined, rejectIfTimeout } from 'web3-utils';
import { pollTillDefinedAndReturnIntervalId, rejectIfTimeout } from 'web3-utils';
// eslint-disable-next-line import/no-cycle
import { rejectIfBlockTimeout } from './reject_if_block_timeout.js';
// eslint-disable-next-line import/no-cycle
Expand All @@ -31,10 +31,11 @@ export async function waitForTransactionReceipt<ReturnFormat extends DataFormat>
transactionHash: Bytes,
returnFormat: ReturnFormat,
): Promise<TransactionReceipt> {

const pollingInterval =
web3Context.transactionReceiptPollingInterval ?? web3Context.transactionPollingInterval;

const awaitableTransactionReceipt: Promise<TransactionReceipt> = pollTillDefined(async () => {
const [awaitableTransactionReceipt, IntervalId] = pollTillDefinedAndReturnIntervalId(async () => {
try {
return getTransactionReceipt(web3Context, transactionHash, returnFormat);
} catch (error) {
Expand Down Expand Up @@ -64,7 +65,10 @@ export async function waitForTransactionReceipt<ReturnFormat extends DataFormat>
rejectOnBlockTimeout, // this will throw an error on Transaction Block Timeout
]);
} finally {
clearTimeout(timeoutId);
if(timeoutId)
clearTimeout(timeoutId);
if(IntervalId)
clearInterval(IntervalId);
blockTimeoutResourceCleaner.clean();
}
}
2 changes: 1 addition & 1 deletion packages/web3-eth/test/e2e/e2e_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { getSystemTestBackend } from '../fixtures/system_test_utils';
import secrets from '../../../../.secrets.json';

export const getSystemE2ETestProvider = (): string => {
if (process.env.WEB3_SYTEM_TEST_MODE === 'http') {
if (process.env.WEB3_SYSTEM_TEST_MODE === 'http') {
return getSystemTestBackend() === 'sepolia'
? process.env.INFURA_SEPOLIA_HTTP ?? secrets.SEPOLIA.HTTP
: process.env.INFURA_MAINNET_HTTP ?? secrets.MAINNET.HTTP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ describe('defaults', () => {
beforeEach(() => {
clientUrl = getSystemTestProvider();
web3 = new Web3(clientUrl);
// Make the test run faster by casing the polling to start after 2 blocks
web3.eth.transactionBlockTimeout = 2;

// Increase other timeouts so only `transactionBlockTimeout` would be reached
web3.eth.transactionSendTimeout = MAX_32_SIGNED_INTEGER;
Expand All @@ -64,6 +62,7 @@ describe('defaults', () => {
account1 = await createLocalAccount(web3);
account2 = await createLocalAccount(web3);
// Setting a high `nonce` when sending a transaction, to cause the RPC call to stuck at the Node

const sentTx: Web3PromiEvent<
TransactionReceipt,
SendTransactionEvents<typeof DEFAULT_RETURN_FORMAT>
Expand All @@ -81,18 +80,13 @@ describe('defaults', () => {
// So, send 2 transactions, one after another, because in this test `transactionBlockTimeout = 2`.
// eslint-disable-next-line no-void
await sendFewSampleTxs(2);

web3.eth.transactionBlockTimeout = 2;

await expect(sentTx).rejects.toThrow(/was not mined within [0-9]+ blocks/);

await expect(sentTx).rejects.toThrow(TransactionBlockTimeoutError);

try {
await sentTx;
throw new Error(
'The test should fail if there is no exception when sending a transaction that could not be mined within transactionBlockTimeout',
);
} catch (error) {
// eslint-disable-next-line jest/no-conditional-expect
expect(error).toBeInstanceOf(TransactionBlockTimeoutError);
// eslint-disable-next-line jest/no-conditional-expect
expect((error as Error).message).toMatch(/was not mined within [0-9]+ blocks/);
}
await closeOpenConnection(web3.eth);
});

Expand Down Expand Up @@ -128,6 +122,8 @@ describe('defaults', () => {
// eslint-disable-next-line no-void, @typescript-eslint/no-unsafe-call
void sendFewSampleTxs(2);

web3.eth.transactionBlockTimeout = 2;

await expect(sentTx).rejects.toThrow(/was not mined within [0-9]+ blocks/);

await expect(sentTx).rejects.toThrow(TransactionBlockTimeoutError);
Expand Down
Loading

0 comments on commit e28bba7

Please sign in to comment.