aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-tracing-utils/test/source_maps_test.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2019-01-11 07:47:57 +0800
committerFabio Berger <me@fabioberger.com>2019-01-11 07:47:57 +0800
commit583e690b7a028c85809a8be2c7afe3b65264adbe (patch)
treebc7ba2fe96833633455daaebf44d7382d0e20b7d /packages/sol-tracing-utils/test/source_maps_test.ts
parenta516b00a0397a567fd233bd955206d46321cc178 (diff)
parenta5b7a351609a5e6689bb97990216153f64302462 (diff)
downloaddexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar
dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.gz
dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.bz2
dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.lz
dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.xz
dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.zst
dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.zip
Merge branch 'development' into fix/dev-tools-pages/finalTouches
* development: (49 commits) upgrade to ddex api v3 (#1507) Add new deployment related instructions to pipeline README (#1499) feature: implement logging and friendly wallet name for Opera Fix prettier Add missing dependencies Remove second yarn call Add .gitkeep Rename sol-trace-based-tools-common to sol-tracing-utils Update packages/sol-trace/README.md Update packages/sol-trace/CHANGELOG.json Update packages/sol-trace-based-tools-common/src/source_maps.ts Update packages/sol-trace-based-tools-common/CHANGELOG.json Update packages/sol-profiler/CHANGELOG.json Update packages/sol-coverage/CHANGELOG.json Update packages/monorepo-scripts/src/test_installation.ts chore: changelog update fix: account for undefined errors in promisify, not only null Clean up docs before publish In README's, don't mention non-existent tests (#1497) fix: use getBackendBaseUrl instead of hardcoded string ...
Diffstat (limited to 'packages/sol-tracing-utils/test/source_maps_test.ts')
-rw-r--r--packages/sol-tracing-utils/test/source_maps_test.ts71
1 files changed, 71 insertions, 0 deletions
diff --git a/packages/sol-tracing-utils/test/source_maps_test.ts b/packages/sol-tracing-utils/test/source_maps_test.ts
new file mode 100644
index 000000000..5820bedd7
--- /dev/null
+++ b/packages/sol-tracing-utils/test/source_maps_test.ts
@@ -0,0 +1,71 @@
+import * as chai from 'chai';
+import * as fs from 'fs';
+import * as _ from 'lodash';
+import 'mocha';
+import * as path from 'path';
+
+import { getLocationByOffset, parseSourceMap } from '../src/source_maps';
+
+const expect = chai.expect;
+
+const simplestContractBaseName = 'Simplest.sol';
+const simplestContractFileName = path.resolve(__dirname, 'fixtures/contracts', simplestContractBaseName);
+const simplestContract = fs.readFileSync(simplestContractFileName).toString();
+
+describe('source maps', () => {
+ describe('#getLocationByOffset', () => {
+ it('correctly computes location by offset', () => {
+ const locationByOffset = getLocationByOffset(simplestContract);
+ const expectedLocationByOffset = {
+ '0': { line: 1, column: 0 },
+ '1': { line: 1, column: 1 },
+ '2': { line: 1, column: 2 },
+ '3': { line: 1, column: 3 },
+ '4': { line: 1, column: 4 },
+ '5': { line: 1, column: 5 },
+ '6': { line: 1, column: 6 },
+ '7': { line: 1, column: 7 },
+ '8': { line: 1, column: 8 },
+ '9': { line: 1, column: 9 },
+ '10': { line: 1, column: 10 },
+ '11': { line: 1, column: 11 },
+ '12': { line: 1, column: 12 },
+ '13': { line: 1, column: 13 },
+ '14': { line: 1, column: 14 },
+ '15': { line: 1, column: 15 },
+ '16': { line: 1, column: 16 },
+ '17': { line: 1, column: 17 },
+ '18': { line: 1, column: 18 },
+ '19': { line: 1, column: 19 },
+ '20': { line: 2, column: 0 },
+ '21': { line: 2, column: 1 },
+ '22': { line: 3, column: 0 },
+ };
+ expect(locationByOffset).to.be.deep.equal(expectedLocationByOffset);
+ });
+ });
+ describe('#parseSourceMap', () => {
+ it('correctly parses the source map', () => {
+ // This is the source map and bytecode for an empty contract like Example.sol
+ const srcMap = '0:21:0:-;;;;;;;;;;;;;;;;;';
+ const bytecodeHex =
+ '60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00a165627a7a72305820377cdef690e46589f40efeef14d8ef73504af059fb3fd46f1da3cd2fc52ef7890029';
+ const sources = [simplestContractBaseName];
+ const pcToSourceRange = parseSourceMap([simplestContract], srcMap, bytecodeHex, sources);
+ const expectedSourceRange = {
+ location: {
+ start: { line: 1, column: 0 },
+ end: { line: 2, column: 1 },
+ },
+ fileName: simplestContractBaseName,
+ };
+ _.forEach(pcToSourceRange, sourceRange => {
+ // Solidity source maps are too short and we map some instructions to undefined
+ // Source: https://github.com/ethereum/solidity/issues/3741
+ if (!_.isUndefined(sourceRange)) {
+ expect(sourceRange).to.be.deep.equal(expectedSourceRange);
+ }
+ });
+ });
+ });
+});