Skip to content

Commit

Permalink
Merge pull request #96 from dfinance/update-to-latest-libra
Browse files Browse the repository at this point in the history
Update to latest libra
  • Loading branch information
mkurnikov authored Jun 23, 2020
2 parents 3e287d5 + 8ebd8b6 commit ea0fa88
Show file tree
Hide file tree
Showing 25 changed files with 758 additions and 767 deletions.
785 changes: 529 additions & 256 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion check_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ fi
# clippy available in stable channel only
cargo +stable clippy --tests --workspace -- -Dwarnings

cargo test --package integration_tests
cargo test
17 changes: 10 additions & 7 deletions crates/analysis/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ impl Analysis {
.map_err(|errors| {
errors
.into_iter()
.filter_map(|err| match self.db.compiler_error_into_diagnostic(err) {
Ok(d) => Some(d),
Err(err) => {
log::error!("{}", err);
None
}
})
.map(
|err| match self.db.compiler_error_into_diagnostic(err.clone()) {
Ok(d) => d,
Err(error) => panic!(
"While converting {:#?} into Diagnostic, error occurred: {:?}",
err,
error.to_string()
),
},
)
.collect()
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/analysis/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Default for Config {
modules_folders: vec![],
sender_address: DialectName::Libra
.get_dialect()
.normalize_account_address("0x0")
.normalize_account_address("0x1")
.unwrap(),
}
}
Expand Down
37 changes: 25 additions & 12 deletions crates/dialects/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,30 @@ bech32 = "0.7.2"

utils = { path = "../utils" }

move-vm-runtime = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
move-vm-types = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
libra-state-view = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
language-e2e-tests = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
move-core-types = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
vm = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
libra-types = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
move-lang = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
libra-canonical-serialization = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
libra-crypto = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
move-ir-types = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
vm-genesis = { git = "https://github.com/dfinance/libra.git", branch = "09.06.2020" }
move-vm-runtime = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
move-vm-types = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
libra-state-view = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
language-e2e-tests = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
move-core-types = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
vm = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
libra-types = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
move-lang = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
libra-canonical-serialization = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
libra-crypto = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
move-ir-types = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }
vm-genesis = { git = "https://github.com/dfinance/libra.git", branch = "16.06.2020" }

#move-vm-runtime = { path = "../../../dvm-libra/language/move-vm/runtime" }
#move-vm-types = { path = "../../../dvm-libra/language/move-vm/types" }
#libra-state-view = { path = "../../../dvm-libra/storage/state-view" }
#language-e2e-tests = { path = "../../../dvm-libra/language/e2e-tests" }
#move-core-types = { path = "../../../dvm-libra/language/move-core/types" }
#vm = { path = "../../../dvm-libra/language/vm" }
#libra-types = { path = "../../../dvm-libra/types" }
#move-lang = { path = "../../../dvm-libra/language/move-lang" }
#libra-canonical-serialization = { path = "../../../dvm-libra/common/lcs" }
#libra-crypto = { path = "../../../dvm-libra/crypto/crypto" }
#move-ir-types = { path = "../../../dvm-libra/language/move-ir/types" }
#vm-genesis = { path = "../../../dvm-libra/language/tools/vm-genesis" }

libra-move-core-types = { package = "move-core-types", git = "https://github.com/dfinance/libra.git", branch = "master" }
2 changes: 1 addition & 1 deletion crates/dialects/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Dialect for LibraDialect {
fn normalize_account_address(&self, addr: &str) -> Result<ProvidedAccountAddress> {
let address = LibraAccountAddress::from_hex_literal(&addr)?;
let normalized_address = format!("0x{}", address);
let lowered = format!("{}00000000", normalized_address);
let lowered = format!("0x00000000{}", address);
Ok(ProvidedAccountAddress::new(
addr.to_string(),
normalized_address,
Expand Down
22 changes: 11 additions & 11 deletions crates/dialects/src/shared/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn replace_16_bytes_libra(source: &str, file_source_map: &mut FileSourceMap)

let orig_address = item.as_str();
let account_address = LibraAccountAddress::from_hex_literal(orig_address).unwrap();
let repl_address = format!("0x{}00000000", account_address);
let repl_address = format!("0x00000000{}", account_address);

file_source_map.insert_address_layer(
item.end(),
Expand All @@ -36,22 +36,22 @@ mod tests {
fn replace_libra_16_byte_address() {
let source = "use 0x00000000000000001111111111111111;";
let replaced = replace_16_bytes_libra(source, &mut FileSourceMap::default());
assert_eq!(replaced, "use 0x0000000000000000111111111111111100000000;");
assert_eq!(replaced, "use 0x0000000000000000000000001111111111111111;");
}

#[test]
fn replace_multiple_addresses() {
let source =
"use 0x00000000000000001111111111111111; \n use 0x00000000000000001111111111111112;";
let replaced = replace_16_bytes_libra(source, &mut FileSourceMap::default());
assert_eq!(replaced, "use 0x0000000000000000111111111111111100000000; \n use 0x0000000000000000111111111111111200000000;");
assert_eq!(replaced, "use 0x0000000000000000000000001111111111111111; \n use 0x0000000000000000000000001111111111111112;");
}

#[test]
fn dont_replace_20_bytes_address() {
let source = "use 0x0000000000000000111111111111111100000000;";
let source = "use 0x0000000000000000000000001111111111111111;";
let replaced = replace_16_bytes_libra(source, &mut FileSourceMap::default());
assert_eq!(replaced, "use 0x0000000000000000111111111111111100000000;");
assert_eq!(replaced, "use 0x0000000000000000000000001111111111111111;");
}

#[test]
Expand All @@ -67,12 +67,12 @@ mod tests {
assert_eq!(
replaced,
r"use 0x0000000000000000000000000000000000000000;
use 0x0000000000000000000000000000000100000000;
use 0x0000000000000000000000000000001100000000;
use 0x0000000000000000000000000000111100000000;
use 0x0000000000000000000000001111111100000000;
use 0x0000000000000000111111111111111100000000;
use 0x0000000000000000111111111111111100000000;"
use 0x0000000000000000000000000000000000000001;
use 0x0000000000000000000000000000000000000011;
use 0x0000000000000000000000000000000000001111;
use 0x0000000000000000000000000000000011111111;
use 0x0000000000000000000000001111111111111111;
use 0x0000000000000000000000001111111111111111;"
)
}
}
28 changes: 22 additions & 6 deletions crates/integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ use analysis::config::Config;
use move_language_server::global_state::{initialize_new_global_state, GlobalStateSnapshot};
use std::path::PathBuf;
use utils::io::read_move_files;
use utils::{leaked_fpath, MoveFile, MoveFilePath};
use utils::{io, leaked_fpath, MoveFile, MoveFilePath};

pub fn get_script_path() -> MoveFilePath {
leaked_fpath(get_modules_path().join("script.move"))
}

// just need some valid fname
pub fn existing_file_abspath() -> MoveFilePath {
pub fn existing_module_file_abspath() -> MoveFilePath {
let abspath = std::env::current_dir()
.unwrap()
.join("resources")
.join("modules")
.join("covid_tracker.move")
.join("record.move")
.into_os_string()
.into_string()
.unwrap();
leaked_fpath(&abspath)
}

pub fn get_resources_dir() -> PathBuf {
pub fn get_test_resources_dir() -> PathBuf {
std::env::current_dir()
.unwrap()
.parent() // crates/
Expand All @@ -34,11 +34,11 @@ pub fn get_resources_dir() -> PathBuf {
}

pub fn get_stdlib_path() -> PathBuf {
get_resources_dir().join("stdlib")
get_test_resources_dir().join("stdlib")
}

pub fn get_modules_path() -> PathBuf {
get_resources_dir().join("modules")
get_test_resources_dir().join("modules")
}

pub fn setup_test_logging() {
Expand Down Expand Up @@ -87,3 +87,19 @@ macro_rules! config {
config
}};
}

pub fn stdlib_mod(name: &str) -> MoveFile {
io::load_move_file(get_stdlib_path().join(name)).unwrap()
}

pub fn modules_mod(name: &str) -> MoveFile {
io::load_move_file(get_modules_path().join(name)).unwrap()
}

pub fn stdlib_transaction_mod() -> MoveFile {
stdlib_mod("Transaction.move")
}

pub fn record_mod() -> MoveFile {
io::load_move_file(get_modules_path().join("record.move")).unwrap()
}
92 changes: 33 additions & 59 deletions crates/integration_tests/tests/test_compilation_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use analysis::analysis::Analysis;
use analysis::change::AnalysisChange;
use analysis::config::Config;
use analysis::db::FileDiagnostic;
use integration_tests::{get_modules_path, get_resources_dir, global_state_snapshot};
use integration_tests::{get_modules_path, get_test_resources_dir, global_state_snapshot};
use move_language_server::global_state::initialize_new_global_state;

use crossbeam_channel::unbounded;
use move_language_server::main_loop::{compute_file_diagnostics, Task};
use threadpool::ThreadPool;
use utils::{leaked_fpath, MoveFile, MoveFilePath};

fn range(start: (u64, u64), end: (u64, u64)) -> Range {
Expand All @@ -24,7 +23,7 @@ fn diagnostics_with_config(text: &str, config: Config) -> Vec<Diagnostic> {
let loc_ds = diagnostics_with_config_and_filename(
text,
config,
leaked_fpath(get_resources_dir().join("some_script.move")),
leaked_fpath(get_test_resources_dir().join("some_script.move")),
);
loc_ds.into_iter().filter_map(|d| d.diagnostic).collect()
}
Expand All @@ -35,11 +34,9 @@ fn diagnostics_with_config_and_filename(
fpath: MoveFilePath,
) -> Vec<FileDiagnostic> {
let state_snapshot = global_state_snapshot((fpath, text.to_string()), config, vec![]);
let pool = ThreadPool::new(1);
let (task_sender, task_receiver) = unbounded::<Task>();

compute_file_diagnostics(&pool, state_snapshot.analysis, task_sender, vec![fpath]);
pool.join();
compute_file_diagnostics(state_snapshot.analysis, task_sender, vec![fpath]);

let task = task_receiver.try_recv().unwrap();
let mut ds = match task {
Expand Down Expand Up @@ -84,7 +81,7 @@ mod tests {
use analysis::db::RootDatabase;

use integration_tests::{
config, get_modules_path, get_script_path, get_stdlib_path, setup_test_logging,
config, get_modules_path, get_script_path, get_stdlib_path, modules_mod,
};
use utils::{leaked_fpath, FilesSourceText};

Expand Down Expand Up @@ -203,10 +200,10 @@ module M {
fn test_stdlib_modules_are_available_if_loaded() {
let source_text = r"
module MyModule {
use 0x0::Transaction;
use 0x1::Signer;
public fun how_main(_country: u8) {
let _ = Transaction::sender();
public fun how_main(s: &signer) {
let _ = Signer::address_of(s);
}
}
";
Expand All @@ -218,12 +215,15 @@ module MyModule {
#[test]
fn test_compile_check_script_with_additional_dependencies() {
// hardcoded sender address
setup_test_logging();
let script_source_text = r"
script {
use 0x8572f83cee01047effd6e7d0b5c19743::CovidTracker;
fun main() {
CovidTracker::how_many(5);
use 0x1::Signer;
use 0x2::Record;
fun main(s: &signer) {
let signer_address = Signer::address_of(s);
let record = Record::get_record(signer_address);
Record::save(record);
}
}
";
Expand All @@ -239,44 +239,16 @@ script {

#[test]
fn test_compile_check_module_from_a_folder_with_folder_provided_as_dependencies() {
let module_source_text = r"
module CovidTracker {
use 0x0::Vector;
use 0x0::Transaction;
struct NewsReport {
news_source_id: u64,
infected_count: u64,
}
resource struct CovidSituation {
country_id: u8,
reports: vector<NewsReport>
}
public fun how_many(_country: u8): u64 acquires CovidSituation {
let case = borrow_global<CovidSituation>(Transaction::sender());
let len = Vector::length(&case.reports);
let sum = 0u64;
let i = 0;
while (i < len) {
sum = sum + Vector::borrow(&case.reports, i).infected_count;
};
sum
}
}
";
let (record_module_fpath, record_module_text) = modules_mod("record.move");
let config = config!({
"stdlib_folder": get_stdlib_path(),
"modules_folders": [get_modules_path()],
});
let covid_tracker_module = leaked_fpath(
get_modules_path()
.join("covid_tracker.move")
.to_str()
.unwrap(),
);

let errors = diagnostics_with_config_and_filename(
module_source_text,
&record_module_text,
config,
covid_tracker_module,
record_module_fpath,
);
assert!(errors.is_empty());
}
Expand All @@ -286,35 +258,39 @@ module CovidTracker {
// hardcoded sender address
let script_source_text = r"
script {
use 0x11111111111111111111111111111111::CovidTracker;
use 0x1::Signer;
use 0x2::Record;
fun main() {
CovidTracker::how_many(5);
fun main(s: &signer) {
let signer_address = Signer::address_of(s);
let record = Record::get_record(signer_address);
Record::save(record);
}
}
";
let config = config!({
"dialect": "libra",
"stdlib_folder": get_stdlib_path(),
"modules_folders": [get_modules_path()],
"sender_address": "0x11111111111111111111111111111111",
"sender_address": "0x1",
});
let errors = diagnostics_with_config(script_source_text, config);
assert!(errors.is_empty(), "{:?}", errors);
assert!(errors.is_empty(), "{:#?}", errors);
}

#[test]
fn test_compiler_out_of_bounds_multimessage_diagnostic() {
let source_text = r"
script {
use 0x0::CovidTracker;
use 0x1::Signer;
use 0x2::Record;
fun main() {
let how_many: u8;
how_many = CovidTracker::how_many(10);
fun main(s: &signer) {
let signer_address = Signer::address_of(s);
let record: u8;
record = Record::get_record(signer_address);
}
}
";
} ";
let config = config!({
"stdlib_folder": get_stdlib_path(),
"modules_folders": [get_modules_path()]
Expand Down Expand Up @@ -663,8 +639,6 @@ module DFI {

#[test]
fn test_when_module_resolution_fails_error_should_be_at_use_site() {
setup_test_logging();

let script_text = r"script {
use 0x0::UnknownPayments;
fun main(s: &signer) {
Expand Down
Loading

0 comments on commit ea0fa88

Please sign in to comment.