rpc: test decoderawtransaction trailing byte rejection
What changed, and why it matters
This commit adds a new test to make sure the 'decoderawtransaction' RPC command rejects transaction data that has extra bytes tacked on after a valid transaction. It does not change the actual command behavior; it only adds a test confirming the existing behavior works correctly.
No immediate action required. The commit is a test-only addition that validates existing strict parsing behavior. Reviewers may want to confirm that handleDecodeRawTransaction already rejects trailing bytes in production and that similar strictness exists for other deserialization RPCs.
Security signals we found
Strict deserialization / trailing-byte rejection
RPC input validation regression test
Evidence from the diff
The patch adds TestHandleDecodeRawTransactionRejectsTrailingBytes in rpcserver_test.go. It constructs a DecodeRawTransactionCmd with txHex1 plus an extra trailing ‘00’ byte, calls handleDecodeRawTransaction, and asserts that the function returns a deserialization error (btcjson.ErrRPCDeserialization) and no result. This is a defensive regression test for input strictness.
Changed components
rpcserver_test.gohandleDecodeRawTransaction RPC handler (tested, not modified)Inspect captured patch +15 / −0
diff --git a/rpcserver_test.go b/rpcserver_test.go
index 12c2d66..a54a425 100644
--- a/rpcserver_test.go
+++ b/rpcserver_test.go
@@ -99,6 +99,21 @@ func TestHandleSendRawTransactionRejectsTrailingBytes(t *testing.T) {
require.Nil(t, result)
}
+// TestHandleDecodeRawTransactionRejectsTrailingBytes ensures
+// decoderawtransaction rejects byte strings that contain a valid transaction
+// plus trailing data.
+func TestHandleDecodeRawTransactionRejectsTrailingBytes(t *testing.T) {
+ t.Parallel()
+
+ cmd := btcjson.NewDecodeRawTransactionCmd(txHex1 + "00")
+ result, err := handleDecodeRawTransaction(
+ &rpcServer{}, cmd, make(chan struct{}),
+ )
+
+ requireRPCErrorCode(t, err, btcjson.ErrRPCDeserialization)
+ require.Nil(t, result)
+}
+
var (
// TODO(yy): make a `btctest` package and move these testing txns there
// so they be used in other tests.
Why this scored 30/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.