Skip to content

Commit

Permalink
Merge pull request #63 from MostroP2P/bilthon-test
Browse files Browse the repository at this point in the history
added request_id to message for client testing
  • Loading branch information
grunch authored Oct 22, 2024
2 parents 91b1ec1 + 5217ba6 commit d87f4bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod test {
fn test_order_message() {
let uuid = uuid!("308e1272-d5f4-47e6-bd97-3504baea9c23");
let test_message = Message::Order(MessageKind::new(
1,
Some(uuid),
Action::NewOrder,
Some(Content::Order(SmallOrder::new(
Expand All @@ -56,7 +57,7 @@ mod test {
None,
))),
));
let sample_message = r#"{"order":{"version":1,"id":"308e1272-d5f4-47e6-bd97-3504baea9c23","pubkey":null,"action":"new-order","content":{"order":{"id":"308e1272-d5f4-47e6-bd97-3504baea9c23","kind":"sell","status":"pending","amount":100,"fiat_code":"eur","fiat_amount":100,"payment_method":"SEPA","premium":1,"created_at":1627371434}}}}"#;
let sample_message = r#"{"order":{"version":1,"request_id":1,"id":"308e1272-d5f4-47e6-bd97-3504baea9c23","pubkey":null,"action":"new-order","content":{"order":{"id":"308e1272-d5f4-47e6-bd97-3504baea9c23","kind":"sell","status":"pending","amount":100,"fiat_code":"eur","fiat_amount":100,"payment_method":"SEPA","premium":1,"created_at":1627371434}}}}"#;
let message = Message::from_json(sample_message).unwrap();
assert!(message.verify());
let message_json = message.as_json().unwrap();
Expand All @@ -68,6 +69,7 @@ mod test {
fn test_payment_request_content_message() {
let uuid = uuid!("308e1272-d5f4-47e6-bd97-3504baea9c23");
let test_message = Message::Order(MessageKind::new(
1,
Some(uuid),
Action::PayInvoice,
Some(Content::PaymentRequest(
Expand All @@ -94,7 +96,7 @@ mod test {
None,
)),
));
let sample_message = r#"{"order":{"version":1,"id":"308e1272-d5f4-47e6-bd97-3504baea9c23","pubkey":null,"action":"pay-invoice","content":{"payment_request":[{"id":"308e1272-d5f4-47e6-bd97-3504baea9c23","kind":"sell","status":"waiting-payment","amount":100,"fiat_code":"eur","fiat_amount":100,"payment_method":"SEPA","premium":1,"created_at":1627371434},"lnbcrt78510n1pj59wmepp50677g8tffdqa2p8882y0x6newny5vtz0hjuyngdwv226nanv4uzsdqqcqzzsxqyz5vqsp5skn973360gp4yhlpmefwvul5hs58lkkl3u3ujvt57elmp4zugp4q9qyyssqw4nzlr72w28k4waycf27qvgzc9sp79sqlw83j56txltz4va44j7jda23ydcujj9y5k6k0rn5ms84w8wmcmcyk5g3mhpqepf7envhdccp72nz6e",null]}}}"#;
let sample_message = r#"{"order":{"version":1,"request_id":1,"id":"308e1272-d5f4-47e6-bd97-3504baea9c23","pubkey":null,"action":"pay-invoice","content":{"payment_request":[{"id":"308e1272-d5f4-47e6-bd97-3504baea9c23","kind":"sell","status":"waiting-payment","amount":100,"fiat_code":"eur","fiat_amount":100,"payment_method":"SEPA","premium":1,"created_at":1627371434},"lnbcrt78510n1pj59wmepp50677g8tffdqa2p8882y0x6newny5vtz0hjuyngdwv226nanv4uzsdqqcqzzsxqyz5vqsp5skn973360gp4yhlpmefwvul5hs58lkkl3u3ujvt57elmp4zugp4q9qyyssqw4nzlr72w28k4waycf27qvgzc9sp79sqlw83j56txltz4va44j7jda23ydcujj9y5k6k0rn5ms84w8wmcmcyk5g3mhpqepf7envhdccp72nz6e",null]}}}"#;
let message = Message::from_json(sample_message).unwrap();
assert!(message.verify());
let message_json = message.as_json().unwrap();
Expand Down
32 changes: 25 additions & 7 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,32 @@ pub enum Message {

impl Message {
/// New order message
pub fn new_order(id: Option<Uuid>, action: Action, content: Option<Content>) -> Self {
let kind = MessageKind::new(id, action, content);
pub fn new_order(
request_id: u64,
id: Option<Uuid>,
action: Action,
content: Option<Content>,
) -> Self {
let kind = MessageKind::new(request_id, id, action, content);

Self::Order(kind)
}

/// New dispute message
pub fn new_dispute(id: Option<Uuid>, action: Action, content: Option<Content>) -> Self {
let kind = MessageKind::new(id, action, content);
pub fn new_dispute(
request_id: u64,
id: Option<Uuid>,
action: Action,
content: Option<Content>,
) -> Self {
let kind = MessageKind::new(request_id, id, action, content);

Self::Dispute(kind)
}

/// New can't do template message message
pub fn cant_do(id: Option<Uuid>, content: Option<Content>) -> Self {
let kind = MessageKind::new(id, Action::CantDo, content);
pub fn cant_do(request_id: u64, id: Option<Uuid>, content: Option<Content>) -> Self {
let kind = MessageKind::new(request_id, id, Action::CantDo, content);

Self::CantDo(kind)
}
Expand Down Expand Up @@ -161,6 +171,8 @@ impl Message {
pub struct MessageKind {
/// Message version
pub version: u8,
/// Request_id for test on client
pub request_id: u64,
/// Message id is not mandatory
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<Uuid>,
Expand Down Expand Up @@ -188,9 +200,15 @@ pub enum Content {
#[allow(dead_code)]
impl MessageKind {
/// New message
pub fn new(id: Option<Uuid>, action: Action, content: Option<Content>) -> Self {
pub fn new(
request_id: u64,
id: Option<Uuid>,
action: Action,
content: Option<Content>,
) -> Self {
Self {
version: PROTOCOL_VER,
request_id,
id,
action,
content,
Expand Down

0 comments on commit d87f4bf

Please sign in to comment.