Refactor test for existing peer connection into own function
Summary:
This is a backport of core#20187 [2/4]
https://github.com/bitcoin/bitcoin/pull/20187/commits/e8b215a086d91a8774210bb6ce8d1560aaaf0789
Depends on D10694
Test Plan: ninja all check-all
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D10695