aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/test
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-15 02:01:18 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 06:20:34 +0800
commit974575b695108dd70f4b165f6789f71c3647c2b1 (patch)
tree3d589c157c51c02066583a08bdec879aa7a18735 /packages/sol-cov/test
parent60b1fdd367101047d433d4b9c1c47925925296a2 (diff)
downloaddexon-sol-tools-974575b695108dd70f4b165f6789f71c3647c2b1.tar
dexon-sol-tools-974575b695108dd70f4b165f6789f71c3647c2b1.tar.gz
dexon-sol-tools-974575b695108dd70f4b165f6789f71c3647c2b1.tar.bz2
dexon-sol-tools-974575b695108dd70f4b165f6789f71c3647c2b1.tar.lz
dexon-sol-tools-974575b695108dd70f4b165f6789f71c3647c2b1.tar.xz
dexon-sol-tools-974575b695108dd70f4b165f6789f71c3647c2b1.tar.zst
dexon-sol-tools-974575b695108dd70f4b165f6789f71c3647c2b1.zip
Make sol-cov work with truffle and other artifact adapters
Diffstat (limited to 'packages/sol-cov/test')
-rw-r--r--packages/sol-cov/test/collect_contracts_data_test.ts7
-rw-r--r--packages/sol-cov/test/trace_test.ts57
2 files changed, 61 insertions, 3 deletions
diff --git a/packages/sol-cov/test/collect_contracts_data_test.ts b/packages/sol-cov/test/collect_contracts_data_test.ts
index d84ac5a39..906b7f4e2 100644
--- a/packages/sol-cov/test/collect_contracts_data_test.ts
+++ b/packages/sol-cov/test/collect_contracts_data_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 { ZeroExArtifactAdapter } from '../src/artifact_adapters/0x';
const expect = chai.expect;
describe('Collect contracts data', () => {
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 ZeroExArtifactAdapter(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..b9d846732
--- /dev/null
+++ b/packages/sol-cov/test/trace_test.ts
@@ -0,0 +1,57 @@
+import { 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: 'DEFAULT',
+ pc: 0,
+ stack: [],
+ storage: {},
+};
+
+function addDefaultStructLogFields(compactStructLog: Partial<StructLog> & { op: string; 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: 'DELEGATECALL',
+ stack: ['0x', '0x', delegateCallAddress],
+ depth: 0,
+ },
+ {
+ op: 'RETURN',
+ depth: 1,
+ },
+ {
+ op: '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);
+ });
+ });
+});