Skip to content

Commit

Permalink
Refactor the integration-test to allow it to import moveos_stdlib and…
Browse files Browse the repository at this point in the history
… other third-party Move Packages. (#464)

Update the git version of the Move library.

restore the init function

rename init_ to init_for_test

Integration-test now supports importing moveos-stdlib and building the model successfully.

Adjusted the dependency order and merged the dependencies with Script's Expansion::Program::Modules.

regenerate genesis file

use the latest genesis file from the main branch

update the genesis file

reset type_info.move to avoid the conflict of genesis file
  • Loading branch information
steelgeek091 authored Jul 19, 2023
1 parent ffcbde9 commit 62cd768
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 95 deletions.
66 changes: 33 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
184 changes: 135 additions & 49 deletions crates/rooch/src/commands/move_cli/commands/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Vec<_>>();
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::<BTreeMap<String, NumericalAddress>>(),
);
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);
Expand All @@ -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::<Vec<_>>();

Expand Down Expand Up @@ -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(())
}
}
6 changes: 2 additions & 4 deletions crates/rooch/src/commands/move_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -42,7 +42,7 @@ pub enum MoveCommand {
Publish(Publish),
Run(RunFunction),
View(RunViewFunction),
// IntegrationTest(IntegrationTest),
IntegrationTest(IntegrationTest),
}

#[async_trait]
Expand Down Expand Up @@ -91,12 +91,10 @@ impl CommandAction<String> 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),
*/
}
}
}
2 changes: 1 addition & 1 deletion examples/counter/integration-tests/counter.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
processed 2 tasks

task 1 'run'. lines 4-11:
task 1 'run'. lines 4-12:
status EXECUTED
5 changes: 3 additions & 2 deletions examples/counter/integration-tests/counter.move
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading

0 comments on commit 62cd768

Please sign in to comment.