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/libs/remix-debug/test/sourceMappingDecoder.ts

135 lines
4.8 KiB

'use strict'
const tape = require('tape')
const sourceMapping = require('./resources/sourceMapping')
4 years ago
import * as sourceMappingDecoder from '../src/source/sourceMappingDecoder'
const compiler = require('solc')
const compilerInput = require('./helpers/compilerHelper').compilerInput
7 years ago
tape('sourceMappingDecoder', function (t) {
t.test('sourceMappingDecoder.findNodeAtInstructionIndex', function (st) {
let output = compiler.compile(compilerInput(contracts))
7 years ago
output = JSON.parse(output)
let node = sourceMappingDecoder.findNodeAtInstructionIndex('FunctionDefinition', 2, output.contracts['test.sol']['test'].evm.deployedBytecode.sourceMap, output.sources['test.sol'])
7 years ago
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) {
4 years ago
st.equal(node.name, 'f1')
7 years ago
}
st.end()
})
const testSourceMapping = {}
t.test('sourceMappingDecoder', function (st) {
4 years ago
st.plan(36)
console.log('test decompressAll')
# This is a combination of 50 commits. # This is the 1st commit message: executors # This is the commit message #2: libs # This is the commit message #3: remixd # This is the commit message #4: add react app # This is the commit message #5: debugging # This is the commit message #6: debug + sol # This is the commit message #7: fixes # This is the commit message #8: tsconfig # This is the commit message #9: ast walker # This is the commit message #10: as walker # This is the commit message #11: remixd etc # This is the commit message #12: commander # This is the commit message #13: remove jest # This is the commit message #14: rm ui files # This is the commit message #15: rm reserved keywords # This is the commit message #16: testrunner # This is the commit message #17: compiler # This is the commit message #18: production build # This is the commit message #19: config # This is the commit message #20: config # This is the commit message #21: web types # This is the commit message #22: update react # This is the commit message #23: add vm # This is the commit message #24: add workers # This is the commit message #25: worker2 # This is the commit message #26: rm react app # This is the commit message #27: remixd # This is the commit message #28: worker fix # This is the commit message #29: fix detection # This is the commit message #30: revert react # This is the commit message #31: rename type # This is the commit message #32: loading handler # This is the commit message #33: remove import # This is the commit message #34: rename # This is the commit message #35: local plugin # This is the commit message #36: etherscan # This is the commit message #37: revert react # This is the commit message #38: port # This is the commit message #39: rm worker # This is the commit message #40: publicpath # This is the commit message #41: fix test # This is the commit message #42: 112 # This is the commit message #43: show version # This is the commit message #44: "axios": "1.1.2", # This is the commit message #45: config # This is the commit message #46: lint # This is the commit message #47: fix build # This is the commit message #48: lint # This is the commit message #49: error on purpose # This is the commit message #50: test error
2 years ago
const result = sourceMappingDecoder.decompressAll(sourceMapping.mapping)
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, '-')
testSourceMapping[21] = result[21]
st.equal(result[22].start, 55)
st.equal(result[22].length, 74)
st.equal(result[22].file, 4)
st.equal(result[22].jump, '-')
const last = result.length - 1
st.equal(result[last].start, 142)
st.equal(result[last].length, 61)
st.equal(result[last].file, 4)
st.equal(result[last].jump, 'o')
testSourceMapping['last'] = result[last]
console.log('test decompress')
4 years ago
const result2 = sourceMappingDecoder.atIndex(22, sourceMapping.mapping)
// console.log(result2)
st.equal(result2['start'], 55)
st.equal(result2['length'], 74)
st.equal(result2['file'], 4)
st.equal(result2['jump'], '-')
testSourceMapping[22] = result2
4 years ago
const result3 = sourceMappingDecoder.atIndex(82, sourceMapping.mapping)
// console.log(result)
st.equal(result3['start'], 103)
st.equal(result3['length'], 2)
4 years ago
st.equal(result3['file'], 4)
st.equal(result3['jump'], '-')
4 years ago
testSourceMapping[82] = result3
4 years ago
const result4 = sourceMappingDecoder.atIndex(85, sourceMapping.mapping)
// console.log(result)
st.equal(result4['start'], 99)
st.equal(result4['length'], 6)
st.equal(result4['file'], 4)
st.equal(result4['jump'], '-')
testSourceMapping[85] = result4
// ballot - function deletegate(address)
const delegateSrcMap = sourceMappingDecoder.atIndex(64, sourceMapping.ballotSourceMap)
console.log(delegateSrcMap)
4 years ago
st.equal(delegateSrcMap['start'], 712)
st.equal(delegateSrcMap['length'], 577)
st.equal(delegateSrcMap['file'], 0)
st.equal(delegateSrcMap['jump'], '-')
4 years ago
// TokenSaleChallenge - function test(uint256)
4 years ago
const tokenSaleChallengeMap = sourceMappingDecoder.atIndex(170, sourceMapping.tokenSaleChallengeSourceMap)
console.log(tokenSaleChallengeMap)
4 years ago
st.equal(tokenSaleChallengeMap['start'], 45)
st.equal(tokenSaleChallengeMap['length'], 16)
st.equal(tokenSaleChallengeMap['file'], -1)
st.equal(tokenSaleChallengeMap['jump'], '-')
})
t.test('sourceMappingLineColumnConverter', function (st) {
st.plan(14)
const linesbreak = sourceMappingDecoder.getLinebreakPositions(sourceMapping.source)
st.equal(linesbreak[0], 16)
st.equal(linesbreak[5], 84)
let result = sourceMappingDecoder.convertOffsetToLineColumn(testSourceMapping[21], linesbreak)
st.equal(result.start.line, 0)
st.equal(result.start.column, 0)
st.equal(result.end.line, 15)
st.equal(result.end.column, 1)
result = sourceMappingDecoder.convertOffsetToLineColumn(testSourceMapping[82], linesbreak)
st.equal(result.start.line, 7)
st.equal(result.start.column, 12)
st.equal(result.end.line, 7)
st.equal(result.end.column, 14)
const res = { // point to \n
start: 103,
length: 4,
file: 4,
jump: '-'
}
// case: 'file' is not yet assigned, while processing the srcmap (reverse looping) to find 'start', 'length' (etc..), we tumble on -1 for the file.
// in that case the step has to be discarded
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)
})
})
7 years ago
const contracts = `contract test {
6 years ago
function f1() public returns (uint) {
7 years ago
uint t = 4;
return t;
}
6 years ago
function f2() public {
7 years ago
}
}
`