Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Czabaniuk committed Oct 12, 2023
1 parent c7e5ae9 commit 570f4a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
24 changes: 15 additions & 9 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4789,6 +4789,8 @@ pub mod tests {
// note that this means that slot 0 will always be considered complete
let max_complete_transaction_status_slot = Arc::new(AtomicU64::new(0));
let max_complete_rewards_slot = Arc::new(AtomicU64::new(0));
let optimistically_confirmed_bank =
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks);

let meta = JsonRpcRequestProcessor::new(
config,
Expand All @@ -4797,11 +4799,11 @@ pub mod tests {
block_commitment_cache.clone(),
blockstore.clone(),
validator_exit,
RpcHealth::stub(),
RpcHealth::stub(optimistically_confirmed_bank.clone(), blockstore.clone()),
cluster_info,
Hash::default(),
None,
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks),
optimistically_confirmed_bank,
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
max_slots.clone(),
Arc::new(LeaderScheduleCache::new_from_bank(&bank)),
Expand Down Expand Up @@ -6400,7 +6402,9 @@ pub mod tests {
let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
let (bank_forks, mint_keypair, ..) = new_bank_forks();
let health = RpcHealth::stub();
let optimistically_confirmed_bank =
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks);
let health = RpcHealth::stub(optimistically_confirmed_bank.clone(), blockstore.clone());

// Freeze bank 0 to prevent a panic in `run_transaction_simulation()`
bank_forks.write().unwrap().get(0).unwrap().freeze();
Expand Down Expand Up @@ -6431,7 +6435,7 @@ pub mod tests {
cluster_info,
Hash::default(),
None,
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks),
optimistically_confirmed_bank,
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
Arc::new(MaxSlots::default()),
Arc::new(LeaderScheduleCache::default()),
Expand Down Expand Up @@ -6692,18 +6696,20 @@ pub mod tests {
.my_contact_info()
.tpu(connection_cache.protocol())
.unwrap();
let optimistically_confirmed_bank =
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks);
let (request_processor, receiver) = JsonRpcRequestProcessor::new(
JsonRpcConfig::default(),
None,
bank_forks.clone(),
block_commitment_cache,
blockstore,
blockstore.clone(),
validator_exit,
RpcHealth::stub(),
RpcHealth::stub(optimistically_confirmed_bank.clone(), blockstore),
cluster_info,
Hash::default(),
None,
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks),
optimistically_confirmed_bank,
Arc::new(RwLock::new(LargestAccountsCache::new(30))),
Arc::new(MaxSlots::default()),
Arc::new(LeaderScheduleCache::default()),
Expand Down Expand Up @@ -8329,9 +8335,9 @@ pub mod tests {
None,
bank_forks.clone(),
block_commitment_cache,
blockstore,
blockstore.clone(),
validator_exit,
RpcHealth::stub(),
RpcHealth::stub(optimistically_confirmed_bank.clone(), blockstore.clone()),
cluster_info,
Hash::default(),
None,
Expand Down
10 changes: 6 additions & 4 deletions rpc/src/rpc_health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ impl RpcHealth {
}

#[cfg(test)]
pub(crate) fn stub() -> Arc<Self> {
use crate::rpc::tests::new_test_cluster_info;
pub(crate) fn stub(
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
blockstore: Arc<Blockstore>,
) -> Arc<Self> {
Arc::new(Self::new(
Arc::new(new_test_cluster_info()),
None,
optimistically_confirmed_bank,
blockstore,
42,
Arc::new(AtomicBool::new(false)),
Arc::new(AtomicBool::new(true)),
Expand Down
27 changes: 18 additions & 9 deletions rpc/src/rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ mod tests {
&PathBuf::from("farf"),
validator_exit,
exit,
None,
Arc::new(AtomicBool::new(false)),
Arc::new(AtomicBool::new(true)),
optimistically_confirmed_bank,
Expand Down Expand Up @@ -720,18 +719,25 @@ mod tests {

#[test]
fn test_is_file_get_path() {
let ledger_path = get_tmp_ledger_path!();
let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
let bank_forks = create_bank_forks();
let optimistically_confirmed_bank =
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks);
let health = RpcHealth::stub(optimistically_confirmed_bank, blockstore);

let bank_forks = create_bank_forks();
let rrm = RpcRequestMiddleware::new(
PathBuf::from("/"),
ledger_path.clone(),
None,
bank_forks.clone(),
RpcHealth::stub(),
health.clone(),
);
let rrm_with_snapshot_config = RpcRequestMiddleware::new(
PathBuf::from("/"),
ledger_path.clone(),
Some(SnapshotConfig::default()),
bank_forks,
RpcHealth::stub(),
health,
);

assert!(rrm.is_file_get_path(DEFAULT_GENESIS_DOWNLOAD_PATH));
Expand Down Expand Up @@ -824,14 +830,17 @@ mod tests {
let runtime = Runtime::new().unwrap();

let ledger_path = get_tmp_ledger_path!();
std::fs::create_dir(&ledger_path).unwrap();

let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap());
let genesis_path = ledger_path.join(DEFAULT_GENESIS_ARCHIVE);
let bank_forks = create_bank_forks();
let optimistically_confirmed_bank =
OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks);

let rrm = RpcRequestMiddleware::new(
ledger_path.clone(),
None,
create_bank_forks(),
RpcHealth::stub(),
bank_forks,
RpcHealth::stub(optimistically_confirmed_bank, blockstore),
);

// File does not exist => request should fail.
Expand Down

0 comments on commit 570f4a5

Please sign in to comment.