Skip to content

Commit

Permalink
comments: e2e-test factor out session finish
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemitenkov committed Sep 4, 2024
1 parent 2a12900 commit 0ee41be
Showing 1 changed file with 29 additions and 40 deletions.
69 changes: 29 additions & 40 deletions aptos-move/e2e-tests/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use aptos_vm::{
block_executor::{AptosTransactionOutput, BlockAptosVM},
data_cache::AsMoveResolver,
gas::make_prod_gas_meter,
move_vm_ext::{MoveVmExt, SessionId},
move_vm_ext::{MoveVmExt, SessionExt, SessionId},
AptosVM, VMValidator,
};
use aptos_vm_genesis::{generate_genesis_change_set_for_testing_with_count, GenesisOptions};
Expand All @@ -68,7 +68,10 @@ use move_core_types::{
language_storage::{ModuleId, TypeTag},
move_resource::MoveResource,
};
use move_vm_runtime::module_traversal::{TraversalContext, TraversalStorage};
use move_vm_runtime::{
module_traversal::{TraversalContext, TraversalStorage},
ModuleStorage,
};
use move_vm_types::gas::UnmeteredGasMeter;
use serde::Serialize;
use std::{
Expand Down Expand Up @@ -1031,18 +1034,7 @@ impl FakeExecutor {
println!("Should error, but ignoring for now... {}", err);
}
}
let (change_set, empty_module_write_set) = session
.finish(
&ChangeSetConfigs::unlimited_at_gas_feature_version(LATEST_GAS_FEATURE_VERSION),
&module_storage,
)
.expect("Failed to generate txn effects");
assert_ok!(empty_module_write_set.is_empty_or_invariant_violation());

change_set
.try_combine_into_storage_change_set(empty_module_write_set)
.expect("Failed to convert to storage ChangeSet")
.into_inner()
finish_session_assert_no_modules(session, &module_storage)
};
self.data_store.add_write_set(&write_set);

Expand Down Expand Up @@ -1093,18 +1085,7 @@ impl FakeExecutor {
e.into_vm_status()
)
});
let (change_set, empty_module_write_set) = session
.finish(
&ChangeSetConfigs::unlimited_at_gas_feature_version(LATEST_GAS_FEATURE_VERSION),
&module_storage,
)
.expect("Failed to generate txn effects");
assert_ok!(empty_module_write_set.is_empty_or_invariant_violation());

change_set
.try_combine_into_storage_change_set(empty_module_write_set)
.expect("Failed to convert to storage ChangeSet")
.into_inner()
finish_session_assert_no_modules(session, &module_storage)
};
self.data_store.add_write_set(&write_set);
self.event_store.extend(events);
Expand Down Expand Up @@ -1141,20 +1122,7 @@ impl FakeExecutor {
&module_storage,
)
.map_err(|e| e.into_vm_status())?;

let (change_set, empty_module_write_set) = session
.finish(
&ChangeSetConfigs::unlimited_at_gas_feature_version(LATEST_GAS_FEATURE_VERSION),
&module_storage,
)
.expect("Failed to generate txn effects");
assert_ok!(empty_module_write_set.is_empty_or_invariant_violation());

let (write_set, events) = change_set
.try_combine_into_storage_change_set(empty_module_write_set)
.expect("Failed to convert to storage ChangeSet")
.into_inner();
Ok((write_set, events))
Ok(finish_session_assert_no_modules(session, &module_storage))
}

pub fn execute_view_function(
Expand All @@ -1175,6 +1143,27 @@ impl FakeExecutor {
}
}

/// Finishes the session with [ChangeSetConfigs::unlimited_at_gas_feature_version]
/// configs, and asserts there has been no modules published (publishing is the
/// responsibility of the adapter, e.g., [AptosVM]).
fn finish_session_assert_no_modules(
session: SessionExt,
module_storage: &impl ModuleStorage,
) -> (WriteSet, Vec<ContractEvent>) {
let (change_set, empty_module_write_set) = session
.finish(
&ChangeSetConfigs::unlimited_at_gas_feature_version(LATEST_GAS_FEATURE_VERSION),
&module_storage,
)
.expect("Failed to finish the session");
assert_ok!(empty_module_write_set.is_empty_or_invariant_violation());

change_set
.try_combine_into_storage_change_set(empty_module_write_set)
.expect("Failed to convert to storage ChangeSet")
.into_inner()
}

pub fn assert_outputs_equal(
txns_output_1: &[TransactionOutput],
name1: &str,
Expand Down

0 comments on commit 0ee41be

Please sign in to comment.