[backport#17593][test] move string helper functions into test library
Summary:
https://github.com/bitcoin/bitcoin/pull/17593/commits/2cb4e8bdc7ef75ae8d95c246af1e8e1f9c7045bd
Partial backport of Core PR17593
Test Plan:
ninja check check-functional
Reviewers: #bitcoin_abc, jasonbcox
Reviewed By: #bitcoin_abc, jasonbcox
Differential Revision: https://reviews.bitcoinabc.org/D7283