@@ -21,7 +21,9 @@ extern crate ethabi_derive;
21
21
extern crate ethereum_types;
22
22
extern crate rustc_hex;
23
23
extern crate solaris;
24
+ extern crate solc;
24
25
26
+ use std:: fs;
25
27
use rustc_hex:: FromHex ;
26
28
use ethereum_types:: { Address , U256 } ;
27
29
@@ -40,6 +42,11 @@ use_contract!(
40
42
"contracts/ConstructorTest.abi"
41
43
) ;
42
44
45
+ use_contract ! (
46
+ library_test,
47
+ "contracts/LibraryTest.abi"
48
+ ) ;
49
+
43
50
#[ test]
44
51
fn msg_sender_should_match_value_passed_into_with_sender ( ) {
45
52
let mut evm = solaris:: evm ( ) ;
@@ -187,3 +194,43 @@ fn value_should_match_value_passed_into_constructor() {
187
194
188
195
assert_eq ! ( output, U256 :: from( 100 ) ) ;
189
196
}
197
+
198
+ #[ test]
199
+ fn deploy_contract_with_linking_library_should_succeed ( ) {
200
+ let mut evm = solaris:: evm ( ) ;
201
+
202
+ let contract_owner_address: Address = Address :: from_low_u64_be ( 3 ) ;
203
+
204
+ // deploy TestLibrary
205
+ let code_hex = include_str ! ( "../contracts/TestLibrary.bin" ) ;
206
+ let code_bytes = code_hex. from_hex ( ) . unwrap ( ) ;
207
+ let library_address = evm. with_sender ( contract_owner_address)
208
+ . deploy ( & code_bytes)
209
+ . expect ( "library deployment should succeed" ) ;
210
+
211
+ // link to deployed library
212
+ solc:: link (
213
+ vec ! [ format!( "test.sol:TestLibrary:{:x}" , library_address) ] ,
214
+ "LibraryTest.bin" . into ( ) ,
215
+ concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/contracts/" ) ) ;
216
+
217
+ // deploy LibraryTest
218
+ // can't use include_str because the bytecode is updated linking to library
219
+ let code_hex = fs:: read_to_string ( concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/contracts/LibraryTest.bin" ) ) . unwrap ( ) ;
220
+ let code_bytes = code_hex. from_hex ( ) . unwrap ( ) ;
221
+ let _contract_address = evm. with_sender ( contract_owner_address)
222
+ . deploy ( & code_bytes)
223
+ . expect ( "contract deployment should succeed" ) ;
224
+
225
+ use library_test:: functions;
226
+
227
+ let result_data = evm
228
+ . ensure_funds ( )
229
+ . call ( functions:: get_value_from_library:: encode_input ( ) )
230
+ . unwrap ( ) ;
231
+
232
+ let output: U256 = functions:: get_value_from_library:: decode_output ( & result_data)
233
+ . unwrap ( ) ;
234
+
235
+ assert_eq ! ( output, U256 :: from( 300 ) ) ;
236
+ }
0 commit comments