|
| 1 | +/* |
| 2 | +This file is part of web3.js. |
| 3 | +
|
| 4 | +web3.js is free software: you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU Lesser General Public License as published by |
| 6 | +the Free Software Foundation, either version 3 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +
|
| 9 | +web3.js is distributed in the hope that it will be useful, |
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +GNU Lesser General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU Lesser General Public License |
| 15 | +along with web3.js. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +*/ |
| 17 | + |
| 18 | +import { ethRpcMethods } from 'web3-rpc-methods'; |
| 19 | +import { DEFAULT_RETURN_FORMAT } from 'web3-types'; |
| 20 | +import { numberToHex, isNullish } from 'web3-utils'; |
| 21 | +import * as rpcMethodWrappers from '../../src/rpc_method_wrappers'; |
| 22 | +import { getPastLogsValidFormatData } from '../fixtures/web3_eth_methods_with_parameters'; |
| 23 | +import Web3Eth from '../../src/index'; |
| 24 | + |
| 25 | +jest.mock('web3-rpc-methods'); |
| 26 | +describe('web3_eth_methods formatting', () => { |
| 27 | + let web3Eth: Web3Eth; |
| 28 | + |
| 29 | + beforeAll(() => { |
| 30 | + web3Eth = new Web3Eth('http://127.0.0.1:8545'); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('getPastLogs makes sure data is prepared properly', () => { |
| 34 | + it.each(getPastLogsValidFormatData)('input: %s\nrpcMethodParameters: %s', async filter => { |
| 35 | + jest.spyOn(ethRpcMethods, 'getLogs').mockResolvedValue(['']); |
| 36 | + await rpcMethodWrappers.getLogs(web3Eth, filter, DEFAULT_RETURN_FORMAT); |
| 37 | + let { fromBlock, toBlock } = filter; |
| 38 | + if ( |
| 39 | + !isNullish(filter.fromBlock) && |
| 40 | + (typeof filter.fromBlock === 'bigint' || typeof filter.fromBlock === 'number') |
| 41 | + ) |
| 42 | + fromBlock = numberToHex(filter.fromBlock); |
| 43 | + if ( |
| 44 | + !isNullish(filter.toBlock) && |
| 45 | + (typeof filter.toBlock === 'bigint' || typeof filter.toBlock === 'number') |
| 46 | + ) |
| 47 | + toBlock = numberToHex(filter.toBlock); |
| 48 | + expect(ethRpcMethods.getLogs).toHaveBeenCalledWith(web3Eth.requestManager, { |
| 49 | + ...filter, |
| 50 | + toBlock, |
| 51 | + fromBlock, |
| 52 | + }); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
0 commit comments