fix unit tests

pull/3209/head
yann300 2 years ago
parent ccaba2fb63
commit 5728c26f4c
  1. 10
      libs/remix-debug/test/debugger.ts
  2. 44
      libs/remix-debug/test/decoder/localDecoder.ts
  3. 15
      libs/remix-debug/test/decoder/localsTests/calldata.ts
  4. 13
      libs/remix-debug/test/decoder/localsTests/misc.ts
  5. 13
      libs/remix-debug/test/decoder/localsTests/misc2.ts
  6. 17
      libs/remix-debug/test/decoder/localsTests/structArray.ts
  7. 40
      libs/remix-debug/test/decoder/stateTests/mapping.ts
  8. 4
      libs/remix-debug/test/decoder/storageDecoder.ts

@ -1,4 +1,5 @@
import tape from 'tape' import tape from 'tape'
import { CompilerAbstract } from '@remix-project/remix-solidity'
import deepequal from 'deep-equal' import deepequal from 'deep-equal'
import { compilerInput } from './helpers/compilerHelper' import { compilerInput } from './helpers/compilerHelper'
import * as sourceMappingDecoder from '../src/source/sourceMappingDecoder' import * as sourceMappingDecoder from '../src/source/sourceMappingDecoder'
@ -164,10 +165,13 @@ contract Ballot {
if (error) { if (error) {
throw error throw error
} else { } else {
const sources = {
target: 'test.sol',
sources: { 'test.sol': { content: ballot } }
}
const compilationResults = new CompilerAbstract('json', output, sources)
var debugManager = new Debugger({ var debugManager = new Debugger({
compilationResult: function () { compilationResult: () => compilationResults,
return { data: output }
},
web3: web3, web3: web3,
offsetToLineColumnConverter: { offsetToLineColumnConverter: {
offsetToLineColumn: async (rawLocation) => { offsetToLineColumn: async (rawLocation) => {

@ -1,6 +1,7 @@
'use strict' 'use strict'
import tape from 'tape' import tape from 'tape'
var compiler = require('solc') var compiler = require('solc')
import { CompilerAbstract } from '@remix-project/remix-solidity'
var intLocal = require('./contracts/intLocal') var intLocal = require('./contracts/intLocal')
var miscLocal = require('./contracts/miscLocal') var miscLocal = require('./contracts/miscLocal')
var structArrayLocal = require('./contracts/structArrayLocal') var structArrayLocal = require('./contracts/structArrayLocal')
@ -23,20 +24,53 @@ tape('solidity', function (t) {
async function test (st, privateKey) { async function test (st, privateKey) {
var output = compiler.compile(compilerInput(intLocal.contract)) var output = compiler.compile(compilerInput(intLocal.contract))
output = JSON.parse(output) output = JSON.parse(output)
await intLocalTest(st, privateKey, output.contracts['test.sol']['intLocal'].evm.bytecode.object, output, intLocal.contract) let sources = {
target: 'test.sol',
sources: { 'test.sol': { content: intLocal.contract } }
}
let compilationResults = new CompilerAbstract('json', output, sources)
console.log('intLocalTest')
await intLocalTest(st, privateKey, output.contracts['test.sol']['intLocal'].evm.bytecode.object, compilationResults, intLocal.contract)
output = compiler.compile(compilerInput(miscLocal.contract)) output = compiler.compile(compilerInput(miscLocal.contract))
output = JSON.parse(output) output = JSON.parse(output)
await miscLocalTest(st, privateKey, output.contracts['test.sol']['miscLocal'].evm.bytecode.object, output) sources = {
target: 'test.sol',
sources: { 'test.sol': { content: miscLocal.contract } }
}
compilationResults = new CompilerAbstract('json', output, sources)
console.log('miscLocalTest')
await miscLocalTest(st, privateKey, output.contracts['test.sol']['miscLocal'].evm.bytecode.object, compilationResults, miscLocal.contract)
output = compiler.compile(compilerInput(miscLocal.contract)) output = compiler.compile(compilerInput(miscLocal.contract))
output = JSON.parse(output) output = JSON.parse(output)
await misc2LocalTest(st, privateKey, output.contracts['test.sol']['miscLocal2'].evm.bytecode.object, output) sources = {
target: 'test.sol',
sources: { 'test.sol': { content: miscLocal.contract } }
}
compilationResults = new CompilerAbstract('json', output, sources)
console.log('misc2LocalTest')
await misc2LocalTest(st, privateKey, output.contracts['test.sol']['miscLocal2'].evm.bytecode.object, compilationResults, miscLocal.contract)
output = compiler.compile(compilerInput(structArrayLocal.contract)) output = compiler.compile(compilerInput(structArrayLocal.contract))
output = JSON.parse(output) output = JSON.parse(output)
await structArrayLocalTest(st, privateKey, output.contracts['test.sol']['structArrayLocal'].evm.bytecode.object, output) sources = {
target: 'test.sol',
sources: { 'test.sol': { content: structArrayLocal.contract } }
}
compilationResults = new CompilerAbstract('json', output, sources)
console.log('structArrayLocalTest')
await structArrayLocalTest(st, privateKey, output.contracts['test.sol']['structArrayLocal'].evm.bytecode.object, compilationResults, structArrayLocal.contract)
output = compiler.compile(compilerInput(calldataLocal.contract)) output = compiler.compile(compilerInput(calldataLocal.contract))
output = JSON.parse(output) output = JSON.parse(output)
await calldataLocalTest(st, privateKey, output.contracts['test.sol']['calldataLocal'].evm.bytecode.object, output) sources = {
target: 'test.sol',
sources: { 'test.sol': { content: calldataLocal.contract } }
}
compilationResults = new CompilerAbstract('json', output, sources)
console.log('calldataLocalTest')
await calldataLocalTest(st, privateKey, output.contracts['test.sol']['calldataLocal'].evm.bytecode.object, compilationResults, calldataLocal.contract)
st.end() st.end()
} }

@ -1,6 +1,7 @@
'use strict' 'use strict'
import deepequal from 'deep-equal' import deepequal from 'deep-equal'
import * as sourceMappingDecoder from '../../../src/source/sourceMappingDecoder'
import * as vmCall from '../../vmCall' import * as vmCall from '../../vmCall'
import { TraceManager } from '../../../src/trace/traceManager' import { TraceManager } from '../../../src/trace/traceManager'
import { CodeManager } from '../../../src/code/codeManager' import { CodeManager } from '../../../src/code/codeManager'
@ -9,7 +10,7 @@ import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree
import { EventManager } from '../../../src/eventManager' import { EventManager } from '../../../src/eventManager'
import * as helper from './helper' import * as helper from './helper'
module.exports = async function (st, privateKey, contractBytecode, compilationResult) { module.exports = async function (st, privateKey, contractBytecode, compilationResult, contractCode) {
let txHash let txHash
let web3 let web3
try { try {
@ -34,10 +35,18 @@ module.exports = async function (st, privateKey, contractBytecode, compilationRe
var solidityProxy = new SolidityProxy({ var solidityProxy = new SolidityProxy({
getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager), getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager),
getCode: codeManager.getCode.bind(codeManager), getCode: codeManager.getCode.bind(codeManager),
compilationResult: () => compilationResult compilationResult: () => compilationResult
}) })
var debuggerEvent = new EventManager() var debuggerEvent = new EventManager()
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true }) const offsetToLineColumnConverter = {
offsetToLineColumn: (rawLocation) => {
return new Promise((resolve) => {
const lineBreaks = sourceMappingDecoder.getLinebreakPositions(contractCode)
resolve(sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, lineBreaks))
})
}
}
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true }, offsetToLineColumnConverter)
callTree.event.register('callTreeBuildFailed', (error) => { callTree.event.register('callTreeBuildFailed', (error) => {
st.fail(error) st.fail(error)
}) })

@ -7,8 +7,9 @@ import { EventManager } from '../../../src/eventManager'
import * as helper from './helper' import * as helper from './helper'
import { TraceManager } from '../../../src/trace/traceManager' import { TraceManager } from '../../../src/trace/traceManager'
import { CodeManager } from '../../../src/code/codeManager' import { CodeManager } from '../../../src/code/codeManager'
import * as sourceMappingDecoder from '../../../src/source/sourceMappingDecoder'
module.exports = function (st, privateKey, contractBytecode, compilationResult) { module.exports = function (st, privateKey, contractBytecode, compilationResult, contractCode) {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
const web3 = await (vmCall as any).getWeb3(); const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) { (vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) {
@ -29,7 +30,15 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult)
compilationResult: () => compilationResult compilationResult: () => compilationResult
}) })
var debuggerEvent = new EventManager() var debuggerEvent = new EventManager()
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true }) const offsetToLineColumnConverter = {
offsetToLineColumn: (rawLocation) => {
return new Promise((resolve) => {
const lineBreaks = sourceMappingDecoder.getLinebreakPositions(contractCode)
resolve(sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, lineBreaks))
})
}
}
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true }, offsetToLineColumnConverter)
callTree.event.register('callTreeBuildFailed', (error) => { callTree.event.register('callTreeBuildFailed', (error) => {
st.fail(error) st.fail(error)
}) })

@ -7,8 +7,9 @@ import { EventManager } from '../../../src/eventManager'
import * as helper from './helper' import * as helper from './helper'
import { TraceManager } from '../../../src/trace/traceManager' import { TraceManager } from '../../../src/trace/traceManager'
import { CodeManager } from '../../../src/code/codeManager' import { CodeManager } from '../../../src/code/codeManager'
import * as sourceMappingDecoder from '../../../src/source/sourceMappingDecoder'
module.exports = function (st, privateKey, contractBytecode, compilationResult) { module.exports = function (st, privateKey, contractBytecode, compilationResult, contractCode) {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
const web3 = await (vmCall as any).getWeb3(); const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) { (vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) {
@ -29,7 +30,15 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult)
compilationResult: () => compilationResult compilationResult: () => compilationResult
}) })
var debuggerEvent = new EventManager() var debuggerEvent = new EventManager()
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true }) const offsetToLineColumnConverter = {
offsetToLineColumn: (rawLocation) => {
return new Promise((resolve) => {
const lineBreaks = sourceMappingDecoder.getLinebreakPositions(contractCode)
resolve(sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, lineBreaks))
})
}
}
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true }, offsetToLineColumnConverter)
callTree.event.register('callTreeBuildFailed', (error) => { callTree.event.register('callTreeBuildFailed', (error) => {
st.fail(error) st.fail(error)
}) })

