Skip to content

Commit

Permalink
Wraps MockNode into an Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Aug 30, 2024
1 parent 81f151d commit 816c51c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
28 changes: 18 additions & 10 deletions crates/node/src/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,27 @@ pub enum NodeResults {
Failed(ResultCode),
}

// TODO: wrap `MockNode` in a single `Arc`
// FIXME: look at this todo, not sure it's correct though
#[derive(Clone)]
pub struct MockNode {
pub shell: Arc<Mutex<Shell<storage::PersistentDB, Sha256Hasher>>>,
pub test_dir: Arc<SalvageableTestDir>,
pub tx_result_codes: Arc<Mutex<Vec<NodeResults>>>,
pub tx_results: Arc<Mutex<Vec<namada_sdk::tx::data::TxResult<String>>>>,
pub blocks: Arc<Mutex<HashMap<BlockHeight, block::Response>>>,
pub services: Arc<MockServices>,
pub struct InnerMockNode {
pub shell: Mutex<Shell<storage::PersistentDB, Sha256Hasher>>,
pub test_dir: SalvageableTestDir,
pub tx_result_codes: Mutex<Vec<NodeResults>>,
pub tx_results: Mutex<Vec<namada_sdk::tx::data::TxResult<String>>>,
pub blocks: Mutex<HashMap<BlockHeight, block::Response>>,
pub services: MockServices,
pub auto_drive_services: bool,
}

#[derive(Clone)]
pub struct MockNode(pub Arc<InnerMockNode>);

impl Deref for MockNode {
type Target = Arc<InnerMockNode>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

pub struct SalvageableTestDir {
pub test_dir: ManuallyDrop<TestDir>,
pub keep_temp: bool,
Expand Down
24 changes: 12 additions & 12 deletions crates/tests/src/integration/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use namada_apps_lib::wallet::pre_genesis;
use namada_core::chain::ChainIdPrefix;
use namada_core::collections::HashMap;
use namada_node::shell::testing::node::{
mock_services, MockNode, MockServicesCfg, MockServicesController,
MockServicesPackage, SalvageableTestDir,
mock_services, InnerMockNode, MockNode, MockServicesCfg,
MockServicesController, MockServicesPackage, SalvageableTestDir,
};
use namada_node::shell::testing::utils::TestDir;
use namada_node::shell::Shell;
Expand Down Expand Up @@ -202,8 +202,8 @@ fn create_node(
shell_handlers,
controller,
} = mock_services(services_cfg);
let node = MockNode {
shell: Arc::new(Mutex::new(Shell::new(
let node = MockNode(Arc::new(InnerMockNode {
shell: Mutex::new(Shell::new(
config::Ledger::new(
global_args.base_dir,
chain_id.clone(),
Expand All @@ -218,17 +218,17 @@ fn create_node(
None,
50 * 1024 * 1024, // 50 kiB
50 * 1024 * 1024, // 50 kiB
))),
test_dir: Arc::new(SalvageableTestDir {
)),
test_dir: SalvageableTestDir {
keep_temp,
test_dir: ManuallyDrop::new(test_dir),
}),
services: Arc::new(services),
tx_result_codes: Arc::new(Mutex::new(vec![])),
tx_results: Arc::new(Mutex::new(vec![])),
blocks: Arc::new(Mutex::new(HashMap::new())),
},
services,
tx_result_codes: Mutex::new(vec![]),
tx_results: Mutex::new(vec![]),
blocks: Mutex::new(HashMap::new()),
auto_drive_services,
};
}));
let init_req =
namada_apps_lib::tendermint::abci::request::InitChain {
time: Timestamp {
Expand Down

0 comments on commit 816c51c

Please sign in to comment.