Skip to content

Commit

Permalink
[Testing] Vendorize SwarmBuilder for forge and smoke-tests (0LNetwork…
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Aug 19, 2023
1 parent 53f8553 commit 82b9e0b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
6 changes: 3 additions & 3 deletions crates/aptos/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,14 +890,14 @@ pub struct CompileScriptFunction {
pub compiled_script_path: Option<PathBuf>,

#[clap(flatten)]
pub(crate) framework_package_args: FrameworkPackageArgs,
pub framework_package_args: FrameworkPackageArgs, //////// 0L //////// make public

#[clap(long)]
pub(crate) bytecode_version: Option<u32>,
pub bytecode_version: Option<u32>, //////// 0L //////// make public
}

impl CompileScriptFunction {
pub(crate) fn compile(
pub fn compile( //////// 0L ////////
&self,
script_name: &str,
prompt_options: PromptOptions,
Expand Down
61 changes: 57 additions & 4 deletions crates/aptos/src/move_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,21 @@ pub struct FrameworkPackageArgs {
///
/// This is mutually exclusive with `--framework-local-dir`
#[clap(long, group = "framework_package_args")]
pub(crate) framework_git_rev: Option<String>,
pub framework_git_rev: Option<String>, //////// 0L //////// make public

/// Local framework directory for the Aptos framework
///
/// This is mutually exclusive with `--framework-git-rev`
#[clap(long, value_parser, group = "framework_package_args")]
pub(crate) framework_local_dir: Option<PathBuf>,
#[clap(long, parse(from_os_str), group = "framework_package_args")]
pub framework_local_dir: Option<PathBuf>, //////// 0L //////// make public

/// Skip pulling the latest git dependencies
///
/// If you don't have a network connection, the compiler may fail due
/// to no ability to pull git dependencies. This will allow overriding
/// this for local development.
#[clap(long)]
pub(crate) skip_fetch_latest_git_deps: bool,
pub skip_fetch_latest_git_deps: bool, //////// 0L //////// make public
}

impl FrameworkPackageArgs {
Expand Down Expand Up @@ -231,6 +231,59 @@ impl FrameworkPackageArgs {
}
}

//////// 0L ////////
/// create a move directory with a manifest and a source file
/// this is used to create scripts temporarily that need to be compiled before
/// we can get the sha3 hash of the script "execution_hash"
pub fn init_move_dir_generic(
package_dir: &Path, // path to the .move script
name: &str, // name of the script
// addresses: BTreeMap<String, ManifestNamedAddress>,
// prompt_options: PromptOptions,
framework_name: String,
framework_local_dir: PathBuf,

) -> CliTypedResult<()> {
let prompt_options = PromptOptions::yes();
let move_toml = package_dir.join(SourcePackageLayout::Manifest.path());
check_if_file_exists(move_toml.as_path(), prompt_options)?;
create_dir_if_not_exist(
package_dir
.join(SourcePackageLayout::Sources.path())
.as_path(),
)?;

// Add the framework dependency if it's provided
let mut dependencies = BTreeMap::new();

dependencies.insert(framework_name, Dependency {
local: Some(framework_local_dir.display().to_string()),
git: None,
rev: None,
subdir: None,
aptos: None,
address: None,
});

let manifest = MovePackageManifest {
package: PackageInfo {
name: name.to_string(),
version: "1.0.0".to_string(),
author: None,
},
addresses: BTreeMap::new(),
dependencies,
};

write_to_file(
move_toml.as_path(),
SourcePackageLayout::Manifest.location_str(),
toml::to_string_pretty(&manifest)
.map_err(|err| CliError::UnexpectedError(err.to_string()))?
.as_bytes(),
)
}

/// Creates a new Move package at the given location
///
/// This will create a directory for a Move package and a corresponding
Expand Down
16 changes: 16 additions & 0 deletions testsuite/smoke-test/src/smoke_test_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ pub async fn new_local_swarm_with_aptos(num_validators: usize) -> LocalSwarm {
.await
}

//////// 0L ////////
pub async fn new_local_swarm_with_release(num_validators: usize, release: ReleaseBundle) -> LocalSwarm {
let mut sw = SwarmBuilder {
local: true,
num_validators: NonZeroUsize::new(num_validators).unwrap(),
num_fullnodes: 0,
genesis_framework: Some(release),
init_config: None,
vfn_config: None,
init_genesis_config: None,
};

sw.build().await
}
//////// end 0L ////////

#[tokio::test]
async fn test_prevent_starting_nodes_twice() {
// Create a validator swarm of 1 validator node
Expand Down

0 comments on commit 82b9e0b

Please sign in to comment.