Skip to content

Commit 8b4c2e5

Browse files
committed
Fix host url
1 parent f920076 commit 8b4c2e5

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

downloadCurrentVersion.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import downloader from './downloader';
77
const pkg = require('./package.json');
8-
const BIN_URL = 'https://binaries.soliditylang.org/bin';
8+
const DEFAULT_HOST = 'https://binaries.soliditylang.org';
99

10-
async function download (version, binURL = BIN_URL) {
10+
async function download (version, host = DEFAULT_HOST) {
1111
try {
12-
const list = JSON.parse(await downloader.getVersionList(`${binURL}/list.json`));
12+
const list = JSON.parse(await downloader.getVersionList(host));
1313
const releaseFileName = list.releases[version];
1414
const expectedFile = list.builds.filter(function (entry) { return entry.path === releaseFileName; })[0];
1515

@@ -18,7 +18,7 @@ async function download (version, binURL = BIN_URL) {
1818
}
1919

2020
const expectedHash = expectedFile.keccak256;
21-
await downloader.downloadBinary(binURL, 'soljson.js', releaseFileName, expectedHash);
21+
await downloader.downloadBinary(host, 'soljson.js', releaseFileName, expectedHash);
2222
} catch (err) {
2323
console.log(err.message);
2424
process.exit(1);

downloader.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { https } from 'follow-redirects';
33
import MemoryStream from 'memorystream';
44
import { keccak256 } from 'js-sha3';
55

6-
function getVersionList (url: string): Promise<string> {
6+
function getVersionList (host: string): Promise<string> {
77
console.log('Retrieving available version list...');
88

99
return new Promise<string>((resolve, reject) => {
1010
const mem = new MemoryStream(null, { readable: false });
11-
https.get(url, function (response) {
11+
https.get(`${host}/bin/list.json`, function (response) {
1212
if (response.statusCode !== 200) {
1313
reject(new Error('Error downloading file: ' + response.statusCode));
1414
}
@@ -22,7 +22,7 @@ function getVersionList (url: string): Promise<string> {
2222
});
2323
}
2424

25-
function downloadBinary (binURL: string, outputName: string, releaseFile: string, expectedHash: string): Promise<void> {
25+
function downloadBinary (host: string, outputName: string, releaseFile: string, expectedHash: string): Promise<void> {
2626
console.log('Downloading version', releaseFile);
2727

2828
return new Promise<void>((resolve, reject) => {
@@ -37,7 +37,7 @@ function downloadBinary (binURL: string, outputName: string, releaseFile: string
3737
});
3838

3939
const file = fs.createWriteStream(outputName, { encoding: 'binary' });
40-
https.get(`${binURL}/${releaseFile}`, function (response) {
40+
https.get(`${host}/bin/${releaseFile}`, function (response) {
4141
if (response.statusCode !== 200) {
4242
reject(new Error('Error downloading file: ' + response.statusCode));
4343
}

test/downloader.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ function generateTestFile (t: tape.Test, content: string): tmp.FileResult {
3232
return file;
3333
}
3434

35-
function versionListMock (url: string): nock.Interceptor {
36-
return nock(url).get('/bin/list.json');
35+
function versionListMock (host: string): nock.Interceptor {
36+
return nock(host).get('/bin/list.json');
3737
}
3838

39-
function downloadBinaryMock (url: string, filename: string): nock.Interceptor {
40-
return nock(url).get(`/bin/${path.basename(filename)}`);
39+
function downloadBinaryMock (host: string, filename: string): nock.Interceptor {
40+
return nock(host).get(`/bin/${path.basename(filename)}`);
4141
}
4242

4343
function defaultListener (req: any, res: any): void {
@@ -73,7 +73,7 @@ tape('Download version list', async function (t) {
7373

7474
try {
7575
const list = JSON.parse(
76-
await downloader.getVersionList(`${server.origin}/bin/list.json`)
76+
await downloader.getVersionList(server.origin)
7777
);
7878
const expected = require(dummyListPath);
7979
st.deepEqual(list, expected, 'list should match');
@@ -88,7 +88,7 @@ tape('Download version list', async function (t) {
8888
versionListMock(server.origin).reply(404);
8989

9090
try {
91-
await downloader.getVersionList(`${server.origin}/bin/list.json`);
91+
await downloader.getVersionList(server.origin);
9292
st.fail('should throw file not found error');
9393
} catch (err) {
9494
st.equal(err.message, 'Error downloading file: 404', 'should throw file not found error');
@@ -123,7 +123,7 @@ tape('Download binary', async function (t) {
123123

124124
try {
125125
await downloader.downloadBinary(
126-
`${server.origin}/bin`,
126+
server.origin,
127127
targetFilename,
128128
file.name,
129129
hash(file.name)
@@ -148,7 +148,7 @@ tape('Download binary', async function (t) {
148148

149149
try {
150150
await downloader.downloadBinary(
151-
`${server.origin}/bin`,
151+
server.origin,
152152
targetFilename,
153153
'test.js',
154154
`0x${keccak256('something')}`
@@ -176,7 +176,7 @@ tape('Download binary', async function (t) {
176176

177177
try {
178178
await downloader.downloadBinary(
179-
`${server.origin}/bin`,
179+
server.origin,
180180
targetFilename,
181181
file.name,
182182
`0x${keccak256('something')}`

0 commit comments

Comments
 (0)