diff --git a/packages/web3-core/CHANGELOG.md b/packages/web3-core/CHANGELOG.md index 8d35d0e8d29..3da42baf8c4 100644 --- a/packages/web3-core/CHANGELOG.md +++ b/packages/web3-core/CHANGELOG.md @@ -81,3 +81,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added rpc exception codes following eip-1474 as an experimental feature (if `useRpcCallSpecification` at `enableExperimentalFeatures` is `true`) (#5525) +- Added support of `safe` and `finalized` block tags (#5823) diff --git a/packages/web3-core/src/web3_config.ts b/packages/web3-core/src/web3_config.ts index edfca180e6f..47127559c2b 100644 --- a/packages/web3-core/src/web3_config.ts +++ b/packages/web3-core/src/web3_config.ts @@ -176,6 +176,8 @@ export abstract class Web3Config * - `"earliest"` - String: The genesis block * - `"latest"` - String: The latest block (current head of the blockchain) * - `"pending"` - String: The currently mined block (including pending transactions) + * - `"finalized"` - String: (For POS networks) The finalized block is one which has been accepted as canonical by greater than 2/3 of validators + * - `"safe"` - String: (For POS networks) The safe head block is one which under normal network conditions, is expected to be included in the canonical chain. Under normal network conditions the safe head and the actual tip of the chain will be equivalent (with safe head trailing only by a few seconds). Safe heads will be less likely to be reorged than the proof of work network`s latest blocks. */ public set defaultBlock(val) { this.emit(Web3ConfigEvent.CONFIG_CHANGE, { diff --git a/packages/web3-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index 7c165a0eeb5..beaf8353006 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -227,3 +227,4 @@ const transactionHash = receipt.transactionHash; ### Added - Added functionality of `createAccessList` for contracts ( #5780 ) +- Added support of `safe` and `finalized` block tags (#5823) diff --git a/packages/web3-eth-contract/src/types.ts b/packages/web3-eth-contract/src/types.ts index 6e43d3ce045..1d021fd8692 100644 --- a/packages/web3-eth-contract/src/types.ts +++ b/packages/web3-eth-contract/src/types.ts @@ -61,7 +61,7 @@ export interface ContractEventOptions { */ filter?: Record; /** - * The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as `earliest`, `latest` and `pending` can also be used. For specific range use {@link Contract.getPastEvents}. + * The block number (greater than or equal to) from which to get events on. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized` can also be used. For specific range use {@link Contract.getPastEvents}. */ fromBlock?: BlockNumberOrTag; /** @@ -236,7 +236,7 @@ export interface NonPayableMethodObject * ``` * * @param tx - The options used for calling. - * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks. + * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks. * @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices. */ @@ -355,7 +355,7 @@ export interface NonPayableMethodObject * This method generates an access list for a transaction. You must specify a `from` address and `gas` if it’s not specified in options. * * @param options - The options used for createAccessList. - * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks. + * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks. * @returns The returned data of the createAccessList, e.g. The generated access list for transaction. * * ```ts @@ -426,7 +426,7 @@ export interface PayableMethodObject { * ``` * * @param tx - The options used for calling. - * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks. + * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks. * @returns - The return value(s) of the smart contract method. If it returns a single value, it’s returned as is. If it has multiple return values they are returned as an object with properties and indices. */ call( @@ -544,7 +544,7 @@ export interface PayableMethodObject { * This method generates an access list for a transaction. You must specify a `from` address and `gas` if it’s not specified in options. * * @param options - The options used for createAccessList. - * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, and `pending` can also be used. Useful for requesting data from or replaying transactions in past blocks. + * @param block - If you pass this parameter it will not use the default block set with contract.defaultBlock. Pre-defined block numbers as `earliest`, `latest`, `pending`, `safe` or `finalized can also be used. Useful for requesting data from or replaying transactions in past blocks. * @returns The returned data of the createAccessList, e.g. The generated access list for transaction. * * ```ts diff --git a/packages/web3-eth/CHANGELOG.md b/packages/web3-eth/CHANGELOG.md index d5ea2f8b397..ad3ab61b341 100644 --- a/packages/web3-eth/CHANGELOG.md +++ b/packages/web3-eth/CHANGELOG.md @@ -98,3 +98,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `createAccessList` functionality ( #5780 ) +- Added support of `safe` and `finalized` block tags (#5823) diff --git a/packages/web3-eth/test/fixtures/web3_eth_methods_with_parameters.ts b/packages/web3-eth/test/fixtures/web3_eth_methods_with_parameters.ts index 7e018cf504b..465a3d29ae8 100644 --- a/packages/web3-eth/test/fixtures/web3_eth_methods_with_parameters.ts +++ b/packages/web3-eth/test/fixtures/web3_eth_methods_with_parameters.ts @@ -58,6 +58,14 @@ export const getBalanceValidData: [ ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.PENDING, undefined], ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.LATEST, DEFAULT_RETURN_FORMAT], ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.SAFE, undefined], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.FINALIZED, undefined], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + ], // Undefined blockNumber, returnType = DEFAULT_RETURN_FORMAT [ ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', undefined, DEFAULT_RETURN_FORMAT], @@ -76,6 +84,14 @@ export const getBalanceValidData: [ ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.PENDING, DEFAULT_RETURN_FORMAT], ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.PENDING, DEFAULT_RETURN_FORMAT], ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + ], [ ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x4b7', DEFAULT_RETURN_FORMAT], ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x4b7', DEFAULT_RETURN_FORMAT], @@ -118,6 +134,30 @@ export const getBalanceValidData: [ { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }, ], ], + [ + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.SAFE, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }, + ], + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.SAFE, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }, + ], + ], + [ + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.FINALIZED, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }, + ], + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.FINALIZED, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }, + ], + ], [ [ '0x407d73d8a49eeb85d32cf465507dd71d507100c1', @@ -180,6 +220,30 @@ export const getBalanceValidData: [ { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }, ], ], + [ + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.SAFE, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }, + ], + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.SAFE, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }, + ], + ], + [ + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.FINALIZED, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }, + ], + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.FINALIZED, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }, + ], + ], [ [ '0x407d73d8a49eeb85d32cf465507dd71d507100c1', @@ -242,6 +306,30 @@ export const getBalanceValidData: [ { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }, ], ], + [ + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.SAFE, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }, + ], + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.SAFE, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }, + ], + ], + [ + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.FINALIZED, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }, + ], + [ + '0x407d73d8a49eeb85d32cf465507dd71d507100c1', + BlockTags.FINALIZED, + { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }, + ], + ], [ [ '0x407d73d8a49eeb85d32cf465507dd71d507100c1', @@ -303,6 +391,14 @@ export const getBlockValidData: [ [BlockTags.EARLIEST, undefined, undefined], [BlockTags.EARLIEST, false, DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, undefined, undefined], + [BlockTags.SAFE, false, DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, undefined, undefined], + [BlockTags.FINALIZED, false, DEFAULT_RETURN_FORMAT], + ], [ [BlockTags.PENDING, undefined, undefined], [BlockTags.PENDING, false, DEFAULT_RETURN_FORMAT], @@ -320,6 +416,14 @@ export const getBlockValidData: [ [BlockTags.PENDING, true, undefined], [BlockTags.PENDING, true, DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, true, undefined], + [BlockTags.SAFE, true, DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, true, undefined], + [BlockTags.FINALIZED, true, DEFAULT_RETURN_FORMAT], + ], // Defined block, hydrated = false, and undefined returnType [ [BlockTags.LATEST, false, undefined], @@ -333,6 +437,14 @@ export const getBlockValidData: [ [BlockTags.PENDING, false, undefined], [BlockTags.PENDING, false, DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, false, undefined], + [BlockTags.SAFE, false, DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, false, undefined], + [BlockTags.FINALIZED, false, DEFAULT_RETURN_FORMAT], + ], // Defined block, hydrated = true, and returnType = DEFAULT_RETURN_FORMAT [ [BlockTags.LATEST, true, DEFAULT_RETURN_FORMAT], @@ -346,6 +458,14 @@ export const getBlockValidData: [ [BlockTags.PENDING, true, DEFAULT_RETURN_FORMAT], [BlockTags.PENDING, true, DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, true, DEFAULT_RETURN_FORMAT], + [BlockTags.SAFE, true, DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, true, DEFAULT_RETURN_FORMAT], + [BlockTags.FINALIZED, true, DEFAULT_RETURN_FORMAT], + ], // Defined block, hydrated = true, and returnType = {...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR} [ [BlockTags.LATEST, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], @@ -359,6 +479,14 @@ export const getBlockValidData: [ [BlockTags.PENDING, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], [BlockTags.PENDING, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], ], + [ + [BlockTags.SAFE, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], + [BlockTags.SAFE, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], + ], + [ + [BlockTags.FINALIZED, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], + [BlockTags.FINALIZED, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], + ], // Defined block, hydrated = true, and returnType = {...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER} [ [BlockTags.LATEST, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], @@ -372,6 +500,14 @@ export const getBlockValidData: [ [BlockTags.PENDING, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], [BlockTags.PENDING, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], ], + [ + [BlockTags.SAFE, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], + [BlockTags.SAFE, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], + ], + [ + [BlockTags.FINALIZED, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], + [BlockTags.FINALIZED, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], + ], // Defined block, hydrated = true, and returnType = {...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT} [ [BlockTags.LATEST, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], @@ -385,6 +521,14 @@ export const getBlockValidData: [ [BlockTags.PENDING, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], [BlockTags.PENDING, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], ], + [ + [BlockTags.SAFE, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], + [BlockTags.SAFE, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], + ], + [ + [BlockTags.FINALIZED, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], + [BlockTags.FINALIZED, true, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], + ], ]; /** @@ -421,6 +565,14 @@ export const getBlockTransactionCountValidData: [ [BlockTags.PENDING, undefined], [BlockTags.PENDING, DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, undefined], + [BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, undefined], + [BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + ], // Defined block and returnType = DEFAULT_RETURN_FORMAT [ [BlockTags.LATEST, DEFAULT_RETURN_FORMAT], @@ -434,6 +586,14 @@ export const getBlockTransactionCountValidData: [ [BlockTags.PENDING, DEFAULT_RETURN_FORMAT], [BlockTags.PENDING, DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + [BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + [BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + ], // Defined block and returnType = {...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR} [ [BlockTags.LATEST, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], @@ -447,6 +607,14 @@ export const getBlockTransactionCountValidData: [ [BlockTags.PENDING, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], [BlockTags.PENDING, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], ], + [ + [BlockTags.SAFE, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], + [BlockTags.SAFE, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], + ], + [ + [BlockTags.FINALIZED, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], + [BlockTags.FINALIZED, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.STR }], + ], // Defined block, hydrated = true, and returnType = {...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER} [ [BlockTags.LATEST, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], @@ -473,6 +641,14 @@ export const getBlockTransactionCountValidData: [ [BlockTags.PENDING, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], [BlockTags.PENDING, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], ], + [ + [BlockTags.SAFE, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], + [BlockTags.SAFE, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], + ], + [ + [BlockTags.FINALIZED, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], + [BlockTags.FINALIZED, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], + ], ]; /** @@ -509,6 +685,14 @@ export const getBlockUncleCountValidData: [ [BlockTags.PENDING, undefined], [BlockTags.PENDING, DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, undefined], + [BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, undefined], + [BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + ], // Defined block and returnType = DEFAULT_RETURN_FORMAT [ [BlockTags.LATEST, DEFAULT_RETURN_FORMAT], @@ -548,6 +732,14 @@ export const getBlockUncleCountValidData: [ [BlockTags.PENDING, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], [BlockTags.PENDING, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], ], + [ + [BlockTags.SAFE, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], + [BlockTags.SAFE, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], + ], + [ + [BlockTags.FINALIZED, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], + [BlockTags.FINALIZED, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.NUMBER }], + ], // Defined block and returnType = {...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT} [ [BlockTags.LATEST, { ...DEFAULT_RETURN_FORMAT, number: FMT_NUMBER.BIGINT }], @@ -594,6 +786,14 @@ export const getUncleValidData: [ [BlockTags.EARLIEST, '0x0', undefined], [BlockTags.EARLIEST, '0x0', DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, '0x0', undefined], + [BlockTags.SAFE, '0x0', DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, '0x0', undefined], + [BlockTags.FINALIZED, '0x0', DEFAULT_RETURN_FORMAT], + ], [ [BlockTags.PENDING, '0x0', undefined], [BlockTags.PENDING, '0x0', DEFAULT_RETURN_FORMAT], @@ -778,6 +978,14 @@ export const getTransactionFromBlockValidData: [ [BlockTags.PENDING, '0x0', undefined], [BlockTags.PENDING, '0x0', DEFAULT_RETURN_FORMAT], ], + [ + [BlockTags.SAFE, '0x0', undefined], + [BlockTags.SAFE, '0x0', DEFAULT_RETURN_FORMAT], + ], + [ + [BlockTags.FINALIZED, '0x0', undefined], + [BlockTags.FINALIZED, '0x0', DEFAULT_RETURN_FORMAT], + ], // Defined block, uncleIndex = true, and returnType = DEFAULT_RETURN_FORMAT [ [BlockTags.LATEST, '0x0', DEFAULT_RETURN_FORMAT], @@ -934,6 +1142,14 @@ export const getTransactionCountValidData: [ ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.PENDING, undefined], ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.PENDING, DEFAULT_RETURN_FORMAT], ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.SAFE, undefined], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.FINALIZED, undefined], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + ], // Defined block, uncleIndex = and undefined returnType [ ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.LATEST, undefined], @@ -1120,6 +1336,14 @@ export const estimateGasValidData: [ [transactionWithSender, BlockTags.PENDING, undefined], [transactionWithSender, BlockTags.PENDING, DEFAULT_RETURN_FORMAT], ], + [ + [transactionWithSender, BlockTags.SAFE, undefined], + [transactionWithSender, BlockTags.SAFE, DEFAULT_RETURN_FORMAT], + ], + [ + [transactionWithSender, BlockTags.FINALIZED, undefined], + [transactionWithSender, BlockTags.FINALIZED, DEFAULT_RETURN_FORMAT], + ], // Defined transaction and block number, undefined returnType [ [transactionWithSender, BlockTags.LATEST, undefined], @@ -1300,6 +1524,14 @@ export const getFeeHistoryValidData: [ ['0x4', BlockTags.PENDING, [], undefined], ['0x4', BlockTags.PENDING, [], DEFAULT_RETURN_FORMAT], ], + [ + ['0x4', BlockTags.SAFE, [], undefined], + ['0x4', BlockTags.SAFE, [], DEFAULT_RETURN_FORMAT], + ], + [ + ['0x4', BlockTags.FINALIZED, [], undefined], + ['0x4', BlockTags.FINALIZED, [], DEFAULT_RETURN_FORMAT], + ], // Defined transaction and block number, undefined returnType [ ['0x4', BlockTags.LATEST, [], undefined], @@ -1394,6 +1626,14 @@ export const getStorageAtValidData: [ ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x0', BlockTags.PENDING], ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x0', BlockTags.PENDING], ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x0', BlockTags.SAFE], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x0', BlockTags.SAFE], + ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x0', BlockTags.FINALIZED], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x0', BlockTags.FINALIZED], + ], ]; /** @@ -1423,6 +1663,14 @@ export const getCodeValidData: [ ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.PENDING], ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.PENDING], ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.SAFE], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.SAFE], + ], + [ + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.FINALIZED], + ['0x407d73d8a49eeb85d32cf465507dd71d507100c1', BlockTags.FINALIZED], + ], ]; /** @@ -1515,6 +1763,26 @@ export const getPastLogsValidData: [Filter, Filter][] = [ toBlock: BlockTags.EARLIEST, }, ], + [ + { + fromBlock: BlockTags.SAFE, + toBlock: BlockTags.SAFE, + }, + { + fromBlock: BlockTags.SAFE, + toBlock: BlockTags.SAFE, + }, + ], + [ + { + fromBlock: BlockTags.FINALIZED, + toBlock: BlockTags.FINALIZED, + }, + { + fromBlock: BlockTags.FINALIZED, + toBlock: BlockTags.FINALIZED, + }, + ], ]; /** @@ -1612,6 +1880,34 @@ export const getProofValidData: [ DEFAULT_RETURN_FORMAT, ], ], + [ + [ + '0x1234567890123456789012345678901234567890', + ['0x295a70b2de5e3953354a6a8344e616ed314d7251'], + BlockTags.SAFE, + undefined, + ], + [ + '0x1234567890123456789012345678901234567890', + ['0x295a70b2de5e3953354a6a8344e616ed314d7251'], + BlockTags.SAFE, + DEFAULT_RETURN_FORMAT, + ], + ], + [ + [ + '0x1234567890123456789012345678901234567890', + ['0x295a70b2de5e3953354a6a8344e616ed314d7251'], + BlockTags.FINALIZED, + undefined, + ], + [ + '0x1234567890123456789012345678901234567890', + ['0x295a70b2de5e3953354a6a8344e616ed314d7251'], + BlockTags.FINALIZED, + DEFAULT_RETURN_FORMAT, + ], + ], // Defined block number, returnType = DEFAULT_RETURN_FORMAT [ [ diff --git a/packages/web3-eth/test/integration/block/rpc.getBlock.test.ts b/packages/web3-eth/test/integration/block/rpc.getBlock.test.ts index 9fd0693b3fc..01fbb12aab5 100644 --- a/packages/web3-eth/test/integration/block/rpc.getBlock.test.ts +++ b/packages/web3-eth/test/integration/block/rpc.getBlock.test.ts @@ -42,6 +42,8 @@ describe('rpc with block', () => { earliest: 'earliest'; latest: 'latest'; pending: 'pending'; + finalized: 'finalized'; + safe: 'safe'; blockNumber: number | bigint; blockHash: string; transactionHash: string; @@ -85,6 +87,8 @@ describe('rpc with block', () => { pending: 'pending', latest: 'latest', earliest: 'earliest', + finalized: 'finalized', + safe: 'safe', blockNumber: Number(receipt.blockNumber), blockHash: String(receipt.blockHash), transactionHash: String(receipt.transactionHash), @@ -99,11 +103,18 @@ describe('rpc with block', () => { describe('methods', () => { it.each( toAllVariants<{ - block: 'earliest' | 'latest' | 'pending' | 'blockHash' | 'blockNumber'; + block: + | 'earliest' + | 'latest' + | 'pending' + | 'finalized' + | 'safe' + | 'blockHash' + | 'blockNumber'; hydrated: boolean; format: string; }>({ - block: ['earliest', 'latest', 'blockHash', 'blockNumber'], + block: ['earliest', 'latest', 'safe', 'finalized', 'blockHash', 'blockNumber'], hydrated: [true, false], format: Object.values(FMT_NUMBER), }), diff --git a/packages/web3-eth/test/integration/block/rpc.getBlockTransactionCount.test.ts b/packages/web3-eth/test/integration/block/rpc.getBlockTransactionCount.test.ts index d64d2a43794..3c984e19fd0 100644 --- a/packages/web3-eth/test/integration/block/rpc.getBlockTransactionCount.test.ts +++ b/packages/web3-eth/test/integration/block/rpc.getBlockTransactionCount.test.ts @@ -40,6 +40,8 @@ describe('rpc with block', () => { earliest: 'earliest'; latest: 'latest'; pending: 'pending'; + finalized: 'finalized'; + safe: 'safe'; blockNumber: number | bigint; blockHash: string; transactionHash: string; @@ -83,6 +85,8 @@ describe('rpc with block', () => { pending: 'pending', latest: 'latest', earliest: 'earliest', + finalized: 'finalized', + safe: 'safe', blockNumber: Number(receipt.blockNumber), blockHash: String(receipt.blockHash), transactionHash: String(receipt.transactionHash), @@ -97,9 +101,24 @@ describe('rpc with block', () => { describe('methods', () => { it.each( toAllVariants<{ - block: 'earliest' | 'latest' | 'pending' | 'blockHash' | 'blockNumber'; + block: + | 'earliest' + | 'latest' + | 'pending' + | 'finalized' + | 'safe' + | 'blockHash' + | 'blockNumber'; }>({ - block: ['earliest', 'latest', 'pending', 'blockHash', 'blockNumber'], + block: [ + 'earliest', + 'latest', + 'pending', + 'finalized', + 'safe', + 'blockHash', + 'blockNumber', + ], }), )('getBlockTransactionCount', async ({ block }) => { const res = await web3Eth.getBlockTransactionCount(blockData[block]); @@ -107,7 +126,11 @@ describe('rpc with block', () => { if (getSystemTestBackend() === 'ganache') { shouldBe = blockData[block] === 'earliest' ? 0 : 1; } else { - shouldBe = ['earliest', 'pending'].includes(String(blockData[block])) ? 0 : 1; + shouldBe = ['earliest', 'pending', 'finalized', 'safe'].includes( + String(blockData[block]), + ) + ? 0 + : 1; } expect(Number(res)).toBe(shouldBe); }); diff --git a/packages/web3-eth/test/integration/block/rpc.getBlockUncleCount.test.ts b/packages/web3-eth/test/integration/block/rpc.getBlockUncleCount.test.ts index 3c4d6ef911b..cc1554c248d 100644 --- a/packages/web3-eth/test/integration/block/rpc.getBlockUncleCount.test.ts +++ b/packages/web3-eth/test/integration/block/rpc.getBlockUncleCount.test.ts @@ -39,6 +39,8 @@ describe('rpc with block', () => { earliest: 'earliest'; latest: 'latest'; pending: 'pending'; + finalized: 'finalized'; + safe: 'safe'; blockNumber: number | bigint; blockHash: string; transactionHash: string; @@ -82,6 +84,8 @@ describe('rpc with block', () => { pending: 'pending', latest: 'latest', earliest: 'earliest', + finalized: 'finalized', + safe: 'safe', blockNumber: Number(receipt.blockNumber), blockHash: String(receipt.blockHash), transactionHash: String(receipt.transactionHash), @@ -96,9 +100,24 @@ describe('rpc with block', () => { describe('methods', () => { it.each( toAllVariants<{ - block: 'earliest' | 'latest' | 'pending' | 'blockHash' | 'blockNumber'; + block: + | 'earliest' + | 'latest' + | 'pending' + | 'finalized' + | 'safe' + | 'blockHash' + | 'blockNumber'; }>({ - block: ['earliest', 'latest', 'pending', 'blockHash', 'blockNumber'], + block: [ + 'earliest', + 'latest', + 'pending', + 'finalized', + 'safe', + 'blockHash', + 'blockNumber', + ], }), )('getBlockUncleCount', async ({ block }) => { const res = await web3Eth.getBlockUncleCount(blockData[block]); diff --git a/packages/web3-eth/test/integration/block/rpc.getTransactionFromBlock.test.ts b/packages/web3-eth/test/integration/block/rpc.getTransactionFromBlock.test.ts index 16317373c1a..45603749607 100644 --- a/packages/web3-eth/test/integration/block/rpc.getTransactionFromBlock.test.ts +++ b/packages/web3-eth/test/integration/block/rpc.getTransactionFromBlock.test.ts @@ -38,6 +38,8 @@ describe('rpc with block', () => { earliest: 'earliest'; latest: 'latest'; pending: 'pending'; + finalized: 'finalized'; + safe: 'safe'; blockNumber: number | bigint; blockHash: string; transactionHash: string; @@ -81,6 +83,8 @@ describe('rpc with block', () => { pending: 'pending', latest: 'latest', earliest: 'earliest', + finalized: 'finalized', + safe: 'safe', blockNumber: Number(receipt.blockNumber), blockHash: String(receipt.blockHash), transactionHash: String(receipt.transactionHash), diff --git a/packages/web3-eth/test/integration/block/rpc.getUncle.test.ts b/packages/web3-eth/test/integration/block/rpc.getUncle.test.ts index 89dd0e0b3ca..69a62cb0fe7 100644 --- a/packages/web3-eth/test/integration/block/rpc.getUncle.test.ts +++ b/packages/web3-eth/test/integration/block/rpc.getUncle.test.ts @@ -41,6 +41,8 @@ describe('rpc with block', () => { earliest: 'earliest'; latest: 'latest'; pending: 'pending'; + finalized: 'finalized'; + safe: 'safe'; blockNumber: number | bigint; blockHash: string; transactionHash: string; @@ -84,6 +86,8 @@ describe('rpc with block', () => { pending: 'pending', latest: 'latest', earliest: 'earliest', + finalized: 'finalized', + safe: 'safe', blockNumber: Number(receipt.blockNumber), blockHash: String(receipt.blockHash), transactionHash: String(receipt.transactionHash), @@ -98,9 +102,9 @@ describe('rpc with block', () => { describe('methods', () => { it.each( toAllVariants<{ - block: 'earliest' | 'latest' | 'pending' | 'blockNumber'; + block: 'earliest' | 'latest' | 'pending' | 'finalized' | 'safe' | 'blockNumber'; }>({ - block: ['earliest', 'latest', 'pending', 'blockNumber'], + block: ['earliest', 'latest', 'pending', 'finalized', 'safe', 'blockNumber'], }), )('getUncle', async ({ block }) => { const res = await web3Eth.getUncle(blockData[block], 0); diff --git a/packages/web3-eth/test/integration/defaults.test.ts b/packages/web3-eth/test/integration/defaults.test.ts index 92bc5abba08..089729c40c8 100644 --- a/packages/web3-eth/test/integration/defaults.test.ts +++ b/packages/web3-eth/test/integration/defaults.test.ts @@ -178,6 +178,16 @@ describe('defaults', () => { // default expect(web3Eth.defaultBlock).toBe('latest'); + web3Eth.setConfig({ + defaultBlock: 'safe', + }); + expect(web3Eth.defaultBlock).toBe('safe'); + + web3Eth.setConfig({ + defaultBlock: 'finalized', + }); + expect(web3Eth.defaultBlock).toBe('finalized'); + // after set web3Eth.setConfig({ defaultBlock: 'earliest', diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/call.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/call.ts index e6c34ec3897..e8949e97eab 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/call.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/call.ts @@ -62,6 +62,11 @@ export const testData: TestData[] = [ `${JSON.stringify(transaction)}\nblockNumber = BlockTags.PENDING`, [transaction, BlockTags.PENDING], ], + [`${JSON.stringify(transaction)}\nblockNumber = BlockTags.SAFE`, [transaction, BlockTags.SAFE]], + [ + `${JSON.stringify(transaction)}\nblockNumber = BlockTags.FINALIZED`, + [transaction, BlockTags.FINALIZED], + ], // blockNumber = Numbers [`${JSON.stringify(transaction)}\nblockNumber = "0x4b7"`, [transaction, '0x4b7']], [`${JSON.stringify(transaction)}\nblockNumber = 1207`, [transaction, 1207]], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/createAccessList.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/createAccessList.ts index 8631dbdea66..ae15e0e85fc 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/createAccessList.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/createAccessList.ts @@ -51,6 +51,11 @@ export const testData: TestData[] = [ `${JSON.stringify(transaction)}\nblockNumber = BlockTags.PENDING`, [transaction, BlockTags.PENDING], ], + [`${JSON.stringify(transaction)}\nblockNumber = BlockTags.SAFE`, [transaction, BlockTags.SAFE]], + [ + `${JSON.stringify(transaction)}\nblockNumber = BlockTags.FINALIZED`, + [transaction, BlockTags.FINALIZED], + ], // blockNumber = Numbers [`${JSON.stringify(transaction)}\nblockNumber = "0x4b7"`, [transaction, '0x4b7']], [`${JSON.stringify(transaction)}\nblockNumber = 1207`, [transaction, 1207]], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/estimate_gas.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/estimate_gas.ts index 1f78413a656..2dfc07e11fd 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/estimate_gas.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/estimate_gas.ts @@ -62,6 +62,11 @@ export const testData: TestData[] = [ `${JSON.stringify(transaction)}\nblockNumber = BlockTags.PENDING`, [transaction, BlockTags.PENDING], ], + [`${JSON.stringify(transaction)}\nblockNumber = BlockTags.SAFE`, [transaction, BlockTags.SAFE]], + [ + `${JSON.stringify(transaction)}\nblockNumber = BlockTags.FINALIZED`, + [transaction, BlockTags.FINALIZED], + ], // blockNumber = Numbers [`${JSON.stringify(transaction)}\nblockNumber = "0x4b7"`, [transaction, '0x4b7']], [`${JSON.stringify(transaction)}\nblockNumber = 1207`, [transaction, 1207]], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_balance.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_balance.ts index d687354b4f9..6c933d470ea 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_balance.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_balance.ts @@ -32,6 +32,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [address, BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [address, BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [address, BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [address, BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [address, BlockTags.FINALIZED]], ['blockNumber = "0x4b7"', [address, '0x4b7']], ['blockNumber = 1207', [address, 1207]], ['blockNumber = "1207"', [address, '1207']], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block.ts index 55755902021..bf1d372c758 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block.ts @@ -103,6 +103,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST, hydrated = false', [BlockTags.LATEST, false]], ['blockNumber = BlockTags.EARLIEST, hydrated = false', [BlockTags.EARLIEST, false]], ['blockNumber = BlockTags.PENDING, hydrated = false', [BlockTags.PENDING, false]], + ['blockNumber = BlockTags.SAFE, hydrated = false', [BlockTags.SAFE, false]], + ['blockNumber = BlockTags.FINALIZED, hydrated = false', [BlockTags.FINALIZED, false]], // blockNumber = Numbers ['blockNumber = "0x4b7", hydrated = false', ['0x4b7', false]], ['blockNumber = 1207, hydrated = false', [1207, false]], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block_transaction_count.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block_transaction_count.ts index 4747a1eb2d1..5aacbfb7aec 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block_transaction_count.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block_transaction_count.ts @@ -49,6 +49,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [BlockTags.FINALIZED]], // blockNumber = Numbers ['blockNumber = "0x4b7"', ['0x4b7']], ['blockNumber = 1207', [1207]], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block_uncle_count.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block_uncle_count.ts index 4747a1eb2d1..5aacbfb7aec 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block_uncle_count.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_block_uncle_count.ts @@ -49,6 +49,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [BlockTags.FINALIZED]], // blockNumber = Numbers ['blockNumber = "0x4b7"', ['0x4b7']], ['blockNumber = 1207', [1207]], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_code.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_code.ts index 3122f74453c..d23918f3efa 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_code.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_code.ts @@ -34,6 +34,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [address, BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [address, BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [address, BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [address, BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [address, BlockTags.FINALIZED]], ['blockNumber = "0x4b7"', [address, '0x4b7']], ['blockNumber = 1207', [address, 1207]], ['blockNumber = "1207"', [address, '1207']], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_fee_history.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_fee_history.ts index bc29e8d006d..54ea874c610 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_fee_history.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_fee_history.ts @@ -65,6 +65,14 @@ export const testData: TestData[] = [ 'blockCount = "0x4b7", newestBlock = BlockTags.PENDING, rewardPercentiles = ["0x0"]', ['0x4b7', BlockTags.PENDING, ['0x0']], ], + [ + 'blockCount = "0x4b7", newestBlock = BlockTags.SAFE, rewardPercentiles = ["0x0"]', + ['0x4b7', BlockTags.SAFE, ['0x0']], + ], + [ + 'blockCount = "0x4b7", newestBlock = BlockTags.FINALIZED, rewardPercentiles = ["0x0"]', + ['0x4b7', BlockTags.FINALIZED, ['0x0']], + ], // blockNumber = Numbers [ 'blockCount = "0x4b7", newestBlock = 1207, rewardPercentiles = ["0x0"]', diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_proof.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_proof.ts index c29e1b58a53..57a0bfe988d 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_proof.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_proof.ts @@ -93,6 +93,14 @@ export const testData: TestData[] = [ 'blockNumber = BlockTags.PENDING', [address, ['0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8'], BlockTags.PENDING], ], + [ + 'blockNumber = BlockTags.SAFE', + [address, ['0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8'], BlockTags.SAFE], + ], + [ + 'blockNumber = BlockTags.FINALIZED', + [address, ['0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8'], BlockTags.FINALIZED], + ], // blockNumber = Numbers ['blockNumber = "0x4b7"', [address, ['0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8'], '0x4b7']], ['blockNumber = 1207', [address, ['0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8'], 1207]], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_storage_at.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_storage_at.ts index 7fef3e1ecf8..9afd4c3934c 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_storage_at.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_storage_at.ts @@ -48,6 +48,11 @@ export const testData: TestData[] = [ 'storageSlot = "0x4b7", blockNumber = BlockTags.PENDING', [address, '0x4b7', BlockTags.PENDING], ], + ['storageSlot = "0x4b7", blockNumber = BlockTags.SAFE', [address, '0x4b7', BlockTags.SAFE]], + [ + 'storageSlot = "0x4b7", blockNumber = BlockTags.FINALIZED', + [address, '0x4b7', BlockTags.FINALIZED], + ], ['storageSlot = "0x4b7", blockNumber = "0x4b7"', [address, '0x4b7', '0x4b7']], ['storageSlot = "0x4b7", blockNumber = 1207', [address, '0x4b7', 1207]], ['storageSlot = "0x4b7", blockNumber = "1207"', [address, '0x4b7', '1207']], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_transaction_count.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_transaction_count.ts index d687354b4f9..6c933d470ea 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_transaction_count.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_transaction_count.ts @@ -32,6 +32,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [address, BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [address, BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [address, BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [address, BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [address, BlockTags.FINALIZED]], ['blockNumber = "0x4b7"', [address, '0x4b7']], ['blockNumber = 1207', [address, 1207]], ['blockNumber = "1207"', [address, '1207']], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_transaction_from_block.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_transaction_from_block.ts index b607b6c8386..c66689f3602 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_transaction_from_block.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_transaction_from_block.ts @@ -70,6 +70,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST, transactionIndex = "0x0"', [BlockTags.LATEST, '0x0']], ['blockNumber = BlockTags.EARLIEST, transactionIndex = "0x0"', [BlockTags.EARLIEST, '0x0']], ['blockNumber = BlockTags.PENDING, transactionIndex = "0x0"', [BlockTags.PENDING, '0x0']], + ['blockNumber = BlockTags.SAFE, transactionIndex = "0x0"', [BlockTags.SAFE, '0x0']], + ['blockNumber = BlockTags.FINALIZED, transactionIndex = "0x0"', [BlockTags.FINALIZED, '0x0']], // blockNumber = Numbers, transactionIndex = HexString ['blockNumber = "0x4b7", transactionIndex = "0x0"', ['0x4b7', '0x0']], ['blockNumber = 1207, transactionIndex = "0x0"', [1207, '0x0']], @@ -100,6 +102,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST, transactionIndex = 0', [BlockTags.LATEST, 0]], ['blockNumber = BlockTags.EARLIEST, transactionIndex = 0', [BlockTags.EARLIEST, 0]], ['blockNumber = BlockTags.PENDING, transactionIndex = 0', [BlockTags.PENDING, 0]], + ['blockNumber = BlockTags.SAFE, transactionIndex = "0x0"', [BlockTags.SAFE, 0]], + ['blockNumber = BlockTags.FINALIZED, transactionIndex = "0x0"', [BlockTags.FINALIZED, 0]], // blockNumber = Numbers, transactionIndex = number ['blockNumber = "0x4b7"', ['0x4b7, transactionIndex = 0', 0]], ['blockNumber = 1207, transactionIndex = 0', [1207, 0]], @@ -130,6 +134,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST, transactionIndex = "0"', [BlockTags.LATEST, '0']], ['blockNumber = BlockTags.EARLIEST, transactionIndex = "0"', [BlockTags.EARLIEST, '0']], ['blockNumber = BlockTags.PENDING, transactionIndex = "0"', [BlockTags.PENDING, '0']], + ['blockNumber = BlockTags.SAFE, transactionIndex = "0x0"', [BlockTags.SAFE, '0']], + ['blockNumber = BlockTags.FINALIZED, transactionIndex = "0x0"', [BlockTags.FINALIZED, '0']], // blockNumber = Numbers, transactionIndex = NumberString ['blockNumber = "0x4b7", transactionIndex = "0"', ['0x4b7', '0']], ['blockNumber = 1207, transactionIndex = "0"', [1207, '0']], @@ -169,6 +175,14 @@ export const testData: TestData[] = [ 'blockNumber = BlockTags.PENDING, transactionIndex = BigInt("0x0")', [BlockTags.PENDING, BigInt('0x0')], ], + [ + 'blockNumber = BlockTags.SAFE, transactionIndex = BigInt("0x0")', + [BlockTags.SAFE, BigInt('0x0')], + ], + [ + 'blockNumber = BlockTags.FINALIZED, transactionIndex = BigInt("0x0")', + [BlockTags.FINALIZED, BigInt('0x0')], + ], // blockNumber = Numbers, transactionIndex = BigInt ['blockNumber = "0x4b7", transactionIndex = BigInt("0x0")', ['0x4b7', BigInt('0x0')]], ['blockNumber = 1207, transactionIndex = BigInt("0x0")', [1207, BigInt('0x0')]], diff --git a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_uncle.ts b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_uncle.ts index f2a57bc8085..46ae0db0f95 100644 --- a/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_uncle.ts +++ b/packages/web3-eth/test/unit/rpc_method_wrappers/fixtures/get_uncle.ts @@ -81,6 +81,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST, uncleIndex = "0x0"', [BlockTags.LATEST, '0x0']], ['blockNumber = BlockTags.EARLIEST, uncleIndex = "0x0"', [BlockTags.EARLIEST, '0x0']], ['blockNumber = BlockTags.PENDING, uncleIndex = "0x0"', [BlockTags.PENDING, '0x0']], + ['blockNumber = BlockTags.SAFE, uncleIndex = "0x0"', [BlockTags.SAFE, '0x0']], + ['blockNumber = BlockTags.FINALIZED, uncleIndex = "0x0"', [BlockTags.FINALIZED, '0x0']], // blockNumber = Numbers, uncleIndex = HexString ['blockNumber = "0x4b7", uncleIndex = "0x0"', ['0x4b7', '0x0']], ['blockNumber = 1207, uncleIndex = "0x0"', [1207, '0x0']], @@ -111,6 +113,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST, uncleIndex = 0', [BlockTags.LATEST, 0]], ['blockNumber = BlockTags.EARLIEST, uncleIndex = 0', [BlockTags.EARLIEST, 0]], ['blockNumber = BlockTags.PENDING, uncleIndex = 0', [BlockTags.PENDING, 0]], + ['blockNumber = BlockTags.SAFE, uncleIndex = 0', [BlockTags.SAFE, 0]], + ['blockNumber = BlockTags.FINALIZED, uncleIndex = 0', [BlockTags.FINALIZED, 0]], // blockNumber = Numbers, uncleIndex = number ['blockNumber = "0x4b7"', ['0x4b7, uncleIndex = 0', 0]], ['blockNumber = 1207, uncleIndex = 0', [1207, 0]], @@ -141,6 +145,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST, uncleIndex = "0"', [BlockTags.LATEST, '0']], ['blockNumber = BlockTags.EARLIEST, uncleIndex = "0"', [BlockTags.EARLIEST, '0']], ['blockNumber = BlockTags.PENDING, uncleIndex = "0"', [BlockTags.PENDING, '0']], + ['blockNumber = BlockTags.SAFE, uncleIndex = "0"', [BlockTags.SAFE, '0']], + ['blockNumber = BlockTags.FINALIZED, uncleIndex = "0"', [BlockTags.FINALIZED, '0']], // blockNumber = Numbers, uncleIndex = NumberString ['blockNumber = "0x4b7", uncleIndex = "0"', ['0x4b7', '0']], ['blockNumber = 1207, uncleIndex = "0"', [1207, '0']], @@ -180,6 +186,11 @@ export const testData: TestData[] = [ 'blockNumber = BlockTags.PENDING, uncleIndex = BigInt("0x0")', [BlockTags.PENDING, BigInt('0x0')], ], + ['blockNumber = BlockTags.SAFE, uncleIndex = BigInt("0x0")', [BlockTags.SAFE, BigInt('0x0')]], + [ + 'blockNumber = BlockTags.FINALIZED, uncleIndex = BigInt("0x0")', + [BlockTags.FINALIZED, BigInt('0x0')], + ], // blockNumber = Numbers, uncleIndex = BigInt ['blockNumber = "0x4b7", uncleIndex = BigInt("0x0")', ['0x4b7', BigInt('0x0')]], ['blockNumber = 1207, uncleIndex = BigInt("0x0")', [1207, BigInt('0x0')]], diff --git a/packages/web3-rpc-methods/CHANGELOG.md b/packages/web3-rpc-methods/CHANGELOG.md index b3878311e7b..d8122c0f0db 100644 --- a/packages/web3-rpc-methods/CHANGELOG.md +++ b/packages/web3-rpc-methods/CHANGELOG.md @@ -64,3 +64,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `createAccessList` functionality ( #5780 ) +- Added support of `safe` and `finalized` block tags (#5823) diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/call.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/call.ts index 33d5decd414..327a79fb8ba 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/call.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/call.ts @@ -52,5 +52,10 @@ export const testData: TestData[] = [ `${JSON.stringify(transaction)}\nblockNumber = BlockTags.PENDING`, [transaction, BlockTags.PENDING], ], + [`${JSON.stringify(transaction)}\nblockNumber = BlockTags.SAFE`, [transaction, BlockTags.SAFE]], + [ + `${JSON.stringify(transaction)}\nblockNumber = BlockTags.FINALIZED`, + [transaction, BlockTags.FINALIZED], + ], [`${JSON.stringify(transaction)}\nblockNumber = "0x4b7"`, [transaction, '0x4b7']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/createAccessList.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/createAccessList.ts index 65e809bc504..536b6781b93 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/createAccessList.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/createAccessList.ts @@ -46,5 +46,10 @@ export const testData: TestData[] = [ [`${JSON.stringify(callObj)}\nblockNumber = BlockTags.LATEST`, [callObj, BlockTags.LATEST]], [`${JSON.stringify(callObj)}\nblockNumber = BlockTags.EARLIEST`, [callObj, BlockTags.EARLIEST]], [`${JSON.stringify(callObj)}\nblockNumber = BlockTags.PENDING`, [callObj, BlockTags.PENDING]], + [`${JSON.stringify(callObj)}\nblockNumber = BlockTags.SAFE`, [callObj, BlockTags.SAFE]], + [ + `${JSON.stringify(callObj)}\nblockNumber = BlockTags.FINALIZED`, + [callObj, BlockTags.FINALIZED], + ], [`${JSON.stringify(callObj)}\nblockNumber = "0x4b7"`, [callObj, '0x4b7']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/estimate_gas.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/estimate_gas.ts index e41e11faabd..62f547eaa8b 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/estimate_gas.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/estimate_gas.ts @@ -53,5 +53,10 @@ export const testData: TestData[] = [ `${JSON.stringify(transaction)}\nblockNumber = BlockTags.PENDING`, [transaction, BlockTags.PENDING], ], + [`${JSON.stringify(transaction)}\nblockNumber = BlockTags.SAFE`, [transaction, BlockTags.SAFE]], + [ + `${JSON.stringify(transaction)}\nblockNumber = BlockTags.FINALIZED`, + [transaction, BlockTags.FINALIZED], + ], [`${JSON.stringify(transaction)}\nblockNumber = "0x4b7"`, [transaction, '0x4b7']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_balance.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_balance.ts index bbb5147b559..bd9a6247798 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_balance.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_balance.ts @@ -32,5 +32,7 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [address, BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [address, BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [address, BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [address, BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [address, BlockTags.FINALIZED]], ['blockNumber = "0x4b7"', [address, '0x4b7']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_block_by_number.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_block_by_number.ts index e4a85204ebf..421894fdbb7 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_block_by_number.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_block_by_number.ts @@ -34,5 +34,7 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [BlockTags.LATEST, true]], ['blockNumber = BlockTags.EARLIEST', [BlockTags.EARLIEST, true]], ['blockNumber = BlockTags.PENDING', [BlockTags.PENDING, true]], + ['blockNumber = BlockTags.SAFE', [BlockTags.SAFE, true]], + ['blockNumber = BlockTags.FINALIZED', [BlockTags.FINALIZED, true]], ['blockNumber = "0x4b7"', ['0x4b7', true]], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_block_transaction_count_by_number.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_block_transaction_count_by_number.ts index 41200c9b427..8bd2e8a04bb 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_block_transaction_count_by_number.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_block_transaction_count_by_number.ts @@ -27,5 +27,7 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [BlockTags.FINALIZED]], ['blockNumber = "0x4b7"', ['0x4b7']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_code.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_code.ts index c1d52fce751..78f2161f288 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_code.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_code.ts @@ -33,6 +33,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [address, BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [address, BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [address, BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [address, BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [address, BlockTags.FINALIZED]], // blockNumber = Numbers ['blockNumber = "0x4b7"', [address, '0x4b7']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_fee_history.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_fee_history.ts index 2dd72a97a76..c7791a1fb34 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_fee_history.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_fee_history.ts @@ -42,5 +42,10 @@ export const testData: TestData[] = [ 'blockCount = "0x88df016", newestBlock = BlockTags.PENDING', ['0x88df016', BlockTags.PENDING, []], ], + ['blockCount = "0x88df016", newestBlock = BlockTags.SAFE', ['0x88df016', BlockTags.SAFE, []]], + [ + 'blockCount = "0x88df016", newestBlock = BlockTags.FINALIZED', + ['0x88df016', BlockTags.FINALIZED, []], + ], ['blockCount = "0x88df016", newestBlock = "0x4b7"', ['0x88df016', '0x4b7', []]], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_storage_at.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_storage_at.ts index 23c01cfcce6..a098e4e7b74 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_storage_at.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_storage_at.ts @@ -40,5 +40,10 @@ export const testData: TestData[] = [ 'storageSlot = "0x4b7", blockNumber = BlockTags.PENDING', [address, '0x4b7', BlockTags.PENDING], ], + ['storageSlot = "0x4b7", blockNumber = BlockTags.SAFE', [address, '0x4b7', BlockTags.SAFE]], + [ + 'storageSlot = "0x4b7", blockNumber = BlockTags.FINALIZED', + [address, '0x4b7', BlockTags.FINALIZED], + ], ['storageSlot = "0x4b7", blockNumber = "0x4b7"', [address, '0x4b7', '0x4b7']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_transaction_by_block_number_and_index.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_transaction_by_block_number_and_index.ts index 8b6e709be95..006b65f6825 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_transaction_by_block_number_and_index.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_transaction_by_block_number_and_index.ts @@ -32,5 +32,7 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [BlockTags.LATEST, '0x88df016']], ['blockNumber = BlockTags.EARLIEST', [BlockTags.EARLIEST, '0x88df016']], ['blockNumber = BlockTags.PENDING', [BlockTags.PENDING, '0x88df016']], + ['blockNumber = BlockTags.SAFE', [BlockTags.SAFE, '0x88df016']], + ['blockNumber = BlockTags.FINALIZED', [BlockTags.FINALIZED, '0x88df016']], ['blockNumber = "0x4b7"', ['0x4b7', '0x88df016']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_transaction_count.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_transaction_count.ts index 18c472568c8..78b2e69f4bb 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_transaction_count.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_transaction_count.ts @@ -32,5 +32,7 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [address, BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [address, BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [address, BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [address, BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [address, BlockTags.FINALIZED]], ['blockNumber = "0x4b7"', [address, '0x4b7']], ]; diff --git a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_uncle_count_by_block_number.ts b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_uncle_count_by_block_number.ts index 2e010f371fc..40a2dfdf1d2 100644 --- a/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_uncle_count_by_block_number.ts +++ b/packages/web3-rpc-methods/test/unit/eth_rpc_methods/fixtures/get_uncle_count_by_block_number.ts @@ -30,6 +30,8 @@ export const testData: TestData[] = [ ['blockNumber = BlockTags.LATEST', [BlockTags.LATEST]], ['blockNumber = BlockTags.EARLIEST', [BlockTags.EARLIEST]], ['blockNumber = BlockTags.PENDING', [BlockTags.PENDING]], + ['blockNumber = BlockTags.SAFE', [BlockTags.SAFE]], + ['blockNumber = BlockTags.FINALIZED', [BlockTags.FINALIZED]], // blockNumber = Numbers ['blockNumber = "0x4b7"', ['0x4b7']], ]; diff --git a/packages/web3-types/CHANGELOG.md b/packages/web3-types/CHANGELOG.md index d3c3471488f..49de1e86bc4 100644 --- a/packages/web3-types/CHANGELOG.md +++ b/packages/web3-types/CHANGELOG.md @@ -76,3 +76,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added types from `web3-eth-abi` and `TypedArray` from (#5771) - Added `TypedArray` from `web3-utils` and `web3-validator` (it was defined twice) (#5771) +- Added `safe` and `finalized` block tags in `BlockTags` and `BlockTag` types (#5823) diff --git a/packages/web3-types/src/eth_types.ts b/packages/web3-types/src/eth_types.ts index ac2732fe6ed..3115d96c99c 100644 --- a/packages/web3-types/src/eth_types.ts +++ b/packages/web3-types/src/eth_types.ts @@ -45,8 +45,11 @@ export enum BlockTags { EARLIEST = 'earliest', LATEST = 'latest', PENDING = 'pending', + SAFE = 'safe', + FINALIZED = 'finalized', } -export type BlockTag = 'earliest' | 'latest' | 'pending'; +export type BlockTag = `${BlockTags}`; + export type BlockNumberOrTag = Numbers | BlockTag; export interface Proof { diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index 8991fc6b2bd..f42c77cdd61 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -77,3 +77,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - Moved `TypedArray` to `web3-types` (was also duplicated at `web3-validator`) (#5771) +- Removed support of `genesis` tag in `compareBlockNumbers` function (#5823) + +### Added + +- Added support of `safe` and `finalized` block tags (#5823) + diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index 5f6751a3168..9aebbcc3814 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -28,8 +28,9 @@ import { isTopicInBloom as isTopicInBloomValidator, isUserEthereumAddressInBloom as isUserEthereumAddressInBloomValidator, isNullish as isNullishValidator, + isBlockTag, } from 'web3-validator'; -import { Numbers } from 'web3-types'; +import { BlockNumberOrTag } from 'web3-types'; /** * @deprecated Will be removed in next release. Please use `web3-validator` package instead. @@ -107,49 +108,39 @@ export const isTopicInBloom = isTopicInBloomValidator; * Compares between block A and block B * Returns -1 if a \< b, returns 1 if a \> b and returns 0 if a == b */ -export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { +export const compareBlockNumbers = (blockA: BlockNumberOrTag, blockB: BlockNumberOrTag) => { // string validation - if ( - typeof blockA === 'string' && - !( - blockA === 'genesis' || - blockA === 'earliest' || - blockA === 'pending' || - blockA === 'latest' - ) - ) - throw new InvalidBlockError(blockA); - if ( - typeof blockB === 'string' && - !( - blockB === 'genesis' || - blockB === 'earliest' || - blockB === 'pending' || - blockB === 'latest' - ) - ) - throw new InvalidBlockError(blockB); + if (blockA === 'genesis' || blockB === 'genesis') + throw new InvalidBlockError('Genesis tag not supported'); // for more specific error message + if (typeof blockA === 'string' && !isBlockTag(blockA)) throw new InvalidBlockError(blockA); + if (typeof blockB === 'string' && !isBlockTag(blockB)) throw new InvalidBlockError(blockB); + + // Increasing order: earliest, finalized , safe, latest, pending + // safe vs block-num cant be compared as block number provided can be on left or right side of safe tag, until safe tag block number is extracted and compared + if ( blockA === blockB || - ((blockA === 'genesis' || blockA === 'earliest' || blockA === 0) && - (blockB === 'genesis' || blockB === 'earliest' || blockB === 0)) - ) + ((blockA === 'earliest' || blockA === 0) && (blockB === 'earliest' || blockB === 0)) + ) { return 0; - - // b !== a, thus a < b - if (blockA === 'genesis' || blockA === 'earliest') return -1; - - // b !== a, thus a > b - if (blockB === 'genesis' || blockB === 'earliest') return 1; - - if (blockA === 'latest') { - if (blockB === 'pending') { + } + if (blockA === 'earliest' || blockA === 0) { + // b !== a, thus a < b + return -1; + } + if (blockB === 'earliest' || blockB === 0) { + // b !== a, thus a > b + return 1; + } + if (blockA === 'latest' || blockA === 'safe') { + if (blockB === 'pending' || blockB === 'latest') { return -1; - } // b !== ("pending" OR "latest"), thus a > b + } + // b !== ("pending" OR "latest"), thus a > b return 1; } - if (blockB === 'latest') { - if (blockA === 'pending') { + if (blockB === 'latest' || blockB === 'safe') { + if (blockA === 'pending' || blockA === 'latest') { return 1; } // b !== ("pending" OR "latest"), thus a > b @@ -162,8 +153,17 @@ export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { if (blockB === 'pending') { return -1; } + + if (blockA === 'finalized' || blockB === 'finalized') { + // either a or b is "finalized" and the other one did not fall into any of the conditions above, so the other one is a number + throw new InvalidBlockError( + `Cannot compare finalized tag with ${blockA === 'finalized' ? blockB : blockA}`, + ); + } + const bigIntA = BigInt(blockA); const bigIntB = BigInt(blockB); + if (bigIntA < bigIntB) { return -1; } diff --git a/packages/web3-utils/test/fixtures/validation.ts b/packages/web3-utils/test/fixtures/validation.ts index 6b19273ef78..b7f194fcfad 100644 --- a/packages/web3-utils/test/fixtures/validation.ts +++ b/packages/web3-utils/test/fixtures/validation.ts @@ -28,16 +28,12 @@ export const compareBlockNumbersValidData: [[Numbers, Numbers], number][] = [ [[1, BigInt(1)], 0], [[1, BigInt(2)], -1], [[2, BigInt(1)], 1], - [['genesis', 'earliest'], 0], - [['genesis', 0], 0], + [['earliest', 0], 0], [['pending', 'pending'], 0], [['latest', 'latest'], 0], [['earliest', 2], -1], [['earliest', 'pending'], -1], - [['genesis', 2], -1], - [['genesis', 'latest'], -1], - [['genesis', 'pending'], -1], [[BigInt('9007199254740992'), BigInt('9007199254740991')], 1], [[13532346, 13532300], 1], [['pending', 'latest'], 1], @@ -45,11 +41,28 @@ export const compareBlockNumbersValidData: [[Numbers, Numbers], number][] = [ [['latest', BigInt(1)], 1], [['pending', 0], 1], [['pending', BigInt(1)], 1], + [['safe', 'safe'], 0], + [['earliest', 'safe'], -1], + [['safe', 0], 1], + [[0, 'safe'], -1], + [['safe', 'pending'], -1], + [['pending', 'safe'], 1], + [['finalized', 'finalized'], 0], + [['earliest', 'finalized'], -1], + [['finalized', 0], 1], + [['finalized', 'pending'], -1], + [[0, 'finalized'], -1], + [['pending', 'finalized'], 1], + [['safe', 'latest'], -1], + [['latest', 'safe'], 1], ]; export const compareBlockNumbersInvalidData: [[Numbers, Numbers], InvalidBlockError][] = [ [['pending', 'unknown'], new InvalidBlockError('unknown')], [['', 'pending'], new InvalidBlockError('')], + [[22, 'finalized'], new InvalidBlockError('Cannot compare finalized tag with 22')], + [['finalized', 22], new InvalidBlockError('Cannot compare finalized tag with 22')], + [['genesis', 'finalized'], new InvalidBlockError('Genesis tag not supported')], ]; export const isBloomValidData: [any, true][] = [ diff --git a/packages/web3-validator/CHANGELOG.md b/packages/web3-validator/CHANGELOG.md index 1064ddba96d..47f6084c27a 100644 --- a/packages/web3-validator/CHANGELOG.md +++ b/packages/web3-validator/CHANGELOG.md @@ -74,3 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - Moved `TypedArray` to `web3-types` (was also duplicated at `web3-utils`) (#5771) + +### Added + +- Added support of `safe` and `finalized` block tags in `isBlockTag` method (#5823) diff --git a/packages/web3-validator/src/validation/block.ts b/packages/web3-validator/src/validation/block.ts index 64ec1ce0876..8a988a65bcc 100644 --- a/packages/web3-validator/src/validation/block.ts +++ b/packages/web3-validator/src/validation/block.ts @@ -21,10 +21,9 @@ import { isUInt } from './numbers'; export const isBlockNumber = (value: string | number | bigint): boolean => isUInt(value); /** - * Returns true if the given blockNumber is 'latest', 'pending', or 'earliest. + * Returns true if the given blockNumber is 'latest', 'pending', 'earliest, 'safe' or 'finalized' */ -export const isBlockTag = (value: string) => - BlockTags.LATEST === value || BlockTags.PENDING === value || BlockTags.EARLIEST === value; +export const isBlockTag = (value: string) => Object.values(BlockTags).includes(value as BlockTags); /** * Returns true if given value is valid hex string and not negative, or is a valid BlockTag