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.
141 lines
4.3 KiB
141 lines
4.3 KiB
8 years ago
|
'use strict'
|
||
|
var tape = require('tape')
|
||
7 years ago
|
var sourceMapping = require('./resources/sourceMapping')
|
||
|
var SourceMappingDecoder = require('../src/sourceMappingDecoder')
|
||
|
var compiler = require('solc')
|
||
|
|
||
|
tape('SourceMappingDecoder', function (t) {
|
||
|
t.test('SourceMappingDecoder.findNodeAtInstructionIndex', function (st) {
|
||
|
var output = compiler.compileStandardWrapper(compilerInput(contracts))
|
||
|
output = JSON.parse(output)
|
||
|
var sourceMappingDecoder = new SourceMappingDecoder()
|
||
|
var node = sourceMappingDecoder.findNodeAtInstructionIndex('FunctionDefinition', 2, output.contracts['test.sol']['test'].evm.deployedBytecode.sourceMap, output.sources['test.sol'])
|
||
|
st.equal(node, null)
|
||
|
node = sourceMappingDecoder.findNodeAtInstructionIndex('FunctionDefinition', 80, output.contracts['test.sol']['test'].evm.deployedBytecode.sourceMap, output.sources['test.sol'])
|
||
|
st.notEqual(node, null)
|
||
|
if (node) {
|
||
|
st.equal(node.attributes.name, 'f1')
|
||
|
}
|
||
|
st.end()
|
||
8 years ago
|
})
|
||
|
|
||
8 years ago
|
var testSourceMapping = {}
|
||
|
t.test('sourceMappingDecoder', function (st) {
|
||
|
st.plan(28)
|
||
7 years ago
|
var sourceMappingDecoder = new SourceMappingDecoder()
|
||
8 years ago
|
console.log('test decompressAll')
|
||
|
var result = sourceMappingDecoder.decompressAll(sourceMapping.mapping)
|
||
8 years ago
|
st.equal(result[0].start, 0)
|
||
|
st.equal(result[0].length, 205)
|
||
|
st.equal(result[0].file, 4)
|
||
|
st.equal(result[0].jump, '-')
|
||
|
|
||
|
st.equal(result[21].start, 0)
|
||
|
st.equal(result[21].length, 205)
|
||
|
st.equal(result[21].file, 4)
|
||
|
st.equal(result[21].jump, '-')
|
||
8 years ago
|
testSourceMapping[21] = result[21]
|
||
|
|
||
8 years ago
|
st.equal(result[22].start, 55)
|
||
|
st.equal(result[22].length, 74)
|
||
|
st.equal(result[22].file, 4)
|
||
|
st.equal(result[22].jump, '-')
|
||
8 years ago
|
|
||
|
var last = result.length - 1
|
||
8 years ago
|
st.equal(result[last].start, 142)
|
||
|
st.equal(result[last].length, 61)
|
||
|
st.equal(result[last].file, 4)
|
||
|
st.equal(result[last].jump, 'o')
|
||
8 years ago
|
testSourceMapping['last'] = result[last]
|
||
|
|
||
|
console.log('test decompress')
|
||
|
result = sourceMappingDecoder.atIndex(22, sourceMapping.mapping)
|
||
|
console.log(result)
|
||
8 years ago
|
st.equal(result.start, 55)
|
||
|
st.equal(result.length, 74)
|
||
|
st.equal(result.file, 4)
|
||
|
st.equal(result.jump, '-')
|
||
8 years ago
|
testSourceMapping[22] = result
|
||
|
|
||
|
result = sourceMappingDecoder.atIndex(82, sourceMapping.mapping)
|
||
|
console.log(result)
|
||
8 years ago
|
st.equal(result.start, 103)
|
||
|
st.equal(result.length, 2)
|
||
|
st.equal(result.file, 4)
|
||
|
st.equal(result.jump, '-')
|
||
8 years ago
|
testSourceMapping[82] = result
|
||
|
|
||
|
result = sourceMappingDecoder.atIndex(85, sourceMapping.mapping)
|
||
|
console.log(result)
|
||
8 years ago
|
st.equal(result.start, 99)
|
||
|
st.equal(result.length, 6)
|
||
|
st.equal(result.file, 4)
|
||
|
st.equal(result.jump, '-')
|
||
8 years ago
|
testSourceMapping[85] = result
|
||
|
})
|
||
|
|
||
|
t.test('sourceMappingLineColumnConverter', function (st) {
|
||
8 years ago
|
st.plan(14)
|
||
7 years ago
|
var sourceMappingDecoder = new SourceMappingDecoder()
|
||
8 years ago
|
var linesbreak = sourceMappingDecoder.getLinebreakPositions(sourceMapping.source)
|
||
8 years ago
|
st.equal(linesbreak[0], 16)
|
||
|
st.equal(linesbreak[5], 84)
|
||
8 years ago
|
var result = sourceMappingDecoder.convertOffsetToLineColumn(testSourceMapping[21], linesbreak)
|
||
8 years ago
|
st.equal(result.start.line, 0)
|
||
|
st.equal(result.start.column, 0)
|
||
|
st.equal(result.end.line, 15)
|
||
|
st.equal(result.end.column, 1)
|
||
8 years ago
|
result = sourceMappingDecoder.convertOffsetToLineColumn(testSourceMapping[82], linesbreak)
|
||
8 years ago
|
st.equal(result.start.line, 7)
|
||
|
st.equal(result.start.column, 12)
|
||
|
st.equal(result.end.line, 7)
|
||
|
st.equal(result.end.column, 14)
|
||
|
|
||
|
var res = { // point to \n
|
||
|
start: 103,
|
||
|
length: 4,
|
||
|
file: 4,
|
||
|
jump: '-'
|
||
|
}
|
||
|
result = sourceMappingDecoder.convertOffsetToLineColumn(res, linesbreak)
|
||
|
st.equal(result.start.line, 7)
|
||
|
st.equal(result.start.column, 12)
|
||
|
st.equal(result.end.line, 7)
|
||
|
st.equal(result.end.column, 16)
|
||
8 years ago
|
})
|
||
|
})
|
||
7 years ago
|
|
||
|
var contracts = `contract test {
|
||
|
function f1() returns (uint) {
|
||
|
uint t = 4;
|
||
|
return t;
|
||
|
}
|
||
|
|
||
|
function f2() {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
`
|
||
|
|
||
|
function compilerInput (contracts) {
|
||
|
return JSON.stringify({
|
||
|
language: 'Solidity',
|
||
|
sources: {
|
||
|
'test.sol': {
|
||
|
content: contracts
|
||
|
}
|
||
|
},
|
||
|
settings: {
|
||
|
optimizer: {
|
||
|
enabled: false,
|
||
|
runs: 500
|
||
|
}
|
||
|
},
|
||
|
outputSelection: {
|
||
|
'*': {
|
||
|
'*': [ 'metadata', 'evm.bytecode', 'abi', 'legacyAST', 'metadata', 'evm.assembly', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|