This repository has been archived by the owner on Mar 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 94
/
config.js
81 lines (69 loc) · 2.46 KB
/
config.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Configuration defaults
*/
class Config {
constructor(options = {}) {
this.blockLimit = options.blockLimit || 6718946;
this.defaultGasPrice = 5;
this.currency = options.currency || "eur";
this.coinmarketcap =
options.coinmarketcap || "d25b5576-a4ee-41be-bb2b-aca2ba3ae5d8";
this.ethPrice = options.ethPrice || null;
this.gasPrice = options.gasPrice || null;
this.outputFile = options.outputFile || null;
this.rst = options.rst || false;
this.rstTitle = options.rstTitle || "";
this.showTimeSpent = options.showTimeSpent || false;
this.srcPath = options.src || "contracts";
this.artifactType = options.artifactType || "truffle-v5";
this.getContracts = options.getContracts || null;
this.noColors = options.noColors;
this.proxyResolver = options.proxyResolver || null;
this.metadata = options.metadata || null;
this.showMethodSig = options.showMethodSig || false;
this.provider = options.provider || null;
this.maxMethodDiff = options.maxMethodDiff;
this.maxDeploymentDiff = options.maxDeploymentDiff;
this.excludeContracts = Array.isArray(options.excludeContracts)
? options.excludeContracts
: [];
this.onlyCalledMethods = options.onlyCalledMethods === false ? false : true;
this.url = options.url
? this._normalizeUrl(options.url)
: this.resolveClientUrl();
}
/**
* Tries to obtain the client url reporter's sync-requests will target.
* @return {String} url e.g http://localhost:8545
*/
resolveClientUrl() {
// Case: web3 globally available in mocha test context
try {
if (web3 && web3.currentProvider) {
const cp = web3.currentProvider;
// Truffle/Web3 http
if (cp.host) return cp.host;
// Truffle/Web3 websockets
if (cp.connection) return this._normalizeUrl(cp.connection.url);
}
} catch (err) {
// Web3 undefined
}
// Case: Failure
const message =
`ERROR: eth-gas-reporter was unable to resolve a client url ` +
`from the provider available in your test context. Try setting the ` +
`url as a mocha reporter option (ex: url='http://localhost:8545')`;
console.log(message);
process.exit(1);
}
/**
* Forces websockets to http
* @param {String} url e.g web3.provider.connection.url
* @return {String} http:// prefixed url
*/
_normalizeUrl(url) {
return url.replace("ws://", "http://");
}
}
module.exports = Config;