Skip to content

Commit d6eaeac

Browse files
committed
Group linker tests in one place
1 parent f248554 commit d6eaeac

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
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 & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -596,61 +596,3 @@ tape('Loading Legacy Versions', function (t) {
596596
});
597597
});
598598
});
599-
600-
tape('Linking', function (t) {
601-
t.test('link properly', function (st) {
602-
/*
603-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
604-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
605-
*/
606-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
607-
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:L': '0x123456' });
608-
st.ok(bytecode.indexOf('_') < 0);
609-
st.end();
610-
});
611-
612-
t.test('link properly with two-level configuration (from standard JSON)', function (st) {
613-
/*
614-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
615-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
616-
*/
617-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
618-
bytecode = linker.linkBytecode(bytecode, { 'lib.sol': { 'L': '0x123456' } });
619-
st.ok(bytecode.indexOf('_') < 0);
620-
st.end();
621-
});
622-
623-
t.test('linker to fail with missing library', function (st) {
624-
/*
625-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
626-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
627-
*/
628-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
629-
bytecode = linker.linkBytecode(bytecode, { });
630-
st.ok(bytecode.indexOf('_') >= 0);
631-
st.end();
632-
});
633-
634-
t.test('linker to fail with invalid address', function (st) {
635-
/*
636-
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
637-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
638-
*/
639-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
640-
st.throws(function () {
641-
linker.linkBytecode(bytecode, { 'lib.sol:L': '' });
642-
});
643-
st.end();
644-
});
645-
646-
t.test('linker properly with truncated library name', function (st) {
647-
/*
648-
'lib.sol': 'library L1234567890123456789012345678901234567890 { function f() public returns (uint) { return 7; } }',
649-
'cont.sol': 'import "lib.sol"; contract x { function g() public { L1234567890123456789012345678901234567890.f(); } }'
650-
*/
651-
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L123456789012345678901234567__6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a723058209f88ff686bd8ceb0fc08853dc1332d5ff81dbcf5af3a1e9aa366828091761f8c0029';
652-
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:L1234567890123456789012345678901234567890': '0x123456' });
653-
st.ok(bytecode.indexOf('_') < 0);
654-
st.end();
655-
});
656-
});

0 commit comments

Comments
 (0)