Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and add execution tests #4504

Merged
merged 9 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions massa-db-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ name = "massa_db_exports"
version = "0.26.1"
edition = "2021"

[features]
test-exports = ["mockall", "mockall_wrap"]

[dependencies]
displaydoc = {workspace = true}
thiserror = {workspace = true}
parking_lot = {workspace = true}
massa_hash = {workspace = true}
massa_models = {workspace = true}
mockall = {workspace = true, optional = true}
mockall_wrap = {workspace = true, optional = true}
1 change: 1 addition & 0 deletions massa-db-exports/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{fmt::Debug, sync::Arc};
pub type ShareableMassaDBController = Arc<RwLock<Box<dyn MassaDBController>>>;

/// Controller trait for the MassaDB
/// TODO: MOCK IT WITH MOCKALL. HAVING LIFETIMES ERRORS WITH AUTO MOCK
pub trait MassaDBController: Send + Sync + Debug {
/// Creates a new hard copy of the DB, for the given slot
fn backup_db(&self, slot: Slot) -> PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion massa-execution-exports/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct ExecutionQueryResponse {
pub enum ExecutionQueryRequestItem {
/// checks if address exists (candidate) returns ExecutionQueryResponseItem::Boolean(true) if it does
AddressExistsCandidate(Address),
/// checks if address exists (finak) returns ExecutionQueryResponseItem::Boolean(true) if it does
/// checks if address exists (final) returns ExecutionQueryResponseItem::Boolean(true) if it does
AddressExistsFinal(Address),
/// gets the balance (candidate) of an address, returns ExecutionQueryResponseItem::Amount(balance) or an error if the address is not found
AddressBalanceCandidate(Address),
Expand Down
17 changes: 1 addition & 16 deletions massa-execution-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ gas_calibration = [
"massa_execution_exports/gas_calibration",
"massa_final_state/test-exports",
"massa_pos_worker",
"massa_ledger_worker",
"massa_db_worker",
"tempfile",
]
test-exports = [
"massa_execution_exports/test-exports",
Expand All @@ -26,20 +23,14 @@ test-exports = [
"massa_final_state/test-exports",
"massa-sc-runtime/testing",
"massa_wallet/test-exports",
"tempfile",
"massa_pos_worker",
"massa_ledger_worker",
"massa_metrics/test-exports",
"massa_db_worker",
"massa_metrics/test-exports",
]
benchmarking = [
"massa-sc-runtime/gas_calibration",
"criterion",
"massa_pos_worker",
"massa_ledger_worker",
"massa_db_worker",
"tempfile",
]
metrics = []

Expand All @@ -59,8 +50,6 @@ sha2 = { workspace = true }
sha3 = { workspace = true }
libsecp256k1 = { workspace = true }
criterion = { workspace = true, "optional" = true }
tempfile = { workspace = true, "optional" = true } # BOM UPGRADE Revert to {"version": "3.3", "optional": true} if problem
massa_ledger_worker = { workspace = true, "optional" = true }
massa_pos_worker = { workspace = true, "optional" = true }
massa_async_pool = { workspace = true }
massa_channel = { workspace = true }
Expand All @@ -79,7 +68,6 @@ massa_pos_exports = { workspace = true }
massa_final_state = { workspace = true }
massa_versioning = { workspace = true }
massa_db_exports = { workspace = true }
massa_db_worker = { workspace = true, "optional" = true }
massa_wallet = { workspace = true }
massa-proto-rs = { workspace = true }

Expand All @@ -93,9 +81,6 @@ massa_pos_worker = { workspace = true }
massa-sc-runtime = { workspace = true, features = ["testing"] }
massa_wallet = { workspace = true, features = ["test-exports"] }
massa_metrics = { workspace = true, features = ["test-exports"] }
massa_db_worker = { workspace = true }
massa_test_framework = {workspace = true}
tokio = { workspace = true, features = ["sync"] }
massa_ledger_worker = { workspace = true }
serial_test = { workspace = true }
tempfile = { workspace = true } # BOM UPGRADE Revert to "3.2" if problem
hex-literal = { workspace = true }
13 changes: 12 additions & 1 deletion massa-execution-worker/src/interface_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,25 @@ impl InterfaceImpl {
sender_addr: Address,
operation_datastore: Option<Datastore>,
) -> InterfaceImpl {
use massa_final_state::test_exports::get_sample_state;
use massa_ledger_exports::{LedgerEntry, SetUpdateOrDelete};
use massa_models::config::MIP_STORE_STATS_BLOCK_CONSIDERED;
use massa_module_cache::{config::ModuleCacheConfig, controller::ModuleCache};
use massa_pos_exports::SelectorConfig;
use massa_pos_worker::start_selector_worker;
use massa_versioning::versioning::{MipStatsConfig, MipStore};
use parking_lot::RwLock;

let config = ExecutionConfig::default();
let (final_state, _tempfile, _tempdir) = super::tests::get_sample_state(0).unwrap();
let mip_stats_config = MipStatsConfig {
block_count_considered: MIP_STORE_STATS_BLOCK_CONSIDERED,
warn_announced_version_ratio: Ratio::new_raw(30, 100),
};
let mip_store = MipStore::try_from(([], mip_stats_config)).unwrap();
let (_, selector_controller) = start_selector_worker(SelectorConfig::default())
.expect("could not start selector controller");
let (final_state, _tempfile, _tempdir) =
get_sample_state(config.last_start_period, selector_controller, mip_store).unwrap();
let module_cache = Arc::new(RwLock::new(ModuleCache::new(ModuleCacheConfig {
hd_cache_path: config.hd_cache_path.clone(),
gas_costs: config.gas_costs.clone(),
Expand Down
7 changes: 1 addition & 6 deletions massa-execution-worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,5 @@ pub use interface_impl::InterfaceImpl;
#[cfg(feature = "benchmarking")]
use criterion as _;

#[cfg(any(
test,
feature = "gas_calibration",
feature = "benchmarking",
feature = "test-exports"
))]
#[cfg(test)]
mod tests;
5 changes: 0 additions & 5 deletions massa-execution-worker/src/speculative_async_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,6 @@ impl SpeculativeAsyncPool {

msgs
}

#[cfg(any(test, feature = "test"))]
pub fn get_message_infos(&self) -> BTreeMap<AsyncMessageId, AsyncMessageInfo> {
self.message_infos.clone()
}
}

/// Check in the ledger changes if a message trigger has been triggered
Expand Down
33 changes: 15 additions & 18 deletions massa-execution-worker/src/tests/interface.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// Copyright (c) 2022 MASSA LABS <[email protected]>

#[cfg(test)]
mod tests {
use hex_literal::hex;
use massa_models::address::Address;
use massa_sc_runtime::Interface;
use std::str::FromStr;
use hex_literal::hex;
use massa_models::address::Address;
use massa_sc_runtime::Interface;
use std::str::FromStr;

use crate::interface_impl::InterfaceImpl;
#[test]
fn test_hash_sha256() {
let interface = InterfaceImpl::new_default(
Address::from_str("AU12cMW9zRKFDS43Z2W88VCmdQFxmHjAo54XvuVV34UzJeXRLXW9M").unwrap(),
None,
);
let actual_hash = interface.hash_sha256(b"something").unwrap();
let expected_hash =
&hex!("3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb")[..];
assert_eq!(actual_hash, expected_hash);
}
use crate::interface_impl::InterfaceImpl;
#[test]
fn test_hash_sha256() {
let interface = InterfaceImpl::new_default(
Address::from_str("AU12cMW9zRKFDS43Z2W88VCmdQFxmHjAo54XvuVV34UzJeXRLXW9M").unwrap(),
None,
);
let actual_hash = interface.hash_sha256(b"something").unwrap();
let expected_hash =
&hex!("3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb")[..];
assert_eq!(actual_hash, expected_hash);
}
24 changes: 5 additions & 19 deletions massa-execution-worker/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
// Copyright (c) 2022 MASSA LABS <[email protected]>

#[cfg(any(
test,
feature = "gas_calibration",
feature = "benchmarking",
feature = "test-exports",
test
))]
mod mock;

#[cfg(all(not(feature = "gas_calibration"), not(feature = "benchmarking")))]
#[cfg(test)]
mod scenarios_mandatories;

#[cfg(all(not(feature = "gas_calibration"), not(feature = "benchmarking")))]
#[cfg(test)]
mod universe;

#[cfg(test)]
mod tests_active_history;

mod interface;

#[cfg(any(
feature = "gas_calibration",
feature = "benchmarking",
feature = "test-exports",
test
))]
pub use mock::get_sample_state;
Loading
Loading