Skip to content

Commit

Permalink
test(iroh-net): fix relay's codec proptesting (#2283)
Browse files Browse the repository at this point in the history
## Description

Closes #2278 
proptest take overall less than 2 seconds, which I think is fast enough
compared to the time of compiling in release and running all the tests.

Regression prop test was not being used (it was in a derp path) and it's
obsolete since the client info message changed at some point

## Breaking Changes
n/a

## Notes & open questions

n/a

## Change checklist

- [x] Self-review.
- [ ] ~Documentation updates if relevant.~
- [x] Tests if relevant.
- [ ] ~All breaking changes documented.~
  • Loading branch information
divagant-martian committed May 13, 2024
1 parent 6ed6b34 commit 5343cea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
8 changes: 0 additions & 8 deletions iroh-net/proptest-regressions/derp/codec.txt

This file was deleted.

22 changes: 10 additions & 12 deletions iroh-net/src/relay/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ pub(crate) enum FrameType {
///
/// Handled on the `[relay::Client]`, but currently never sent on the `[relay::Server]`
Restarting = 15,
/// 32B src pub key + 32B dst pub key + packet bytes
ForwardPacket = 16,
#[num_enum(default)]
Unknown = 255,
}
Expand Down Expand Up @@ -565,9 +563,7 @@ mod tests {
}
}

/// these test are slow in debug mode, so only run them in release mode
#[cfg(test)]
#[cfg(not(debug_assertions))]
mod proptests {
use super::*;
use proptest::prelude::*;
Expand All @@ -588,11 +584,16 @@ mod proptests {

/// Generates a random valid frame
fn frame() -> impl Strategy<Value = Frame> {
let server_key = key().prop_map(|key| Frame::ServerKey { key });
let client_info = (key(), data(32)).prop_map(|(client_public_key, encrypted_message)| {
let client_info = (secret_key()).prop_map(|secret_key| {
let info = ClientInfo {
version: PROTOCOL_VERSION,
};
let msg = postcard::to_stdvec(&info).expect("using default ClientInfo");
let signature = secret_key.sign(&msg);
Frame::ClientInfo {
client_public_key,
encrypted_message,
client_public_key: secret_key.public(),
message: msg.into(),
signature,
}
});
let send_packet =
Expand All @@ -611,9 +612,7 @@ mod proptests {
try_for,
});
prop_oneof![
server_key,
client_info,
server_info,
send_packet,
recv_packet,
keep_alive,
Expand All @@ -629,8 +628,7 @@ mod proptests {
fn inject_error(buf: &mut BytesMut) {
fn is_fixed_size(tpe: FrameType) -> bool {
match tpe {
FrameType::ServerKey
| FrameType::KeepAlive
FrameType::KeepAlive
| FrameType::NotePreferred
| FrameType::Ping
| FrameType::Pong
Expand Down

0 comments on commit 5343cea

Please sign in to comment.