Refactor common RPC test code to BitcoinTestFramework base class

Inspired by #3956, with a little more flexibility built in.

I didn't touch rpcbind_test.py, because it only runs on Linux.
Print better errors, and add util stop_node() function.
Only remove actualy failed blocks from setBlockIndexValid
Fix Error: No file at @loader_path/libboost_system-mt.dylib
Avoid a segfault on getblock if it can't read a block from disk.