Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sequencer): simplify boolean expressions in transaction container #1595

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions crates/astria-sequencer/src/mempool/transactions_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,6 @@ mod tests {

// From https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html
#[test]
// TODO (https://github.com/astriaorg/astria/issues/1583): rework assertions and remove attribute
#[expect(
clippy::nonminimal_bool,
reason = "we want explicit assertions here to match the documented expected behavior"
)]
fn transaction_priority_comparisons_should_be_consistent_nonce_diff() {
let instant = Instant::now();

Expand All @@ -850,41 +845,37 @@ mod tests {

// 1. a == b if and only if partial_cmp(a, b) == Some(Equal)
assert!(high == high); // Some(Equal)
assert!(!(high == low)); // Some(Greater)
assert!(!(low == high)); // Some(Less)
assert!(high != low); // Some(Greater)
assert!(low != high); // Some(Less)

// 2. a < b if and only if partial_cmp(a, b) == Some(Less)
assert!(low < high); // Some(Less)
assert!(!(high < high)); // Some(Equal)
assert!(!(high < low)); // Some(Greater)
assert!(high >= high); // Some(Equal)
assert!(high >= low); // Some(Greater)

// 3. a > b if and only if partial_cmp(a, b) == Some(Greater)
assert!(high > low); // Some(Greater)
assert!(!(high > high)); // Some(Equal)
assert!(!(low > high)); // Some(Less)
assert!(high <= high); // Some(Equal)
assert!(low <= high); // Some(Less)

// 4. a <= b if and only if a < b || a == b
assert!(low <= high); // a < b
assert!(high <= high); // a == b
assert!(!(high <= low)); // a > b
assert!(high > low); // !(b <= a)

// 5. a >= b if and only if a > b || a == b
assert!(high >= low); // a > b
assert!(high >= high); // a == b
assert!(!(low >= high)); // a < b
assert!(low < high); // !(b >= a)

// 6. a != b if and only if !(a == b)
assert!(high != low); // asserted !(high == low) above
assert!(low != high); // asserted !(low == high) above
assert!(!(high != high)); // asserted high == high above
assert!(high == high); // asserted high == high above
}

// From https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html
#[test]
#[expect(
clippy::nonminimal_bool,
reason = "we want explicit assertions here to match the documented expected behavior"
)]
fn transaction_priority_comparisons_should_be_consistent_time_gap() {
let high = TransactionPriority {
nonce_diff: 0,
Expand All @@ -901,33 +892,33 @@ mod tests {

// 1. a == b if and only if partial_cmp(a, b) == Some(Equal)
assert!(high == high); // Some(Equal)
assert!(!(high == low)); // Some(Greater)
assert!(!(low == high)); // Some(Less)
assert!(high != low); // Some(Greater)
assert!(low != high); // Some(Less)

// 2. a < b if and only if partial_cmp(a, b) == Some(Less)
assert!(low < high); // Some(Less)
assert!(!(high < high)); // Some(Equal)
assert!(!(high < low)); // Some(Greater)
assert!(high >= high); // Some(Equal)
assert!(high >= low); // Some(Greater)

// 3. a > b if and only if partial_cmp(a, b) == Some(Greater)
assert!(high > low); // Some(Greater)
assert!(!(high > high)); // Some(Equal)
assert!(!(low > high)); // Some(Less)
assert!(high <= high); // Some(Equal)
assert!(low <= high); // Some(Less)

// 4. a <= b if and only if a < b || a == b
assert!(low <= high); // a < b
assert!(high <= high); // a == b
assert!(!(high <= low)); // a > b
assert!(high > low); // !(b <= a)

// 5. a >= b if and only if a > b || a == b
assert!(high >= low); // a > b
assert!(high >= high); // a == b
assert!(!(low >= high)); // a < b
assert!(low < high); // !(low >= high)

// 6. a != b if and only if !(a == b)
assert!(high != low); // asserted !(high == low) above
assert!(low != high); // asserted !(low == high) above
assert!(!(high != high)); // asserted high == high above
assert!(high == high); // asserted !(high != high) above
}

#[test]
Expand Down
Loading