const Environment = require('./environment.js')
const U256 = require('./u256.js')
const Address = require('./address.js')
const BN = require('bn.js')

module.exports = class TestEnvironment extends Environment {
  constructor (data) {
    super()

    if (typeof data === 'string') {
      data = JSON.parse(data)
    }

    let self = this

    if (data.accounts) {
      data.accounts.forEach((account) => {
        let tmp = account[1]
        self.state.set(new Address(account[0]).toString(), {
          balance: new U256(tmp.balance)
        })
      })
    }

    if (data.address) {
      self.address = new Address(data.address)
    }

    if (data.origin) {
      self.origin = new Address(data.origin)
    }

    if (data.caller) {
      self.caller = new Address(data.caller)
    }

    if (data.coinbase) {
      self.coinbase = new Address(data.coinbase)
    }

    if (data.callValue) {
      self.callValue = new U256(data.callValue)
    }

    if (data.callData) {
      self.callData = hexStr2arrayBuf(data.callData)
    }

    if (data.gasPrice) {
      self.gasPrice = data.gasPrice
    }

    if (data.gasLimit) {
      self.gasLimit = data.gasLimit
    }
  }
}

function hexStr2arrayBuf (string) {
  const view = new Uint8Array(string.length / 2)
  string = [...string]
  let temp = ''
  string.forEach((el, i) => {
    temp += el
    if (i % 2) {
      view[(i + 1) / 2 - 1] = parseInt(temp, 16)
      temp = ''
    }
  })
  return view
}

@@ -998,31 +998,42 @@
 lData = 
-hexStr2arrayBuf
+Uint8Array.from(new Buffer
 (data.ca
@@ -1038,16 +1038,24 @@
 callData
+, 'hex')
 )%0A    %7D%0A
@@ -1194,289 +1194,10 @@
   %7D%0A
+
   %7D%0A%7D%0A
-%0Afunction hexStr2arrayBuf (string) %7B%0A  const view = new Uint8Array(string.length / 2)%0A  string = %5B...string%5D%0A  let temp = ''%0A  string.forEach((el, i) =%3E %7B%0A    temp += el%0A    if (i %25 2) %7B%0A      view%5B(i + 1) / 2 - 1%5D = parseInt(temp, 16)%0A      temp = ''%0A    %7D%0A  %7D)%0A  return view%0A%7D%0A

use Buffer to replace hex processing