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

@ -1,6 +1,7 @@
'use strict'
import tape from 'tape'
var compiler = require('solc')
import { CompilerAbstract } from '@remix-project/remix-solidity'
var intLocal = require('./contracts/intLocal')
var miscLocal = require('./contracts/miscLocal')
var structArrayLocal = require('./contracts/structArrayLocal')
@ -23,20 +24,53 @@ tape('solidity', function (t) {
async function test (st, privateKey) {
var output = compiler.compile(compilerInput(intLocal.contract))
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 = 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 = 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 = 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 = 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()
}

@ -1,6 +1,7 @@
'use strict'
import deepequal from 'deep-equal'
import * as sourceMappingDecoder from '../../../src/source/sourceMappingDecoder'
import * as vmCall from '../../vmCall'
import { TraceManager } from '../../../src/trace/traceManager'
import { CodeManager } from '../../../src/code/codeManager'
@ -9,7 +10,7 @@ import { InternalCallTree } from '../../../src/solidity-decoder/internalCallTree
import { EventManager } from '../../../src/eventManager'
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 web3
try {
@ -34,10 +35,18 @@ module.exports = async function (st, privateKey, contractBytecode, compilationRe
var solidityProxy = new SolidityProxy({
getCurrentCalledAddressAt: traceManager.getCurrentCalledAddressAt.bind(traceManager),
getCode: codeManager.getCode.bind(codeManager),
compilationResult: () => compilationResult
compilationResult: () => compilationResult
})
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) => {
st.fail(error)
})

@ -7,8 +7,9 @@ import { EventManager } from '../../../src/eventManager'
import * as helper from './helper'
import { TraceManager } from '../../../src/trace/traceManager'
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) => {
const web3 = await (vmCall as any).getWeb3();
(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
})
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) => {
st.fail(error)
})

@ -7,8 +7,9 @@ import { EventManager } from '../../../src/eventManager'
import * as helper from './helper'
import { TraceManager } from '../../../src/trace/traceManager'
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) => {
const web3 = await (vmCall as any).getWeb3();
(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
})
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) => {
st.fail(error)
})

@ -7,8 +7,9 @@ import { EventManager } from '../../../src/eventManager'
import * as helper from './helper'
import { TraceManager } from '../../../src/trace/traceManager'
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) => {
const web3 = await (vmCall as any).getWeb3();
(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
})
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) => {
st.fail(error)
})
callTree.event.register('callTreeReady', (scopes, scopeStarts) => {
helper.decodeLocals(st, 1622, traceManager, callTree, function (locals) {
try {
console.log('at 1622', locals)
st.equals(locals['bytesSimple'].length, '0x14')
st.equals(locals['bytesSimple'].value, '0x746573745f7375706572')
st.equals(locals['e'].value['a'].value, 'test')
@ -101,9 +111,10 @@ module.exports = function (st, privateKey, contractBytecode, compilationResult)
st.fail(e.message)
}
})
helper.decodeLocals(st, 7, traceManager, callTree, function (locals) {
try {
console.log('at 7', locals)
st.equals(0, 0)
// st.equals(Object.keys(locals).length, 0)
} catch (e) {

@ -1,7 +1,12 @@
import { CompilerAbstract } from '@remix-project/remix-solidity'
import { EventManager } from '../../../src/eventManager'
import { compilerInput } from '../../helpers/compilerHelper'
import { TraceManager } from '../../../src/trace/traceManager'
import { CodeManager } from '../../../src/code/codeManager'
import { compile } from 'solc'
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 { StorageResolver } from '../../../src/storage/storageResolver'
import { StorageViewer } from '../../../src/storage/storageViewer'
@ -12,6 +17,11 @@ module.exports = async function testMappingStorage (st, cb) {
var privateKey = Buffer.from('503f38a9c967ed597e47fe25643985f032b072db8075426a92110f82df48dfcb', 'hex')
var output = compile(compilerInput(mappingStorage.contract))
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();
(vmCall as any).sendTx(web3, {nonce: 0, privateKey: privateKey}, null, 0, output.contracts['test.sol']['SimpleMappingState'].evm.bytecode.object, function (error, hash) {
if (error) {
@ -26,7 +36,7 @@ module.exports = async function testMappingStorage (st, cb) {
// 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().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()
}
})
@ -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',
function (error, hash) {
if (error) {
@ -46,8 +56,24 @@ function testMapping (st, privateKey, contractAddress, output, web3, cb) {
console.log(error)
st.end(error)
} else {
var traceManager = new TraceManager({web3})
traceManager.resolveTrace(tx).then(() => {
var traceManager = new TraceManager({ web3 })
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({
stepIndex: 268,
tx: tx,
@ -69,6 +95,12 @@ function testMapping (st, privateKey, contractAddress, output, web3, cb) {
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) {
t.test('storage decoder', function (st) {
console.log('test int storage')
testIntStorage(st, function () {
console.log('test byte storage')
testByteStorage(st, function () {
console.log('test struct storage')
testStructArrayStorage(st, function () {
console.log('test mapping storage')
testMappingStorage(st, function () {
st.end()
})

Loading…
Cancel
Save