Skip to content

Commit 5231691

Browse files
committed
Test solc-js download
1 parent 78997dd commit 5231691

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

test/downloader.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import tape from 'tape';
2+
import * as semver from 'semver';
3+
import * as tmp from 'tmp';
4+
import wrapper from '../wrapper';
5+
import downloader from '../downloader';
6+
7+
const pkg = require('../package.json');
8+
9+
tape('Download latest binary', function (t) {
10+
t.test('checking whether the current version is the latest available for download', async function (st) {
11+
try {
12+
const list = JSON.parse(await downloader.getVersionList());
13+
const wanted = pkg.version.match(/^(\d+\.\d+\.\d+)$/)[1];
14+
if (semver.neq(wanted, list.latestRelease)) {
15+
st.fail(`Version ${wanted} is not the latest release ${list.latestRelease}`);
16+
}
17+
18+
const releaseFileName = list.releases[wanted];
19+
const expectedFile = list.builds.filter(function (entry) { return entry.path === releaseFileName; })[0];
20+
if (!expectedFile) {
21+
st.fail(`Version ${wanted} not found. Version list is invalid or corrupted?`);
22+
}
23+
24+
const tempDir = tmp.dirSync({ unsafeCleanup: true, prefix: 'solc-js-compiler-test-' }).name;
25+
const solcjsBin = `${tempDir}/${expectedFile.path}`;
26+
await downloader.downloadBinary(solcjsBin, releaseFileName, expectedFile.keccak256);
27+
28+
const solc = wrapper(require(solcjsBin));
29+
if (semver.neq(solc.version(), wanted)) {
30+
st.fail('Downloaded version differs from package version');
31+
}
32+
st.pass(`Version ${wanted} successfully downloaded`);
33+
} catch (err) {
34+
st.fail(err.message);
35+
}
36+
st.end();
37+
});
38+
});

test/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import('./compiler');
66
import('./smtcallback');
77
import('./smtchecker');
88
import('./abi');
9+
import('./downloader');
910

1011
// The CLI doesn't support Node 4
1112
if (semver.gte(process.version, '5.0.0')) {

0 commit comments

Comments
 (0)