File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,8 @@ var linkBytecode = function (bytecode, libraries) {
19
19
librariesComplete [ libraryName + ':' + lib ] = libraries [ libraryName ] [ lib ] ;
20
20
}
21
21
} 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 ( / ^ ( [ ^ : ] + ) : ( . + ) $ / ) ;
24
24
if ( parsed ) {
25
25
librariesComplete [ parsed [ 2 ] ] = libraries [ libraryName ] ;
26
26
}
Original file line number Diff line number Diff line change @@ -81,6 +81,15 @@ tape('Link references', function (t) {
81
81
) ;
82
82
st . end ( ) ;
83
83
} ) ;
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
+ } ) ;
84
93
} ) ;
85
94
86
95
tape ( 'Linking' , function ( t ) {
@@ -146,4 +155,15 @@ tape('Linking', function (t) {
146
155
st . equal ( bytecode , '6060604052341561000000000000000000000000000000000000012345666606060606060' ) ;
147
156
st . end ( ) ;
148
157
} ) ;
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
+ } ) ;
149
169
} ) ;
You can’t perform that action at this time.
0 commit comments