| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import { web3, ethers } from "hardhat";
- import axios from 'axios'
- import logger from "../../utils/logger";
- import contracts from "../../config/contracts";
- function test1() {}
- function test2() {
- new web3.eth.Contract([], contracts.UNIV3)
- }
- function test21() {
- new ethers.Contract(contracts.UNIV3, [])
- }
- function test3() {
- web3.utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2')
- }
- function test31() {
- ethers.utils.getAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2')
- }
- async function test4() {
- await web3.eth.getBlockNumber()
- }
- async function test5() {
- // @ts-ignore
- await web3.eth.getBlockNumber2()
- }
- async function test6() {
- await axios.post('http://127.0.0.1:18545', {
- 'jsonrpc': '2.0',
- 'method': 'eth_blockNumber',
- 'params': [],
- 'id': new Date().getTime()
- }, {
- headers: {'Content-type': 'application/json'}
- })
- }
- async function test7() {
- // @ts-ignore
- await web3.eth.ethCall({
- 'from':'0x1712B216FdD1943E5FCd75ec945588dDB4765c0f',
- 'to':'0xe0208a3B4C3cd0583F04fB002ebD5dCDd0D3FEB5',
- 'data':'0x0ad5a3af0000000000000000000000008b4a890b407c0a2e85a5c915546b8d9aeb731b98000000000000000000000000053b77ac4f8ef8d19830a429fa55e56a7529fac100000000000000000000000000000000000000000000000000000000000006a40000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cb730e11b12beab590b623a83534803491059ede00000000000000000000000000000000000000000000000000038d7ea4c68000'
- }, "latest")
- }
- async function test8() {
- // @ts-ignore
- await web3.eth.call({
- 'from':'0x1712B216FdD1943E5FCd75ec945588dDB4765c0f',
- 'to':'0xe0208a3B4C3cd0583F04fB002ebD5dCDd0D3FEB5',
- 'data':'0x0ad5a3af0000000000000000000000008b4a890b407c0a2e85a5c915546b8d9aeb731b98000000000000000000000000053b77ac4f8ef8d19830a429fa55e56a7529fac100000000000000000000000000000000000000000000000000000000000006a40000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cb730e11b12beab590b623a83534803491059ede00000000000000000000000000000000000000000000000000038d7ea4c68000'
- }, "latest")
- }
- async function run(fun: Function) {
- const startTs = new Date().getTime()
- let count = 0
- // logger.debug(`start test...`)
- while (true) {
- if (new Date().getTime() < startTs + 1000) {
- await fun()
- count++
- } else {
- break
- }
- }
- logger.debug(`${count}, end test.`)
- }
- async function main() {
- const testCount = 10
- // logger.debug('web3 getBlockNumber:')
- // for (let i = 0; i < testCount; i++) {
- // await run(test4)
- // }
- //
- //
- // web3.extend({
- // property: 'eth',
- // methods: [
- // {
- // name: 'getBlockNumber2',
- // call: 'eth_blockNumber'
- // }
- // ]
- // })
- // logger.debug('web3 getBlockNumber2.send():')
- // for (let i = 0; i < testCount; i++) {
- // await run(test5)
- // }
- //
- //
- //
- // logger.debug('web3 http,http,http,http,http test.')
- // for (let i = 0; i < testCount; i++) {
- // await run(test6)
- // }
- //
- //
- // web3.extend({
- // property: 'eth',
- // methods: [
- // {
- // name: 'ethCall',
- // call: 'eth_call',
- // params: 2
- // }
- // ]
- // })
- // logger.debug('web3 ethCall,ethCall,ethCall,ethCall,ethCall test.')
- // for (let i = 0; i < testCount; i++) {
- // await run(test7)
- // }
- //
- //
- // logger.debug('web3 call,call,call,call,call test.')
- // for (let i = 0; i < testCount; i++) {
- // await run(test8)
- // }
- // web3.extend({
- // property: 'eth',
- // methods: [
- // {
- // name: 'batchCall',
- // call: 'eth_batchCall',
- // params: 1,
- // }
- // ]
- // })
- //
- // // @ts-ignore
- // const rst = await web3.eth.batchCall({
- // Block: "latest",
- // Calls:[{
- // 'from':'0x1712B216FdD1943E5FCd75ec945588dDB4765c0f',
- // 'to':'0xe0208a3B4C3cd0583F04fB002ebD5dCDd0D3FEB5',
- // 'data':'0x0ad5a3af0000000000000000000000008b4a890b407c0a2e85a5c915546b8d9aeb731b98000000000000000000000000053b77ac4f8ef8d19830a429fa55e56a7529fac100000000000000000000000000000000000000000000000000000000000006a40000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cb730e11b12beab590b623a83534803491059ede00000000000000000000000000000000000000000000000000038d7ea4c68000'
- // }]
- // })
- // logger.debug(rst)
- }
- main().catch((error) => {
- console.error(error);
- process.exitCode = 1;
- })
|