Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 0701721

Browse files
committed
Add LibraryTest
1 parent dd3edb7 commit 0701721

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ethabi = "12.0.0"
88
ethabi-derive = "12.0.0"
99
ethabi-contract = "11.0.0"
1010
solaris = { path = "../solaris", version = "0.1" }
11+
solc = { path = "../solc", version = "0.1" }
1112
ethereum-types = "0.9.0"
1213
rustc-hex = "1.0"
1314

tests/contracts/test.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
pragma solidity ^0.5.17;
22

3+
library TestLibrary {
4+
function getValue() public returns(uint) {
5+
return 300;
6+
}
7+
}
8+
39
contract GetSenderTest {
410
function getSender() public returns(address) {
511
return msg.sender;
@@ -37,3 +43,9 @@ contract EventLogTest {
3743
emit Bar(value);
3844
}
3945
}
46+
47+
contract LibraryTest {
48+
function getValueFromLibrary() public returns(uint) {
49+
return TestLibrary.getValue();
50+
}
51+
}

tests/tests/test.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ extern crate ethabi_derive;
2121
extern crate ethereum_types;
2222
extern crate rustc_hex;
2323
extern crate solaris;
24+
extern crate solc;
2425

26+
use std::fs;
2527
use rustc_hex::FromHex;
2628
use ethereum_types::{Address, U256};
2729

@@ -40,6 +42,11 @@ use_contract!(
4042
"contracts/ConstructorTest.abi"
4143
);
4244

45+
use_contract!(
46+
library_test,
47+
"contracts/LibraryTest.abi"
48+
);
49+
4350
#[test]
4451
fn msg_sender_should_match_value_passed_into_with_sender() {
4552
let mut evm = solaris::evm();
@@ -187,3 +194,43 @@ fn value_should_match_value_passed_into_constructor() {
187194

188195
assert_eq!(output, U256::from(100));
189196
}
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

Comments
 (0)