Skip to content

Commit 04abed9

Browse files
authored
Merge pull request #299 from jhokkar/linker-code-coverage
Achieve 100% test coverage on the linker
2 parents 913ceee + eee04d7 commit 04abed9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

linker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var linkBytecode = function (bytecode, libraries) {
1919
librariesComplete[libraryName + ':' + lib] = libraries[libraryName][lib];
2020
}
2121
} else {
22-
// backwards compatible API for early solc-js verisons
23-
var parsed = libraryName.match(/^([^:]*):?(.*)$/);
22+
// backwards compatible API for early solc-js versions
23+
var parsed = libraryName.match(/^([^:]+):(.+)$/);
2424
if (parsed) {
2525
librariesComplete[parsed[2]] = libraries[libraryName];
2626
}

test/linker.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ tape('Link references', function (t) {
8181
);
8282
st.end();
8383
});
84+
85+
t.test('Two references with same library name', function (st) {
86+
var bytecode = '6060604052341561000f57600080fd5b61011a8061001e6000396000f30060606040526004361060255763ffffffff60e060020a60003504166326121ff08114602a575b600080fd5b3415603457600080fd5b603a603c565b005b73__lib2.sol:L____________________________6326121ff06040518163ffffffff1660e060020a02815260040160006040518083038186803b1515608157600080fd5b6102c65a03f41515609157600080fd5b50505073__lib2.sol:L____________________________6326121ff06040518163ffffffff1660e060020a02815260040160006040518083038186803b151560d957600080fd5b6102c65a03f4151560e957600080fd5b5050505600a165627a7a72305820fdfb8eab411d7bc86d7dfbb0c985c30bebf1cc105dc5b807291551b3d5aa29d90029';
87+
st.deepEqual(
88+
linker.findLinkReferences(bytecode),
89+
{ 'lib2.sol:L': [ { start: 92, length: 20 }, { start: 180, length: 20 } ] }
90+
);
91+
st.end();
92+
});
8493
});
8594

8695
tape('Linking', function (t) {
@@ -146,4 +155,15 @@ tape('Linking', function (t) {
146155
st.equal(bytecode, '6060604052341561000000000000000000000000000000000000012345666606060606060');
147156
st.end();
148157
});
158+
159+
t.test('link properly when library doesn\'t have colon in name', function (st) {
160+
/*
161+
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
162+
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
163+
*/
164+
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__libName_______________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
165+
bytecode = linker.linkBytecode(bytecode, { 'libName': '0x123456' });
166+
st.ok(bytecode.indexOf('_') < 0);
167+
st.end();
168+
});
149169
});

0 commit comments

Comments
 (0)