Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions crates/challenge-registry/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ mod tests {
#[test]
fn test_registry_error_display_already_registered() {
let err = RegistryError::AlreadyRegistered("my-challenge".to_string());
assert_eq!(err.to_string(), "Challenge already registered: my-challenge");
assert_eq!(
err.to_string(),
"Challenge already registered: my-challenge"
);
}

#[test]
Expand Down Expand Up @@ -181,8 +184,7 @@ mod tests {
fn test_from_bincode_error() {
// Create invalid bincode data to trigger an error
let invalid_data: &[u8] = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
let bincode_err: bincode::Error =
bincode::deserialize::<String>(invalid_data).unwrap_err();
let bincode_err: bincode::Error = bincode::deserialize::<String>(invalid_data).unwrap_err();
let registry_err: RegistryError = bincode_err.into();

match registry_err {
Expand Down
4 changes: 3 additions & 1 deletion crates/challenge-registry/src/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ mod tests {

health.metrics.insert("cpu_usage".to_string(), 45.5);
health.metrics.insert("memory_mb".to_string(), 512.0);
health.metrics.insert("requests_per_sec".to_string(), 1000.0);
health
.metrics
.insert("requests_per_sec".to_string(), 1000.0);

assert_eq!(health.metrics.len(), 3);
assert_eq!(health.metrics.get("cpu_usage"), Some(&45.5));
Expand Down
16 changes: 4 additions & 12 deletions crates/challenge-registry/src/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ mod tests {
&LifecycleState::Running,
&LifecycleState::Failed("crash".to_string())
));
assert!(
lifecycle.is_valid_transition(&LifecycleState::Running, &LifecycleState::Migrating)
);
assert!(lifecycle.is_valid_transition(&LifecycleState::Running, &LifecycleState::Migrating));

// From Stopping
assert!(lifecycle.is_valid_transition(&LifecycleState::Stopping, &LifecycleState::Stopped));
Expand All @@ -233,9 +231,7 @@ mod tests {
));

// From Migrating
assert!(
lifecycle.is_valid_transition(&LifecycleState::Migrating, &LifecycleState::Running)
);
assert!(lifecycle.is_valid_transition(&LifecycleState::Migrating, &LifecycleState::Running));
assert!(lifecycle.is_valid_transition(
&LifecycleState::Migrating,
&LifecycleState::Failed("migration failed".to_string())
Expand Down Expand Up @@ -353,14 +349,10 @@ mod tests {
let lifecycle = ChallengeLifecycle::new();

// Valid: Running -> Migrating
assert!(
lifecycle.is_valid_transition(&LifecycleState::Running, &LifecycleState::Migrating)
);
assert!(lifecycle.is_valid_transition(&LifecycleState::Running, &LifecycleState::Migrating));

// Valid: Migrating -> Running (successful migration)
assert!(
lifecycle.is_valid_transition(&LifecycleState::Migrating, &LifecycleState::Running)
);
assert!(lifecycle.is_valid_transition(&LifecycleState::Migrating, &LifecycleState::Running));

// Valid: Migrating -> Failed (migration failed)
assert!(lifecycle.is_valid_transition(
Expand Down
20 changes: 16 additions & 4 deletions crates/challenge-registry/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,20 @@ mod tests {

map.insert(v3, "version_one_updated");
assert_eq!(map.len(), 2);
assert_eq!(map.get(&ChallengeVersion::new(1, 0, 0)), Some(&"version_one_updated"));
assert_eq!(
map.get(&ChallengeVersion::new(1, 0, 0)),
Some(&"version_one_updated")
);
}

#[test]
fn test_version_constraint_range() {
let min = ChallengeVersion::new(1, 0, 0);
let max = ChallengeVersion::new(2, 0, 0);
let range = VersionConstraint::Range { min: min.clone(), max: max.clone() };
let range = VersionConstraint::Range {
min: min.clone(),
max: max.clone(),
};

assert!(range.satisfies(&ChallengeVersion::new(1, 0, 0)));
assert!(range.satisfies(&ChallengeVersion::new(1, 5, 0)));
Expand Down Expand Up @@ -346,7 +352,10 @@ mod tests {

assert_eq!(challenge.challenge_id, "test-challenge");
assert_eq!(challenge.version, ChallengeVersion::new(1, 0, 0));
assert_eq!(challenge.min_platform_version, Some(ChallengeVersion::new(0, 5, 0)));
assert_eq!(
challenge.min_platform_version,
Some(ChallengeVersion::new(0, 5, 0))
);
assert!(!challenge.deprecated);
assert!(challenge.deprecation_message.is_none());

Expand All @@ -359,7 +368,10 @@ mod tests {
};

assert!(deprecated_challenge.deprecated);
assert_eq!(deprecated_challenge.deprecation_message, Some("Use new-challenge instead".to_string()));
assert_eq!(
deprecated_challenge.deprecation_message,
Some("Use new-challenge instead".to_string())
);
}

#[test]
Expand Down
13 changes: 6 additions & 7 deletions crates/distributed-storage/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ mod tests {

// Test NamespaceNotFound variant
let namespace_err = StorageError::NamespaceNotFound("missing_ns".to_string());
assert_eq!(
namespace_err.to_string(),
"Namespace not found: missing_ns"
);
assert_eq!(namespace_err.to_string(), "Namespace not found: missing_ns");

// Test Dht variant
let dht_err = StorageError::Dht("peer unreachable".to_string());
assert_eq!(dht_err.to_string(), "DHT error: peer unreachable");

// Test Replication variant
let replication_err = StorageError::Replication("sync failed".to_string());
assert_eq!(replication_err.to_string(), "Replication error: sync failed");
assert_eq!(
replication_err.to_string(),
"Replication error: sync failed"
);

// Test QuorumNotReached variant
let quorum_err = StorageError::QuorumNotReached {
Expand Down Expand Up @@ -201,8 +201,7 @@ mod tests {
fn test_from_bincode_error() {
// Create a bincode error by attempting to deserialize invalid data
let invalid_data: &[u8] = &[0xff, 0xff, 0xff, 0xff];
let bincode_result: Result<String, bincode::Error> =
bincode::deserialize(invalid_data);
let bincode_result: Result<String, bincode::Error> = bincode::deserialize(invalid_data);
if let Err(bincode_err) = bincode_result {
let storage_err: StorageError = bincode_err.into();
let display = storage_err.to_string();
Expand Down
7 changes: 7 additions & 0 deletions crates/distributed-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub mod error;
pub mod local;
pub mod query;
pub mod replication;
pub mod state_consensus;
pub mod store;
pub mod submission;
pub mod weights;
Expand Down Expand Up @@ -122,6 +123,12 @@ pub use challenge_store::{
ChallengeStorage, ChallengeStore, ChallengeStoreRegistry, MerkleNode, MerkleProof,
};

// State consensus protocol
pub use state_consensus::{
ConsensusResult as StateConsensusResult, FraudProof, GlobalStateLinker, InclusionProof,
StateRootConsensus, StateRootConsensusError, StateRootProposal, StateRootVote,
};

#[cfg(test)]
mod integration_tests {
use super::*;
Expand Down
Loading