@@ -32,6 +32,53 @@ func TestScriptPubkeyFromRaw(t *testing.T) {
3232 }
3333}
3434
35+ func TestScriptPubkeyEmpty (t * testing.T ) {
36+ tests := []struct {
37+ name string
38+ data []byte
39+ }{
40+ {name : "nil slice" , data : nil },
41+ {name : "empty slice" , data : []byte {}},
42+ }
43+
44+ for _ , tt := range tests {
45+ t .Run (tt .name , func (t * testing.T ) {
46+ scriptPubkey := NewScriptPubkey (tt .data )
47+ if scriptPubkey == nil {
48+ t .Fatal ("ScriptPubkey is nil" )
49+ }
50+ defer scriptPubkey .Destroy ()
51+
52+ bytes , err := scriptPubkey .Bytes ()
53+ if err != nil {
54+ t .Fatalf ("ScriptPubkey.Bytes() error = %v" , err )
55+ }
56+ if len (bytes ) != 0 {
57+ t .Fatalf ("Expected empty script serialization, got %x" , bytes )
58+ }
59+
60+ // Minimal coinbase-style transaction with a single empty scriptSig and
61+ // zero-value output; used to trigger verification paths.
62+ txHex := "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff0100000000000000000000000000"
63+ txBytes , err := hex .DecodeString (txHex )
64+ if err != nil {
65+ t .Fatalf ("Failed to decode transaction hex: %v" , err )
66+ }
67+ tx , err := NewTransaction (txBytes )
68+ if err != nil {
69+ t .Fatalf ("Failed to create transaction: %v" , err )
70+ }
71+ defer tx .Destroy ()
72+
73+ var scriptErr * ScriptVerifyError
74+ err = scriptPubkey .Verify (0 , tx , nil , 0 , ScriptFlagsVerifyNone )
75+ if err == nil || ! errors .As (err , & scriptErr ) {
76+ t .Fatalf ("Expected script verification error for empty script, got %v" , err )
77+ }
78+ })
79+ }
80+ }
81+
3582func TestScriptPubkeyCopy (t * testing.T ) {
3683 scriptHex := "76a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe26158088ac"
3784 scriptBytes , err := hex .DecodeString (scriptHex )
0 commit comments