@ -7,8 +7,9 @@ import { EventManager } from '../../../src/eventManager'
import * as helper from './helper' import * as helper from './helper'
import { TraceManager } from '../../../src/trace/traceManager' import { TraceManager } from '../../../src/trace/traceManager'
import { CodeManager } from '../../../src/code/codeManager' import { CodeManager } from '../../../src/code/codeManager'
import * as sourceMappingDecoder from '../../../src/source/sourceMappingDecoder'
module.exports = function (st, privateKey, contractBytecode, compilationResult) { module.exports = function (st, privateKey, contractBytecode, compilationResult,contractCode) {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
const web3 = await (vmCall as any).getWeb3(); const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) { (vmCall as any).sendTx(web3, { nonce: 0, privateKey: privateKey }, null, 0, contractBytecode, function (error, hash) {
@ -29,13 +30,22 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult)
compilationResult: () => compilationResult compilationResult: () => compilationResult
}) })
var debuggerEvent = new EventManager() var debuggerEvent = new EventManager()
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true }) const offsetToLineColumnConverter = {
offsetToLineColumn: (rawLocation) => {
return new Promise((resolve) => {
const lineBreaks = sourceMappingDecoder.getLinebreakPositions(contractCode)
resolve(sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, lineBreaks))
})
}
}
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true }, offsetToLineColumnConverter)
callTree.event.register('callTreeBuildFailed', (error) => { callTree.event.register('callTreeBuildFailed', (error) => {
st.fail(error) st.fail(error)
}) })
callTree.event.register('callTreeReady', (scopes, scopeStarts) => { callTree.event.register('callTreeReady', (scopes, scopeStarts) => {
helper.decodeLocals(st, 1622, traceManager, callTree, function (locals) { helper.decodeLocals(st, 1622, traceManager, callTree, function (locals) {
try { try {
console.log('at 1622', locals)
st.equals(locals['bytesSimple'].length, '0x14') st.equals(locals['bytesSimple'].length, '0x14')
st.equals(locals['bytesSimple'].value, '0x746573745f7375706572') st.equals(locals['bytesSimple'].value, '0x746573745f7375706572')
st.equals(locals['e'].value['a'].value, 'test') st.equals(locals['e'].value['a'].value, 'test')
@ -101,9 +111,10 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult)
st.fail(e.message) st.fail(e.message)
} }
}) })
helper.decodeLocals(st, 7, traceManager, callTree, function (locals) { helper.decodeLocals(st, 7, traceManager, callTree, function (locals) {
try { try {
console.log('at 7', locals)
st.equals(0, 0) st.equals(0, 0)
// st.equals(Object.keys(locals).length, 0) // st.equals(Object.keys(locals).length, 0)
} catch (e) { } catch (e) {

@ -1,7 +1,12 @@
import { CompilerAbstract } from '@remix-project/remix-solidity'
import { EventManager } from '../../../src/eventManager'
import { compilerInput } from '../../helpers/compilerHelper' import { compilerInput } from '../../helpers/compilerHelper'
import { TraceManager } from '../../../src/trace/traceManager' import { TraceManager } from '../../../src/trace/traceManager'
import { CodeManager } from '../../../src/code/codeManager'
import { compile } from 'solc' import { compile } from 'solc'
import * as stateDecoder from '../../../src/solidity-decoder/stateDecoder' import * as stateDecoder from '../../../src/solidity-decoder/stateDecoder'
import { SolidityProxy } from '../../../src/solidity-decoder/solidityProxy'
import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree'
import * as vmCall from '../../vmCall' import * as vmCall from '../../vmCall'
import { StorageResolver } from '../../../src/storage/storageResolver' import { StorageResolver } from '../../../src/storage/storageResolver'
import { StorageViewer } from '../../../src/storage/storageViewer' import { StorageViewer } from '../../../src/storage/storageViewer'
@ -12,6 +17,11 @@ module.exports = async function testMappingStorage (st, cb) {
var privateKey = Buffer.from('503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb', 'hex') var privateKey = Buffer.from('503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb', 'hex')
var output = compile(compilerInput(mappingStorage.contract)) var output = compile(compilerInput(mappingStorage.contract))
output = JSON.parse(output); output = JSON.parse(output);
const sources = {
target: 'test.sol',
sources: { 'test.sol': { content: mappingStorage.contract } }
}
const compilationResults = new CompilerAbstract('json', output, sources)
const web3 = await (vmCall as any).getWeb3(); const web3 = await (vmCall as any).getWeb3();
(vmCall as any).sendTx(web3, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, hash) { (vmCall as any).sendTx(web3, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, hash) {
if (error) { if (error) {
@ -26,7 +36,7 @@ module.exports = async function testMappingStorage (st, cb) {
// const storage = await this.vm.stateManager.dumpStorage(data.to) // const storage = await this.vm.stateManager.dumpStorage(data.to)
// (vmCall as any).web3().eth.getCode(tx.contractAddress).then((code) => console.log('code:', code)) // (vmCall as any).web3().eth.getCode(tx.contractAddress).then((code) => console.log('code:', code))
// (vmCall as any).web3().debug.traceTransaction(hash).then((code) => console.log('trace:', code)) // (vmCall as any).web3().debug.traceTransaction(hash).then((code) => console.log('trace:', code))
testMapping(st, privateKey, tx.contractAddress, output, web3, cb) testMapping(st, privateKey, tx.contractAddress, output, compilationResults, web3, cb)
// st.end() // st.end()
} }
}) })
@ -34,7 +44,7 @@ module.exports = async function testMappingStorage (st, cb) {
}) })
} }
function testMapping (st, privateKey, contractAddress, output, web3, cb) { function testMapping (st, privateKey, contractAddress, output, compilationResults, web3, cb) {
(vmCall as any).sendTx(web3, {nonce: 1, privateKey: privateKey}, contractAddress, 0, '2fd0a83a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001074686973206973206120737472696e6700000000000000000000000000000000', (vmCall as any).sendTx(web3, {nonce: 1, privateKey: privateKey}, contractAddress, 0, '2fd0a83a00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001074686973206973206120737472696e6700000000000000000000000000000000',
function (error, hash) { function (error, hash) {
if (error) { if (error) {
@ -46,8 +56,24 @@ function testMapping (st, privateKey, contractAddress, output, web3, cb) {
console.log(error) console.log(error)
st.end(error) st.end(error)
} else { } else {
var traceManager = new TraceManager({web3}) var traceManager = new TraceManager({ web3 })
traceManager.resolveTrace(tx).then(() => { var codeManager = new CodeManager(traceManager)
codeManager.clear()
console.log(compilationResults)
var solidityProxy = new SolidityProxy({
getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager),
getCode: codeManager.getCode.bind(codeManager),
compilationResult: () => compilationResults
})
var debuggerEvent = new EventManager()
var callTree = new InternalCallTree(debuggerEvent, traceManager, solidityProxy, codeManager, { includeLocalVariables: true })
callTree.event.register('callTreeBuildFailed', (error) => {
st.fail(error)
})
callTree.event.register('callTreeNotReady', (reason) => {
st.fail(reason)
})
callTree.event.register('callTreeReady', (scopes, scopeStarts) => {
var storageViewer = new StorageViewer({ var storageViewer = new StorageViewer({
stepIndex: 268, stepIndex: 268,
tx: tx, tx: tx,
@ -69,6 +95,12 @@ function testMapping (st, privateKey, contractAddress, output, web3, cb) {
st.end(reason) st.end(reason)
}) })
}) })
traceManager.resolveTrace(tx).then(() => {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
}).catch((error) => {
st.fail(error)
})
} }
}) })
} }

@ -8,9 +8,13 @@ var testMappingStorage = require('./stateTests/mapping')
tape('solidity', function (t) { tape('solidity', function (t) {
t.test('storage decoder', function (st) { t.test('storage decoder', function (st) {
console.log('test int storage')
testIntStorage(st, function () { testIntStorage(st, function () {
console.log('test byte storage')
testByteStorage(st, function () { testByteStorage(st, function () {
console.log('test struct storage')
testStructArrayStorage(st, function () { testStructArrayStorage(st, function () {
console.log('test mapping storage')
testMappingStorage(st, function () { testMappingStorage(st, function () {
st.end() st.end()
}) })

Loading…
Cancel
Save