remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/remix-debugger/test-browser/resources/insertTestWeb3.js

78 lines
2.1 KiB

7 years ago
/* global XMLHttpRequest */
8 years ago
function loadJSON (url, callback) {
var xobj = new XMLHttpRequest()
xobj.overrideMimeType('application/json')
xobj.open('GET', url, true)
xobj.onreadystatechange = function () {
7 years ago
if (xobj.readyState === 4 && xobj.status === 200) {
8 years ago
callback(xobj.responseText)
}
}
xobj.send(null)
}
function loadTestWeb3 (data) {
var container = document.getElementById('app')
var vmdebugger = container.debugger
var uiTestweb3 = {}
uiTestweb3.eth = {}
uiTestweb3.debug = {}
uiTestweb3.eth.getCode = function (address, callback) {
if (callback) {
callback(null, data.testCodes[address])
} else {
return data.testCodes[address]
}
}
7 years ago
8 years ago
uiTestweb3.debug.traceTransaction = function (txHash, options, callback) {
callback(null, data.testTraces[txHash])
}
8 years ago
uiTestweb3.debug.storageRangeAt = function (blockNumber, txIndex, address, start, size, callback) {
8 years ago
callback(null, { storage: {}, complete: true })
8 years ago
}
uiTestweb3.eth.getTransaction = function (txHash, callback) {
if (callback) {
callback(null, data.testTxs[txHash])
} else {
return data.testTxs[txHash]
}
}
uiTestweb3.eth.getTransactionFromBlock = function (blockNumber, txIndex, callback) {
if (callback) {
callback(null, data.testTxsByBlock[blockNumber + '-' + txIndex])
} else {
return data.testTxsByBlock[blockNumber + '-' + txIndex]
}
}
uiTestweb3.eth.getBlockNumber = function (callback) { callback(null, 'web3 modified for testing purposes :)') }
uiTestweb3.providers = { 'HttpProvider': function (url) {} }
uiTestweb3.setProvider = function (provider) {}
7 years ago
uiTestweb3.currentProvider = {host: 'web3 modified for testing purposes :)'}
8 years ago
vmdebugger.addProvider('TEST', uiTestweb3)
vmdebugger.switchProvider('TEST')
}
function waitForRemix (data) {
setTimeout(function () {
if (!document.getElementById('app').debugger) {
waitForRemix(data)
} else {
loadTestWeb3(data)
}
}, 500)
}
7 years ago
loadJSON('/test-browser/resources/testWeb3.json', function (result) {
8 years ago
var data = JSON.parse(result)
waitForRemix(data)
})