-
Notifications
You must be signed in to change notification settings - Fork 4
/
straighten.js
58 lines (48 loc) · 2.76 KB
/
straighten.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const Straightener = require('../'),
expect = require('chai').expect,
fs = require('fs');
describe('sol-straightener', () => {
it('Contract with single import', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/SampleWithImport.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/SampleWithImport.sol');
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});
it('Fails for contract with non existing file import', async () => {
try {
await Straightener.straighten(__dirname + '/contracts/SampleWithImportNotExisting.sol');
} catch (error) {
expect(error.message).to.include('no such file or directory');
}
});
it('Contract with nested imports', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/SampleWithNestedImport.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/SampleWithNestedImport.sol');
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});
it('Contract with multiple imports', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/SampleWithMultiImport.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/SampleWithMultiImport.sol');
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});
it('Contract with imports from node_modules', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/ImportFromNodeModules.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/ImportFromNodeModules.sol');
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});
it('Contract with imports from parent node_modules', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/ImportFromParentNodeModules.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/ImportFromParentNodeModules.sol');
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});
it('Contract with multiple imports from Github', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/MultiImportFromGithub.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/MultiImportFromGithub.sol');
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});
it('Contract with nested imports from Github', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/NestedImportFromGithub.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/NestedImportFromGithub.sol');
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});
});