Skip to content

Commit

Permalink
fix: remove one unneeded instance of key_pair.copy()
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Apr 22, 2022
1 parent 2f4624b commit 825ad99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
2 changes: 1 addition & 1 deletion sui_core/src/authority_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use typed_store::Map;

#[cfg(test)]
#[path = "unit_tests/batch_tests.rs"]
mod batch_tests;
pub(crate) mod batch_tests;

/*
Expand Down
43 changes: 16 additions & 27 deletions sui_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use move_binary_format::{
};
use move_core_types::{account_address::AccountAddress, ident_str, language_storage::TypeTag};
use narwhal_executor::ExecutionIndices;
use rand::{prelude::StdRng, SeedableRng};
use sui_adapter::genesis;
use sui_types::{
base_types::dbg_addr,
Expand Down Expand Up @@ -1125,13 +1126,11 @@ async fn test_account_state_unknown_account() {

#[tokio::test]
async fn test_authority_persist() {
let (_, authority_key) = get_key_pair();
let mut authorities = BTreeMap::new();
authorities.insert(
/* address */ *authority_key.public_key_bytes(),
/* voting right */ 1,
);
let committee = Committee::new(authorities);
let seed = [1u8; 32];
let (committee, _, authority_key) =
crate::authority_batch::batch_tests::init_state_parameters_from_rng(
&mut StdRng::from_seed(seed),
);

// Create a random directory to store the DB
let dir = env::temp_dir();
Expand All @@ -1142,16 +1141,8 @@ async fn test_authority_persist() {
let mut opts = rocksdb::Options::default();
opts.set_max_open_files(max_files_authority_tests());
let store = Arc::new(AuthorityStore::open(&path, Some(opts)));
let authority = AuthorityState::new(
committee.clone(),
*authority_key.public_key_bytes(),
// we assume that the node runner is in charge for its key -> it's ok to reopen a copy below.
Arc::pin(authority_key.copy()),
store,
vec![],
&mut genesis::get_genesis_context(),
)
.await;
let authority =
crate::authority_batch::batch_tests::init_state(committee, authority_key, store).await;

// Create an object
let recipient = dbg_addr(2);
Expand All @@ -1164,19 +1155,17 @@ async fn test_authority_persist() {
// Close the authority
drop(authority);

// Reopen the authority with the same path
// Reopen the same authority with the same path
let mut opts = rocksdb::Options::default();
opts.set_max_open_files(max_files_authority_tests());
let seed = [1u8; 32];
let (committee, _, authority_key) =
crate::authority_batch::batch_tests::init_state_parameters_from_rng(
&mut StdRng::from_seed(seed),
);
let store = Arc::new(AuthorityStore::open(&path, Some(opts)));
let authority2 = AuthorityState::new(
committee,
*authority_key.public_key_bytes(),
Arc::pin(authority_key),
store,
vec![],
&mut genesis::get_genesis_context(),
)
.await;
let authority2 =
crate::authority_batch::batch_tests::init_state(committee, authority_key, store).await;
let obj2 = authority2.get_object(&object_id).await.unwrap().unwrap();

// Check the object is present
Expand Down
4 changes: 2 additions & 2 deletions sui_core/src/unit_tests/batch_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sui_types::messages::{
};
use sui_types::object::Object;

fn init_state_parameters_from_rng<R>(rng: &mut R) -> (Committee, SuiAddress, KeyPair)
pub(crate) fn init_state_parameters_from_rng<R>(rng: &mut R) -> (Committee, SuiAddress, KeyPair)
where
R: rand::CryptoRng + rand::RngCore,
{
Expand All @@ -43,7 +43,7 @@ where
(committee, authority_address, authority_key)
}

async fn init_state(
pub(crate) async fn init_state(
committee: Committee,
authority_key: KeyPair,
store: Arc<AuthorityStore>,
Expand Down

0 comments on commit 825ad99

Please sign in to comment.