Skip to content

Commit

Permalink
Remove use of default() for unit structs
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-mobilecoin committed Oct 18, 2023
1 parent ef240ac commit d2318ba
Show file tree
Hide file tree
Showing 57 changed files with 203 additions and 250 deletions.
2 changes: 1 addition & 1 deletion api/src/convert/input_ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod tests {
block_version,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion api/src/convert/signed_contingent_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod tests {
BlockVersion::MAX,
input_credentials,
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion api/src/convert/signing_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mod tests {
block_version,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand Down
10 changes: 5 additions & 5 deletions api/src/convert/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ mod tests {
block_version,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand Down Expand Up @@ -152,7 +152,7 @@ mod tests {
block_version,
input_credentials,
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand All @@ -175,7 +175,7 @@ mod tests {
block_version,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand Down Expand Up @@ -270,7 +270,7 @@ mod tests {
block_version,
input_credentials,
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand Down Expand Up @@ -302,7 +302,7 @@ mod tests {
block_version,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion api/src/convert/unsigned_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {
block_version,
Amount::new(Mob::MINIMUM_FEE, Mob::ID),
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();

Expand Down
6 changes: 3 additions & 3 deletions api/tests/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn signed_contingent_input_examples<T: RngCore + CryptoRng>(
block_version,
input_credentials,
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();
builder
Expand All @@ -87,7 +87,7 @@ fn signed_contingent_input_examples<T: RngCore + CryptoRng>(
block_version,
input_credentials,
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();
builder
Expand All @@ -109,7 +109,7 @@ fn signed_contingent_input_examples<T: RngCore + CryptoRng>(
block_version,
input_credentials,
fpr.clone(),
EmptyMemoBuilder::default(),
EmptyMemoBuilder,
)
.unwrap();
builder
Expand Down
2 changes: 1 addition & 1 deletion attest/untrusted/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl SimQuotingEnclave {
let sgx_quote = sgx_quote(report.body(), &cert_data);
let mut quote_bytes = c_struct_as_bytes(&sgx_quote).to_vec();

let mut rng = McRng::default();
let mut rng = McRng;
let signing_key = SigningKey::random(&mut rng);
// Per <https://download.01.org/intel-sgx/latest/dcap-latest/linux/docs/Intel_SGX_ECDSA_QuoteLibReference_DCAP_API.pdf#%5B%7B%22num%22%3A75%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C69%2C687%2C0%5D>
// the signature is only over the header and report body of the quote.
Expand Down
4 changes: 2 additions & 2 deletions attest/verifier/src/dcap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ mod test {

// The certs, TCB info, and QE identity are generated at build time, so `now()`
// should be alright to use in testing.
let now = SystemTimeProvider::default()
let now = SystemTimeProvider
.since_epoch()
.expect("Failed to get duration since epoch");
let time =
Expand Down Expand Up @@ -342,7 +342,7 @@ mod test {

// The certs, TCB info, and QE identity are generated at build time, so `now()`
// should be alright to use in testing.
let now = SystemTimeProvider::default()
let now = SystemTimeProvider
.since_epoch()
.expect("Failed to get duration since epoch");
let time =
Expand Down
2 changes: 1 addition & 1 deletion common/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ cfg_if::cfg_if! {
fn default() -> Self {
Self {
cur_since_epoch: Arc::new(Mutex::new(
SystemTimeProvider::default()
SystemTimeProvider
.since_epoch()
.expect("failed getting initial value for cur_since_epoch"),
)),
Expand Down
4 changes: 2 additions & 2 deletions connection/src/thick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<CP: CredentialsProvider> AttestedConnection for ThickClient<CP> {
// If we have an existing attestation, nuke it.
self.deattest();

let mut csprng = McRng::default();
let mut csprng = McRng;

let initiator = Start::new(self.uri.responder_id()?.to_string());

Expand All @@ -324,7 +324,7 @@ impl<CP: CredentialsProvider> AttestedConnection for ThickClient<CP> {
.map_err(ThickClientAttestationError::from)
})?;

let epoch_time = SystemTimeProvider::default()
let epoch_time = SystemTimeProvider
.since_epoch()
.map_err(|_| ThickClientAttestationError::Other("Time went backwards".to_owned()))?;
let time = DateTime::from_unix_duration(epoch_time)
Expand Down
2 changes: 1 addition & 1 deletion consensus/enclave/impl/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Ed25519Identity {
impl Default for Ed25519Identity {
fn default() -> Self {
Self {
signing_keypair: Mutex::new(Ed25519Pair::from_random(&mut McRng::default())),
signing_keypair: Mutex::new(Ed25519Pair::from_random(&mut McRng)),
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions consensus/enclave/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ impl SgxConsensusEnclave {
pub fn new(logger: Logger) -> Self {
Self {
ake: Default::default(),
locally_encrypted_tx_cipher: Mutex::new(AesMessageCipher::new(&mut McRng::default())),
well_formed_encrypted_tx_cipher: Mutex::new(AesMessageCipher::new(
&mut McRng::default(),
)),
locally_encrypted_tx_cipher: Mutex::new(AesMessageCipher::new(&mut McRng)),
well_formed_encrypted_tx_cipher: Mutex::new(AesMessageCipher::new(&mut McRng)),
logger,
blockchain_config: Default::default(),
ct_min_fee_map: Default::default(),
Expand Down Expand Up @@ -612,7 +610,7 @@ impl ConsensusEnclave for SgxConsensusEnclave {
// Convert to TxContext
let maybe_locally_encrypted_tx: Result<LocallyEncryptedTx> = {
let mut cipher = self.locally_encrypted_tx_cipher.lock()?;
let mut rng = McRng::default();
let mut rng = McRng;

Ok(LocallyEncryptedTx(cipher.encrypt_bytes(&mut rng, tx_bytes)))
};
Expand Down Expand Up @@ -641,7 +639,7 @@ impl ConsensusEnclave for SgxConsensusEnclave {
let txs = mc_util_serial::decode::<TxList>(&data)?.txs;

// Convert to TxContexts
let mut rng = McRng::default();
let mut rng = McRng;
txs.into_iter()
.map(|tx| {
let tx_bytes = mc_util_serial::encode(&tx);
Expand Down Expand Up @@ -703,7 +701,7 @@ impl ConsensusEnclave for SgxConsensusEnclave {
let fee_token_id = TokenId::from(tx.prefix.fee_token_id);

// Validate.
let mut csprng = McRng::default();
let mut csprng = McRng;
let minimum_fee = ct_min_fee_map
.get(&fee_token_id)
.ok_or(TransactionValidationError::TokenNotYetConfigured)?;
Expand Down Expand Up @@ -771,7 +769,7 @@ impl ConsensusEnclave for SgxConsensusEnclave {
inputs: FormBlockInputs,
root_element: &TxOutMembershipElement,
) -> Result<(Block, BlockContents, BlockSignature)> {
let mut rng = McRng::default();
let mut rng = McRng;
let config = self
.blockchain_config
.get()
Expand Down
2 changes: 1 addition & 1 deletion consensus/enclave/mock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl ConsensusEnclave for ConsensusServiceMockEnclave {
// root_elements contains the root hash of the Merkle tree of all TxOuts in the
// ledger that were used to validate the tranasctions.
let mut root_elements = Vec::new();
let mut rng = McRng::default();
let mut rng = McRng;

for (tx, proofs) in transactions_with_proofs.iter() {
mc_transaction_core::validation::validate(
Expand Down
2 changes: 1 addition & 1 deletion consensus/enclave/tests/enclave_api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lazy_static::lazy_static! {
/// as expected.
#[test_with_logger]
fn consensus_enclave_client_tx_propose(logger: Logger) {
let mut rng = McRng::default();
let mut rng = McRng;

let responder_id = ResponderId::from_str("127.0.0.1:3000").unwrap();
let block_version = BlockVersion::MAX;
Expand Down
3 changes: 1 addition & 2 deletions consensus/mint-client/src/fog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ impl FogContext {
let validated_fog_pubkey = self.resolve_one_fog_url(public_address)?;

Ok((
FogHint::from(public_address)
.encrypt(&validated_fog_pubkey.pubkey, &mut McRng::default()),
FogHint::from(public_address).encrypt(&validated_fog_pubkey.pubkey, &mut McRng),
validated_fog_pubkey.pubkey_expiry,
))
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/service/src/api/attested_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ mod peer_tests {
let authenticator = Arc::new(TokenAuthenticator::new(
[1; 32],
Duration::from_secs(60),
SystemTimeProvider::default(),
SystemTimeProvider,
));
let enclave = Arc::new(MockConsensusEnclave::new());

Expand Down Expand Up @@ -239,7 +239,7 @@ mod client_tests {
let authenticator = Arc::new(TokenAuthenticator::new(
[1; 32],
Duration::from_secs(60),
SystemTimeProvider::default(),
SystemTimeProvider,
));
let enclave = Arc::new(MockConsensusEnclave::new());

Expand Down
12 changes: 6 additions & 6 deletions consensus/service/src/api/blockchain_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ mod tests {
FeeMap::try_from_iter([(Mob::ID, 4000000000), (TokenId::from(60), 128000)]).unwrap();

let mut ledger_db = create_ledger();
let authenticator = Arc::new(AnonymousAuthenticator::default());
let authenticator = Arc::new(AnonymousAuthenticator);
let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);
let account_key = AccountKey::random(&mut rng);
let blocks_data = initialize_ledger(
Expand Down Expand Up @@ -253,7 +253,7 @@ mod tests {
let authenticator = Arc::new(TokenAuthenticator::new(
[1; 32],
Duration::from_secs(60),
SystemTimeProvider::default(),
SystemTimeProvider,
));

let blockchain_api_service = BlockchainApiService::new(
Expand Down Expand Up @@ -283,7 +283,7 @@ mod tests {
// `get_blocks` should returns the correct range of blocks.
fn test_get_blocks_response_range(logger: Logger) {
let mut ledger_db = create_ledger();
let authenticator = Arc::new(AnonymousAuthenticator::default());
let authenticator = Arc::new(AnonymousAuthenticator);
let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);
let account_key = AccountKey::random(&mut rng);
let expected_blocks = initialize_ledger(
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
// data if a client requests data that does not exist.
fn test_get_blocks_request_out_of_bounds(logger: Logger) {
let mut ledger_db = create_ledger();
let authenticator = Arc::new(AnonymousAuthenticator::default());
let authenticator = Arc::new(AnonymousAuthenticator);
let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);
let account_key = AccountKey::random(&mut rng);
let _blocks = initialize_ledger(
Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {
// requested range is larger.
fn test_get_blocks_max_size(logger: Logger) {
let mut ledger_db = create_ledger();
let authenticator = Arc::new(AnonymousAuthenticator::default());
let authenticator = Arc::new(AnonymousAuthenticator);
let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);
let account_key = AccountKey::random(&mut rng);
let expected_blocks = initialize_ledger(
Expand Down Expand Up @@ -407,7 +407,7 @@ mod tests {
let authenticator = Arc::new(TokenAuthenticator::new(
[1; 32],
Duration::from_secs(60),
SystemTimeProvider::default(),
SystemTimeProvider,
));

let blockchain_api_service = BlockchainApiService::new(
Expand Down
Loading

0 comments on commit d2318ba

Please sign in to comment.