[backport#17593][test] move mining helper functions into test library
Summary:
https://github.com/bitcoin/bitcoin/pull/17593/commits/f613e5dfdafe708f63ebb5193c44e2bc770c6651
Depends on D7283
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/D7284