Skip to content

Commit

Permalink
Enter your commit message (end with an empty line):
Browse files Browse the repository at this point in the history
  • Loading branch information
fahertym committed Aug 1, 2024
1 parent 5d0d2c0 commit 3545324
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 76 deletions.
76 changes: 38 additions & 38 deletions PROJECT_STRUCTURE_AND_CODE_CONTENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ pub enum Error {
pub type Result<T> = std::result::Result<T, Error>;===== END OF /home/matt/InterCooperative-Network/crates/icn_core/src/error.rs =====

===== START OF /home/matt/InterCooperative-Network/crates/icn_core/src/lib.rs =====
// File: crates/icn_core/src/lib.rs
// File: icn_core/src/lib.rs

use icn_common::{Config, Transaction, Proposal, ProposalStatus, Vote, CurrencyType, IcnResult, IcnError, NetworkStats};
use icn_blockchain::Blockchain;
Expand Down Expand Up @@ -2956,27 +2956,31 @@ mod tests {
}

#[tokio::test]
async fn test_reputation_management() {
async fn test_zkp_operations() {
let node = create_test_node().await;
let node_id = "test_node";

// Initial reputation should be 0 or a default value
let initial_reputation = node.get_node_reputation(node_id).await.unwrap();
assert_eq!(initial_reputation, 0.0);
// Create a transaction
let transaction = Transaction {
from: "Alice".to_string(),
to: "Bob".to_string(),
amount: 100.0,
currency_type: CurrencyType::BasicNeeds,
timestamp: Utc::now().timestamp(),
signature: None,
};

// Update reputation
node.update_node_reputation(node_id, 0.5).await.unwrap();
let updated_reputation = node.get_node_reputation(node_id).await.unwrap();
assert_eq!(updated_reputation, 0.5);
}
// Create a ZKP for the transaction
let (proof, committed_values) = node.create_zkp(&transaction).await.unwrap();

#[tokio::test]
async fn test_sharding() {
let node = create_test_node().await;
let address = "test_address";
// Verify the ZKP
let is_valid = node.verify_zkp(&proof, &committed_values).await.unwrap();
assert!(is_valid);

let shard_id = node.get_shard_for_address(address).await;
assert!(shard_id < node.get_shard_count().await);
// Test with tampered data
let mut tampered_values = committed_values.clone();
tampered_values[0] ^= 1; // Flip a bit
let is_invalid = node.verify_zkp(&proof, &tampered_values).await.unwrap();
assert!(!is_invalid);
}

#[tokio::test]
Expand Down Expand Up @@ -3008,31 +3012,27 @@ mod tests {
}

#[tokio::test]
async fn test_zkp_operations() {
async fn test_reputation_management() {
let node = create_test_node().await;
let node_id = "test_node";

// Create a transaction
let transaction = Transaction {
from: "Alice".to_string(),
to: "Bob".to_string(),
amount: 100.0,
currency_type: CurrencyType::BasicNeeds,
timestamp: Utc::now().timestamp(),
signature: None,
};
// Initial reputation should be 0 or a default value
let initial_reputation = node.get_node_reputation(node_id).await.unwrap();
assert_eq!(initial_reputation, 0.0);

// Create a ZKP for the transaction
let (proof, committed_values) = node.create_zkp(&transaction).await.unwrap();
// Update reputation
node.update_node_reputation(node_id, 0.5).await.unwrap();
let updated_reputation = node.get_node_reputation(node_id).await.unwrap();
assert_eq!(updated_reputation, 0.5);
}

// Verify the ZKP
let is_valid = node.verify_zkp(&proof, &committed_values).await.unwrap();
assert!(is_valid);
#[tokio::test]
async fn test_sharding() {
let node = create_test_node().await;
let address = "test_address";

// Test with tampered data
let mut tampered_values = committed_values.clone();
tampered_values[0] ^= 1; // Flip a bit
let is_invalid = node.verify_zkp(&proof, &tampered_values).await.unwrap();
assert!(!is_invalid);
let shard_id = node.get_shard_for_address(address).await;
assert!(shard_id < node.get_shard_count().await);
}
}===== END OF /home/matt/InterCooperative-Network/crates/icn_core/src/lib.rs =====

Expand Down Expand Up @@ -4714,7 +4714,7 @@ chrono = { version = "0.4", features = ["serde"] }
uuid = { version = "1.0", features = ["v4"] }===== END OF /home/matt/InterCooperative-Network/crates/icn_demo/Cargo.toml =====

===== START OF /home/matt/InterCooperative-Network/crates/icn_demo/src/main.rs =====
// File: crates/icn_demo/src/main.rs
// File: icn_demo/src/main.rs

use icn_core::{IcnNode, Config};
use icn_common::{Transaction, Proposal, ProposalType, ProposalCategory, CurrencyType, ProposalStatus, IcnResult, IcnError};
Expand Down
74 changes: 37 additions & 37 deletions crates/icn_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// File: crates/icn_core/src/lib.rs
// File: icn_core/src/lib.rs

use icn_common::{Config, Transaction, Proposal, ProposalStatus, Vote, CurrencyType, IcnResult, IcnError, NetworkStats};
use icn_blockchain::Blockchain;
Expand Down Expand Up @@ -423,27 +423,31 @@ mod tests {
}

#[tokio::test]
async fn test_reputation_management() {
async fn test_zkp_operations() {
let node = create_test_node().await;
let node_id = "test_node";

// Initial reputation should be 0 or a default value
let initial_reputation = node.get_node_reputation(node_id).await.unwrap();
assert_eq!(initial_reputation, 0.0);
// Create a transaction
let transaction = Transaction {
from: "Alice".to_string(),
to: "Bob".to_string(),
amount: 100.0,
currency_type: CurrencyType::BasicNeeds,
timestamp: Utc::now().timestamp(),
signature: None,
};

// Update reputation
node.update_node_reputation(node_id, 0.5).await.unwrap();
let updated_reputation = node.get_node_reputation(node_id).await.unwrap();
assert_eq!(updated_reputation, 0.5);
}
// Create a ZKP for the transaction
let (proof, committed_values) = node.create_zkp(&transaction).await.unwrap();

#[tokio::test]
async fn test_sharding() {
let node = create_test_node().await;
let address = "test_address";
// Verify the ZKP
let is_valid = node.verify_zkp(&proof, &committed_values).await.unwrap();
assert!(is_valid);

let shard_id = node.get_shard_for_address(address).await;
assert!(shard_id < node.get_shard_count().await);
// Test with tampered data
let mut tampered_values = committed_values.clone();
tampered_values[0] ^= 1; // Flip a bit
let is_invalid = node.verify_zkp(&proof, &tampered_values).await.unwrap();
assert!(!is_invalid);
}

#[tokio::test]
Expand Down Expand Up @@ -475,30 +479,26 @@ mod tests {
}

#[tokio::test]
async fn test_zkp_operations() {
async fn test_reputation_management() {
let node = create_test_node().await;
let node_id = "test_node";

// Create a transaction
let transaction = Transaction {
from: "Alice".to_string(),
to: "Bob".to_string(),
amount: 100.0,
currency_type: CurrencyType::BasicNeeds,
timestamp: Utc::now().timestamp(),
signature: None,
};
// Initial reputation should be 0 or a default value
let initial_reputation = node.get_node_reputation(node_id).await.unwrap();
assert_eq!(initial_reputation, 0.0);

// Create a ZKP for the transaction
let (proof, committed_values) = node.create_zkp(&transaction).await.unwrap();
// Update reputation
node.update_node_reputation(node_id, 0.5).await.unwrap();
let updated_reputation = node.get_node_reputation(node_id).await.unwrap();
assert_eq!(updated_reputation, 0.5);
}

// Verify the ZKP
let is_valid = node.verify_zkp(&proof, &committed_values).await.unwrap();
assert!(is_valid);
#[tokio::test]
async fn test_sharding() {
let node = create_test_node().await;
let address = "test_address";

// Test with tampered data
let mut tampered_values = committed_values.clone();
tampered_values[0] ^= 1; // Flip a bit
let is_invalid = node.verify_zkp(&proof, &tampered_values).await.unwrap();
assert!(!is_invalid);
let shard_id = node.get_shard_for_address(address).await;
assert!(shard_id < node.get_shard_count().await);
}
}
2 changes: 1 addition & 1 deletion crates/icn_demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// File: crates/icn_demo/src/main.rs
// File: icn_demo/src/main.rs

use icn_core::{IcnNode, Config};
use icn_common::{Transaction, Proposal, ProposalType, ProposalCategory, CurrencyType, ProposalStatus, IcnResult, IcnError};
Expand Down

0 comments on commit 3545324

Please sign in to comment.