Skip to content

Commit 77c35ca

Browse files
authored
move: upgrade command in transactional tests (#10128)
## Description Enables `#upgrade` in transactional tests. ## Test Plan It is tests.
1 parent 8d158cc commit 77c35ca

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

testing-infra/transactional-test-runner/src/framework.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use move_command_line_common::{
2626
use move_compiler::{
2727
compiled_unit::AnnotatedCompiledUnit,
2828
diagnostics::{Diagnostics, FilesSourceText},
29-
shared::NumericalAddress,
29+
shared::{NumberFormat, NumericalAddress},
3030
FullyCompiledProgram,
3131
};
3232
use move_core_types::{
@@ -221,7 +221,7 @@ pub trait MoveTestAdapter<'a>: Sized {
221221
let state = self.compiled_state();
222222
let (modules, warnings_opt) = match syntax {
223223
SyntaxChoice::Source => {
224-
let (units, warnings_opt) = compile_source_units(state, data.path())?;
224+
let (units, warnings_opt) = compile_source_units(state, data.path(), None)?;
225225
let modules = units
226226
.into_iter()
227227
.map(|unit| match unit {
@@ -283,7 +283,8 @@ pub trait MoveTestAdapter<'a>: Sized {
283283
let state = self.compiled_state();
284284
let (script, warning_opt) = match syntax {
285285
SyntaxChoice::Source => {
286-
let (mut units, warning_opt) = compile_source_units(state, data.path())?;
286+
let (mut units, warning_opt) =
287+
compile_source_units(state, data.path(), None)?;
287288
let len = units.len();
288289
if len != 1 {
289290
panic!("Invalid input. Expected 1 compiled unit but got {}", len)
@@ -540,6 +541,7 @@ impl<'a> CompiledState<'a> {
540541
pub fn compile_source_units(
541542
state: &CompiledState,
542543
file_name: impl AsRef<Path>,
544+
package_name: Option<String>,
543545
) -> Result<(Vec<AnnotatedCompiledUnit>, Option<String>)> {
544546
fn rendered_diags(files: &FilesSourceText, diags: Diagnostics) -> Option<String> {
545547
if diags.is_empty() {
@@ -555,10 +557,20 @@ pub fn compile_source_units(
555557
}
556558

557559
use move_compiler::PASS_COMPILATION;
560+
let mut named_address_mapping = state.named_address_mapping.clone();
561+
if let Some(package_name) = package_name {
562+
// When a package_name is specified, create a fresh mapping for it by
563+
// zero-ing the address for an existing mapping. Required for upgrading
564+
// (i.e, re-publishing) an existing named package.
565+
named_address_mapping.insert(
566+
package_name,
567+
NumericalAddress::new(AccountAddress::ZERO.into_bytes(), NumberFormat::Hex),
568+
);
569+
};
558570
let (mut files, comments_and_compiler_res) = move_compiler::Compiler::from_files(
559571
vec![file_name.as_ref().to_str().unwrap().to_owned()],
560572
state.source_files().cloned().collect::<Vec<_>>(),
561-
state.named_address_mapping.clone(),
573+
named_address_mapping,
562574
)
563575
.set_pre_compiled_lib_opt(state.pre_compiled_deps)
564576
.set_flags(move_compiler::Flags::empty().set_sources_shadow_deps(true))

0 commit comments

Comments
 (0)