• Mark Tyneway's avatar
    dtl: enable typed batch support · 3873b696
    Mark Tyneway authored
    The data transport layer will now be able to index
    typed batches. A typed batch has the first batch context
    have a timestamp of 0 and the blocknumber is used as an
    enum to determine the type of the batch.
    
    It is not possible to have a timestamp of 0 in realistic
    conditions. Batches that have a non zero timestamp
    as the first batch context are considered a legacy batch.
    
    The first typed batch is type 0 where the blocknumber is 0
    and the transaction data is compressed with zlib.
    3873b696
setup.ts 1.47 KB
import fs from 'fs'
import path from 'path'

import chai = require('chai')
import Mocha from 'mocha'
import chaiAsPromised from 'chai-as-promised'
import { BigNumber } from 'ethers'

// Chai plugins go here.
chai.use(chaiAsPromised)

const should = chai.should()
const expect = chai.expect

const readMockData = () => {
  const mockDataPath = path.join(__dirname, 'unit-tests', 'examples')
  const paths = fs.readdirSync(mockDataPath)
  const files = []
  for (const filename of paths) {
    // Skip non .txt files
    if (!filename.endsWith('.txt')) {
      continue
    }
    const filePath = path.join(mockDataPath, filename)
    const file = fs.readFileSync(filePath)
    const obj = JSON.parse(file.toString())
    // Reserialize the BigNumbers
    obj.input.extraData.prevTotalElements = BigNumber.from(
      obj.input.extraData.prevTotalElements
    )
    obj.input.extraData.batchIndex = BigNumber.from(
      obj.input.extraData.batchIndex
    )
    if (obj.input.event.args.length !== 3) {
      throw new Error(`ABI mismatch`)
    }
    obj.input.event.args = obj.input.event.args.map(BigNumber.from)
    obj.input.event.args._startingQueueIndex = obj.input.event.args[0]
    obj.input.event.args._numQueueElements = obj.input.event.args[1]
    obj.input.event.args._totalElements = obj.input.event.args[2]
    obj.input.extraData.batchSize = BigNumber.from(
      obj.input.extraData.batchSize
    )
    files.push(obj)
  }
  return files
}

export { should, expect, Mocha, readMockData }