-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Move] Allow Bytecode Dependencies for Unit Testing #15252
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
998113c
fix bytecode deps for unit tests
3157579
add tests
65ded3e
linter & remove debug print
c9868f8
reset Cargo.lock
b274549
add bytecode files
1a46201
reset Cargo.lock
898ee3a
add .gitkeep for empty dir
1e3e7e8
address comments
0876ea5
resolve merge conflicts
b6a64ec
Merge branch 'main' into bytecode-dep-unit-test
fEst1ck 811033c
Merge branch 'main' into bytecode-dep-unit-test
fEst1ck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
third_party/move/tools/move-unit-test/tests/packages/dep/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "Dep" | ||
version = "1.0.0" | ||
authors = [] |
46 changes: 46 additions & 0 deletions
46
third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/BuildInfo.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
compiled_package_info: | ||
package_name: Dep | ||
address_alias_instantiation: {} | ||
source_digest: B01B575F8492F72C72DBF502E1F788F49A9CA8AC335FB9E52B0455ACA35677E0 | ||
build_flags: | ||
dev_mode: false | ||
test_mode: false | ||
override_std: ~ | ||
generate_docs: false | ||
generate_abis: false | ||
generate_move_model: true | ||
full_model_generation: false | ||
install_dir: ~ | ||
force_recompilation: false | ||
additional_named_addresses: {} | ||
architecture: ~ | ||
fetch_deps_only: false | ||
skip_fetch_latest_git_deps: false | ||
compiler_config: | ||
bytecode_version: 7 | ||
known_attributes: | ||
- bytecode_instruction | ||
- deprecated | ||
- event | ||
- expected_failure | ||
- "fmt::skip" | ||
- legacy_entry_fun | ||
- "lint::allow_unsafe_randomness" | ||
- "lint::skip" | ||
- "mutation::skip" | ||
- native_interface | ||
- randomness | ||
- resource_group | ||
- resource_group_member | ||
- test | ||
- test_only | ||
- verify_only | ||
- view | ||
skip_attribute_checks: false | ||
compiler_version: V2_0 | ||
language_version: V2_1 | ||
experiments: | ||
- optimize=on | ||
dependencies: [] | ||
bytecode_deps: [] |
Binary file added
BIN
+118 Bytes
third_party/move/tools/move-unit-test/tests/packages/dep/build/Dep/bytecode_modules/foo.mv
Binary file not shown.
Empty file.
14 changes: 14 additions & 0 deletions
14
third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/Move.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "unit-test" | ||
version = "1.0.0" | ||
authors = [] | ||
|
||
[addresses] | ||
|
||
[dev-addresses] | ||
|
||
[dependencies] | ||
Dep = { local = "../dep" } | ||
MoveStdlib = { local = "../../../../../../../aptos-move/framework/move-stdlib" } | ||
|
||
[dev-dependencies] |
9 changes: 9 additions & 0 deletions
9
third_party/move/tools/move-unit-test/tests/packages/one-bytecode-dep/sources/test.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module 0x42::test { | ||
#[test_only] | ||
use 0x42::foo; | ||
|
||
#[test] | ||
fun test() { | ||
assert!(foo::foo() == 42, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use move_cli::base::test::{run_move_unit_tests, UnitTestResult}; | ||
use move_core_types::{account_address::AccountAddress, effects::ChangeSet}; | ||
use move_model::metadata::CompilerVersion; | ||
use move_package::CompilerConfig; | ||
use move_stdlib::natives::{all_natives, GasParameters}; | ||
use move_unit_test::UnitTestingConfig; | ||
use std::path::PathBuf; | ||
use tempfile::tempdir; | ||
|
||
pub fn path_in_crate<S>(relative: S) -> PathBuf | ||
where | ||
S: Into<String>, | ||
{ | ||
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
path.push(relative.into()); | ||
path | ||
} | ||
|
||
fn run_tests_for_pkg(path_to_pkg: impl Into<String>, v2: bool) { | ||
let pkg_path = path_in_crate(path_to_pkg); | ||
|
||
let natives = all_natives( | ||
AccountAddress::from_hex_literal("0x1").unwrap(), | ||
GasParameters::zeros(), | ||
); | ||
|
||
let result = run_move_unit_tests( | ||
&pkg_path, | ||
move_package::BuildConfig { | ||
test_mode: true, | ||
install_dir: Some(tempdir().unwrap().path().to_path_buf()), | ||
compiler_config: CompilerConfig { | ||
compiler_version: if v2 { | ||
Some(CompilerVersion::latest()) | ||
} else { | ||
None | ||
}, | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}, | ||
UnitTestingConfig::default(), | ||
natives, | ||
ChangeSet::new(), | ||
/* gas_limit */ Some(100_000), | ||
/* cost_table */ None, | ||
/* compute_coverage */ false, | ||
&mut std::io::stdout(), | ||
) | ||
.unwrap(); | ||
if result != UnitTestResult::Success { | ||
panic!("aborting because of Move unit test failures"); | ||
} | ||
} | ||
|
||
#[test] | ||
fn one_bytecode_dep() { | ||
// TODO: automatically discovers all Move packages under a package directory and runs unit tests for them | ||
run_tests_for_pkg("tests/packages/one-bytecode-dep", true); | ||
run_tests_for_pkg("tests/packages/one-bytecode-dep", false); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better not to make
third_party
to depend onaptos-move
. Note that you don't know whetherframework/move-stdlib
has been compiled at this point or not because there may or may not be an earlier build offramework/move_stdlib
or not. Can you create a smaller local test library tothird_party
to use here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a simple test like this that doesn't depend on any real Move logic, I think we can manage to not use the stdlib at all.