In the course of reviewing #29589 I noticed the following buggy call-site of CScriptOp.decode_op_n in the CScript's GetSigOpCount method:
https://github.com/bitcoin/bitcoin/blob/4cc99df44aec4d104590aee46cf18318e22a8568/test/functional/test_framework/script.py#L591-L593
This should be lastOpcode rather than opcode. The latter is either OP_CHECKMULTISIG or OP_CHECKMULTISIGVERIFY at this point, so decode_op_n would result in an error. Also, in CScript.raw_iter, we have to return the op as CScriptOp type instead of a bare integer, otherwise we can't call the decode method on it. To prevent this in the future, add some simple unit tests for GetSigOpCount.
Note that this was unnoticed, as the code part was never hit so far in the test framework.