From 11052d99d068e6e67710dbfb8fc5c72d70cd09ed Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 7 Feb 2023 15:25:00 -0500 Subject: [PATCH 1/2] update encodeeventabi --- .../web3-core/src/web3_request_manager.ts | 1 - packages/web3-eth-contract/src/contract.ts | 1 - packages/web3-eth-contract/src/encoding.ts | 21 ++++++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/web3-core/src/web3_request_manager.ts b/packages/web3-core/src/web3_request_manager.ts index 35242c5e620..2ccbaca1e27 100644 --- a/packages/web3-core/src/web3_request_manager.ts +++ b/packages/web3-core/src/web3_request_manager.ts @@ -186,7 +186,6 @@ export class Web3RequestManager< // Check if the provider throw an error instead of reject with error response = error as JsonRpcResponse; } - return this._processJsonRpcResponse(payload, response, { legacy: false, error: false }); } diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index 8d98b118a42..49f08e7af18 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -896,7 +896,6 @@ export class Contract this.options, abi, filter ?? {}, - returnFormat, ); const logs = await getLogs(this, { fromBlock, toBlock, topics, address }, returnFormat); diff --git a/packages/web3-eth-contract/src/encoding.ts b/packages/web3-eth-contract/src/encoding.ts index df8a370f132..5b9bc1b6a60 100644 --- a/packages/web3-eth-contract/src/encoding.ts +++ b/packages/web3-eth-contract/src/encoding.ts @@ -15,7 +15,14 @@ You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -import { DataFormat, DEFAULT_RETURN_FORMAT, format, isNullish } from 'web3-utils'; +import { + DataFormat, + DEFAULT_RETURN_FORMAT, + FMT_BYTES, + FMT_NUMBER, + format, + isNullish, +} from 'web3-utils'; import { AbiConstructorFragment, @@ -59,7 +66,6 @@ export const encodeEventABI = ( // eslint-disable-next-line @typescript-eslint/ban-types topics?: (null | Topic | Topic[])[]; }, - returnFormat: DataFormat = DEFAULT_RETURN_FORMAT, ) => { const opts: { filter: Filter; @@ -72,11 +78,16 @@ export const encodeEventABI = ( }; if (!isNullish(options?.fromBlock)) { - opts.fromBlock = format(blockSchema.properties.number, options?.fromBlock, returnFormat); + opts.fromBlock = format(blockSchema.properties.number, options?.fromBlock, { + number: FMT_NUMBER.HEX, + bytes: FMT_BYTES.HEX, + }); } - if (!isNullish(options?.toBlock)) { - opts.toBlock = format(blockSchema.properties.number, options?.toBlock, returnFormat); + opts.toBlock = format(blockSchema.properties.number, options?.toBlock, { + number: FMT_NUMBER.HEX, + bytes: FMT_BYTES.HEX, + }); } if (options?.topics && Array.isArray(options.topics)) { From 248ceaa73bcaab7d9de0c62aff817f84f2da2921 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 7 Feb 2023 15:57:04 -0500 Subject: [PATCH 2/2] add more getpastevent tests --- .../test/integration/contract_events.test.ts | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/web3-eth-contract/test/integration/contract_events.test.ts b/packages/web3-eth-contract/test/integration/contract_events.test.ts index 2d83e0f0834..209a918c05f 100644 --- a/packages/web3-eth-contract/test/integration/contract_events.test.ts +++ b/packages/web3-eth-contract/test/integration/contract_events.test.ts @@ -186,7 +186,7 @@ describe('contract', () => { describeIf(isWs)('getPastEvents', () => { // TODO: Debug why this tests is hanging the websocket - it('should return all past events', async () => { + it('should return all past events using earliest and latest options', async () => { await contractDeployed.methods .firesMultiValueEvent('New Greeting 1', 11, true) .send(sendOptions); @@ -201,5 +201,50 @@ describe('contract', () => { }), ).toHaveLength(2); }); + it('should return all past events using number options', async () => { + await contractDeployed.methods + .firesMultiValueEvent('New Greeting 1', 11, true) + .send(sendOptions); + await contractDeployed.methods + .firesMultiValueEvent('New Greeting 2', 12, true) + .send(sendOptions); + + expect( + await contractDeployed.getPastEvents('MultiValueEvent', { + fromBlock: 0, + toBlock: 1000, + }), + ).toHaveLength(2); + }); + it('should return all past events using string options', async () => { + await contractDeployed.methods + .firesMultiValueEvent('New Greeting 1', 11, true) + .send(sendOptions); + await contractDeployed.methods + .firesMultiValueEvent('New Greeting 2', 12, true) + .send(sendOptions); + + expect( + await contractDeployed.getPastEvents('MultiValueEvent', { + fromBlock: '0', + toBlock: '1000', + }), + ).toHaveLength(2); + }); + it('should return all past events using bigint options', async () => { + await contractDeployed.methods + .firesMultiValueEvent('New Greeting 1', 11, true) + .send(sendOptions); + await contractDeployed.methods + .firesMultiValueEvent('New Greeting 2', 12, true) + .send(sendOptions); + + expect( + await contractDeployed.getPastEvents('MultiValueEvent', { + fromBlock: BigInt(0), + toBlock: BigInt(1000), + }), + ).toHaveLength(2); + }); }); });