Skip to content

Commit

Permalink
Add test cases to cover new code
Browse files Browse the repository at this point in the history
  • Loading branch information
arthcp authored and axic committed Nov 6, 2019
1 parent e3c5f10 commit 8dbd9a4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,26 @@ tape('Linking', function (t) {
st.ok(bytecode.indexOf('_') < 0);
st.end();
});

t.test('link properly by providing link reference', function (st) {
/*
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
*/
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:L': '0x123456' }, { 'lib.sol:L': [ { start: 122, length: 20 } ] });
st.ok(bytecode.indexOf('_') < 0);
st.end();
});

t.test('link properly using manual reference search', function (st) {
/*
'lib.sol': 'library L { function f() public returns (uint) { return 7; } }',
'cont.sol': 'import "lib.sol"; contract x { function g() public { L.f(); } }'
*/
var bytecode = '608060405234801561001057600080fd5b5061011f806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e2179b8e146044575b600080fd5b348015604f57600080fd5b5060566058565b005b73__lib.sol:L_____________________________6326121ff06040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801560b757600080fd5b505af415801560ca573d6000803e3d6000fd5b505050506040513d602081101560df57600080fd5b8101908080519060200190929190505050505600a165627a7a72305820ea2f6353179c181d7162544d637b7fe2d9e8da9803a0e2d9eafc2188d1d59ee30029';
bytecode = linker.linkBytecode(bytecode, { 'lib.sol:L': '0x123456' }, {});
st.ok(bytecode.indexOf('_') < 0);
st.end();
});
});

0 comments on commit 8dbd9a4

Please sign in to comment.