Skip to content

Commit 3c8df6a

Browse files
committed
Test that supplied library addresses are linked
1 parent 987ecd8 commit 3c8df6a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/package.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const tape = require('tape');
22
const semver = require('semver');
33
const solc = require('../index.js');
4+
const linker = require('../linker.js');
45

56
function getBytecode (output, fileName, contractName) {
67
try {
@@ -373,6 +374,50 @@ tape('Compilation', function (t) {
373374
st.ok(L.length > 0);
374375
st.end();
375376
});
377+
378+
t.test('compiling standard JSON (using wrapper and libraries)', function (st) {
379+
// Example needs support for compileJSONMulti
380+
// FIXME: add test for wrapper without multiple files
381+
if (semver.lt(solc.semver(), '0.1.6')) {
382+
st.skip('Not supported by solc <0.1.6');
383+
st.end();
384+
return;
385+
}
386+
387+
var input = {
388+
'language': 'Solidity',
389+
'settings': {
390+
'libraries': {
391+
'lib.sol': {
392+
'L': '4200000000000000000000000000000000000001'
393+
}
394+
},
395+
'outputSelection': {
396+
'*': {
397+
'*': [ 'evm.bytecode' ]
398+
}
399+
}
400+
},
401+
'sources': {
402+
'lib.sol': {
403+
'content': 'library L { function f() returns (uint) { return 7; } }'
404+
},
405+
'cont.sol': {
406+
'content': 'import "lib.sol"; contract x { function g() { L.f(); } }'
407+
}
408+
}
409+
};
410+
411+
var output = JSON.parse(solc.compileStandardWrapper(JSON.stringify(input)));
412+
var x = getBytecodeStandard(output, 'cont.sol', 'x');
413+
st.ok(x);
414+
st.ok(x.length > 0);
415+
st.ok(Object.keys(linker.findLinkReferences(x)).length === 0);
416+
var L = getBytecodeStandard(output, 'lib.sol', 'L');
417+
st.ok(L);
418+
st.ok(L.length > 0);
419+
st.end();
420+
});
376421
});
377422

378423
tape('Loading Legacy Versions', function (t) {

0 commit comments

Comments
 (0)