Skip to content

Commit

Permalink
test: remove mock_time() test function
Browse files Browse the repository at this point in the history
  • Loading branch information
rumenov committed Feb 20, 2024
1 parent 8e3b66b commit a37afc5
Show file tree
Hide file tree
Showing 81 changed files with 441 additions and 458 deletions.
3 changes: 1 addition & 2 deletions rs/artifact_pool/src/backup.rs
Expand Up @@ -628,7 +628,6 @@ impl BackupArtifact {
mod tests {
use super::*;
use ic_test_utilities::{consensus::fake::*, types::ids::node_test_id};
use ic_test_utilities_time::mock_time;
use ic_types::{
batch::*,
consensus::*,
Expand Down Expand Up @@ -690,7 +689,7 @@ mod tests {
ValidationContext {
registry_version: RegistryVersion::from(99),
certified_height: Height::from(42),
time: mock_time(),
time: UNIX_EPOCH,
},
),
node_test_id(333),
Expand Down
8 changes: 4 additions & 4 deletions rs/artifact_pool/src/canister_http_pool.rs
Expand Up @@ -187,12 +187,12 @@ impl HasLabel for CanisterHttpResponse {
mod tests {
use ic_logger::replica_logger::no_op_logger;
use ic_test_utilities::{consensus::fake::FakeSigner, types::ids::node_test_id};
use ic_test_utilities_time::mock_time;
use ic_types::{
canister_http::{CanisterHttpResponseContent, CanisterHttpResponseMetadata},
crypto::{CryptoHash, Signed},
messages::CallbackId,
signature::BasicSignature,
time::UNIX_EPOCH,
CanisterId, RegistryVersion,
};

Expand All @@ -204,15 +204,15 @@ mod tests {
UnvalidatedArtifact::<CanisterHttpResponseShare> {
message,
peer_id: node_test_id(0),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
}
}

fn fake_share(id: u64) -> CanisterHttpResponseShare {
Signed {
content: CanisterHttpResponseMetadata {
id: CallbackId::from(id),
timeout: mock_time(),
timeout: UNIX_EPOCH,
content_hash: CryptoHashOf::from(CryptoHash(vec![1, 2, 3])),
registry_version: RegistryVersion::from(id),
},
Expand All @@ -223,7 +223,7 @@ mod tests {
fn fake_response(id: u64) -> CanisterHttpResponse {
CanisterHttpResponse {
id: CallbackId::from(id),
timeout: mock_time(),
timeout: UNIX_EPOCH,
canister_id: CanisterId::from_u64(id),
content: CanisterHttpResponseContent::Success(Vec::new()),
}
Expand Down
17 changes: 9 additions & 8 deletions rs/artifact_pool/src/consensus_pool.rs
Expand Up @@ -911,11 +911,12 @@ mod tests {
types::ids::{node_test_id, subnet_test_id},
};
use ic_test_utilities_registry::{setup_registry, SubnetRecordBuilder};
use ic_test_utilities_time::{mock_time, FastForwardTimeSource};
use ic_test_utilities_time::FastForwardTimeSource;
use ic_types::{
batch::ValidationContext,
consensus::{BlockProposal, RandomBeacon},
crypto::{crypto_hash, CryptoHash, CryptoHashOf},
time::UNIX_EPOCH,
RegistryVersion, ReplicaVersion,
};
use prost::Message;
Expand Down Expand Up @@ -1202,7 +1203,7 @@ mod tests {
ValidationContext {
registry_version: RegistryVersion::from(99),
certified_height: Height::from(42),
time: mock_time(),
time: UNIX_EPOCH,
},
)
};
Expand Down Expand Up @@ -1382,7 +1383,7 @@ mod tests {
ValidationContext {
registry_version: RegistryVersion::from(99),
certified_height: Height::from(42),
time: mock_time(),
time: UNIX_EPOCH,
},
)
};
Expand Down Expand Up @@ -1557,7 +1558,7 @@ mod tests {
ValidationContext {
registry_version: RegistryVersion::from(98),
certified_height: Height::from(41),
time: mock_time(),
time: UNIX_EPOCH,
},
);
let proposal3 = BlockProposal::fake(block, node_test_id(333));
Expand All @@ -1574,7 +1575,7 @@ mod tests {
ValidationContext {
registry_version: RegistryVersion::from(101),
certified_height: Height::from(42),
time: mock_time(),
time: UNIX_EPOCH,
},
);
let proposal3_final = BlockProposal::fake(block.clone(), node_test_id(333));
Expand All @@ -1594,7 +1595,7 @@ mod tests {
ValidationContext {
registry_version: RegistryVersion::from(99),
certified_height: Height::from(42),
time: mock_time(),
time: UNIX_EPOCH,
},
);
let finalization_at_4 = Finalization::fake(FinalizationContent::new(
Expand All @@ -1615,7 +1616,7 @@ mod tests {
ValidationContext {
registry_version: RegistryVersion::from(98),
certified_height: Height::from(41),
time: mock_time(),
time: UNIX_EPOCH,
},
);
let proposal_non_final = BlockProposal::fake(block, node_test_id(333));
Expand Down Expand Up @@ -1921,7 +1922,7 @@ mod tests {
ValidationContext {
registry_version: RegistryVersion::from(99),
certified_height: Height::from(42),
time: mock_time(),
time: UNIX_EPOCH,
},
);
let finalization = Finalization::fake(FinalizationContent::new(
Expand Down
5 changes: 3 additions & 2 deletions rs/artifact_pool/src/consensus_pool_cache.rs
Expand Up @@ -475,8 +475,9 @@ mod test {
types::ids::{node_test_id, subnet_test_id},
};
use ic_test_utilities_registry::{setup_registry, SubnetRecordBuilder};
use ic_test_utilities_time::{mock_time, FastForwardTimeSource};
use ic_test_utilities_time::FastForwardTimeSource;
use ic_types::consensus::*;
use ic_types::time::UNIX_EPOCH;
use std::sync::Arc;
use std::time::Duration;

Expand Down Expand Up @@ -531,7 +532,7 @@ mod test {

assert_eq!(pool.advance_round_normal_operation_n(2), Height::from(2));
let mut block = pool.make_next_block();
let time = mock_time() + Duration::from_secs(10);
let time = UNIX_EPOCH + Duration::from_secs(10);
block.content.as_mut().context.time = time;
// recompute the hash to make sure it's still correct
block.update_content();
Expand Down
8 changes: 4 additions & 4 deletions rs/artifact_pool/src/dkg_pool.rs
Expand Up @@ -196,10 +196,10 @@ mod test {
consensus::fake::FakeSigner,
types::ids::{node_test_id, subnet_test_id},
};
use ic_test_utilities_time::mock_time;
use ic_types::{
crypto::threshold_sig::ni_dkg::{NiDkgDealing, NiDkgId, NiDkgTag, NiDkgTargetSubnet},
signature::BasicSignature,
time::UNIX_EPOCH,
NodeId,
};

Expand All @@ -226,7 +226,7 @@ mod test {
pool.insert(UnvalidatedArtifact {
message,
peer_id: node_test_id(1),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
assert!(pool.contains(&id));

Expand Down Expand Up @@ -256,12 +256,12 @@ mod test {
pool.insert(UnvalidatedArtifact {
message: make_message(current_dkg_id_start_height, node_test_id(1)),
peer_id: node_test_id(1),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
pool.insert(UnvalidatedArtifact {
message: make_message(last_dkg_id_start_height, node_test_id(1)),
peer_id: node_test_id(1),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
// ensure we have 2 validated and 2 unvalidated artifacts
assert_eq!(result.adverts.len(), 2);
Expand Down
12 changes: 6 additions & 6 deletions rs/artifact_pool/src/ingress_pool.rs
Expand Up @@ -477,8 +477,8 @@ mod tests {
use ic_interfaces::time_source::TimeSource;
use ic_test_utilities::{types::ids::node_test_id, types::messages::SignedIngressBuilder};
use ic_test_utilities_logger::with_test_replica_logger;
use ic_test_utilities_time::mock_time;
use ic_test_utilities_time::FastForwardTimeSource;
use ic_types::time::UNIX_EPOCH;
use rand::Rng;
use std::time::Duration;

Expand All @@ -494,7 +494,7 @@ mod tests {
UnvalidatedIngressArtifact {
message: IngressPoolObject::from(ingress_msg),
peer_id: node_test_id(0),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
},
);
assert_eq!(ingress_pool.size(), 1);
Expand Down Expand Up @@ -522,7 +522,7 @@ mod tests {
message_id.clone(),
ValidatedIngressArtifact {
msg: IngressPoolObject::from(ingress_msg),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
},
);
assert!(ingress_pool.contains(&message_id));
Expand Down Expand Up @@ -551,7 +551,7 @@ mod tests {
message_id,
ValidatedIngressArtifact {
msg: IngressPoolObject::from(ingress_msg),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
},
);

Expand Down Expand Up @@ -616,7 +616,7 @@ mod tests {
message_id.clone(),
ValidatedIngressArtifact {
msg: IngressPoolObject::from(ingress_msg),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
},
);
}
Expand Down Expand Up @@ -847,7 +847,7 @@ mod tests {
insert_validated_artifact_with_timestamps(
ingress_pool,
nonce,
mock_time(),
UNIX_EPOCH,
ic_types::time::expiry_time_from_now(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion rs/artifact_pool/src/lmdb_pool.rs
Expand Up @@ -2113,7 +2113,7 @@ mod tests {
fn validated_block_proposal(height: Height, rank: Rank) -> ValidatedConsensusArtifact {
ValidatedConsensusArtifact {
msg: ConsensusMessage::BlockProposal(fake_block_proposal_with_rank(height, rank)),
timestamp: ic_test_utilities_time::mock_time(),
timestamp: ic_types::time::UNIX_EPOCH,
}
}

Expand Down
26 changes: 13 additions & 13 deletions rs/artifact_pool/src/test_utils.rs
Expand Up @@ -16,7 +16,6 @@ use ic_test_utilities::{
consensus::{fake::*, make_genesis},
types::ids::node_test_id,
};
use ic_test_utilities_time::mock_time;
use ic_types::{
artifact::ConsensusMessageId,
consensus::{
Expand All @@ -27,6 +26,7 @@ use ic_types::{
},
crypto::{ThresholdSigShare, ThresholdSigShareOf},
signature::*,
time::UNIX_EPOCH,
Height,
};
use std::{
Expand Down Expand Up @@ -68,7 +68,7 @@ where
let mut ops = PoolSectionOps::new();
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
pool.mutate(ops);
}
Expand Down Expand Up @@ -437,7 +437,7 @@ where
T: PoolTestHelper,
{
T::run_persistent_pool_test("test_purge_survives_reboot", |config, log| {
let time_0 = mock_time() + Duration::from_secs(1234);
let time_0 = UNIX_EPOCH + Duration::from_secs(1234);
// create a pool and insert an artifact
{
let mut pool = T::new_consensus_pool(config.clone(), log.clone());
Expand Down Expand Up @@ -479,7 +479,7 @@ pub(crate) fn random_beacon_ops(
let msg = ConsensusMessage::RandomBeacon(random_beacon);
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
ops
Expand All @@ -494,7 +494,7 @@ pub(crate) fn block_proposal_ops(
let msg = ConsensusMessage::BlockProposal(block_proposal);
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
ops
Expand All @@ -511,7 +511,7 @@ fn finalization_ops() -> PoolSectionOps<ValidatedConsensusArtifact> {
let msg = ConsensusMessage::Finalization(Finalization { content, signature });
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
ops
Expand All @@ -528,7 +528,7 @@ fn notarization_ops() -> PoolSectionOps<ValidatedConsensusArtifact> {
let msg = ConsensusMessage::Notarization(Notarization { content, signature });
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
ops
Expand All @@ -548,7 +548,7 @@ fn random_beacon_share_ops() -> PoolSectionOps<ValidatedConsensusArtifact> {
let msg = ConsensusMessage::RandomBeaconShare(RandomBeaconShare { content, signature });
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
}
Expand All @@ -567,7 +567,7 @@ pub(crate) fn notarization_share_ops() -> PoolSectionOps<ValidatedConsensusArtif
let msg = ConsensusMessage::NotarizationShare(NotarizationShare { content, signature });
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
}
Expand All @@ -586,7 +586,7 @@ pub(crate) fn finalization_share_ops() -> PoolSectionOps<ValidatedConsensusArtif
let msg = ConsensusMessage::FinalizationShare(FinalizationShare { content, signature });
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
}
Expand All @@ -600,7 +600,7 @@ fn random_tape_ops() -> PoolSectionOps<ValidatedConsensusArtifact> {
let msg = ConsensusMessage::RandomTape(random_tape);
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
ops
Expand All @@ -618,7 +618,7 @@ fn random_tape_share_ops() -> PoolSectionOps<ValidatedConsensusArtifact> {
let msg = ConsensusMessage::RandomTapeShare(RandomTapeShare { content, signature });
ops.insert(ValidatedConsensusArtifact {
msg,
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
});
}
}
Expand Down Expand Up @@ -716,7 +716,7 @@ fn make_random_beacon_at_height(i: u64) -> ValidatedConsensusArtifact {
let random_beacon = fake_random_beacon(Height::from(i));
ValidatedConsensusArtifact {
msg: ConsensusMessage::RandomBeacon(random_beacon),
timestamp: mock_time(),
timestamp: UNIX_EPOCH,
}
}

Expand Down
4 changes: 2 additions & 2 deletions rs/bitcoin/consensus/src/payload_builder/proptests.rs
Expand Up @@ -8,7 +8,7 @@ use ic_btc_types_internal::{
use ic_interfaces::batch_payload::BatchPayloadBuilder;
use ic_logger::replica_logger::no_op_logger;
use ic_metrics::MetricsRegistry;
use ic_test_utilities::{mock_time, types::ids::subnet_test_id};
use ic_test_utilities::types::ids::subnet_test_id;
use ic_types::{batch::ValidationContext, Height, NumBytes};
use proptest::{prelude::*, proptest};

Expand Down Expand Up @@ -73,7 +73,7 @@ fn proptest_round(
let validation_context = ValidationContext {
registry_version: REGISTRY_VERSION,
certified_height: CERTIFIED_HEIGHT,
time: mock_time(),
time: UNIX_EPOCH,
};

let payload = bitcoin_payload_builder.build_payload(height, max_size, &[], &validation_context);
Expand Down

0 comments on commit a37afc5

Please sign in to comment.