Skip to content

Commit 903cc60

Browse files
committed
Expand TestCustomMessage enum to support arbitrary number of message exchanges.
- The current test suite architecture is limited as it allows only one request followed by one response and doesn't support arbitrary number of back-and-forth messages. - Expand the TestCustomMessage enum to introduce this functionality within the test suite. - These two variants will serve as responses to each other, allowing unlimited back-and-forth communication to test the response mechanism.
1 parent e730884 commit 903cc60

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,28 @@ impl OffersMessageHandler for TestOffersMessageHandler {
8282
enum TestCustomMessage {
8383
Request,
8484
Response,
85+
/// Variants to allow reponse ping-pong.
86+
ResponseA,
87+
ResponseB,
8588
}
8689

8790
const CUSTOM_REQUEST_MESSAGE_TYPE: u64 = 4242;
8891
const CUSTOM_RESPONSE_MESSAGE_TYPE: u64 = 4343;
92+
const CUSTOM_RESPONSE_A_MESSAGE_TYPE: u64 = 4344;
93+
const CUSTOM_RESPONSE_B_MESSAGE_TYPE: u64 = 4345;
94+
8995
const CUSTOM_REQUEST_MESSAGE_CONTENTS: [u8; 32] = [42; 32];
9096
const CUSTOM_RESPONSE_MESSAGE_CONTENTS: [u8; 32] = [43; 32];
97+
const CUSTOM_RESPONSE_A_MESSAGE_CONTENTS: [u8; 32] = [44; 32];
98+
const CUSTOM_RESPONSE_B_MESSAGE_CONTENTS: [u8; 32] = [45; 32];
9199

92100
impl OnionMessageContents for TestCustomMessage {
93101
fn tlv_type(&self) -> u64 {
94102
match self {
95103
TestCustomMessage::Request => CUSTOM_REQUEST_MESSAGE_TYPE,
96104
TestCustomMessage::Response => CUSTOM_RESPONSE_MESSAGE_TYPE,
105+
TestCustomMessage::ResponseA => CUSTOM_RESPONSE_A_MESSAGE_TYPE,
106+
TestCustomMessage::ResponseB => CUSTOM_RESPONSE_B_MESSAGE_TYPE,
97107
}
98108
}
99109
fn msg_type(&self) -> &'static str {
@@ -106,6 +116,8 @@ impl Writeable for TestCustomMessage {
106116
match self {
107117
TestCustomMessage::Request => Ok(CUSTOM_REQUEST_MESSAGE_CONTENTS.write(w)?),
108118
TestCustomMessage::Response => Ok(CUSTOM_RESPONSE_MESSAGE_CONTENTS.write(w)?),
119+
TestCustomMessage::ResponseA => Ok(CUSTOM_RESPONSE_A_MESSAGE_CONTENTS.write(w)?),
120+
TestCustomMessage::ResponseB => Ok(CUSTOM_RESPONSE_B_MESSAGE_CONTENTS.write(w)?),
109121
}
110122
}
111123
}
@@ -145,6 +157,8 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
145157
let response_option = match msg {
146158
TestCustomMessage::Request => Some(TestCustomMessage::Response),
147159
TestCustomMessage::Response => None,
160+
TestCustomMessage::ResponseA => Some(TestCustomMessage::ResponseB),
161+
TestCustomMessage::ResponseB => Some(TestCustomMessage::ResponseA),
148162
};
149163
if let (Some(response), Some(responder)) = (response_option, responder) {
150164
responder.respond(response)
@@ -164,6 +178,16 @@ impl CustomOnionMessageHandler for TestCustomMessageHandler {
164178
assert_eq!(buf, CUSTOM_RESPONSE_MESSAGE_CONTENTS);
165179
Ok(Some(TestCustomMessage::Response))
166180
},
181+
CUSTOM_RESPONSE_A_MESSAGE_TYPE => {
182+
let buf = read_to_end(buffer)?;
183+
assert_eq!(buf, CUSTOM_RESPONSE_A_MESSAGE_CONTENTS);
184+
Ok(Some(TestCustomMessage::ResponseA))
185+
},
186+
CUSTOM_RESPONSE_B_MESSAGE_TYPE => {
187+
let buf = read_to_end(buffer)?;
188+
assert_eq!(buf, CUSTOM_RESPONSE_B_MESSAGE_CONTENTS);
189+
Ok(Some(TestCustomMessage::ResponseB))
190+
}
167191
_ => Ok(None),
168192
}
169193
}

0 commit comments

Comments
 (0)