Automatic script test generation and checksig tests

This is a replacement/extension of #4949, which also adds code for automatically generating the json tests.

The test generation is always executed (to prevent bitrot), and verified as if it was read from the json file itself (to make sure it remains consistent with the code), but not written out by default.