In https://github.com/bitcoin/bitcoin/pull/34927/changes/fa04bad48b2e825b28a0a9f0300ff235409cc684#r3727565203 test: Check that RPCs do not time out, even under load
My understanding is that random data is not necessarily the same as invalid transaction data. Most random payloads will not decode, but occasionally the bytes can have the structure of a transaction such as a version, input count, inputs, outputs, and locktime. In that case, decoding succeeds, and it moves on to validation
I checked this by temporarily submitting the following syntactically valid serialized transaction
valid_tx = "020000000101010101010101010101010101010101010101010101010101010101010101010000000000ffffffff010000000000000000016a00000000"
assert_raises_rpc_error( -26, "tx-size-small", node.sendrawtransaction, valid_tx,)
This returned tx-size-small rather than tx decode failed', indicating that the payload was successfully decoded and reached transaction validation. If the randomized test selects such a payload, its existing error message check will fail even though the RPC behaved correctly.
I am not sure how likely this is in practice, and it may be very unlikely. However, the test makes hundreds of random selections per run and may be executed many times across CI. Since the test depends on the payload being undecodable, it seems better to guarantee that condition rather than rely on random data being invalid.
Could we guarantee that the payload is undecodable by appending a non-hex character?
rpc.sendrawtransaction(payload + "x")
Since x is not hexadecimal, the payload cannot be decoded as a serialized transaction and must take the expected decode-error path.