|
| 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 | +}); |
0 commit comments