Skip to content

Commit

Permalink
Add some execution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-zinger committed Mar 2, 2022
1 parent 8e40158 commit c37a5ee
Show file tree
Hide file tree
Showing 22 changed files with 366 additions and 243 deletions.
64 changes: 33 additions & 31 deletions Cargo.lock

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

12 changes: 10 additions & 2 deletions massa-consensus-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ serial_test = "0.5"
massa_models = { path = "../massa-models", features = ["testing"] }

[features]
instrument = ["tokio/tracing", "massa_graph/instrument", "massa_models/instrument", "massa_pool/instrument", "massa_proof_of_stake_exports/instrument", "massa_protocol_exports/instrument", "massa_time/instrument"]
instrument = [
"tokio/tracing",
"massa_graph/instrument",
"massa_models/instrument",
"massa_pool/instrument",
"massa_proof_of_stake_exports/instrument",
"massa_protocol_exports/instrument",
"massa_time/instrument",
]
sandbox = []
testing = []
testing = ["massa_models/testing", "massa_execution_exports/testing"]
3 changes: 2 additions & 1 deletion massa-execution-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tracing = { version = "0.1", features = [
"release_max_level_debug",
] }
# custom modules
massa_hash = { path = "../massa-hash" }
massa_models = { path = "../massa-models" }
massa_time = { path = "../massa-time" }
massa_ledger = { path = "../massa-ledger" }
Expand All @@ -26,4 +27,4 @@ pretty_assertions = "1.0"
serial_test = "0.5"

[features]
testing = []
testing = ["massa_ledger/testing", "massa_models/testing"]
6 changes: 6 additions & 0 deletions massa-execution-exports/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ pub enum ExecutionError {

/// Runtime error: {0}
RuntimeError(String),

/// MassaHashError: {0}
MassaHashError(#[from] massa_hash::MassaHashError),

/// ModelsError: {0}
ModelsError(#[from] massa_models::ModelsError),
}
6 changes: 3 additions & 3 deletions massa-execution-exports/src/event_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ impl EventStore {

/// get vec of event for given slot range (start included, end excluded)
/// Get events optionnally filtered by:
/// * start slot
/// * end slot
/// * start slot (default Slot(0,0))
/// * end slot (default Slot(0,0))
/// * emitter address
/// * original caller address
/// * operation id
Expand All @@ -234,7 +234,7 @@ impl EventStore {
.iter()
// filter on slots
.filter_map(|(slot, ids)| {
if slot >= &start && slot < &end {
if slot >= &start && slot <= &end {
Some(ids)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions massa-execution-exports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@
//! When the crate feature `testing` is enabled, tooling useful for testing purposes is exported.
//! See test_exports/mod.rs for details.
mod config;
mod controller_traits;
mod error;
mod event_store;
mod settings;
mod types;

pub use config::ExecutionConfig;
pub use controller_traits::{ExecutionController, ExecutionManager};
pub use error::ExecutionError;
pub use event_store::EventStore;
pub use settings::ExecutionConfig;
pub use types::{ExecutionOutput, ExecutionStackElement, ReadOnlyExecutionRequest};

#[cfg(feature = "testing")]
Expand Down
File renamed without changes.
22 changes: 0 additions & 22 deletions massa-execution-exports/src/test_exports/config.rs

This file was deleted.

5 changes: 2 additions & 3 deletions massa-execution-exports/src/test_exports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
//! Provides a mock of ExecutionController to simulate interactions
//! with an execution worker within tests.
mod config;
mod mock;

pub use config::*;
mod settings;
pub use mock::*;
pub use settings::*;
25 changes: 25 additions & 0 deletions massa-execution-exports/src/test_exports/settings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2022 MASSA LABS <info@massa.net>

//! This file defines testing tools related to the config
use massa_time::MassaTime;

use crate::ExecutionConfig;

/// Default value of ExecutionConfig used for tests
impl Default for ExecutionConfig {
fn default() -> Self {
use massa_models::constants::default_testing::*;

Self {
readonly_queue_length: READONLY_QUEUE_LENGTH,
max_final_events: MAX_FINAL_EVENTS,
thread_count: THREAD_COUNT,
cursor_delay: CURSOR_DELAY,
clock_compensation: Default::default(),
// reset genesis timestamp because we are in test mode that can take a while to process
genesis_timestamp: MassaTime::now().expect("Impossible to reset the timestamp in test"),
t0: 10.into(),
}
}
}
7 changes: 5 additions & 2 deletions massa-execution-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rand_xoshiro = "0.6"
parking_lot = "0.12"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tempfile = "3.2"
thiserror = "1.0"
tokio = { version = "1.15", features = ["full"] }
tracing = "0.1"
Expand All @@ -30,7 +31,9 @@ massa_ledger = { path = "../massa-ledger" }
[dev-dependencies]
pretty_assertions = "1.0"
serial_test = "0.5"
tempfile = "3.2"

# custom modules with testing enabled
massa_execution_exports = { path = "../massa-execution-exports", features = ["testing"] }
massa_execution_exports = { path = "../massa-execution-exports", features = [
"testing",
] }
massa_ledger = { path = "../massa-ledger", features = ["testing"] }
2 changes: 1 addition & 1 deletion massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl ExecutionState {
// https://github.com/massalabs/massa/issues/2335
self.active_history
.iter()
.filter(|item| item.slot >= start && item.slot < end)
.filter(|item| item.slot >= start && item.slot <= end)
.flat_map(|item| {
item.events.get_filtered_sc_output_event(
start,
Expand Down
Binary file added massa-execution-worker/src/tests/event_test.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion massa-execution-worker/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Copyright (c) 2022 MASSA LABS <info@massa.net>

//TODO mod scenarios_mandatories; https://github.com/massalabs/massa/pull/2296
mod scenarios_mandatories;
Loading

0 comments on commit c37a5ee

Please sign in to comment.