From 7478ee232d8c6e5683f8a2a08a3af5cafe2bc51c Mon Sep 17 00:00:00 2001 From: jdevcs Date: Tue, 7 Feb 2023 12:15:37 +0100 Subject: [PATCH 01/17] finalized and safe tags --- packages/web3-types/src/eth_types.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/web3-types/src/eth_types.ts b/packages/web3-types/src/eth_types.ts index ac2732fe6ed..b1477126e72 100644 --- a/packages/web3-types/src/eth_types.ts +++ b/packages/web3-types/src/eth_types.ts @@ -45,8 +45,10 @@ export enum BlockTags { EARLIEST = 'earliest', LATEST = 'latest', PENDING = 'pending', + SAFE = `safe`, + FINALIZED = `finalized`, } -export type BlockTag = 'earliest' | 'latest' | 'pending'; +export type BlockTag = keyof typeof BlockTags; export type BlockNumberOrTag = Numbers | BlockTag; export interface Proof { From 057b52645cb77ec0bfdf924e44c14410e997a0f4 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Wed, 8 Feb 2023 17:06:48 +0100 Subject: [PATCH 02/17] doc updates --- packages/web3-core/src/web3_config.ts | 2 ++ packages/web3-eth-contract/src/types.ts | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) 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/src/types.ts b/packages/web3-eth-contract/src/types.ts index 2a7110ef2f7..2b7761d2b78 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; /** @@ -232,7 +232,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. */ @@ -351,7 +351,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 @@ -422,7 +422,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( @@ -540,7 +540,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 From c34099803892a8487a2b531425346b7100018de0 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Wed, 8 Feb 2023 17:07:16 +0100 Subject: [PATCH 03/17] block tag tests --- .../integration/block/rpc.getBlock.test.ts | 13 ++++++++- .../rpc.getBlockTransactionCount.test.ts | 29 +++++++++++++++++-- .../block/rpc.getBlockUncleCount.test.ts | 23 +++++++++++++-- .../block/rpc.getTransactionFromBlock.test.ts | 4 +++ .../integration/block/rpc.getUncle.test.ts | 8 +++-- .../test/integration/defaults.test.ts | 10 +++++++ 6 files changed, 79 insertions(+), 8 deletions(-) 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..46128f05ff8 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,7 +103,14 @@ 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; }>({ 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', From 7247ae615b979afa0c24403a24167b786dc4e774 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Wed, 8 Feb 2023 17:10:01 +0100 Subject: [PATCH 04/17] test fixtures --- .../web3_eth_methods_with_parameters.ts | 296 ++++++++++++++++++ 1 file changed, 296 insertions(+) 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 [ [ From 0fa84d88b113771a2d881019d26c48245df06ea7 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Wed, 8 Feb 2023 17:10:57 +0100 Subject: [PATCH 05/17] types optimization --- packages/web3-types/src/eth_types.ts | 3 ++- packages/web3-validator/src/validation/block.ts | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/web3-types/src/eth_types.ts b/packages/web3-types/src/eth_types.ts index b1477126e72..a89fc5e03f9 100644 --- a/packages/web3-types/src/eth_types.ts +++ b/packages/web3-types/src/eth_types.ts @@ -48,7 +48,8 @@ export enum BlockTags { SAFE = `safe`, FINALIZED = `finalized`, } -export type BlockTag = keyof typeof BlockTags; +export type BlockTag = `${BlockTags}`; + export type BlockNumberOrTag = Numbers | BlockTag; export interface Proof { 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 From 25d9b6905861ff3b7fce903f6c2afe7768abb1d7 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Wed, 8 Feb 2023 17:16:07 +0100 Subject: [PATCH 06/17] updated validation of blocks comp --- packages/web3-utils/src/validation.ts | 62 +++++++++++++-------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index 5f6751a3168..adc0d2e4669 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -28,6 +28,7 @@ import { isTopicInBloom as isTopicInBloomValidator, isUserEthereumAddressInBloom as isUserEthereumAddressInBloomValidator, isNullish as isNullishValidator, + isBlockTag, } from 'web3-validator'; import { Numbers } from 'web3-types'; @@ -109,46 +110,38 @@ export const isTopicInBloom = isTopicInBloomValidator; */ export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { // string validation - if ( - typeof blockA === 'string' && - !( - blockA === 'genesis' || - blockA === 'earliest' || - blockA === 'pending' || - blockA === 'latest' - ) - ) + if (typeof blockA === 'string' && !(isBlockTag(blockA) || blockA === 'genesis')) throw new InvalidBlockError(blockA); - if ( - typeof blockB === 'string' && - !( - blockB === 'genesis' || - blockB === 'earliest' || - blockB === 'pending' || - blockB === 'latest' - ) - ) + if (typeof blockB === 'string' && !(isBlockTag(blockB) || blockB === 'genesis')) throw new InvalidBlockError(blockB); + + // Increasing order: (genesis = earliest), safe, (finalized ~ 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) { + return 0; + } if ( - blockA === blockB || - ((blockA === 'genesis' || blockA === 'earliest' || blockA === 0) && - (blockB === 'genesis' || blockB === 'earliest' || blockB === 0)) - ) + (blockA === 'genesis' || blockA === 'earliest' || blockA === 0) && + (blockB === 'genesis' || 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 (blockA === 'genesis' || blockA === 'earliest' || blockA === 0) { + // b !== a, thus a < b + return -1; + } + if (blockB === 'genesis' || blockB === 'earliest' || blockB === 0) { + // b !== a, thus a > b + return 1; + } + if (blockA === 'latest' || blockA === 'finalized') { if (blockB === 'pending') { return -1; - } // b !== ("pending" OR "latest"), thus a > b + } + // b !== ("pending" OR "latest"), thus a > b return 1; } - if (blockB === 'latest') { + if (blockB === 'latest' || blockB === 'finalized') { if (blockA === 'pending') { return 1; } @@ -162,6 +155,11 @@ export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { if (blockB === 'pending') { return -1; } + if (blockA === 'safe' || blockB === 'safe') { + // either a or b is "safe" and the other one did not fall into any of the conditions above, so the other one is a number + return undefined; + } + const bigIntA = BigInt(blockA); const bigIntB = BigInt(blockB); if (bigIntA < bigIntB) { From b7e740cd695b43a61f449c3fd602adf192f755a1 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Thu, 9 Feb 2023 16:26:33 +0100 Subject: [PATCH 07/17] modified tests and added tests data --- .../test/integration/block/rpc.getBlock.test.ts | 2 +- .../test/unit/rpc_method_wrappers/fixtures/call.ts | 5 +++++ .../fixtures/createAccessList.ts | 5 +++++ .../rpc_method_wrappers/fixtures/estimate_gas.ts | 5 +++++ .../rpc_method_wrappers/fixtures/get_balance.ts | 2 ++ .../unit/rpc_method_wrappers/fixtures/get_block.ts | 2 ++ .../fixtures/get_block_transaction_count.ts | 2 ++ .../fixtures/get_block_uncle_count.ts | 2 ++ .../unit/rpc_method_wrappers/fixtures/get_code.ts | 2 ++ .../fixtures/get_fee_history.ts | 8 ++++++++ .../unit/rpc_method_wrappers/fixtures/get_proof.ts | 8 ++++++++ .../rpc_method_wrappers/fixtures/get_storage_at.ts | 5 +++++ .../fixtures/get_transaction_count.ts | 2 ++ .../fixtures/get_transaction_from_block.ts | 14 ++++++++++++++ .../unit/rpc_method_wrappers/fixtures/get_uncle.ts | 11 +++++++++++ .../test/unit/eth_rpc_methods/fixtures/call.ts | 5 +++++ .../eth_rpc_methods/fixtures/createAccessList.ts | 5 +++++ .../unit/eth_rpc_methods/fixtures/estimate_gas.ts | 5 +++++ .../unit/eth_rpc_methods/fixtures/get_balance.ts | 2 ++ .../fixtures/get_block_by_number.ts | 2 ++ .../get_block_transaction_count_by_number.ts | 2 ++ .../test/unit/eth_rpc_methods/fixtures/get_code.ts | 2 ++ .../eth_rpc_methods/fixtures/get_fee_history.ts | 5 +++++ .../eth_rpc_methods/fixtures/get_storage_at.ts | 5 +++++ .../get_transaction_by_block_number_and_index.ts | 2 ++ .../fixtures/get_transaction_count.ts | 2 ++ .../fixtures/get_uncle_count_by_block_number.ts | 2 ++ 27 files changed, 113 insertions(+), 1 deletion(-) 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 46128f05ff8..01fbb12aab5 100644 --- a/packages/web3-eth/test/integration/block/rpc.getBlock.test.ts +++ b/packages/web3-eth/test/integration/block/rpc.getBlock.test.ts @@ -114,7 +114,7 @@ describe('rpc with block', () => { 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/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/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']], ]; From 3fd86f7a97bc78e442b7b8b68a1b2e67cfd73d0e Mon Sep 17 00:00:00 2001 From: jdevcs Date: Thu, 9 Feb 2023 16:47:35 +0100 Subject: [PATCH 08/17] blocks validation updated --- packages/web3-utils/src/validation.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index adc0d2e4669..f8bd242fd68 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -117,20 +117,19 @@ export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { // Increasing order: (genesis = earliest), safe, (finalized ~ 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) { - return 0; - } + if ( - (blockA === 'genesis' || blockA === 'earliest' || blockA === 0) && - (blockB === 'genesis' || blockB === 'earliest' || blockB === 0) + blockA === blockB || + ((blockA === 'genesis' || blockA === 'earliest' || blockA === 0) && + (blockB === 'genesis' || blockB === 'earliest' || blockB === 0)) ) { return 0; } - if (blockA === 'genesis' || blockA === 'earliest' || blockA === 0) { + if (blockA === 'genesis' || blockA === 'earliest') { // b !== a, thus a < b return -1; } - if (blockB === 'genesis' || blockB === 'earliest' || blockB === 0) { + if (blockB === 'genesis' || blockB === 'earliest') { // b !== a, thus a > b return 1; } From 4a5ce0a4660f3bc5dc5da165fecaf71e31787f35 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Thu, 9 Feb 2023 17:37:54 +0100 Subject: [PATCH 09/17] updated compareBlockNumbers and added tests --- packages/web3-utils/src/validation.ts | 11 ++++++++++- .../web3-utils/test/fixtures/validation.ts | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index f8bd242fd68..e46a45d56be 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -154,13 +154,22 @@ export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { if (blockB === 'pending') { return -1; } + if (blockA === 'safe' && blockB === 0) { + return 1; + } + if (blockA === 0 && blockB === 'safe') { + return -1; + } if (blockA === 'safe' || blockB === 'safe') { // either a or b is "safe" and the other one did not fall into any of the conditions above, so the other one is a number - return undefined; + throw new InvalidBlockError( + `Cannot compare safe tag with ${blockA === 'safe' ? 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..4651bbdd7f1 100644 --- a/packages/web3-utils/test/fixtures/validation.ts +++ b/packages/web3-utils/test/fixtures/validation.ts @@ -45,11 +45,29 @@ export const compareBlockNumbersValidData: [[Numbers, Numbers], number][] = [ [['latest', BigInt(1)], 1], [['pending', 0], 1], [['pending', BigInt(1)], 1], + [['safe', 'safe'], 0], + [['earliest', 'safe'], -1], + [['genesis', 'safe'], -1], + [['safe', 0], 1], + [[0, 'safe'], -1], + [['safe', 'pending'], -1], + [['pending', 'safe'], 1], + [['finalized', 'finalized'], 0], + [['earliest', 'finalized'], -1], + [['genesis', 'finalized'], -1], + [['finalized', 0], 1], + [['finalized', BigInt('1')], 1], + [['finalized', 'pending'], -1], + [[0, 'finalized'], -1], + [[BigInt('1'), 'finalized'], -1], + [['pending', 'finalized'], 1], ]; export const compareBlockNumbersInvalidData: [[Numbers, Numbers], InvalidBlockError][] = [ [['pending', 'unknown'], new InvalidBlockError('unknown')], [['', 'pending'], new InvalidBlockError('')], + [[22, 'safe'], new InvalidBlockError('Cannot compare safe tag with 22')], + [['safe', 22], new InvalidBlockError('Cannot compare safe tag with 22')], ]; export const isBloomValidData: [any, true][] = [ From 5255a96a436e800ede2474c7d06db55aeccae147 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Thu, 9 Feb 2023 17:44:25 +0100 Subject: [PATCH 10/17] change log updates --- packages/web3-core/CHANGELOG.md | 1 + packages/web3-eth-contract/CHANGELOG.md | 1 + packages/web3-eth/CHANGELOG.md | 1 + packages/web3-rpc-methods/CHANGELOG.md | 1 + packages/web3-types/CHANGELOG.md | 1 + packages/web3-utils/CHANGELOG.md | 1 + packages/web3-validator/CHANGELOG.md | 1 + 7 files changed, 7 insertions(+) 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-eth-contract/CHANGELOG.md b/packages/web3-eth-contract/CHANGELOG.md index ce09d2e910f..9505aab9db5 100644 --- a/packages/web3-eth-contract/CHANGELOG.md +++ b/packages/web3-eth-contract/CHANGELOG.md @@ -223,3 +223,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/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-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-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-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index 8991fc6b2bd..ef425212e9e 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -77,3 +77,4 @@ 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) +- Added support of `safe` and `finalized` block tags (#5823) diff --git a/packages/web3-validator/CHANGELOG.md b/packages/web3-validator/CHANGELOG.md index 1064ddba96d..deca39cf7b7 100644 --- a/packages/web3-validator/CHANGELOG.md +++ b/packages/web3-validator/CHANGELOG.md @@ -74,3 +74,4 @@ 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 support of `safe` and `finalized` block tags in isBlockTag method (#5823) From dc61466e2a36eda10946b8f0be290e8a51d57eec Mon Sep 17 00:00:00 2001 From: jdevcs Date: Fri, 10 Feb 2023 19:10:56 +0100 Subject: [PATCH 11/17] updated same style --- packages/web3-types/src/eth_types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/web3-types/src/eth_types.ts b/packages/web3-types/src/eth_types.ts index a89fc5e03f9..3115d96c99c 100644 --- a/packages/web3-types/src/eth_types.ts +++ b/packages/web3-types/src/eth_types.ts @@ -45,8 +45,8 @@ export enum BlockTags { EARLIEST = 'earliest', LATEST = 'latest', PENDING = 'pending', - SAFE = `safe`, - FINALIZED = `finalized`, + SAFE = 'safe', + FINALIZED = 'finalized', } export type BlockTag = `${BlockTags}`; From 9dc7f1e681ba26691244360b5fd2928e6f0163cf Mon Sep 17 00:00:00 2001 From: jdevcs Date: Mon, 13 Feb 2023 11:56:58 +0100 Subject: [PATCH 12/17] removed genesis tag support and updated test data --- packages/web3-utils/src/validation.ts | 17 ++++++++--------- packages/web3-utils/test/fixtures/validation.ts | 9 ++------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index e46a45d56be..1835b29c7d0 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -110,26 +110,25 @@ export const isTopicInBloom = isTopicInBloomValidator; */ export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { // string validation - if (typeof blockA === 'string' && !(isBlockTag(blockA) || blockA === 'genesis')) - throw new InvalidBlockError(blockA); - if (typeof blockB === 'string' && !(isBlockTag(blockB) || blockB === 'genesis')) - 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: (genesis = earliest), safe, (finalized ~ latest), pending + // Increasing order: earliest, safe, (finalized ~ 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; } - if (blockA === 'genesis' || blockA === 'earliest') { + if (blockA === 'earliest') { // b !== a, thus a < b return -1; } - if (blockB === 'genesis' || blockB === 'earliest') { + if (blockB === 'earliest') { // b !== a, thus a > b return 1; } diff --git a/packages/web3-utils/test/fixtures/validation.ts b/packages/web3-utils/test/fixtures/validation.ts index 4651bbdd7f1..7a8d8522326 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], @@ -47,14 +43,12 @@ export const compareBlockNumbersValidData: [[Numbers, Numbers], number][] = [ [['pending', BigInt(1)], 1], [['safe', 'safe'], 0], [['earliest', 'safe'], -1], - [['genesis', 'safe'], -1], [['safe', 0], 1], [[0, 'safe'], -1], [['safe', 'pending'], -1], [['pending', 'safe'], 1], [['finalized', 'finalized'], 0], [['earliest', 'finalized'], -1], - [['genesis', 'finalized'], -1], [['finalized', 0], 1], [['finalized', BigInt('1')], 1], [['finalized', 'pending'], -1], @@ -68,6 +62,7 @@ export const compareBlockNumbersInvalidData: [[Numbers, Numbers], InvalidBlockEr [['', 'pending'], new InvalidBlockError('')], [[22, 'safe'], new InvalidBlockError('Cannot compare safe tag with 22')], [['safe', 22], new InvalidBlockError('Cannot compare safe tag with 22')], + [['genesis', 'finalized'], new InvalidBlockError('Genesis tag not supported')], ]; export const isBloomValidData: [any, true][] = [ From 0ec33dd54185ac12b16da62c6b889336f9c8b471 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Mon, 13 Feb 2023 11:57:11 +0100 Subject: [PATCH 13/17] updated changelog --- packages/web3-utils/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/web3-utils/CHANGELOG.md b/packages/web3-utils/CHANGELOG.md index ef425212e9e..f42c77cdd61 100644 --- a/packages/web3-utils/CHANGELOG.md +++ b/packages/web3-utils/CHANGELOG.md @@ -77,4 +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) + From e57fc1340416af4f696f7fb294b1107b8f3b8938 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Mon, 13 Feb 2023 12:03:12 +0100 Subject: [PATCH 14/17] update changelog --- packages/web3-validator/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/web3-validator/CHANGELOG.md b/packages/web3-validator/CHANGELOG.md index deca39cf7b7..5421991ec9c 100644 --- a/packages/web3-validator/CHANGELOG.md +++ b/packages/web3-validator/CHANGELOG.md @@ -74,4 +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) From 97abd3676d8ee4935ffbbe7bda31076ec89d749d Mon Sep 17 00:00:00 2001 From: jdevcs Date: Mon, 13 Feb 2023 12:04:10 +0100 Subject: [PATCH 15/17] changelog update --- packages/web3-validator/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-validator/CHANGELOG.md b/packages/web3-validator/CHANGELOG.md index 5421991ec9c..47f6084c27a 100644 --- a/packages/web3-validator/CHANGELOG.md +++ b/packages/web3-validator/CHANGELOG.md @@ -77,4 +77,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Added support of `safe` and `finalized` block tags in isBlockTag method (#5823) +- Added support of `safe` and `finalized` block tags in `isBlockTag` method (#5823) From 5441768d4023f0202eb82bb95f51c111b907ea8a Mon Sep 17 00:00:00 2001 From: jdevcs Date: Mon, 13 Feb 2023 18:27:52 +0100 Subject: [PATCH 16/17] updates --- packages/web3-utils/src/validation.ts | 27 ++++++++----------- .../web3-utils/test/fixtures/validation.ts | 6 ++--- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index 1835b29c7d0..a7095bfafb6 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -30,7 +30,7 @@ import { 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. @@ -108,14 +108,14 @@ 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 (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, safe, (finalized ~ latest), pending + // 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 ( @@ -124,22 +124,22 @@ export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { ) { return 0; } - if (blockA === 'earliest') { + if (blockA === 'earliest' || blockA === 0) { // b !== a, thus a < b return -1; } - if (blockB === 'earliest') { + if (blockB === 'earliest' || blockB === 0) { // b !== a, thus a > b return 1; } - if (blockA === 'latest' || blockA === 'finalized') { + if (blockA === 'latest' || blockA === 'safe') { if (blockB === 'pending') { return -1; } // b !== ("pending" OR "latest"), thus a > b return 1; } - if (blockB === 'latest' || blockB === 'finalized') { + if (blockB === 'latest' || blockB === 'safe') { if (blockA === 'pending') { return 1; } @@ -153,16 +153,11 @@ export const compareBlockNumbers = (blockA: Numbers, blockB: Numbers) => { if (blockB === 'pending') { return -1; } - if (blockA === 'safe' && blockB === 0) { - return 1; - } - if (blockA === 0 && blockB === 'safe') { - return -1; - } - if (blockA === 'safe' || blockB === 'safe') { - // either a or b is "safe" and the other one did not fall into any of the conditions above, so the other one is a number + + 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 safe tag with ${blockA === 'safe' ? blockB : blockA}`, + `Cannot compare finalized tag with ${blockA === 'finalized' ? blockB : blockA}`, ); } diff --git a/packages/web3-utils/test/fixtures/validation.ts b/packages/web3-utils/test/fixtures/validation.ts index 7a8d8522326..c965f4310b6 100644 --- a/packages/web3-utils/test/fixtures/validation.ts +++ b/packages/web3-utils/test/fixtures/validation.ts @@ -50,18 +50,16 @@ export const compareBlockNumbersValidData: [[Numbers, Numbers], number][] = [ [['finalized', 'finalized'], 0], [['earliest', 'finalized'], -1], [['finalized', 0], 1], - [['finalized', BigInt('1')], 1], [['finalized', 'pending'], -1], [[0, 'finalized'], -1], - [[BigInt('1'), 'finalized'], -1], [['pending', 'finalized'], 1], ]; export const compareBlockNumbersInvalidData: [[Numbers, Numbers], InvalidBlockError][] = [ [['pending', 'unknown'], new InvalidBlockError('unknown')], [['', 'pending'], new InvalidBlockError('')], - [[22, 'safe'], new InvalidBlockError('Cannot compare safe tag with 22')], - [['safe', 22], new InvalidBlockError('Cannot compare safe tag with 22')], + [[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')], ]; From c421ff227158e10c707b764508552357c51ff3f5 Mon Sep 17 00:00:00 2001 From: jdevcs Date: Tue, 14 Feb 2023 10:14:16 +0100 Subject: [PATCH 17/17] latest vs safe test --- packages/web3-utils/src/validation.ts | 4 ++-- packages/web3-utils/test/fixtures/validation.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/web3-utils/src/validation.ts b/packages/web3-utils/src/validation.ts index a7095bfafb6..9aebbcc3814 100644 --- a/packages/web3-utils/src/validation.ts +++ b/packages/web3-utils/src/validation.ts @@ -133,14 +133,14 @@ export const compareBlockNumbers = (blockA: BlockNumberOrTag, blockB: BlockNumbe return 1; } if (blockA === 'latest' || blockA === 'safe') { - if (blockB === 'pending') { + if (blockB === 'pending' || blockB === 'latest') { return -1; } // b !== ("pending" OR "latest"), thus a > b return 1; } if (blockB === 'latest' || blockB === 'safe') { - if (blockA === 'pending') { + if (blockA === 'pending' || blockA === 'latest') { return 1; } // b !== ("pending" OR "latest"), thus a > b diff --git a/packages/web3-utils/test/fixtures/validation.ts b/packages/web3-utils/test/fixtures/validation.ts index c965f4310b6..b7f194fcfad 100644 --- a/packages/web3-utils/test/fixtures/validation.ts +++ b/packages/web3-utils/test/fixtures/validation.ts @@ -53,6 +53,8 @@ export const compareBlockNumbersValidData: [[Numbers, Numbers], number][] = [ [['finalized', 'pending'], -1], [[0, 'finalized'], -1], [['pending', 'finalized'], 1], + [['safe', 'latest'], -1], + [['latest', 'safe'], 1], ]; export const compareBlockNumbersInvalidData: [[Numbers, Numbers], InvalidBlockError][] = [