Skip to content

Commit dd6ee77

Browse files
authored
Merge pull request #274 from ethereum/linker
Group linker tests in one place
2 parents bba0eaa + d6eaeac commit dd6ee77

File tree

2 files changed

+58
-66
lines changed

2 files changed

+58
-66
lines changed

test/linker.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,61 @@ tape('Link references', function (t) {
8282
st.end();
8383
});
8484
});
85+
86+
tape('Linking', function (t) {
87+
t.test('link properly', function (st) {
88+
/*
89+
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
90+
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
91+
*/
92+
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
93+
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:L': '0x123456' });
94+
st.ok(bytecode.indexOf('_') < 0);
95+
st.end();
96+
});
97+
98+
t.test('link properly with two-level configuration (from standard JSON)', function (st) {
99+
/*
100+
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
101+
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
102+
*/
103+
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
104+
bytecode = linker.linkBytecode(bytecode, { 'lib.sol': { 'L': '0x123456' } });
105+
st.ok(bytecode.indexOf('_') < 0);
106+
st.end();
107+
});
108+
109+
t.test('linker to fail with missing library', function (st) {
110+
/*
111+
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
112+
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
113+
*/
114+
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
115+
bytecode = linker.linkBytecode(bytecode, { });
116+
st.ok(bytecode.indexOf('_') >= 0);
117+
st.end();
118+
});
119+
120+
t.test('linker to fail with invalid address', function (st) {
121+
/*
122+
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
123+
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
124+
*/
125+
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
126+
st.throws(function () {
127+
linker.linkBytecode(bytecode, { 'lib.sol:L': '' });
128+
});
129+
st.end();
130+
});
131+
132+
t.test('linker properly with truncated library name', function (st) {
133+
/*
134+
'lib.sol': 'library L1234567890123456789012345678901234567890 { function f() public returns (uint) { return 7; } }',
135+
'cont.sol': 'import "lib.sol"; contract x { function g() public { L1234567890123456789012345678901234567890.f(); } }'
136+
*/
137+
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L123456789012345678901234567__6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a723058209f88ff686bd8ceb0fc08853dc1332d5ff81dbcf5af3a1e9aa366828091761f8c0029';
138+
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:L1234567890123456789012345678901234567890': '0x123456' });
139+
st.ok(bytecode.indexOf('_') < 0);
140+
st.end();
141+
});
142+
});

test/package.js

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -596,69 +596,3 @@ tape('Loading Legacy Versions', function (t) {
596596
});
597597
});
598598
});
599-
600-
tape('Linking', function (t) {
601-
// FIXME: all the linking tests require compileJSONMulti support,
602-
// create test cases which have all files in a single source and could run with 0.1.3
603-
if (semver.lt(solc.semver(), '0.1.6')) {
604-
t.skip('Not supported by solc <0.1.6');
605-
t.end();
606-
return;
607-
}
608-
609-
t.test('link properly', function (st) {
610-
/*
611-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
612-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
613-
*/
614-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
615-
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:L': '0x123456' });
616-
st.ok(bytecode.indexOf('_') < 0);
617-
st.end();
618-
});
619-
620-
t.test('link properly with two-level configuration (from standard JSON)', function (st) {
621-
/*
622-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
623-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
624-
*/
625-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
626-
bytecode = linker.linkBytecode(bytecode, { 'lib.sol': { 'L': '0x123456' } });
627-
st.ok(bytecode.indexOf('_') < 0);
628-
st.end();
629-
});
630-
631-
t.test('linker to fail with missing library', function (st) {
632-
/*
633-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
634-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
635-
*/
636-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
637-
bytecode = linker.linkBytecode(bytecode, { });
638-
st.ok(bytecode.indexOf('_') >= 0);
639-
st.end();
640-
});
641-
642-
t.test('linker to fail with invalid address', function (st) {
643-
/*
644-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
645-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
646-
*/
647-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
648-
st.throws(function () {
649-
linker.linkBytecode(bytecode, { 'lib.sol:L': '' });
650-
});
651-
st.end();
652-
});
653-
654-
t.test('linker properly with truncated library name', function (st) {
655-
/*
656-
'lib.sol': 'library L1234567890123456789012345678901234567890 { function f() public returns (uint) { return 7; } }',
657-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L1234567890123456789012345678901234567890.f(); } }'
658-
*/
659-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L123456789012345678901234567__6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a723058209f88ff686bd8ceb0fc08853dc1332d5ff81dbcf5af3a1e9aa366828091761f8c0029';
660-
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:L1234567890123456789012345678901234567890': '0x123456' });
661-
st.ok(bytecode.indexOf('_') < 0);
662-
st.end();
663-
});
664-
});

0 commit comments

Comments
 (0)