Skip to content

Commit

Permalink
Do less genesis, and more testing (MystenLabs#2099)
Browse files Browse the repository at this point in the history
Co-authored-by: George Danezis <[email protected]>
  • Loading branch information
gdanezis and George Danezis authored May 21, 2022
1 parent d396fa3 commit 22e1535
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
15 changes: 12 additions & 3 deletions sui_core/src/authority_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use sui_types::{
object::Object,
};

#[cfg(test)]
use sui_config::genesis::Genesis;

#[async_trait]
pub trait AuthorityAPI {
/// Initiate a new transaction to a Sui or Primary account.
Expand Down Expand Up @@ -321,7 +324,12 @@ impl AuthorityAPI for LocalAuthorityClient {

impl LocalAuthorityClient {
#[cfg(test)]
pub async fn new(committee: Committee, address: PublicKeyBytes, secret: KeyPair) -> Self {
pub async fn new(
committee: Committee,
address: PublicKeyBytes,
secret: KeyPair,
genesis: &Genesis,
) -> Self {
use crate::authority::AuthorityStore;
use crate::checkpoints::CheckpointStore;
use parking_lot::Mutex;
Expand Down Expand Up @@ -355,7 +363,7 @@ impl LocalAuthorityClient {
store,
None,
Some(Arc::new(Mutex::new(checkpoints))),
&sui_config::genesis::Genesis::get_default_genesis(),
genesis,
)
.await;
Self {
Expand All @@ -370,8 +378,9 @@ impl LocalAuthorityClient {
address: PublicKeyBytes,
secret: KeyPair,
objects: Vec<Object>,
genesis: &Genesis,
) -> Self {
let client = Self::new(committee, address, secret).await;
let client = Self::new(committee, address, secret, genesis).await;

for object in objects {
client.state.insert_genesis_object(object).await;
Expand Down
4 changes: 2 additions & 2 deletions sui_core/src/checkpoints/tests/checkpoint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,7 @@ async fn checkpoint_tests_setup() -> TestSetup {
let mut authorities = Vec::new();

// Make all authorities and their services.
let genesis = sui_config::genesis::Genesis::get_default_genesis();
for k in &keys {
let dir = env::temp_dir();
let path = dir.join(format!("SC_{:?}", ObjectID::random()));
Expand Down Expand Up @@ -1357,15 +1358,14 @@ async fn checkpoint_tests_setup() -> TestSetup {
.set_consensus(Box::new(sender.clone()))
.expect("No issues");
let checkpoint = Arc::new(Mutex::new(checkpoint));

let authority = AuthorityState::new(
committee.clone(),
*secret.public_key_bytes(),
secret,
store.clone(),
None,
Some(checkpoint.clone()),
&sui_config::genesis::Genesis::get_default_genesis(),
&genesis,
)
.await;

Expand Down
23 changes: 22 additions & 1 deletion sui_core/src/unit_tests/authority_aggregator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use once_cell::sync::Lazy;
use signature::Signer;

use sui_adapter::genesis;
use sui_config::genesis::Genesis;
use sui_types::crypto::get_key_pair;
use sui_types::crypto::Signature;

Expand Down Expand Up @@ -37,6 +38,17 @@ pub async fn init_local_authorities(
) -> (
AuthorityAggregator<LocalAuthorityClient>,
Vec<Arc<AuthorityState>>,
) {
let genesis = sui_config::genesis::Genesis::get_default_genesis();
init_local_authorities_with_genesis(&genesis, genesis_objects).await
}

pub async fn init_local_authorities_with_genesis(
genesis: &Genesis,
genesis_objects: Vec<Vec<Object>>,
) -> (
AuthorityAggregator<LocalAuthorityClient>,
Vec<Arc<AuthorityState>>,
) {
#[allow(clippy::no_effect)]
*LOGGING_INIT; // Initialize logging if needed
Expand All @@ -58,6 +70,7 @@ pub async fn init_local_authorities(
authority_name,
secret,
objects,
genesis,
)
.await;
states.push(client.state.clone());
Expand Down Expand Up @@ -282,6 +295,7 @@ pub async fn get_latest_ref<A: AuthorityAPI>(authority: &A, object_id: ObjectID)
}

async fn execute_transaction_with_fault_configs(
genesis: &Genesis,
configs_before_process_transaction: &[(usize, LocalAuthorityClientFaultConfig)],
configs_before_process_certificate: &[(usize, LocalAuthorityClientFaultConfig)],
) -> SuiResult {
Expand All @@ -291,7 +305,9 @@ async fn execute_transaction_with_fault_configs(
let gas_object2 = Object::with_owner_for_testing(addr1);
let genesis_objects =
authority_genesis_objects(4, vec![gas_object1.clone(), gas_object2.clone()]);
let mut authorities = init_local_authorities(genesis_objects).await.0;
let mut authorities = init_local_authorities_with_genesis(genesis, genesis_objects)
.await
.0;

for (index, config) in configs_before_process_transaction {
get_local_client(&mut authorities, *index).fault_config = *config;
Expand Down Expand Up @@ -775,6 +791,7 @@ async fn test_process_transaction_fault_success() {
// A transaction is sent to all authories, however one of them will error out either before or after processing the transaction.
// A cert should still be created, and sent out to all authorities again. This time
// a different authority errors out either before or after processing the cert.
let genesis = sui_config::genesis::Genesis::get_default_genesis();
for i in 0..4 {
let mut config_before_process_transaction = LocalAuthorityClientFaultConfig::default();
if i % 2 == 0 {
Expand All @@ -789,6 +806,7 @@ async fn test_process_transaction_fault_success() {
config_before_process_certificate.fail_after_handle_confirmation = true;
}
execute_transaction_with_fault_configs(
&genesis,
&[(0, config_before_process_transaction)],
&[(1, config_before_process_certificate)],
)
Expand All @@ -806,7 +824,9 @@ async fn test_process_transaction_fault_fail() {
fail_before_handle_transaction: true,
..Default::default()
};
let genesis = sui_config::genesis::Genesis::get_default_genesis();
assert!(execute_transaction_with_fault_configs(
&genesis,
&[
(0, fail_before_process_transaction_config),
(1, fail_before_process_transaction_config),
Expand All @@ -821,6 +841,7 @@ async fn test_process_transaction_fault_fail() {
..Default::default()
};
assert!(execute_transaction_with_fault_configs(
&genesis,
&[],
&[
(0, fail_before_process_certificate_config),
Expand Down
3 changes: 2 additions & 1 deletion test_utils/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ where
I: IntoIterator<Item = Object> + Clone,
{
let mut handles = Vec::new();
let genesis = sui_config::genesis::Genesis::get_default_genesis();
for validator in config.validator_configs() {
let state = AuthorityState::new(
validator.committee_config().committee(),
Expand All @@ -59,7 +60,7 @@ where
Arc::new(test_authority_store()),
None,
None,
&sui_config::genesis::Genesis::get_default_genesis(),
&genesis,
)
.await;

Expand Down

0 comments on commit 22e1535

Please sign in to comment.