From 3bb43e1b88edebea38e4b16dac25fda47a735046 Mon Sep 17 00:00:00 2001 From: Muhammad Waqas Raza Date: Fri, 10 Jun 2022 12:33:40 +0100 Subject: [PATCH] Fix for IsMultiSigOut index out of range error (#116) * Fix for IsMultiSigOut index out of range error * Updating test for linter --- bscript/script.go | 2 +- bscript/script_test.go | 23 ++++++++++++++++++----- fees_test.go | 11 ++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bscript/script.go b/bscript/script.go index 42bf7626..0ff6dadd 100644 --- a/bscript/script.go +++ b/bscript/script.go @@ -322,7 +322,7 @@ func (s *Script) IsMultiSigOut() bool { } } - return isSmallIntOp(parts[len(parts)-2][0]) && + return len(parts[len(parts)-2]) > 0 && isSmallIntOp(parts[len(parts)-2][0]) && len(parts[len(parts)-1]) > 0 && parts[len(parts)-1][0] == OpCHECKMULTISIG } diff --git a/bscript/script_test.go b/bscript/script_test.go index 349dfc76..b3eec7d8 100644 --- a/bscript/script_test.go +++ b/bscript/script_test.go @@ -181,12 +181,25 @@ func TestScript_IsData(t *testing.T) { func TestScript_IsMultisigOut(t *testing.T) { // TODO: check this t.Parallel() - b, err := hex.DecodeString("5201110122013353ae") - assert.NoError(t, err) + t.Run("is multisig", func(t *testing.T) { + b, err := hex.DecodeString("5201110122013353ae") + assert.NoError(t, err) - scriptPub := bscript.NewFromBytes(b) - assert.NotNil(t, scriptPub) - assert.Equal(t, true, scriptPub.IsMultiSigOut()) + scriptPub := bscript.NewFromBytes(b) + assert.NotNil(t, scriptPub) + assert.Equal(t, true, scriptPub.IsMultiSigOut()) + }) + + t.Run("is not multisig and no error", func(t *testing.T) { + //Test Txid:de22e20422dbba8e8eeab87d5532480499abb01d6619bb66fe374f4d4a7500ee, vout:1 + + b, err := hex.DecodeString("5101400176018801a901ac615e7961007901687f7700005279517f75007f77007901fd8763615379537f75517f77007901007e81517a7561537a75527a527a5379535479937f75537f77527a75517a67007901fe8763615379557f75517f77007901007e81517a7561537a75527a527a5379555479937f75557f77527a75517a67007901ff8763615379597f75517f77007901007e81517a7561537a75527a527a5379595479937f75597f77527a75517a67615379517f75007f77007901007e81517a7561537a75527a527a5379515479937f75517f77527a75517a6868685179517a75517a75517a75517a7561517a7561007982770079011494527951797f77537952797f750001127900a063610113795a7959797e01147e51797e5a797e58797e517a7561610079011479007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a527975757568607900a06351790112797e610079011279007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575685e7900a063615f795a7959797e01147e51797e5a797e58797e517a75616100796079007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575685c7900a063615d795a7959797e01147e51797e5a797e58797e517a75616100795e79007958806152790079827700517902fd009f63615179515179517951938000795179827751947f75007f77517a75517a75517a7561517a75675179030000019f6301fd615279525179517951938000795179827751947f75007f77517a75517a75517a75617e517a756751790500000000019f6301fe615279545179517951938000795179827751947f75007f77517a75517a75517a75617e517a75675179090000000000000000019f6301ff615279585179517951938000795179827751947f75007f77517a75517a75517a75617e517a7568686868007953797e517a75517a75517a75617e517a75517a7561527951797e537a75527a527a5279757575680079aa007961011679007982775179517958947f7551790128947f77517a75517a75618769011679a954798769011779011779ac69610115796100792097dfd76851bf465e8f715593b217714858bbe9570ff3bd5e33840a34e20ff0262102ba79df5f8ae7604a9830f03c7933028186aede0675a16f025dc4f8be8eec0382210ac407f0e4bd44bfc207355a778b046225a7068fc59ee7eda43ad905aadbffc800206c266b30e6a1319c66dc401e5bd6b432ba49688eecd118297041da8074ce0810201008ce7480da41702918d1ec8e6849ba32b4d65b1e40dc669c31a1e6306b266c011379011379855679aa616100790079517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e01007e81517a756157795679567956795679537956795479577995939521414136d08c5ed2bf3ba048afe6dcaebafeffffffffffffffffffffffffffffff0061517951795179517997527a75517a5179009f635179517993527a75517a685179517a75517a7561527a75517a517951795296a0630079527994527a75517a68537982775279827754527993517993013051797e527e53797e57797e527e52797e5579517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f517f7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7c7e7e56797e0079517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a75517a756100795779ac517a75517a75517a75517a75517a75517a75517a75517a75517a7561517a75617777777777777777777777777777777777777777777777776ae0cfa0c0930b63270459fe368d5ed31da74c00de") + assert.NoError(t, err) + + scriptPub := bscript.NewFromBytes(b) + assert.NotNil(t, scriptPub) + assert.Equal(t, false, scriptPub.IsMultiSigOut()) + }) } func TestScript_PublicKeyHash(t *testing.T) { diff --git a/fees_test.go b/fees_test.go index d49fdbd3..2ff2baaa 100644 --- a/fees_test.go +++ b/fees_test.go @@ -617,10 +617,15 @@ func TestFeeQuote_MarshalUnmarshalJSON(t *testing.T) { } for name, test := range tests { t.Run(name, func(t *testing.T) { - // nolint:errchkjson // it's a test, who cares - bb, _ := json.Marshal(test.quote) + bb, err := json.Marshal(test.quote) + if err != nil { + assert.Error(t, err) + assert.EqualError(t, err, test.err.Error()) + return + } + var quote *FeeQuote - err := json.Unmarshal(bb, "e) + err = json.Unmarshal(bb, "e) if test.err != nil { assert.Error(t, err) assert.EqualError(t, err, test.err.Error())