• Kevin Ho's avatar
    EOA and Decompressor (#33) · f06c8652
    Kevin Ho authored
    * decompression (not working)
    
    * start EIP155 serialization
    
    * working decompressor
    
    * working CreateEOA, working native EIP155tx
    
    * all three tx types working
    
    * remove only
    
    * fix ECDSAUtil tests
    
    * restore original version of smock
    
    * add proxys
    
    * clean up tests
    
    * clean up decompressor tests
    
    * clean up ProxyDecompressor
    
    * clean up decompressor tests
    
    * add CREATEEOA, SETNONCE, GETNONCE tests
    
    * working ECDSAContractAccount
    
    * fix decompressor
    
    * renaming, add deploy
    
    * add proxyeoa test, cleanup
    
    * remove createEOA type, add extcodesize check
    
    * fix decompressor test
    
    * support create txs
    
    * Decompressor -> Entrypoint
    
    * use safeREVERT instead of requires
    
    * add isAuthenticated state manager test
    
    * update smock
    
    * fix sequencerEntrypoint test
    
    * add isAuthenticated
    
    * Revert "update smock"
    
    This reverts commit 286a222414accf9387dcd12ecbed0a66be586bc8.
    
    * fix test
    
    * Updates to EM
    
    * removed kall from contract account
    
    * Fixed SSLOAD and SSTORE problems
    
    * Fix some broken tests
    
    * Fix more bugs & rename to ProxyEOA
    
    * WIP fix call test
    
    * fix all tests
    
    * add gas check
    
    * update tests
    
    * lint and remove 2000 gas check
    
    * Add fees to default EOA (#56)
    Co-authored-by: default avatarKelvin Fichter <kelvinfichter@gmail.com>
    Co-authored-by: default avatarKarl Floersch <karl@karlfloersch.com>
    f06c8652
json-test-runner.ts 1.12 KB
import { expect } from '../../setup'

/* External Imports */
import { ethers } from '@nomiclabs/buidler'
import { Contract, BigNumber } from 'ethers'

const bigNumberify = (arr) => {
  return arr.map((el: any) => {
    if (typeof el === 'number') {
      return BigNumber.from(el)
    } else if (Array.isArray(el)) {
      return bigNumberify(el)
    } else {
      return el
    }
  })
}

export const runJsonTest = (contractName: string, json: any): void => {
  let contract: Contract
  before(async () => {
    contract = await (await ethers.getContractFactory(contractName)).deploy()
  })

  for (const [functionName, functionTests] of Object.entries(json)) {
    describe(functionName, () => {
      for (const [key, test] of Object.entries(functionTests)) {
        it(`should run test: ${key}`, async () => {
          if (test.revert) {
            await expect(contract.functions[functionName](...test.in)).to.be
              .reverted
          } else {
            expect(
              await contract.functions[functionName](...test.in)
            ).to.deep.equal(bigNumberify(test.out))
          }
        })
      }
    })
  }
}