use web3Test.js for tape framework instead of testTraceRetriever.js

pull/7/head
yann300 9 years ago
parent 732c21efd9
commit 08f19ed20c
  1. 8
      test-browser/index.js
  2. 38
      test/TestTraceRetriever.js
  3. 5
      test/codeManager.js
  4. 12
      test/init.js
  5. 10
      test/resources/testWeb3.js
  6. 5
      test/traceManager.js

@ -1,3 +1,4 @@
/* global web3Override */
module.exports = {
beforeEach: function (browser, done) {
init(browser, done)
@ -50,6 +51,13 @@ function injectScript (file, browser, callback) {
if (!error) {
browser.execute(function (data) {
eval.call(null, data) // eslint-disable-line
var vmdebugger = document.getElementById('app').vmdebugger
vmdebugger.web3.eth.getCode = web3Override.getCode
vmdebugger.web3.debug.traceTransaction = web3Override.traceTransaction
vmdebugger.web3.debug.storageAt = web3Override.storageAt
vmdebugger.web3.eth.getTransaction = web3Override.getTransaction
vmdebugger.web3.eth.getTransactionFromBlock = web3Override.getTransactionFromBlock
vmdebugger.web3.eth.getBlockNumber = web3Override.getBlockNumber
}, [result], function () {
callback()
})

@ -1,38 +0,0 @@
'use strict'
var traceHelper = require('../src/helpers/traceHelper')
var traceInvokation = require('./resources/contractInvokationTrace')
function TestTraceRetriever () {
this.storages = {} // contains all intial storage (by addresses)
}
TestTraceRetriever.prototype.getTrace = function (txHash, callback) {
console.log(traceInvokation)
callback(null, traceInvokation)
}
/* not used */
TestTraceRetriever.prototype.getStorage = function (tx, address, callback) {
if (traceHelper.isContractCreation(address)) {
callback(null, {})
} else if (this.storages[address]) {
callback(null, this.storages[address])
} else {
/*
return storage
*/
/*
var self = this
this.web3.debug.storageAt(tx.blockNumber.toString(), tx.transactionIndex, address, function (error, result) {
self.storages[address] = result
callback(error, result)
})
*/
}
}
TestTraceRetriever.prototype.debugStorageAtAvailable = function () {
return false // test scenario does not require web3.
}
module.exports = TestTraceRetriever

@ -2,16 +2,17 @@
var tape = require('tape')
var init = require('../src/helpers/init')
var txInvokation = require('./resources/contractInvokationTx')
var TestTraceRetriever = require('./TestTraceRetriever')
var contractCode = require('./resources/contractInvokationCode')
var TraceManager = require('../src/trace/traceManager')
var CodeManager = require('../src/code/codeManager')
var web3Test = require('./resources/testWeb3')
var initWeb3 = require('./init')
tape('CodeManager', function (t) {
var codeManager
var web3 = init.loadWeb3()
initWeb3.overrideWeb3(web3, web3Test)
var traceManager = new TraceManager(web3)
traceManager.traceRetriever = new TestTraceRetriever()
codeManager = new CodeManager(web3, traceManager)
codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary
traceManager.resolveTrace(txInvokation, function (error, result) {

@ -0,0 +1,12 @@
var init = {
overrideWeb3: function (web3, web3Override) {
web3.eth.getCode = web3Override.getCode
web3.debug.traceTransaction = web3Override.traceTransaction
web3.debug.storageAt = web3Override.storageAt
web3.eth.getTransaction = web3Override.getTransaction
web3.eth.getTransactionFromBlock = web3Override.getTransactionFromBlock
web3.eth.getBlockNumber = web3Override.getBlockNumber
}
}
module.exports = init

@ -45,10 +45,6 @@ var web3Override = {
getBlockNumber: function (callback) { callback('web3 modified testing purposes :)') }
}
var vmdebugger = document.getElementById('app').vmdebugger
vmdebugger.web3.eth.getCode = web3Override.getCode
vmdebugger.web3.debug.traceTransaction = web3Override.traceTransaction
vmdebugger.web3.debug.storageAt = web3Override.storageAt
vmdebugger.web3.eth.getTransaction = web3Override.getTransaction
vmdebugger.web3.eth.getTransactionFromBlock = web3Override.getTransactionFromBlock
vmdebugger.web3.eth.getBlockNumber = web3Override.getBlockNumber
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = web3Override
}

@ -2,16 +2,17 @@
var TraceManager = require('../src/trace/traceManager')
var tape = require('tape')
var init = require('../src/helpers/init')
var TestTraceRetriever = require('./TestTraceRetriever')
var txInvokation = require('./resources/contractInvokationTx')
var web3Test = require('./resources/testWeb3')
var initWeb3 = require('./init')
tape('TraceManager', function (t) {
var traceManager
t.test('TraceManager.init', function (st) {
var web3 = init.loadWeb3()
initWeb3.overrideWeb3(web3, web3Test)
traceManager = new TraceManager(web3)
traceManager.traceRetriever = new TestTraceRetriever()
st.end()
})

Loading…
Cancel
Save