diff --git a/Cargo.toml b/Cargo.toml index 5ffc57cfe8..70dd9bff5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -185,39 +185,39 @@ rust_secp256k1 = { version = "0.27.0", package = "secp256k1", features = ["recov # Note: the BEGIN and END comments below are required for external tooling. Do not remove. # BEGIN MOVE DEPENDENCIES -move-abigen = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-binary-format = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-bytecode-verifier = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-bytecode-utils = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-cli = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-command-line-common = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-compiler ={ git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-core-types = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["address32"] } -move-coverage = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-disassembler = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-docgen = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-errmapgen = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-ir-compiler = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-model = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-package = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-prover = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-prover-boogie-backend = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-stackless-bytecode = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-prover-test-utils = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-resource-viewer = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-stackless-bytecode-interpreter = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-stdlib = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["address32", "testing"] } -move-symbol-pool = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -#move-table-extension = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-transactional-test-runner = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-unit-test = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["table-extension"] } -move-vm-runtime = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["lazy_natives"] } -move-vm-test-utils = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c", features = ["table-extension"] } -move-vm-types = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -read-write-set = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -read-write-set-dynamic = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-bytecode-source-map = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } -move-ir-types = { git = "https://github.com/rooch-network/move", rev = "5597bcfd78d952f428360ba2eae81f2f79d2627c" } +move-abigen = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-binary-format = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-bytecode-verifier = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-bytecode-utils = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-cli = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-command-line-common = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-compiler ={ git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-core-types = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["address32"] } +move-coverage = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-disassembler = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-docgen = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-errmapgen = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-ir-compiler = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-model = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-package = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-prover = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-prover-boogie-backend = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-stackless-bytecode = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-prover-test-utils = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-resource-viewer = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-stackless-bytecode-interpreter = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-stdlib = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["address32", "testing"] } +move-symbol-pool = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +#move-table-extension = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-transactional-test-runner = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-unit-test = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["table-extension"] } +move-vm-runtime = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["lazy_natives"] } +move-vm-test-utils = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756", features = ["table-extension"] } +move-vm-types = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +read-write-set = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +read-write-set-dynamic = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-bytecode-source-map = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } +move-ir-types = { git = "https://github.com/rooch-network/move", rev = "cbc2bf4d1420e324d6b40bd8f65490993fec5756" } # END MOVE DEPENDENCIES # keep this for convenient debug Move in local repo diff --git a/crates/rooch/src/commands/move_cli/commands/integration_test.rs b/crates/rooch/src/commands/move_cli/commands/integration_test.rs index 280856de82..966556108c 100644 --- a/crates/rooch/src/commands/move_cli/commands/integration_test.rs +++ b/crates/rooch/src/commands/move_cli/commands/integration_test.rs @@ -4,15 +4,16 @@ use clap::{Args, Parser}; use move_cli::Move; use move_command_line_common::address::NumericalAddress; -use move_command_line_common::files::{extension_equals, find_filenames, MOVE_EXTENSION}; -use move_command_line_common::parser::NumberFormat; use move_command_line_common::testing::UPDATE_BASELINE; -use move_compiler::command_line::compiler::construct_pre_compiled_lib; -use move_compiler::shared::PackagePaths; -use move_compiler::FullyCompiledProgram; -use move_core_types::account_address::AccountAddress; +use move_compiler::command_line::compiler::construct_pre_compiled_lib_from_compiler; +use move_compiler::diagnostics::report_diagnostics; +use move_compiler::shared::unique_map::UniqueMap; +use move_compiler::shared::{NamedAddressMapIndex, NamedAddressMaps}; +use move_compiler::{ + cfgir, expansion, hlir, naming, parser, typing, Compiler, FullyCompiledProgram, +}; +use move_package::compilation::build_plan::BuildPlan; use move_package::source_package::layout::SourcePackageLayout; -use move_stdlib::path_in_crate; use moveos_types::addresses::MOVEOS_NAMED_ADDRESS_MAPPING; use once_cell::sync::Lazy; use rooch_integration_test_runner; @@ -142,52 +143,137 @@ impl IntegrationTest { SourcePackageLayout::try_find_root(&path.as_ref().unwrap().canonicalize()?)? }; + // force move to rebuild all packages, so that we can use compile_driver to generate the full compiled program. let mut build_config = move_arg.build_config; - build_config.additional_named_addresses = self + let _ = self .named_addresses - .clone() - .into_iter() - .map(|(key, value)| (key, AccountAddress::from_hex_literal(&value).unwrap())) - .collect(); + .iter() + .map(|(key, value)| { + build_config.additional_named_addresses.insert( + key.clone(), + NumericalAddress::parse_str(value.as_str()) + .unwrap() + .into_inner(), + ) + }) + .collect::>(); + build_config.force_recompilation = true; + let resolved_graph = build_config.resolution_graph_for_package(&rerooted_path, &mut std::io::stdout())?; - let path = path_in_crate(rerooted_path.join("sources").to_str().unwrap()); - let files = find_filenames(&[path], |p| extension_equals(p, MOVE_EXTENSION)).unwrap(); - let targets = vec![PackagePaths { - name: None, - paths: files, - named_address_map: { - let mut address_mapping = match &resolved_graph.root_package.addresses { - Some(named_address_map) => named_address_map - .iter() - .filter(|(_, v)| v.is_some()) - .map(|(k, v)| { - ( - k.clone().as_str().to_string(), - NumericalAddress::new(v.unwrap().into_bytes(), NumberFormat::Hex), - ) - }) - .collect(), - None => BTreeMap::new(), - }; - // address_mapping.extend(named_addresses()); - address_mapping.extend( - self.named_addresses - .into_iter() - .map(|(key, value)| (key, NumericalAddress::parse_str(&value).unwrap())) - .collect::>(), - ); - address_mapping - }, - }]; + let (pre_compiled_lib, _compiled_package) = { + let mut pre_compiled_lib = FullyCompiledProgram { + files: Default::default(), + parser: parser::ast::Program { + named_address_maps: NamedAddressMaps::new(), + source_definitions: vec![], + lib_definitions: vec![], + }, + expansion: expansion::ast::Program { + modules: UniqueMap::new(), + scripts: Default::default(), + }, + naming: naming::ast::Program { + modules: UniqueMap::new(), + scripts: Default::default(), + }, + typing: typing::ast::Program { + modules: UniqueMap::new(), + scripts: Default::default(), + }, + hlir: hlir::ast::Program { + modules: UniqueMap::new(), + scripts: Default::default(), + }, + cfgir: cfgir::ast::Program { + modules: UniqueMap::new(), + scripts: Default::default(), + }, + compiled: vec![], + }; + let compiled = BuildPlan::create(resolved_graph)?.compile_with_driver( + &mut std::io::stdout(), + Some(6), + |compiler: Compiler| { + let full_program = match construct_pre_compiled_lib_from_compiler(compiler)? { + Ok(full_program) => full_program, + Err((file, s)) => report_diagnostics(&file, s), + }; + pre_compiled_lib.files.extend(full_program.files.clone()); + pre_compiled_lib + .parser + .source_definitions + .extend(full_program.parser.source_definitions); + pre_compiled_lib.parser.named_address_maps = + full_program.parser.named_address_maps.clone(); + pre_compiled_lib.expansion.modules = + pre_compiled_lib.expansion.modules.union_with( + &full_program.expansion.modules.filter_map(|_k, v| { + if v.is_source_module { + Some(v) + } else { + None + } + }), + |_k, v1, _v2| v1.clone(), + ); + pre_compiled_lib.naming.modules = pre_compiled_lib.naming.modules.union_with( + &full_program.naming.modules.filter_map(|_k, v| { + if v.is_source_module { + Some(v) + } else { + None + } + }), + |_k, v1, _v2| v1.clone(), + ); + pre_compiled_lib.typing.modules = pre_compiled_lib.typing.modules.union_with( + &full_program.typing.modules.filter_map(|_k, v| { + if v.is_source_module { + Some(v) + } else { + None + } + }), + |_k, v1, _v2| v1.clone(), + ); + pre_compiled_lib.hlir.modules = pre_compiled_lib.hlir.modules.union_with( + &full_program.hlir.modules.filter_map(|_k, v| { + if v.is_source_module { + Some(v) + } else { + None + } + }), + |_k, v1, _v2| v1.clone(), + ); + pre_compiled_lib.cfgir.modules = pre_compiled_lib.cfgir.modules.union_with( + &full_program.cfgir.modules.filter_map(|_k, v| { + if v.is_source_module { + Some(v) + } else { + None + } + }), + |_k, v1, _v2| v1.clone(), + ); + pre_compiled_lib + .compiled + .extend(full_program.compiled.clone()); - let program_res = - construct_pre_compiled_lib(targets.clone(), None, move_compiler::Flags::empty())?; - let pre_compiled_lib = match program_res { - Ok(af) => af, - Err((files, errors)) => move_compiler::diagnostics::report_diagnostics(&files, errors), + Ok((full_program.files, full_program.compiled)) + }, + )?; + (pre_compiled_lib, compiled) }; + + let named_addresses_maps = pre_compiled_lib + .parser + .named_address_maps + .get(NamedAddressMapIndex(0)) + .clone(); + { // update the global *G_PRE_COMPILED_LIB.lock().unwrap() = Some(pre_compiled_lib); @@ -200,12 +286,11 @@ impl IntegrationTest { return Ok(()); } - let named_address_map = targets.get(0).unwrap().named_address_map.clone(); let mut named_address_string_map = BTreeMap::new(); - let _ = named_address_map + let _ = named_addresses_maps .iter() .map(|(key, value)| { - named_address_string_map.insert(key.clone(), value.to_string()); + named_address_string_map.insert(key.to_string(), value.to_string()); }) .collect::>(); @@ -249,6 +334,7 @@ impl IntegrationTest { let test_opts = datatest_stable::TestOpts::try_parse_from(test_args.as_slice())?; datatest_stable::runner_with_opts(&[requirements], test_opts); + Ok(()) } } diff --git a/crates/rooch/src/commands/move_cli/mod.rs b/crates/rooch/src/commands/move_cli/mod.rs index 5ab8cc11c6..44d5b088cf 100644 --- a/crates/rooch/src/commands/move_cli/mod.rs +++ b/crates/rooch/src/commands/move_cli/mod.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use commands::{ - build::Build, /* integration_test::IntegrationTest ,*/ new::New, publish::Publish, + build::Build, integration_test::IntegrationTest, new::New, publish::Publish, run_function::RunFunction, run_view_function::RunViewFunction, unit_test::Test, }; use move_cli::{ @@ -42,7 +42,7 @@ pub enum MoveCommand { Publish(Publish), Run(RunFunction), View(RunViewFunction), - // IntegrationTest(IntegrationTest), + IntegrationTest(IntegrationTest), } #[async_trait] @@ -91,12 +91,10 @@ impl CommandAction for MoveCli { MoveCommand::Publish(c) => c.execute_serialized().await, MoveCommand::Run(c) => c.execute_serialized().await, MoveCommand::View(c) => c.execute_serialized().await, - /* MoveCommand::IntegrationTest(c) => c .execute(move_args) .map(|_| "Success".to_owned()) .map_err(RoochError::from), - */ } } } diff --git a/examples/counter/integration-tests/counter.exp b/examples/counter/integration-tests/counter.exp index c27c6354c5..b3d35b50d0 100644 --- a/examples/counter/integration-tests/counter.exp +++ b/examples/counter/integration-tests/counter.exp @@ -1,4 +1,4 @@ processed 2 tasks -task 1 'run'. lines 4-11: +task 1 'run'. lines 4-12: status EXECUTED diff --git a/examples/counter/integration-tests/counter.move b/examples/counter/integration-tests/counter.move index ea0448f020..742e4f050e 100644 --- a/examples/counter/integration-tests/counter.move +++ b/examples/counter/integration-tests/counter.move @@ -3,9 +3,10 @@ //create account by bob self //# run --signers genesis script { + use moveos_std::storage_context::StorageContext; use rooch_examples::counter; - fun main(sender: &signer) { - counter::init_(sender); + fun main(ctx: &mut StorageContext, sender: &signer) { + counter::init_for_test(ctx, sender); } } \ No newline at end of file diff --git a/examples/counter/sources/counter.move b/examples/counter/sources/counter.move index f54dc8215f..0ed4b38f6d 100644 --- a/examples/counter/sources/counter.move +++ b/examples/counter/sources/counter.move @@ -6,8 +6,12 @@ module rooch_examples::counter { value:u64, } - fun init(ctx: &mut StorageContext, account: &signer){ - account_storage::global_move_to(ctx, account, Counter{value:0}); + public fun init_for_test(ctx: &mut StorageContext, account: &signer) { + account_storage::global_move_to(ctx, account, Counter { value: 0 }); + } + + fun init(ctx: &mut StorageContext, account: &signer) { + account_storage::global_move_to(ctx, account, Counter { value: 0 }); } public fun increase_(ctx: &mut StorageContext) { diff --git a/moveos/moveos/src/moveos_test_model_builder.rs b/moveos/moveos/src/moveos_test_model_builder.rs index 100830ce4b..235f9eef0a 100644 --- a/moveos/moveos/src/moveos_test_model_builder.rs +++ b/moveos/moveos/src/moveos_test_model_builder.rs @@ -3,11 +3,8 @@ use move_command_line_common::address::NumericalAddress; use move_compiler::command_line::compiler::PASS_COMPILATION; - use move_compiler::expansion::ast::{self as E}; - use move_compiler::{compiled_unit, FullyCompiledProgram}; - use move_model::model::GlobalEnv; use move_model::options::ModelBuilderOptions; use move_model::{add_move_lang_diagnostics, collect_related_modules_recursive, run_spec_checker}; @@ -24,6 +21,21 @@ pub fn build_file_to_module_env( let mut env = GlobalEnv::new(); env.set_extension(options); + if let Some(fully_compiled_prog) = pre_compiled_deps { + for package_def in fully_compiled_prog.parser.source_definitions.iter() { + let fhash = package_def.def.file_hash(); + let (fname, fsrc) = fully_compiled_prog.files.get(&fhash).unwrap(); + let aliases = fully_compiled_prog + .parser + .named_address_maps + .get(package_def.named_address_map) + .iter() + .map(|(symbol, addr)| (env.symbol_pool().make(symbol.as_str()), *addr)) + .collect(); + env.add_source(fhash, Rc::new(aliases), fname.as_str(), fsrc, false); + } + } + use move_compiler::command_line::compiler::PASS_PARSER; // Step 1: parse the program to get comments and a separation of targets and dependencies. @@ -194,8 +206,22 @@ pub fn build_file_to_module_env( return Ok(env); } + let mut ordered_units = vec![]; + let mut ea = expansion_ast; + if let Some(pre_compiled) = pre_compiled_deps { + ordered_units.extend(pre_compiled.clone().compiled); + let dep_expansion_ast = pre_compiled.clone().expansion.modules; + + for (m_ident, m_def) in dep_expansion_ast { + ea.modules + .add(m_ident, m_def) + .expect("expansion modules: duplicate item"); + } + } + ordered_units.extend(units); + // Now that it is known that the program has no errors, run the spec checker on verified units // plus expanded AST. This will populate the environment including any errors. - run_spec_checker(&mut env, units, expansion_ast); + run_spec_checker(&mut env, ordered_units, ea); Ok(env) }