diff options
Diffstat (limited to 'packages/sol-cov/test')
-rw-r--r-- | packages/sol-cov/test/collect_coverage_entries_test.ts | 3 | ||||
-rw-r--r-- | packages/sol-cov/test/instructions_test.ts | 1 | ||||
-rw-r--r-- | packages/sol-cov/test/sol_compiler_artifact_adapter_test.ts (renamed from packages/sol-cov/test/collect_contracts_data_test.ts) | 9 | ||||
-rw-r--r-- | packages/sol-cov/test/trace_test.ts | 57 |
4 files changed, 66 insertions, 4 deletions
diff --git a/packages/sol-cov/test/collect_coverage_entries_test.ts b/packages/sol-cov/test/collect_coverage_entries_test.ts index 82012edfa..a03be19cd 100644 --- a/packages/sol-cov/test/collect_coverage_entries_test.ts +++ b/packages/sol-cov/test/collect_coverage_entries_test.ts @@ -40,12 +40,14 @@ describe('Collect coverage entries', () => { const coverageEntries = collectCoverageEntries(simpleStorageContract); const fnIds = _.keys(coverageEntries.fnMap); expect(coverageEntries.fnMap[fnIds[0]].name).to.be.equal('set'); + // tslint:disable-next-line:custom-no-magic-numbers expect(coverageEntries.fnMap[fnIds[0]].line).to.be.equal(5); const setFunction = `function set(uint x) { storedData = x; }`; expect(getRange(simpleStorageContract, coverageEntries.fnMap[fnIds[0]].loc)).to.be.equal(setFunction); expect(coverageEntries.fnMap[fnIds[1]].name).to.be.equal('get'); + // tslint:disable-next-line:custom-no-magic-numbers expect(coverageEntries.fnMap[fnIds[1]].line).to.be.equal(8); const getFunction = `function get() constant returns (uint retVal) { return storedData; @@ -122,6 +124,7 @@ describe('Collect coverage entries', () => { const branchDescriptions = _.values(coverageEntries.branchMap); const branchLines = _.map(branchDescriptions, branchDescription => branchDescription.line); + // tslint:disable-next-line:custom-no-magic-numbers expect(branchLines).to.be.deep.equal([94, 115, 119, 130, 151, 187]); const branchTypes = _.map(branchDescriptions, branchDescription => branchDescription.type); expect(branchTypes).to.be.deep.equal(['if', 'if', 'if', 'if', 'binary-expr', 'if']); diff --git a/packages/sol-cov/test/instructions_test.ts b/packages/sol-cov/test/instructions_test.ts index f66612f5f..8012674f5 100644 --- a/packages/sol-cov/test/instructions_test.ts +++ b/packages/sol-cov/test/instructions_test.ts @@ -12,6 +12,7 @@ const expect = chai.expect; describe('instructions', () => { describe('#getPcToInstructionIndexMapping', () => { it('correctly maps pcs to instruction indexed', () => { + // tslint:disable-next-line:custom-no-magic-numbers const bytecode = new Uint8Array([constants.PUSH1, 42, constants.PUSH2, 1, 2, constants.TIMESTAMP]); const pcToInstruction = getPcToInstructionIndexMapping(bytecode); const expectedPcToInstruction = { '0': 0, '2': 1, '5': 2 }; diff --git a/packages/sol-cov/test/collect_contracts_data_test.ts b/packages/sol-cov/test/sol_compiler_artifact_adapter_test.ts index d84ac5a39..0ebad669b 100644 --- a/packages/sol-cov/test/collect_contracts_data_test.ts +++ b/packages/sol-cov/test/sol_compiler_artifact_adapter_test.ts @@ -4,16 +4,17 @@ import 'make-promises-safe'; import 'mocha'; import * as path from 'path'; -import { collectContractsData } from '../src/collect_contract_data'; +import { SolCompilerArtifactAdapter } from '../src/artifact_adapters/sol_compiler_artifact_adapter'; const expect = chai.expect; -describe('Collect contracts data', () => { +describe('SolCompilerArtifactAdapter', () => { describe('#collectContractsData', () => { - it('correctly collects contracts data', () => { + it('correctly collects contracts data', async () => { const artifactsPath = path.resolve(__dirname, 'fixtures/artifacts'); const sourcesPath = path.resolve(__dirname, 'fixtures/contracts'); - const contractsData = collectContractsData(artifactsPath, sourcesPath); + const zeroExArtifactsAdapter = new SolCompilerArtifactAdapter(artifactsPath, sourcesPath); + const contractsData = await zeroExArtifactsAdapter.collectContractsDataAsync(); _.forEach(contractsData, contractData => { expect(contractData).to.have.keys([ 'sourceCodes', diff --git a/packages/sol-cov/test/trace_test.ts b/packages/sol-cov/test/trace_test.ts new file mode 100644 index 000000000..c140cba0d --- /dev/null +++ b/packages/sol-cov/test/trace_test.ts @@ -0,0 +1,57 @@ +import { OpCode, StructLog } from '@0xproject/types'; +import * as chai from 'chai'; +import * as fs from 'fs'; +import * as _ from 'lodash'; +import 'mocha'; +import * as path from 'path'; + +import { getTracesByContractAddress } from '../src/trace'; + +const expect = chai.expect; + +const DEFAULT_STRUCT_LOG: StructLog = { + depth: 0, + error: '', + gas: 0, + gasCost: 0, + memory: [], + op: OpCode.Invalid, + pc: 0, + stack: [], + storage: {}, +}; + +function addDefaultStructLogFields(compactStructLog: Partial<StructLog> & { op: OpCode; depth: number }): StructLog { + return { ...DEFAULT_STRUCT_LOG, ...compactStructLog }; +} + +describe('Trace', () => { + describe('#getTracesByContractAddress', () => { + it('correctly splits trace by contract address', () => { + const delegateCallAddress = '0x0000000000000000000000000000000000000002'; + const trace = [ + { + op: OpCode.DelegateCall, + stack: [delegateCallAddress, '0x'], + depth: 0, + }, + { + op: OpCode.Return, + depth: 1, + }, + { + op: OpCode.Return, + depth: 0, + }, + ]; + const fullTrace = _.map(trace, compactStructLog => addDefaultStructLogFields(compactStructLog)); + const startAddress = '0x0000000000000000000000000000000000000001'; + const traceByContractAddress = getTracesByContractAddress(fullTrace, startAddress); + const expectedTraceByContractAddress = { + [startAddress]: [fullTrace[0], fullTrace[2]], + [delegateCallAddress]: [fullTrace[1]], + }; + expect(traceByContractAddress).to.be.deep.equal(expectedTraceByContractAddress); + }); + }); +}); |