Skip to content

Commit 207a7b7

Browse files
committed
Add tests for gas estimation
1 parent 24a8cce commit 207a7b7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

test/compiler.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ function runTests (solc, versionText) {
3535
}
3636
}
3737

38+
function getGasEstimate (output, fileName, contractName) {
39+
try {
40+
var outputFile;
41+
if (semver.lt(solc.semver(), '0.4.9')) {
42+
outputFile = output.contracts[''];
43+
} else {
44+
outputFile = output.contracts[fileName];
45+
}
46+
return outputFile[contractName]['evm']['gasEstimates'];
47+
} catch (e) {
48+
return '';
49+
}
50+
}
51+
3852
function expectError (output, errorType, message) {
3953
if (output.errors) {
4054
for (var error in output.errors) {
@@ -406,7 +420,7 @@ function runTests (solc, versionText) {
406420
'settings': {
407421
'outputSelection': {
408422
'*': {
409-
'*': [ 'evm.bytecode' ]
423+
'*': [ 'evm.bytecode', 'evm.gasEstimates' ]
410424
}
411425
}
412426
},
@@ -415,7 +429,7 @@ function runTests (solc, versionText) {
415429
'content': 'library L { function f() public returns (uint) { return 7; } }'
416430
},
417431
'cont.sol': {
418-
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
432+
'content': 'import "lib.sol"; contract x { function g() public { L.f(); } function h() internal {} }'
419433
}
420434
}
421435
};
@@ -424,6 +438,14 @@ function runTests (solc, versionText) {
424438
var x = getBytecodeStandard(output, 'cont.sol', 'x');
425439
st.ok(typeof x === 'string');
426440
st.ok(x.length > 0);
441+
var xGas = getGasEstimate(output, 'cont.sol', 'x');
442+
st.ok(typeof xGas === 'object');
443+
st.ok(typeof xGas['creation'] === 'object');
444+
st.ok(typeof xGas['creation']['codeDepositCost'] === 'string');
445+
st.ok(typeof xGas['external'] === 'object');
446+
st.ok(typeof xGas['external']['g()'] === 'string');
447+
st.ok(typeof xGas['internal'] === 'object');
448+
st.ok(typeof xGas['internal']['h()'] === 'string');
427449
var L = getBytecodeStandard(output, 'lib.sol', 'L');
428450
st.ok(typeof L === 'string');
429451
st.ok(L.length > 0);

0 commit comments

Comments
 (0)