Skip to content

Commit

Permalink
feat: message timestamp in subscription payload
Browse files Browse the repository at this point in the history
  • Loading branch information
heilhead committed Feb 13, 2023
1 parent 64ba9c3 commit 0ed6b74
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Description

<!--
Please include:
* summary of the changes and the related issue
* relevant motivation and context
-->

Resolves # (issue)

## How Has This Been Tested?

<!--
Please:
* describe the tests that you ran to verify your changes.
* provide instructions so we can reproduce.
-->

<!-- If valid for smoke test on feature add screenshots -->

## Due Diligence

* [ ] Breaking change
* [ ] Requires a documentation update
* [ ] Requires a e2e/integration test update
6 changes: 6 additions & 0 deletions relay_rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ impl Publish {
&self,
message_id: MessageId,
subscription_id: SubscriptionId,
published_at: i64,
) -> Request {
Request {
id: message_id,
Expand All @@ -452,6 +453,7 @@ impl Publish {
data: SubscriptionData {
topic: self.topic.clone(),
message: self.message.clone(),
published_at,
},
}),
}
Expand Down Expand Up @@ -542,12 +544,16 @@ impl RequestPayload for Subscription {

/// Data structure representing subscription message params.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionData {
/// The topic of the subscription.
pub topic: Topic,

/// The message for the subscription.
pub message: Arc<str>,

/// Message publish timestamp in UTC milliseconds.
pub published_at: i64,
}

/// Enum representing parameters of all possible RPC requests.
Expand Down
9 changes: 7 additions & 2 deletions relay_rpc/src/rpc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fn subscription() {
let data = SubscriptionData {
topic: "test_topic".into(),
message: "test_message".into(),
published_at: 123,
};
let params = Subscription {
id: "test_id".into(),
Expand All @@ -102,7 +103,7 @@ fn subscription() {

assert_eq!(
&serialized,
r#"{"id":1,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message"}}}"#
r#"{"id":1,"jsonrpc":"2.0","method":"irn_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123}}}"#
);

let deserialized: Payload = serde_json::from_str(&serialized).unwrap();
Expand All @@ -112,7 +113,7 @@ fn subscription() {

#[test]
fn deserialize_iridium_method() {
let serialized = r#"{"id":1,"jsonrpc":"2.0","method":"iridium_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message"}}}"#;
let serialized = r#"{"id":1,"jsonrpc":"2.0","method":"iridium_subscription","params":{"id":"test_id","data":{"topic":"test_topic","message":"test_message","publishedAt":123}}}"#;
assert!(serde_json::from_str::<'_, Payload>(serialized).is_ok());
}

Expand Down Expand Up @@ -315,6 +316,7 @@ fn validation() {
data: SubscriptionData {
topic: topic.clone(),
message: message.clone(),
published_at: 123,
},
}),
};
Expand All @@ -329,6 +331,7 @@ fn validation() {
data: SubscriptionData {
topic: topic.clone(),
message: message.clone(),
published_at: 123,
},
}),
};
Expand All @@ -348,6 +351,7 @@ fn validation() {
data: SubscriptionData {
topic: Topic::from("invalid"),
message,
published_at: 123,
},
}),
};
Expand All @@ -365,6 +369,7 @@ fn validation() {
data: SubscriptionData {
topic: topic.clone(),
message: "0".repeat(MAX_MESSAGE_LENGTH + 1).into(),
published_at: 123,
},
}),
};
Expand Down

0 comments on commit 0ed6b74

Please sign in to comment.