Modified Peer payload to send taker infos about maker#99
Conversation
WalkthroughThe changes modify the Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Peer as Peer Struct
App->>Peer: new(pubkey, reputation)
Note right of Peer: Initialize pubkey and reputation fields
Peer-->>App: Return new Peer instance
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai can you add some tests for this? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 12472 🏁 Script executed: Length of output: 8784 🏁 Script executed: Length of output: 295 🏁 Script executed: Length of output: 7586 @grunch I'll create tests for the changes made to the #[test]
fn test_peer_with_reputation() {
// Test creating a Peer with reputation information
let reputation = UserDisputeInfo {
rating: 4.5,
reviews: 10,
operating_days: 30,
};
let peer = Peer::new(
"npub1testjsf0runcqdht5apkfcalajxkf8txdxqqk5kgm0agc38ke4vsfsgzf8".to_string(),
Some(reputation.clone()),
);
// Assert the fields are set correctly
assert_eq!(peer.pubkey, "npub1testjsf0runcqdht5apkfcalajxkf8txdxqqk5kgm0agc38ke4vsfsgzf8");
assert!(peer.reputation.is_some());
let peer_reputation = peer.reputation.unwrap();
assert_eq!(peer_reputation.rating, 4.5);
assert_eq!(peer_reputation.reviews, 10);
assert_eq!(peer_reputation.operating_days, 30);
// Test JSON serialization and deserialization
let json = peer.as_json().unwrap();
let deserialized_peer = Peer::from_json(&json).unwrap();
assert_eq!(deserialized_peer.pubkey, peer.pubkey);
assert!(deserialized_peer.reputation.is_some());
let deserialized_reputation = deserialized_peer.reputation.unwrap();
assert_eq!(deserialized_reputation.rating, 4.5);
assert_eq!(deserialized_reputation.reviews, 10);
assert_eq!(deserialized_reputation.operating_days, 30);
}
#[test]
fn test_peer_without_reputation() {
// Test creating a Peer without reputation information
let peer = Peer::new(
"npub1testjsf0runcqdht5apkfcalajxkf8txdxqqk5kgm0agc38ke4vsfsgzf8".to_string(),
None,
);
// Assert the reputation field is None
assert_eq!(peer.pubkey, "npub1testjsf0runcqdht5apkfcalajxkf8txdxqqk5kgm0agc38ke4vsfsgzf8");
assert!(peer.reputation.is_none());
// Test JSON serialization and deserialization
let json = peer.as_json().unwrap();
let deserialized_peer = Peer::from_json(&json).unwrap();
assert_eq!(deserialized_peer.pubkey, peer.pubkey);
assert!(deserialized_peer.reputation.is_none());
}
#[test]
fn test_peer_in_message() {
let uuid = uuid!("308e1272-d5f4-47e6-bd97-3504baea9c23");
// Test with reputation
let reputation = UserDisputeInfo {
rating: 4.5,
reviews: 10,
operating_days: 30,
};
let peer_with_reputation = Peer::new(
"npub1testjsf0runcqdht5apkfcalajxkf8txdxqqk5kgm0agc38ke4vsfsgzf8".to_string(),
Some(reputation),
);
let payload_with_reputation = Payload::Peer(peer_with_reputation);
let message_with_reputation = Message::Order(MessageKind::new(
Some(uuid),
Some(1),
Some(2),
Action::FiatSentOk,
Some(payload_with_reputation),
));
// Verify message with reputation
assert!(message_with_reputation.verify());
let message_json = message_with_reputation.as_json().unwrap();
let deserialized_message = Message::from_json(&message_json).unwrap();
assert!(deserialized_message.verify());
// Test without reputation
let peer_without_reputation = Peer::new(
"npub1testjsf0runcqdht5apkfcalajxkf8txdxqqk5kgm0agc38ke4vsfsgzf8".to_string(),
None,
);
let payload_without_reputation = Payload::Peer(peer_without_reputation);
let message_without_reputation = Message::Order(MessageKind::new(
Some(uuid),
Some(1),
Some(2),
Action::FiatSentOk,
Some(payload_without_reputation),
));
// Verify message without reputation
assert!(message_without_reputation.verify());
let message_json = message_without_reputation.as_json().unwrap();
let deserialized_message = Message::from_json(&message_json).unwrap();
assert!(deserialized_message.verify());
}Also, I need to fix the existing test that uses the old #[test]
fn test_message_payload_signature() {
let uuid = uuid!("308e1272-d5f4-47e6-bd97-3504baea9c23");
let peer = Peer::new(
"npub1testjsf0runcqdht5apkfcalajxkf8txdxqqk5kgm0agc38ke4vsfsgzf8".to_string(),
None, // Add None for the reputation parameter
);
let payload = Payload::Peer(peer);
let test_message = Message::Order(MessageKind::new(
Some(uuid),
Some(1),
Some(2),
Action::FiatSentOk,
Some(payload),
));
assert!(test_message.verify());
let test_message_json = test_message.as_json().unwrap();
// Message should be signed with the trade keys
let trade_keys =
Keys::parse("110e43647eae221ab1da33ddc17fd6ff423f2b2f49d809b9ffa40794a2ab996c")
.unwrap();
let sig = Message::sign(test_message_json.clone(), &trade_keys);
assert!(Message::verify_signature(
test_message_json,
trade_keys.public_key(),
sig
));
}These tests cover:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/message.rs (1)
544-572: Duplicate test implementation.This test duplicates the same test from
src/lib.rs. While not causing immediate issues, maintaining duplicate test cases across different files could lead to maintenance problems if one is updated but the other isn't.Consider either:
- Removing this duplicate test since it's already covered in
src/lib.rs- Extracting common test logic into a helper function used by both test modules
- Adding a comment explaining why the duplication exists
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/lib.rs(1 hunks)src/message.rs(3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/message.rs (2)
src/dispute.rs (2)
new(125-186)new(190-202)src/rating.rs (1)
new(16-30)
🔇 Additional comments (5)
src/lib.rs (1)
118-121: Updated Peer constructor call to accommodate new reputation parameter.The constructor call now includes
Nonefor the reputation parameter, aligning with the modified signature in thePeerstruct.src/message.rs (4)
2-2: Import added for UserDisputeInfo.Correctly imports the UserDisputeInfo struct from the dispute module to support the new reputation field.
24-25: Added reputation field to Peer struct.The new optional field allows for storing reputation information about users. Using
Option<UserDisputeInfo>is appropriate as it makes the field optional, maintaining backward compatibility with existing code.
29-31: Updated Peer constructor to handle reputation information.The constructor signature has been properly updated to accommodate the new optional reputation parameter, maintaining the structure of the original method.
430-543: Test coverage added for new reputation functionality.Comprehensive tests cover:
- Creating a Peer with reputation
- Creating a Peer without reputation
- Using Peers in Messages with and without reputation
- JSON serialization/deserialization
The tests are well-designed and thoroughly validate the new functionality.
|
fixed tests and added new one suggested by rabbit. |
@grunch @Catrya
this is another update on
mostro-core.I added an optional field in Peer payload to inform maker about taker reputation, as said if it's a privacy user all values will be 0.
Let me know if you like it @grunch ...
Summary by CodeRabbit
Peerstruct to ensure proper functionality with and without the new reputation field.