refactor: Reducing code redundancy - #3778
Conversation
|
PR title type suggestion: This PR changes only test files, so the type prefix should probably be Suggested title: |
Pull request overviewConsolidates four repeated domain-lookup blocks in Changes:
Reviewed changesPer-file summary
FindingsBlocking: none. Non-blocking (nits, follow-ups, suggestions):
✅ Approved |
|
PR title type suggestion: This PR changes only test files, so the type prefix should probably be Suggested title: |
| .find(|d| d.protocol == protocol_type) | ||
| .unwrap_or_else(|| panic!("no domain with protocol {protocol_type:?}")) |
There was a problem hiding this comment.
nit (non-blocking): .find() returns the first match and this only panics on zero matches — not on multiple. The doc says "each protocol appears at most once in this test's set," but nothing enforces it, and production actually has two CaitSith domains (Sign + ForeignTx). If default_for_test ever grows a second same-protocol domain, this would silently pick whichever comes first (the old purpose == Sign filter guarded against that). Cheap to make it fail loudly instead:
let mut matches = contract_state.domains.domains.iter().filter(|d| d.protocol == protocol_type);
let domain = matches.next().unwrap_or_else(|| panic!("no domain with protocol {protocol_type:?}"));
assert!(matches.next().is_none(), "multiple domains with protocol {protocol_type:?}");
domain.id
barakeinav1
left a comment
There was a problem hiding this comment.
Thanks, approved — pure test refactor, no logic change. One non-blocking nit on the helper's uniqueness assumption.
Tiny cleanup. Creating a helper function and reducing code redundancy.