From 8cc1dee2eb8e740b56e34551d682ea8718a507c6 Mon Sep 17 00:00:00 2001 From: Arth C Patel Date: Tue, 4 Dec 2018 07:40:20 +0530 Subject: [PATCH] Add test cases to cover new code --- test/linker.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/linker.js b/test/linker.js index 0ddc6401..fd37739f 100644 --- a/test/linker.js +++ b/test/linker.js @@ -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(); + }); });