import history from '../scripts/interface/history'
import contracts from "../config/contracts";
import logger from "../utils/logger";
import v2_routers from "../config/v2_routers";
import fs from 'fs'

describe('Pull pool test', () => {
  it ('pull v3', async () => {
    logger.debug('start pull v3')
    const rst = await history.findByHashOrBlockOrDataVague('0', '', contracts.UNIV3, 0, 3000)

    logger.debug(rst.msg)
    const v3PoolList = []
    for (let v3Index in rst.data) {
      let v3Lp = rst.data[v3Index].dataObj
      v3PoolList.push(v3Lp)
    }
    logger.debug(v3PoolList.length)

    fs.writeFile('./config/v3PoolList.json', JSON.stringify(v3PoolList), (err) => {
      if (err) {
        logger.error(err)
      } else {
        logger.debug("File written successfully\n")
      }
    })
  })

  it ('pull v2', async () => {
    logger.debug('start pull v2')

    const v2PoolList = []
    for (let v2RouterIndex in v2_routers) {
      const rst = await history.findByHashOrBlockOrDataVague('0', '', v2_routers[v2RouterIndex], 0, 110000)

      logger.debug(v2_routers[v2RouterIndex])
      for (let v2Index in rst.data) {
        let v2Lp = rst.data[v2Index].dataObj
        v2PoolList.push(v2Lp)
      }
    }
    logger.debug(v2PoolList.length)

    fs.writeFile('./config/v2PoolList.json', JSON.stringify(v2PoolList), (err) => {
      if (err) {
        logger.error(err);
      } else {
        logger.debug("File written successfully\n");
      }
    })
  })
})