Skip to content

Commit

Permalink
[shuffle] Named Address no longer needs to be Sender
Browse files Browse the repository at this point in the history
  • Loading branch information
dimroc authored and bors-libra committed Dec 10, 2021
1 parent ed2b55e commit cbce190
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
34 changes: 28 additions & 6 deletions shuffle/cli/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use diem_crypto::ed25519::{Ed25519PrivateKey, Ed25519PublicKey};
use diem_sdk::client::AccountAddress;
use diem_types::transaction::authenticator::AuthenticationKey;
use directories::BaseDirs;
use move_package::compilation::compiled_package::CompiledPackage;
use move_package::{
compilation::compiled_package::CompiledPackage,
source_package::{layout::SourcePackageLayout, manifest_parser},
};
use serde::{Deserialize, Serialize};
use serde_generate as serdegen;
use serde_generate::SourceInstaller;
Expand All @@ -29,8 +32,6 @@ pub const MAIN_PKG_PATH: &str = "main";

pub const LOCALHOST_NAME: &str = "localhost";

pub const SENDER_ADDRESS_NAME: &str = "Sender";

/// Temporary address for initial codegen, replaced on subsequent commands
/// when accounts are available.
pub const PLACEHOLDER_ADDRESS: &str = "0xdeadbeef";
Expand Down Expand Up @@ -473,18 +474,39 @@ pub fn build_move_package(
publishing_address: &AccountAddress,
) -> Result<CompiledPackage> {
println!("Building {}...", pkg_path.display());
let mut additional_named_addresses = BTreeMap::new();
additional_named_addresses.insert(SENDER_ADDRESS_NAME.to_string(), *publishing_address);

let named_publishing_addresses =
inject_publishing_address_into_manifest(pkg_path, publishing_address)?;
let config = move_package::BuildConfig {
dev_mode: true,
generate_abis: true,
additional_named_addresses,
additional_named_addresses: named_publishing_addresses,
..Default::default()
};

config.compile_package(pkg_path, &mut std::io::stdout())
}

pub fn inject_publishing_address_into_manifest(
pkg_path: &Path,
publishing_address: &AccountAddress,
) -> Result<BTreeMap<String, AccountAddress>> {
let path = SourcePackageLayout::try_find_root(pkg_path)?;
let manifest_string = std::fs::read_to_string(path.join(SourcePackageLayout::Manifest.path()))?;
let toml_manifest = manifest_parser::parse_move_manifest_string(manifest_string)?;
let manifest = manifest_parser::parse_source_manifest(toml_manifest)?;

let mut additional_named_addresses = BTreeMap::new();
if let Some(address_decls) = manifest.addresses {
for (name, addr) in address_decls {
if addr.is_none() {
additional_named_addresses.insert(name.to_string(), *publishing_address);
}
}
}
Ok(additional_named_addresses)
}

fn generate_transaction_builders(pkg_path: &Path, target_dir: &Path) -> Result<()> {
let module_name = "diemStdlib";
let abi_directory = pkg_path;
Expand Down
15 changes: 10 additions & 5 deletions shuffle/cli/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use move_cli::package::cli::{self, UnitTestResult};
use move_package::BuildConfig;
use move_unit_test::UnitTestingConfig;
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
process::{Command, ExitStatus},
};
Expand Down Expand Up @@ -165,16 +164,22 @@ pub fn run_move_unit_tests(project_path: &Path) -> Result<UnitTestResult> {
let publishing_address = AccountAddress::from_hex_literal(shared::PLACEHOLDER_ADDRESS)?;
cli::run_move_unit_tests(
&project_path.join(shared::MAIN_PKG_PATH),
generate_build_config_for_testing(&publishing_address)?,
generate_build_config_for_testing(
&project_path.join(shared::MAIN_PKG_PATH),
&publishing_address,
)?,
unit_test_config,
diem_vm::natives::diem_natives(),
false,
)
}

fn generate_build_config_for_testing(publishing_address: &AccountAddress) -> Result<BuildConfig> {
let mut additional_named_addresses = BTreeMap::new();
additional_named_addresses.insert(shared::SENDER_ADDRESS_NAME.to_string(), *publishing_address);
fn generate_build_config_for_testing(
pkg_path: &Path,
publishing_address: &AccountAddress,
) -> Result<BuildConfig> {
let additional_named_addresses =
shared::inject_publishing_address_into_manifest(pkg_path, publishing_address)?;
Ok(BuildConfig {
dev_mode: true,
test_mode: true,
Expand Down

0 comments on commit cbce190

Please sign in to comment.