segwit.py is supposed to test that “non-segwit miners get a valid GBT response after the fork”:
0 print("Verify non-segwit miners get a valid GBT response after the fork")
1 send_to_witness(1, self.nodes[0], find_unspent(self.nodes[0], 50), self.pubkey[0], False, Decimal("49.998"))
2 try:
3 tmpl = self.nodes[0].getblocktemplate({})
4 assert(len(tmpl['transactions']) == 1) # Doesn't include witness tx
5 assert(tmpl['sigoplimit'] == 20000)
6 assert(tmpl['transactions'][0]['hash'] == txid)
7 assert(tmpl['transactions'][0]['sigops'] == 2)
8 assert(('!segwit' in tmpl['rules']) or ('segwit' not in tmpl['rules']))
9 except JSONRPCException:
10 # This is an acceptable outcome
11 pass
in fact what happens is that bitcoind returns a “Support for ‘segwit’ rule requires explicit client support” error to the getblocktemplate RPC. We always catch that error in the except: block and continue the test. None of the asserts in the try: branch are ever tested.
I don’t know what the intent here is. I would expect non-segwit miners to continue to be able to use getblocktemplate after segwit activation. If that’s true, then there’s a bug in getblocktemplate(). If miners aren’t supposed to be able use getblocktemplate() after segwit activation without setting the rules:[‘segwit’] option, then we should explicitly test that as follows:
0 assert_raises_jsonrpc(-8, "Support for 'segwit' rule requires explicit client support", self.nodes[0].getblocktemplate, {})
and remove all the test code that isn’t being used.