Skip to content

Commit

Permalink
fix empty version specific data in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aschran committed May 28, 2024
1 parent 198147b commit c6e029c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 51 deletions.
7 changes: 3 additions & 4 deletions crates/sui-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,12 +1361,11 @@ impl CheckpointBuilder {
.filter_map(|e| randomness_rounds.get(e.transaction_digest()))
.copied()
.collect();
let data = CheckpointVersionSpecificData::V1(CheckpointVersionSpecificDataV1 {
Some(CheckpointVersionSpecificData::V1(CheckpointVersionSpecificDataV1 {
randomness_rounds: matching_randomness_rounds,
});
bcs::to_bytes(&data)?
}))
} else {
Vec::new()
None
};

let contents = CheckpointContents::new_with_digests_and_signatures(
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-core/src/unit_tests/batch_verification_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sui_types::committee::Committee;
use sui_types::crypto::{get_key_pair, AccountKeyPair, AuthorityKeyPair};
use sui_types::gas::GasCostSummary;
use sui_types::messages_checkpoint::{
CheckpointContents, CheckpointSummary, SignedCheckpointSummary,
CheckpointContents, CheckpointSummary, CheckpointVersionSpecificData, SignedCheckpointSummary,
};
use sui_types::signature_verification::VerifiedDigestCache;
use sui_types::transaction::CertifiedTransaction;
Expand Down Expand Up @@ -63,7 +63,7 @@ fn gen_ckpts(
GasCostSummary::default(),
None,
0,
Vec::new(),
CheckpointVersionSpecificData::empty_for_tests(),
),
k,
name,
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-data-ingestion-core/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use sui_types::full_checkpoint_content::CheckpointData;
use sui_types::gas::GasCostSummary;
use sui_types::messages_checkpoint::{
CertifiedCheckpointSummary, CheckpointContents, CheckpointSequenceNumber, CheckpointSummary,
SignedCheckpointSummary,
CheckpointVersionSpecificData, SignedCheckpointSummary,
};
use sui_types::utils::make_committee_key;
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -144,7 +144,7 @@ fn mock_checkpoint_data_bytes(seq_number: CheckpointSequenceNumber) -> Vec<u8> {
GasCostSummary::default(),
None,
0,
Vec::new(),
CheckpointVersionSpecificData::empty_for_tests(),
);

let sign_infos: Vec<_> = keys
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-storage/tests/key_value_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use sui_types::error::SuiResult;
use sui_types::event::Event;
use sui_types::messages_checkpoint::{
CertifiedCheckpointSummary, CheckpointContents, CheckpointSequenceNumber, CheckpointSummary,
SignedCheckpointSummary,
CheckpointVersionSpecificData, SignedCheckpointSummary,
};
use sui_types::transaction::Transaction;

Expand Down Expand Up @@ -114,7 +114,7 @@ impl MockTxStore {
Default::default(),
None,
0,
Vec::new(),
CheckpointVersionSpecificData::empty_for_tests(),
);

let signed = SignedCheckpointSummary::new(
Expand Down
21 changes: 16 additions & 5 deletions crates/sui-types/src/messages_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,12 @@ impl CheckpointSummary {
epoch_rolling_gas_cost_summary: GasCostSummary,
end_of_epoch_data: Option<EndOfEpochData>,
timestamp_ms: CheckpointTimestamp,
version_specific_data: Vec<u8>,
version_specific_data: Option<CheckpointVersionSpecificData>,
) -> CheckpointSummary {
let content_digest = *transactions.digest();
let version_specific_data = version_specific_data
.map(|v| bcs::to_bytes(&v).expect("version specific data should serialize"))
.unwrap_or_default();

Self {
epoch,
Expand Down Expand Up @@ -730,6 +733,14 @@ impl CheckpointVersionSpecificData {
Self::V1(v) => v,
}
}

pub fn empty_for_tests() -> Option<CheckpointVersionSpecificData> {
Some(CheckpointVersionSpecificData::V1(
CheckpointVersionSpecificDataV1 {
randomness_rounds: Vec::new(),
},
))
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -782,7 +793,7 @@ mod tests {
GasCostSummary::default(),
None,
0,
Vec::new(),
CheckpointVersionSpecificData::empty_for_tests(),
),
k,
name,
Expand Down Expand Up @@ -817,7 +828,7 @@ mod tests {
GasCostSummary::default(),
None,
0,
Vec::new(),
CheckpointVersionSpecificData::empty_for_tests(),
);

let sign_infos: Vec<_> = keys
Expand Down Expand Up @@ -857,7 +868,7 @@ mod tests {
GasCostSummary::default(),
None,
0,
Vec::new(),
CheckpointVersionSpecificData::empty_for_tests(),
),
k,
name,
Expand Down Expand Up @@ -896,7 +907,7 @@ mod tests {
GasCostSummary::default(),
None,
100,
Vec::new(),
CheckpointVersionSpecificData::empty_for_tests(),
)
}

Expand Down
37 changes: 1 addition & 36 deletions crates/sui-types/src/unit_tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ use crate::programmable_transaction_builder::ProgrammableTransactionBuilder;
use crate::transaction::{SenderSignedData, TEST_ONLY_GAS_UNIT_FOR_TRANSFER};
use crate::SuiAddress;
use crate::{
base_types::{dbg_addr, ExecutionDigests, ObjectID},
base_types::{dbg_addr, ObjectID},
committee::Committee,
crypto::{
get_key_pair, get_key_pair_from_rng, AccountKeyPair, AuthorityKeyPair,
AuthorityPublicKeyBytes, DefaultHash, Signature, SignatureScheme,
},
gas::GasCostSummary,
messages_checkpoint::{
CertifiedCheckpointSummary, CheckpointContents, CheckpointSummary, SignedCheckpointSummary,
},
object::Object,
signature::GenericSignature,
transaction::{Transaction, TransactionData},
Expand Down Expand Up @@ -129,37 +125,6 @@ pub fn to_sender_signed_transaction_with_multi_signers(
Transaction::from_data_and_signer(data, signers)
}

pub fn mock_certified_checkpoint<'a>(
keys: impl Iterator<Item = &'a AuthorityKeyPair>,
committee: Committee,
seq_num: u64,
) -> CertifiedCheckpointSummary {
let contents =
CheckpointContents::new_with_digests_only_for_tests([ExecutionDigests::random()]);

let summary = CheckpointSummary::new(
committee.epoch,
seq_num,
0,
&contents,
None,
GasCostSummary::default(),
None,
0,
Vec::new(),
);

let sign_infos: Vec<_> = keys
.map(|k| {
let name = k.public().into();

SignedCheckpointSummary::sign(committee.epoch, &summary, k, name)
})
.collect();

CertifiedCheckpointSummary::new(summary, sign_infos, &committee).expect("Cert is OK")
}

mod zk_login {
use fastcrypto_zkp::bn254::zk_login::ZkLoginInputs;
use shared_crypto::intent::PersonalMessage;
Expand Down

0 comments on commit c6e029c

Please sign in to comment.