Skip to content

Commit

Permalink
[framework] remove dependencies on aptos-framework-releases
Browse files Browse the repository at this point in the history
  • Loading branch information
davidiw authored and aptos-bot committed Apr 1, 2022
1 parent ab91ee7 commit 09cdf02
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 61 deletions.
12 changes: 5 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ rand = "0.8.3"
reqwest = { version = "0.11.2", features = ["blocking", "json"], default_features = false }

aptos-crypto = { path = "../crates/aptos-crypto" }
aptos-framework-releases = { path = "../aptos-move/framework/aptos-framework/releases" }
aptos-genesis-tool = {path = "../config/management/genesis", features = ["testing"] }
aptos-global-constants = { path = "../config/global-constants" }
aptos-mempool = { path = "../mempool", features = ["fuzzing"] }
Expand All @@ -53,6 +52,7 @@ aptos-vm = { path = "../aptos-move/aptos-vm" }
aptosdb = { path = "../storage/aptosdb", features = ["fuzzing"] }
executor = { path = "../execution/executor" }
executor-types = { path = "../execution/executor-types" }
framework = { path = "../aptos-move/framework" }
mempool-notifications = { path = "../state-sync/inter-component/mempool-notifications" }
vm-validator = { path = "../vm-validator" }

Expand Down
11 changes: 4 additions & 7 deletions api/src/tests/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ pub fn new_test_context(test_name: &'static str) -> TestContext {
tmp_dir.create_as_dir().unwrap();

let mut rng = ::rand::rngs::StdRng::from_seed([0u8; 32]);
let builder = ValidatorBuilder::new(
&tmp_dir,
aptos_framework_releases::current_module_blobs().to_vec(),
)
.publishing_option(VMPublishingOption::open())
.min_price_per_gas_unit(0)
.randomize_first_validator_ports(false);
let builder = ValidatorBuilder::new(&tmp_dir, framework::aptos::module_blobs())
.publishing_option(VMPublishingOption::open())
.min_price_per_gas_unit(0)
.randomize_first_validator_ports(false);

let (root_keys, genesis, genesis_waypoint, validators) = builder.build(&mut rng).unwrap();
let validator_owner = validators[0].storage().get(OWNER_ACCOUNT).unwrap().value;
Expand Down
11 changes: 1 addition & 10 deletions aptos-move/framework/src/aptos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,9 @@ use std::collections::BTreeMap;
const APTOS_MODULES_DIR: &str = "aptos-framework/sources";
static APTOS_PKG: Lazy<CompiledPackage> = Lazy::new(|| super::package("aptos-framework"));

pub fn aptos_modules_full_path() -> String {
format!("{}/{}", env!("CARGO_MANIFEST_DIR"), APTOS_MODULES_DIR)
}

pub fn files() -> Vec<String> {
let mut files = move_stdlib::move_stdlib_files();
files.extend(files_no_dependencies());
files
}

pub fn files_no_dependencies() -> Vec<String> {
let mut files = super::move_files_in_path(APTOS_MODULES_DIR);
files.extend(super::move_files_in_path(APTOS_MODULES_DIR));
files.extend(super::move_files_in_path(super::CORE_MODULES_DIR));
files
}
Expand Down
42 changes: 27 additions & 15 deletions aptos-move/framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![forbid(unsafe_code)]

use move_command_line_common::files::{extension_equals, find_filenames, MOVE_EXTENSION};
use move_command_line_common::files::{extension_equals, find_filenames, MOVE_EXTENSION, MOVE_COMPILED_EXTENSION};
use move_compiler::{
compiled_unit::{CompiledUnit, NamedCompiledModule},
shared::{NumberFormat, NumericalAddress},
Expand Down Expand Up @@ -31,6 +31,32 @@ pub fn core_modules_full_path() -> String {
format!("{}/{}", env!("CARGO_MANIFEST_DIR"), CORE_MODULES_DIR)
}


/// Load the serialized modules from the specified paths.
pub fn load_modules_from_paths(paths: &[PathBuf]) -> Vec<Vec<u8>> {
find_filenames(paths, |path| {
extension_equals(path, MOVE_COMPILED_EXTENSION)
})
.expect("module loading failed")
.iter()
.map(|file_name| std::fs::read(file_name).unwrap())
.collect::<Vec<_>>()
}

pub(crate) fn module_blobs(pkg: &CompiledPackage) -> Vec<Vec<u8>> {
pkg.transitive_compiled_units()
.iter()
.filter_map(|unit| match unit {
CompiledUnit::Module(NamedCompiledModule { module, .. }) => {
let mut bytes = vec![];
module.serialize(&mut bytes).unwrap();
Some(bytes)
}
CompiledUnit::Script(_) => None,
})
.collect()
}

pub(crate) fn move_files_in_path(path: &str) -> Vec<String> {
let modules_path = path_in_crate(path);
find_filenames(&[modules_path], |p| extension_equals(p, MOVE_EXTENSION)).unwrap()
Expand Down Expand Up @@ -58,17 +84,3 @@ pub(crate) fn package(name: &str) -> CompiledPackage {
.compile_package(&path_in_crate(name), &mut Vec::new())
.unwrap()
}

pub(crate) fn module_blobs(pkg: &CompiledPackage) -> Vec<Vec<u8>> {
pkg.transitive_compiled_units()
.iter()
.filter_map(|unit| match unit {
CompiledUnit::Module(NamedCompiledModule { module, .. }) => {
let mut bytes = vec![];
module.serialize(&mut bytes).unwrap();
Some(bytes)
}
CompiledUnit::Script(_) => None,
})
.collect()
}
2 changes: 1 addition & 1 deletion aptos-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ aptos-api = { path = "../api" }
aptos-config = { path = "../config" }
aptos-crypto = { path = "../crates/aptos-crypto" }
aptos-data-client = { path = "../state-sync/aptos-data-client" }
aptos-framework-releases = { path = "../aptos-move/framework/aptos-framework/releases" }
aptos-genesis-tool = {path = "../config/management/genesis", features = ["testing"] }
aptos-infallible = { path = "../crates/aptos-infallible" }
aptos-logger = { path = "../crates/aptos-logger" }
Expand All @@ -46,6 +45,7 @@ debug-interface = { path = "../crates/debug-interface" }
event-notifications = { path = "../state-sync/inter-component/event-notifications" }
executor = { path = "../execution/executor" }
executor-types = { path = "../execution/executor-types" }
framework = { path = "../aptos-move/framework" }
mempool-notifications = { path = "../state-sync/inter-component/mempool-notifications" }
network = { path = "../network" }
network-builder = { path = "../network/builder" }
Expand Down
4 changes: 2 additions & 2 deletions aptos-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ fn main() {
None
};
let genesis_modules = if let Some(module_paths) = args.genesis_modules {
aptos_framework_releases::load_modules_from_paths(&module_paths)
framework::load_modules_from_paths(&module_paths)
} else {
aptos_framework_releases::current_module_blobs().to_vec()
framework::aptos::module_blobs()
};
aptos_node::load_test_environment(
args.config,
Expand Down
2 changes: 1 addition & 1 deletion config/management/genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ executor = { path = "../../../execution/executor" }
bcs = "0.1.2"
aptos-config = { path = "../.."}
aptos-crypto = { path = "../../../crates/aptos-crypto" }
aptos-framework-releases = { path = "../../../aptos-move/framework/aptos-framework/releases" }
aptos-global-constants = { path = "../../global-constants" }
aptos-management = { path = ".." }
aptos-secure-storage = { path = "../../../secure/storage" }
Expand All @@ -31,6 +30,7 @@ aptos-workspace-hack = { version = "0.1", path = "../../../crates/aptos-workspac
aptos-temppath = { path = "../../../crates/aptos-temppath" }
aptos-vm = { path = "../../../aptos-move/aptos-vm" }
aptosdb = { path = "../../../storage/aptosdb" }
framework = { path = "../../../aptos-move/framework" }
storage-interface = { path = "../../../storage/storage-interface" }
vm-genesis = { path = "../../../aptos-move/vm-genesis" }

Expand Down
4 changes: 2 additions & 2 deletions config/management/genesis/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ pub mod tests {
// Step 2) Upload the Move modules
let tempdir = aptos_temppath::TempPath::new();
tempdir.create_as_dir().unwrap();
for b in aptos_framework_releases::current_module_blobs() {
for b in framework::aptos::module_blobs() {
let mut temppath =
aptos_temppath::TempPath::new_with_temp_dir(tempdir.path().to_path_buf());
temppath.create_as_file().unwrap();
temppath.persist(); // otherwise, file will disappear before we call set_move_modules
let mut file = File::create(temppath.path()).unwrap();
file.write_all(b).unwrap();
file.write_all(&b).unwrap();
file.sync_all().unwrap();
}
helper
Expand Down
12 changes: 5 additions & 7 deletions config/management/genesis/src/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ use rand::{rngs::StdRng, SeedableRng};
pub fn test_config() -> (NodeConfig, Ed25519PrivateKey) {
let path = TempPath::new();
path.create_as_dir().unwrap();
let (root_keys, _genesis, _genesis_waypoint, validators) = ValidatorBuilder::new(
path.path(),
aptos_framework_releases::current_module_blobs().to_vec(),
)
.template(NodeConfig::default_for_validator())
.build(StdRng::from_seed([0; 32]))
.unwrap();
let (root_keys, _genesis, _genesis_waypoint, validators) =
ValidatorBuilder::new(path.path(), framework::aptos::module_blobs().to_vec())
.template(NodeConfig::default_for_validator())
.build(StdRng::from_seed([0; 32]))
.unwrap();
let mut configs = validators.into_iter().map(|v| v.config).collect::<Vec<_>>();
let key = root_keys.root_key;

Expand Down
1 change: 0 additions & 1 deletion storage/inspector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ anyhow = "1.0.52"
structopt = "0.3.21"
tempfile = "3.2.0"

aptos-framework-releases = { path = "../../aptos-move/framework/aptos-framework/releases" }
aptosdb = { path = "../aptosdb" }
aptos-config = { path = "../../config" }
aptos-crypto = { path = "../../crates/aptos-crypto" }
Expand Down
2 changes: 1 addition & 1 deletion testsuite/forge-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tokio = { version = "1.8.1", features = ["full"] }
testcases = { path = "../testcases" }
url = "2.2.2"
aptos-workspace-hack = { version = "0.1", path = "../../crates/aptos-workspace-hack" }
aptos-framework-releases = { path = "../../aptos-move/framework/aptos-framework/releases" }
framework = { path = "../../aptos-move/framework" }

[[bin]]
name = "forge"
Expand Down
2 changes: 1 addition & 1 deletion testsuite/forge-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn local_test_suite() -> ForgeConfig<'static> {
.with_aptos_tests(&[&FundAccount, &TransferCoins])
.with_admin_tests(&[&GetMetadata])
.with_network_tests(&[&RestartValidator, &EmitTransaction])
.with_genesis_modules_bytes(aptos_framework_releases::current_module_blobs().to_vec())
.with_genesis_modules_bytes(framework::aptos::module_blobs())
}

fn k8s_test_suite() -> ForgeConfig<'static> {
Expand Down
2 changes: 1 addition & 1 deletion testsuite/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ url = "2.2.2"

debug-interface = { path = "../../crates/debug-interface" }
aptos-config = { path = "../../config" }
aptos-framework-releases = { path = "../../aptos-move/framework/aptos-framework/releases" }
aptos-genesis-tool = { path = "../../config/management/genesis" }
aptos-logger = { path = "../../crates/aptos-logger" }
aptos-retrier = { path = "../../crates/aptos-retrier" }
Expand All @@ -48,4 +47,5 @@ aptos-rest-client = { path = "../../crates/aptos-rest-client"}
aptos-secure-storage = { path = "../../secure/storage" }
aptos-transaction-builder = { path = "../../sdk/transaction-builder" }
aptos-workspace-hack = { version = "0.1", path = "../../crates/aptos-workspace-hack" }
framework = { path = "../../aptos-move/framework" }
transaction-emitter = { path = "../../crates/transaction-emitter" }
2 changes: 1 addition & 1 deletion testsuite/forge/src/backend/local/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl LocalSwarmBuilder {
let (root_keys, genesis, genesis_waypoint, validators) = ValidatorBuilder::new(
&dir,
self.genesis_modules
.unwrap_or_else(|| aptos_framework_releases::current_module_blobs().to_vec()),
.unwrap_or_else(framework::aptos::module_blobs),
)
.num_validators(self.number_of_validators)
.template(self.template)
Expand Down
3 changes: 1 addition & 2 deletions testsuite/smoke-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ walkdir = "2.3.1"
reqwest = { version = "0.11.2", features = ["json"] }

aptos = { path = "../../crates/aptos" }
aptos-framework-releases = { path = "../../aptos-move/framework/aptos-framework/releases" }
aptos-config = { path = "../../config" }
aptos-crypto = { path = "../../crates/aptos-crypto" }
framework = { path = "../../aptos-move/framework" }
aptos-rest-client = { path = "../../crates/aptos-rest-client" }
aptos-sdk = { path = "../../sdk" }
aptos-temppath = { path = "../../crates/aptos-temppath" }
aptos-transaction-builder = { path = "../../sdk/transaction-builder" }
aptos-types = { path = "../../types" }
aptos-workspace-hack = { version = "0.1", path = "../../crates/aptos-workspace-hack" }
forge = { path = "../forge" }
framework = { path = "../../aptos-move/framework" }
move-command-line-common = { git = "https://github.com/diem/move", rev = "3fe033b112eae7df2d15ab3467624165ae510caa" }
move-ir-compiler = { git = "https://github.com/diem/move", rev = "3fe033b112eae7df2d15ab3467624165ae510caa" }
move-stdlib = { git = "https://github.com/diem/move", rev = "3fe033b112eae7df2d15ab3467624165ae510caa" }
Expand Down
2 changes: 1 addition & 1 deletion testsuite/smoke-test/tests/forge-aptos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() -> Result<()> {
&ModulePublish,
&ErrorReport,
])
.with_genesis_modules_bytes(aptos_framework_releases::current_module_blobs().to_vec());
.with_genesis_modules_bytes(framework::aptos::module_blobs());

let options = Options::from_args();
forge_main(tests, LocalFactory::from_workspace()?, &options)
Expand Down
1 change: 1 addition & 0 deletions x.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ members = [

"testcases",
"aptos-e2e-tests-replay",
"aptos-framework-releases",
"aptos-fuzz",
"aptos-fuzzer",
"aptos-keygen",
Expand Down

0 comments on commit 09cdf02

Please sign in to comment.