From 59a3fc2f661a332d386e68f5f8ef3bf1d6d5a02a Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 20 Oct 2016 01:18:31 -0500 Subject: [PATCH] txscript: Consolidate tests into txscript package. Putting the test code in the same package makes it easier for forks since they don't have to change the import paths as much and it also gets rid of the need for internal_test.go to bridge. Also, do some light cleanup on a few tests while here. --- txscript/engine_test.go | 167 +- txscript/internal_test.go | 3753 ------------------------------- txscript/log_test.go | 8 +- txscript/reference_test.go | 14 +- txscript/script_test.go | 3834 +++++++++++++++++++++++++++++++- txscript/scriptbuilder_test.go | 188 +- txscript/sign_test.go | 263 ++- txscript/standard_test.go | 460 ++-- 8 files changed, 4284 insertions(+), 4403 deletions(-) delete mode 100644 txscript/internal_test.go diff --git a/txscript/engine_test.go b/txscript/engine_test.go index f2782fd3..78b47324 100644 --- a/txscript/engine_test.go +++ b/txscript/engine_test.go @@ -2,13 +2,12 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package txscript_test +package txscript import ( "testing" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" ) @@ -17,19 +16,13 @@ import ( func TestBadPC(t *testing.T) { t.Parallel() - type pcTest struct { + tests := []struct { script, off int + }{ + {script: 2, off: 0}, + {script: 0, off: 2}, } - pcTests := []pcTest{ - { - script: 2, - off: 0, - }, - { - script: 0, - off: 2, - }, - } + // tx with almost empty scripts. tx := &wire.MsgTx{ Version: 1, @@ -48,28 +41,27 @@ func TestBadPC(t *testing.T) { }), Index: 0, }, - SignatureScript: []uint8{txscript.OP_NOP}, + SignatureScript: mustParseShortForm("NOP"), Sequence: 4294967295, }, }, - TxOut: []*wire.TxOut{ - { - Value: 1000000000, - PkScript: nil, - }, - }, + TxOut: []*wire.TxOut{{ + Value: 1000000000, + PkScript: nil, + }}, LockTime: 0, } - pkScript := []byte{txscript.OP_NOP} + pkScript := mustParseShortForm("NOP") - for _, test := range pcTests { - vm, err := txscript.NewEngine(pkScript, tx, 0, 0, nil) + for _, test := range tests { + vm, err := NewEngine(pkScript, tx, 0, 0, nil) if err != nil { t.Errorf("Failed to create script: %v", err) } // set to after all scripts - vm.TstSetPC(test.script, test.off) + vm.scriptIdx = test.script + vm.scriptOff = test.off _, err = vm.Step() if err == nil { @@ -93,48 +85,33 @@ func TestCheckErrorCondition(t *testing.T) { // tx with almost empty scripts. tx := &wire.MsgTx{ Version: 1, - TxIn: []*wire.TxIn{ - { - PreviousOutPoint: wire.OutPoint{ - Hash: chainhash.Hash([32]byte{ - 0xc9, 0x97, 0xa5, 0xe5, - 0x6e, 0x10, 0x41, 0x02, - 0xfa, 0x20, 0x9c, 0x6a, - 0x85, 0x2d, 0xd9, 0x06, - 0x60, 0xa2, 0x0b, 0x2d, - 0x9c, 0x35, 0x24, 0x23, - 0xed, 0xce, 0x25, 0x85, - 0x7f, 0xcd, 0x37, 0x04, - }), - Index: 0, - }, - SignatureScript: []uint8{}, - Sequence: 4294967295, + TxIn: []*wire.TxIn{{ + PreviousOutPoint: wire.OutPoint{ + Hash: chainhash.Hash([32]byte{ + 0xc9, 0x97, 0xa5, 0xe5, + 0x6e, 0x10, 0x41, 0x02, + 0xfa, 0x20, 0x9c, 0x6a, + 0x85, 0x2d, 0xd9, 0x06, + 0x60, 0xa2, 0x0b, 0x2d, + 0x9c, 0x35, 0x24, 0x23, + 0xed, 0xce, 0x25, 0x85, + 0x7f, 0xcd, 0x37, 0x04, + }), + Index: 0, }, - }, - TxOut: []*wire.TxOut{ - { - Value: 1000000000, - PkScript: nil, - }, - }, + SignatureScript: nil, + Sequence: 4294967295, + }}, + TxOut: []*wire.TxOut{{ + Value: 1000000000, + PkScript: nil, + }}, LockTime: 0, } - pkScript := []byte{ - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_NOP, - txscript.OP_TRUE, - } + pkScript := mustParseShortForm("NOP NOP NOP NOP NOP NOP NOP NOP NOP" + + " NOP TRUE") - vm, err := txscript.NewEngine(pkScript, tx, 0, 0, nil) + vm, err := NewEngine(pkScript, tx, 0, 0, nil) if err != nil { t.Errorf("failed to create script: %v", err) } @@ -151,7 +128,7 @@ func TestCheckErrorCondition(t *testing.T) { } err = vm.CheckErrorCondition(false) - if err != txscript.ErrStackScriptUnfinished { + if err != ErrStackScriptUnfinished { t.Errorf("got unexepected error %v on %dth iteration", err, i) return @@ -178,8 +155,8 @@ func TestCheckErrorCondition(t *testing.T) { func TestInvalidFlagCombinations(t *testing.T) { t.Parallel() - tests := []txscript.ScriptFlags{ - txscript.ScriptVerifyCleanStack, + tests := []ScriptFlags{ + ScriptVerifyCleanStack, } // tx with almost empty scripts. @@ -200,7 +177,7 @@ func TestInvalidFlagCombinations(t *testing.T) { }), Index: 0, }, - SignatureScript: []uint8{txscript.OP_NOP}, + SignatureScript: []uint8{OP_NOP}, Sequence: 4294967295, }, }, @@ -212,11 +189,11 @@ func TestInvalidFlagCombinations(t *testing.T) { }, LockTime: 0, } - pkScript := []byte{txscript.OP_NOP} + pkScript := []byte{OP_NOP} for i, test := range tests { - _, err := txscript.NewEngine(pkScript, tx, 0, test, nil) - if err != txscript.ErrInvalidFlags { + _, err := NewEngine(pkScript, tx, 0, test, nil) + if err != ErrInvalidFlags { t.Fatalf("TestInvalidFlagCombinations #%d unexpected "+ "error: %v", i, err) } @@ -235,7 +212,7 @@ func TestCheckPubKeyEncoding(t *testing.T) { }{ { name: "uncompressed ok", - key: decodeHex("0411db93e1dcdb8a016b49840f8c53bc1eb68" + + key: hexToBytes("0411db93e1dcdb8a016b49840f8c53bc1eb68" + "a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf" + "9744464f82e160bfa9b8b64f9d4c03f999b8643f656b" + "412a3"), @@ -243,19 +220,19 @@ func TestCheckPubKeyEncoding(t *testing.T) { }, { name: "compressed ok", - key: decodeHex("02ce0b14fb842b1ba549fdd675c98075f12e9" + + key: hexToBytes("02ce0b14fb842b1ba549fdd675c98075f12e9" + "c510f8ef52bd021a9a1f4809d3b4d"), isValid: true, }, { name: "compressed ok", - key: decodeHex("032689c7c2dab13309fb143e0e8fe39634252" + + key: hexToBytes("032689c7c2dab13309fb143e0e8fe39634252" + "1887e976690b6b47f5b2a4b7d448e"), isValid: true, }, { name: "hybrid", - key: decodeHex("0679be667ef9dcbbac55a06295ce870b07029" + + key: hexToBytes("0679be667ef9dcbbac55a06295ce870b07029" + "bfcdb2dce28d959f2815b16f81798483ada7726a3c46" + "55da4fbfc0e1108a8fd17b448a68554199c47d08ffb1" + "0d4b8"), @@ -268,9 +245,9 @@ func TestCheckPubKeyEncoding(t *testing.T) { }, } - flags := txscript.ScriptVerifyStrictEncoding + vm := Engine{flags: ScriptVerifyStrictEncoding} for _, test := range tests { - err := txscript.TstCheckPubKeyEncoding(test.key, flags) + err := vm.checkPubKeyEncoding(test.key) if err != nil && test.isValid { t.Errorf("checkSignatureEncoding test '%s' failed "+ "when it should have succeeded: %v", test.name, @@ -295,7 +272,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }{ { name: "valid signature", - sig: decodeHex("304402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -308,7 +285,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "bad magic", - sig: decodeHex("314402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("314402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -316,7 +293,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "bad 1st int marker magic", - sig: decodeHex("304403204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304403204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -324,7 +301,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "bad 2nd int marker", - sig: decodeHex("304402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41032018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -332,7 +309,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "short len", - sig: decodeHex("304302204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304302204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -340,7 +317,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "long len", - sig: decodeHex("304502204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304502204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -348,7 +325,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "long X", - sig: decodeHex("304402424e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304402424e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -356,7 +333,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "long Y", - sig: decodeHex("304402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022118152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -364,7 +341,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "short Y", - sig: decodeHex("304402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41021918152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -372,7 +349,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "trailing crap", - sig: decodeHex("304402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d0901"), @@ -380,7 +357,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "X == N ", - sig: decodeHex("30440220fffffffffffffffffffffffffffff" + + sig: hexToBytes("30440220fffffffffffffffffffffffffffff" + "ffebaaedce6af48a03bbfd25e8cd0364141022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -388,7 +365,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "X == N ", - sig: decodeHex("30440220fffffffffffffffffffffffffffff" + + sig: hexToBytes("30440220fffffffffffffffffffffffffffff" + "ffebaaedce6af48a03bbfd25e8cd0364142022018152" + "2ec8eca07de4860a4acdd12909d831cc56cbbac46220" + "82221a8768d1d09"), @@ -396,7 +373,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "Y == N", - sig: decodeHex("304402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd410220fffff" + "ffffffffffffffffffffffffffebaaedce6af48a03bb" + "fd25e8cd0364141"), @@ -404,7 +381,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "Y > N", - sig: decodeHex("304402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd410220fffff" + "ffffffffffffffffffffffffffebaaedce6af48a03bb" + "fd25e8cd0364142"), @@ -412,19 +389,19 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "0 len X", - sig: decodeHex("302402000220181522ec8eca07de4860a4acd" + + sig: hexToBytes("302402000220181522ec8eca07de4860a4acd" + "d12909d831cc56cbbac4622082221a8768d1d09"), isValid: false, }, { name: "0 len Y", - sig: decodeHex("302402204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("302402204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd410200"), isValid: false, }, { name: "extra R padding", - sig: decodeHex("30450221004e45e16932b8af514961a1d3a1a" + + sig: hexToBytes("30450221004e45e16932b8af514961a1d3a1a" + "25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181" + "522ec8eca07de4860a4acdd12909d831cc56cbbac462" + "2082221a8768d1d09"), @@ -432,7 +409,7 @@ func TestCheckSignatureEncoding(t *testing.T) { }, { name: "extra S padding", - sig: decodeHex("304502204e45e16932b8af514961a1d3a1a25" + + sig: hexToBytes("304502204e45e16932b8af514961a1d3a1a25" + "fdf3f4f7732e9d624c6c61548ab5fb8cd41022100181" + "522ec8eca07de4860a4acdd12909d831cc56cbbac462" + "2082221a8768d1d09"), @@ -440,9 +417,9 @@ func TestCheckSignatureEncoding(t *testing.T) { }, } - flags := txscript.ScriptVerifyStrictEncoding + vm := Engine{flags: ScriptVerifyStrictEncoding} for _, test := range tests { - err := txscript.TstCheckSignatureEncoding(test.sig, flags) + err := vm.checkSignatureEncoding(test.sig) if err != nil && test.isValid { t.Errorf("checkSignatureEncoding test '%s' failed "+ "when it should have succeeded: %v", test.name, diff --git a/txscript/internal_test.go b/txscript/internal_test.go deleted file mode 100644 index 2e031c39..00000000 --- a/txscript/internal_test.go +++ /dev/null @@ -1,3753 +0,0 @@ -// Copyright (c) 2013-2015 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -/* -This test file is part of the txscript package rather than than the -txscript_test package so it can bridge access to the internals to properly test -cases which are either not possible or can't reliably be tested via the public -interface. The functions are only exported while the tests are being run. -*/ - -package txscript - -import "testing" - -// TstMaxScriptSize makes the internal maxScriptSize constant available to the -// test package. -const TstMaxScriptSize = maxScriptSize - -// TstHasCanoncialPushes makes the internal isCanonicalPush function available -// to the test package. -var TstHasCanonicalPushes = canonicalPush - -// TstParseScript makes the internal parseScript function available to the -// test package. -var TstParseScript = parseScript - -// TstCalcSignatureHash makes the internal calcSignatureHash function available -// to the test package. -var TstCalcSignatureHash = calcSignatureHash - -// TstConcatRawScript makes the ability to add the pass script directly to -// an existing script to the test package. This differs from AddData since it -// doesn't add a push data opcode. -func (b *ScriptBuilder) TstConcatRawScript(data []byte) *ScriptBuilder { - if b.err != nil { - return b - } - - b.script = append(b.script, data...) - return b -} - -// TstCheckPubKeyEncoding makes the internal checkPubKeyEncoding function -// available to the test package. Since it only really needs from the engine -// for the flags, just accept the flags and create a new engine skeleton. -func TstCheckPubKeyEncoding(pubKey []byte, flags ScriptFlags) error { - vm := Engine{flags: flags} - return vm.checkPubKeyEncoding(pubKey) -} - -// TstCheckSignatureEncoding makes the internal checkSignatureEncoding function -// available to the test package. Since it only really needs from the engine -// for the flags, just accept the flags and create a new engine skeleton with -// them. -func TstCheckSignatureEncoding(sig []byte, flags ScriptFlags) error { - vm := Engine{flags: flags} - return vm.checkSignatureEncoding(sig) -} - -// TstRemoveOpcode makes the internal removeOpcode function available to the -// test package. -func TstRemoveOpcode(pkscript []byte, opcode byte) ([]byte, error) { - pops, err := parseScript(pkscript) - if err != nil { - return nil, err - } - pops = removeOpcode(pops, opcode) - return unparseScript(pops) -} - -// TstRemoveOpcodeByData makes the internal removeOpcodeByData function -// available to the test package. -func TstRemoveOpcodeByData(pkscript []byte, data []byte) ([]byte, error) { - pops, err := parseScript(pkscript) - if err != nil { - return nil, err - } - pops = removeOpcodeByData(pops, data) - return unparseScript(pops) -} - -// TestSetPC allows the test modules to set the program counter to whatever they -// want. -func (vm *Engine) TstSetPC(script, off int) { - vm.scriptIdx = script - vm.scriptOff = off -} - -// Internal tests for opcode parsing with bad data templates. -func TestParseOpcode(t *testing.T) { - // Deep copy the array and make one of the opcodes invalid by setting it - // to the wrong length. - fakeArray := opcodeArray - fakeArray[OP_PUSHDATA4] = opcode{value: OP_PUSHDATA4, - name: "OP_PUSHDATA4", length: -8, opfunc: opcodePushData} - - // This script would be fine if -8 was a valid length. - _, err := parseScriptTemplate([]byte{OP_PUSHDATA4, 0x1, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00}, &fakeArray) - if err == nil { - t.Errorf("no error with dodgy opcode array!") - } -} - -func TestUnparsingInvalidOpcodes(t *testing.T) { - tests := []struct { - name string - pop *parsedOpcode - expectedErr error - }{ - { - name: "OP_FALSE", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_FALSE], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_FALSE long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_FALSE], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_1 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_1], - data: nil, - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_1", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_1], - data: make([]byte, 1), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_1 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_1], - data: make([]byte, 2), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_2 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_2], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_2", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_2], - data: make([]byte, 2), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_2 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_2], - data: make([]byte, 3), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_3 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_3], - data: make([]byte, 2), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_3", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_3], - data: make([]byte, 3), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_3 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_3], - data: make([]byte, 4), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_4 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_4], - data: make([]byte, 3), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_4", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_4], - data: make([]byte, 4), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_4 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_4], - data: make([]byte, 5), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_5 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_5], - data: make([]byte, 4), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_5", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_5], - data: make([]byte, 5), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_5 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_5], - data: make([]byte, 6), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_6 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_6], - data: make([]byte, 5), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_6", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_6], - data: make([]byte, 6), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_6 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_6], - data: make([]byte, 7), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_7 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_7], - data: make([]byte, 6), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_7", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_7], - data: make([]byte, 7), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_7 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_7], - data: make([]byte, 8), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_8 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_8], - data: make([]byte, 7), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_8", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_8], - data: make([]byte, 8), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_8 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_8], - data: make([]byte, 9), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_9 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_9], - data: make([]byte, 8), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_9", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_9], - data: make([]byte, 9), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_9 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_9], - data: make([]byte, 10), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_10 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_10], - data: make([]byte, 9), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_10", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_10], - data: make([]byte, 10), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_10 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_10], - data: make([]byte, 11), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_11 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_11], - data: make([]byte, 10), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_11", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_11], - data: make([]byte, 11), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_11 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_11], - data: make([]byte, 12), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_12 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_12], - data: make([]byte, 11), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_12", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_12], - data: make([]byte, 12), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_12 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_12], - data: make([]byte, 13), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_13 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_13], - data: make([]byte, 12), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_13", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_13], - data: make([]byte, 13), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_13 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_13], - data: make([]byte, 14), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_14 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_14], - data: make([]byte, 13), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_14", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_14], - data: make([]byte, 14), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_14 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_14], - data: make([]byte, 15), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_15 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_15], - data: make([]byte, 14), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_15", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_15], - data: make([]byte, 15), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_15 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_15], - data: make([]byte, 16), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_16 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_16], - data: make([]byte, 15), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_16", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_16], - data: make([]byte, 16), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_16 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_16], - data: make([]byte, 17), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_17 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_17], - data: make([]byte, 16), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_17", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_17], - data: make([]byte, 17), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_17 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_17], - data: make([]byte, 18), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_18 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_18], - data: make([]byte, 17), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_18", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_18], - data: make([]byte, 18), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_18 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_18], - data: make([]byte, 19), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_19 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_19], - data: make([]byte, 18), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_19", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_19], - data: make([]byte, 19), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_19 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_19], - data: make([]byte, 20), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_20 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_20], - data: make([]byte, 19), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_20", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_20], - data: make([]byte, 20), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_20 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_20], - data: make([]byte, 21), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_21 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_21], - data: make([]byte, 20), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_21", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_21], - data: make([]byte, 21), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_21 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_21], - data: make([]byte, 22), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_22 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_22], - data: make([]byte, 21), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_22", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_22], - data: make([]byte, 22), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_22 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_22], - data: make([]byte, 23), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_23 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_23], - data: make([]byte, 22), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_23", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_23], - data: make([]byte, 23), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_23 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_23], - data: make([]byte, 24), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_24 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_24], - data: make([]byte, 23), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_24", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_24], - data: make([]byte, 24), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_24 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_24], - data: make([]byte, 25), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_25 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_25], - data: make([]byte, 24), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_25", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_25], - data: make([]byte, 25), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_25 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_25], - data: make([]byte, 26), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_26 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_26], - data: make([]byte, 25), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_26", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_26], - data: make([]byte, 26), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_26 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_26], - data: make([]byte, 27), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_27 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_27], - data: make([]byte, 26), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_27", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_27], - data: make([]byte, 27), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_27 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_27], - data: make([]byte, 28), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_28 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_28], - data: make([]byte, 27), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_28", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_28], - data: make([]byte, 28), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_28 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_28], - data: make([]byte, 29), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_29 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_29], - data: make([]byte, 28), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_29", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_29], - data: make([]byte, 29), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_29 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_29], - data: make([]byte, 30), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_30 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_30], - data: make([]byte, 29), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_30", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_30], - data: make([]byte, 30), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_30 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_30], - data: make([]byte, 31), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_31 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_31], - data: make([]byte, 30), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_31", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_31], - data: make([]byte, 31), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_31 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_31], - data: make([]byte, 32), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_32 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_32], - data: make([]byte, 31), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_32", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_32], - data: make([]byte, 32), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_32 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_32], - data: make([]byte, 33), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_33 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_33], - data: make([]byte, 32), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_33", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_33], - data: make([]byte, 33), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_33 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_33], - data: make([]byte, 34), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_34 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_34], - data: make([]byte, 33), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_34", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_34], - data: make([]byte, 34), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_34 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_34], - data: make([]byte, 35), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_35 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_35], - data: make([]byte, 34), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_35", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_35], - data: make([]byte, 35), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_35 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_35], - data: make([]byte, 36), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_36 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_36], - data: make([]byte, 35), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_36", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_36], - data: make([]byte, 36), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_36 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_36], - data: make([]byte, 37), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_37 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_37], - data: make([]byte, 36), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_37", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_37], - data: make([]byte, 37), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_37 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_37], - data: make([]byte, 38), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_38 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_38], - data: make([]byte, 37), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_38", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_38], - data: make([]byte, 38), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_38 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_38], - data: make([]byte, 39), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_39 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_39], - data: make([]byte, 38), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_39", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_39], - data: make([]byte, 39), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_39 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_39], - data: make([]byte, 40), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_40 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_40], - data: make([]byte, 39), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_40", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_40], - data: make([]byte, 40), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_40 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_40], - data: make([]byte, 41), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_41 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_41], - data: make([]byte, 40), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_41", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_41], - data: make([]byte, 41), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_41 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_41], - data: make([]byte, 42), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_42 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_42], - data: make([]byte, 41), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_42", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_42], - data: make([]byte, 42), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_42 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_42], - data: make([]byte, 43), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_43 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_43], - data: make([]byte, 42), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_43", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_43], - data: make([]byte, 43), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_43 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_43], - data: make([]byte, 44), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_44 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_44], - data: make([]byte, 43), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_44", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_44], - data: make([]byte, 44), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_44 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_44], - data: make([]byte, 45), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_45 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_45], - data: make([]byte, 44), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_45", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_45], - data: make([]byte, 45), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_45 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_45], - data: make([]byte, 46), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_46 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_46], - data: make([]byte, 45), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_46", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_46], - data: make([]byte, 46), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_46 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_46], - data: make([]byte, 47), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_47 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_47], - data: make([]byte, 46), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_47", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_47], - data: make([]byte, 47), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_47 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_47], - data: make([]byte, 48), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_48 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_48], - data: make([]byte, 47), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_48", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_48], - data: make([]byte, 48), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_48 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_48], - data: make([]byte, 49), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_49 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_49], - data: make([]byte, 48), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_49", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_49], - data: make([]byte, 49), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_49 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_49], - data: make([]byte, 50), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_50 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_50], - data: make([]byte, 49), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_50", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_50], - data: make([]byte, 50), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_50 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_50], - data: make([]byte, 51), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_51 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_51], - data: make([]byte, 50), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_51", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_51], - data: make([]byte, 51), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_51 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_51], - data: make([]byte, 52), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_52 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_52], - data: make([]byte, 51), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_52", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_52], - data: make([]byte, 52), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_52 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_52], - data: make([]byte, 53), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_53 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_53], - data: make([]byte, 52), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_53", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_53], - data: make([]byte, 53), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_53 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_53], - data: make([]byte, 54), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_54 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_54], - data: make([]byte, 53), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_54", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_54], - data: make([]byte, 54), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_54 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_54], - data: make([]byte, 55), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_55 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_55], - data: make([]byte, 54), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_55", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_55], - data: make([]byte, 55), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_55 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_55], - data: make([]byte, 56), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_56 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_56], - data: make([]byte, 55), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_56", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_56], - data: make([]byte, 56), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_56 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_56], - data: make([]byte, 57), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_57 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_57], - data: make([]byte, 56), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_57", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_57], - data: make([]byte, 57), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_57 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_57], - data: make([]byte, 58), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_58 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_58], - data: make([]byte, 57), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_58", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_58], - data: make([]byte, 58), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_58 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_58], - data: make([]byte, 59), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_59 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_59], - data: make([]byte, 58), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_59", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_59], - data: make([]byte, 59), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_59 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_59], - data: make([]byte, 60), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_60 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_60], - data: make([]byte, 59), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_60", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_60], - data: make([]byte, 60), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_60 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_60], - data: make([]byte, 61), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_61 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_61], - data: make([]byte, 60), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_61", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_61], - data: make([]byte, 61), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_61 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_61], - data: make([]byte, 62), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_62 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_62], - data: make([]byte, 61), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_62", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_62], - data: make([]byte, 62), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_62 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_62], - data: make([]byte, 63), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_63 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_63], - data: make([]byte, 62), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_63", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_63], - data: make([]byte, 63), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_63 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_63], - data: make([]byte, 64), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_64 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_64], - data: make([]byte, 63), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_64", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_64], - data: make([]byte, 64), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_64 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_64], - data: make([]byte, 65), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_65 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_65], - data: make([]byte, 64), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_65", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_65], - data: make([]byte, 65), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_65 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_65], - data: make([]byte, 66), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_66 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_66], - data: make([]byte, 65), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_66", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_66], - data: make([]byte, 66), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_66 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_66], - data: make([]byte, 67), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_67 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_67], - data: make([]byte, 66), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_67", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_67], - data: make([]byte, 67), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_67 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_67], - data: make([]byte, 68), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_68 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_68], - data: make([]byte, 67), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_68", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_68], - data: make([]byte, 68), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_68 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_68], - data: make([]byte, 69), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_69 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_69], - data: make([]byte, 68), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_69", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_69], - data: make([]byte, 69), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_69 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_69], - data: make([]byte, 70), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_70 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_70], - data: make([]byte, 69), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_70", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_70], - data: make([]byte, 70), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_70 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_70], - data: make([]byte, 71), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_71 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_71], - data: make([]byte, 70), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_71", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_71], - data: make([]byte, 71), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_71 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_71], - data: make([]byte, 72), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_72 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_72], - data: make([]byte, 71), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_72", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_72], - data: make([]byte, 72), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_72 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_72], - data: make([]byte, 73), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_73 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_73], - data: make([]byte, 72), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_73", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_73], - data: make([]byte, 73), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_73 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_73], - data: make([]byte, 74), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_74 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_74], - data: make([]byte, 73), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_74", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_74], - data: make([]byte, 74), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_74 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_74], - data: make([]byte, 75), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_75 short", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_75], - data: make([]byte, 74), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DATA_75", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_75], - data: make([]byte, 75), - }, - expectedErr: nil, - }, - { - name: "OP_DATA_75 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DATA_75], - data: make([]byte, 76), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_PUSHDATA1", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PUSHDATA1], - data: []byte{0, 1, 2, 3, 4}, - }, - expectedErr: nil, - }, - { - name: "OP_PUSHDATA2", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PUSHDATA2], - data: []byte{0, 1, 2, 3, 4}, - }, - expectedErr: nil, - }, - { - name: "OP_PUSHDATA4", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PUSHDATA1], - data: []byte{0, 1, 2, 3, 4}, - }, - expectedErr: nil, - }, - { - name: "OP_1NEGATE", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_1NEGATE], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_1NEGATE long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_1NEGATE], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_RESERVED", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RESERVED], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_RESERVED long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RESERVED], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_TRUE", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_TRUE], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_TRUE long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_TRUE], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_3", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_3], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_3 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_3], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_4", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_4], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_4 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_4], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_5", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_5], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_5 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_5], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_6", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_6], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_6 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_6], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_7", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_7], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_7 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_7], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_8", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_8], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_8 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_8], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_9", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_9], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_9 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_9], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_10", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_10], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_10 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_10], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_11", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_11], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_11 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_11], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_12", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_12], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_12 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_12], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_13", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_13], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_13 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_13], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_14", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_14], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_14 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_14], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_15", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_15], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_15 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_15], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_16", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_16], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_16 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_16], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_VER", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_VER], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_VER long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_VER], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_IF", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_IF], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_IF long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_IF], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOTIF", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOTIF], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOTIF long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOTIF], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_VERIF", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_VERIF], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_VERIF long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_VERIF], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_VERNOTIF", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_VERNOTIF], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_VERNOTIF long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_VERNOTIF], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_ELSE", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ELSE], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_ELSE long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ELSE], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_ENDIF", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ENDIF], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_ENDIF long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ENDIF], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_VERIFY", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_VERIFY], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_VERIFY long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_VERIFY], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_RETURN", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RETURN], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_RETURN long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RETURN], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_TOALTSTACK", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_TOALTSTACK], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_TOALTSTACK long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_TOALTSTACK], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_FROMALTSTACK", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_FROMALTSTACK], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_FROMALTSTACK long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_FROMALTSTACK], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2DROP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2DROP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2DROP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2DROP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2DUP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2DUP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2DUP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2DUP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_3DUP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_3DUP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_3DUP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_3DUP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2OVER", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2OVER], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2OVER long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2OVER], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2ROT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2ROT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2ROT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2ROT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2SWAP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2SWAP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2SWAP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2SWAP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_IFDUP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_IFDUP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_IFDUP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_IFDUP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DEPTH", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DEPTH], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_DEPTH long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DEPTH], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DROP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DROP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_DROP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DROP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DUP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DUP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_DUP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DUP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NIP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NIP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NIP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NIP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_OVER", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_OVER], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_OVER long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_OVER], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_PICK", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PICK], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_PICK long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PICK], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_ROLL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ROLL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_ROLL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ROLL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_ROT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ROT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_ROT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ROT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_SWAP", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SWAP], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_SWAP long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SWAP], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_TUCK", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_TUCK], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_TUCK long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_TUCK], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_CAT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CAT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_CAT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CAT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_SUBSTR", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SUBSTR], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_SUBSTR long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SUBSTR], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_LEFT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LEFT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_LEFT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LEFT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_LEFT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LEFT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_LEFT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LEFT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_RIGHT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RIGHT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_RIGHT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RIGHT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_SIZE", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SIZE], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_SIZE long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SIZE], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_INVERT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_INVERT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_INVERT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_INVERT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_AND", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_AND], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_AND long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_AND], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_OR", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_OR], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_OR long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_OR], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_XOR", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_XOR], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_XOR long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_XOR], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_EQUAL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_EQUAL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_EQUAL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_EQUAL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_EQUALVERIFY", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_EQUALVERIFY], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_EQUALVERIFY long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_EQUALVERIFY], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_RESERVED1", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RESERVED1], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_RESERVED1 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RESERVED1], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_RESERVED2", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RESERVED2], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_RESERVED2 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RESERVED2], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_1ADD", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_1ADD], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_1ADD long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_1ADD], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_1SUB", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_1SUB], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_1SUB long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_1SUB], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2MUL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2MUL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2MUL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2MUL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_2DIV", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2DIV], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_2DIV long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_2DIV], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NEGATE", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NEGATE], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NEGATE long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NEGATE], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_ABS", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ABS], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_ABS long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ABS], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_0NOTEQUAL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_0NOTEQUAL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_0NOTEQUAL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_0NOTEQUAL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_ADD", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ADD], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_ADD long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_ADD], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_SUB", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SUB], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_SUB long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SUB], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_MUL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_MUL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_MUL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_MUL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_DIV", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DIV], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_DIV long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_DIV], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_MOD", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_MOD], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_MOD long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_MOD], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_LSHIFT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LSHIFT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_LSHIFT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LSHIFT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_RSHIFT", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RSHIFT], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_RSHIFT long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RSHIFT], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_BOOLAND", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_BOOLAND], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_BOOLAND long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_BOOLAND], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_BOOLOR", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_BOOLOR], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_BOOLOR long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_BOOLOR], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NUMEQUAL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NUMEQUAL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NUMEQUAL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NUMEQUAL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NUMEQUALVERIFY", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NUMEQUALVERIFY], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NUMEQUALVERIFY long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NUMEQUALVERIFY], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NUMNOTEQUAL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NUMNOTEQUAL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NUMNOTEQUAL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NUMNOTEQUAL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_LESSTHAN", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LESSTHAN], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_LESSTHAN long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LESSTHAN], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_GREATERTHAN", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_GREATERTHAN], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_GREATERTHAN long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_GREATERTHAN], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_LESSTHANOREQUAL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LESSTHANOREQUAL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_LESSTHANOREQUAL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_LESSTHANOREQUAL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_GREATERTHANOREQUAL", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_GREATERTHANOREQUAL], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_GREATERTHANOREQUAL long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_GREATERTHANOREQUAL], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_MIN", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_MIN], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_MIN long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_MIN], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_MAX", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_MAX], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_MAX long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_MAX], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_WITHIN", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_WITHIN], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_WITHIN long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_WITHIN], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_RIPEMD160", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RIPEMD160], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_RIPEMD160 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_RIPEMD160], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_SHA1", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SHA1], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_SHA1 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SHA1], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_SHA256", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SHA256], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_SHA256 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_SHA256], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_HASH160", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_HASH160], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_HASH160 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_HASH160], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_HASH256", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_HASH256], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_HASH256 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_HASH256], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_CODESAPERATOR", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CODESEPARATOR], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_CODESEPARATOR long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CODESEPARATOR], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_CHECKSIG", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CHECKSIG], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_CHECKSIG long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CHECKSIG], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_CHECKSIGVERIFY", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CHECKSIGVERIFY], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_CHECKSIGVERIFY long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CHECKSIGVERIFY], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_CHECKMULTISIG", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CHECKMULTISIG], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_CHECKMULTISIG long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CHECKMULTISIG], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_CHECKMULTISIGVERIFY", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CHECKMULTISIGVERIFY], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_CHECKMULTISIGVERIFY long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_CHECKMULTISIGVERIFY], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP1", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP1], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP1 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP1], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP2", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP2], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP2 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP2], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP3", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP3], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP3 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP3], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP4", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP4], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP4 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP4], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP5", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP5], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP5 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP5], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP6", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP6], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP6 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP6], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP7", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP7], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP7 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP7], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP8", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP8], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP8 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP8], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP9", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP9], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP9 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP9], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_NOP10", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP10], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_NOP10 long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_NOP10], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_PUBKEYHASH", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PUBKEYHASH], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_PUBKEYHASH long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PUBKEYHASH], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_PUBKEY", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PUBKEY], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_PUBKEY long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_PUBKEY], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - { - name: "OP_INVALIDOPCODE", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_INVALIDOPCODE], - data: nil, - }, - expectedErr: nil, - }, - { - name: "OP_INVALIDOPCODE long", - pop: &parsedOpcode{ - opcode: &opcodeArray[OP_INVALIDOPCODE], - data: make([]byte, 1), - }, - expectedErr: ErrStackInvalidOpcode, - }, - } - - for _, test := range tests { - _, err := test.pop.bytes() - if err != test.expectedErr { - t.Errorf("Parsed Opcode test '%s' failed", test.name) - t.Error(err, test.expectedErr) - } - } -} diff --git a/txscript/log_test.go b/txscript/log_test.go index 851f9372..11baa08f 100644 --- a/txscript/log_test.go +++ b/txscript/log_test.go @@ -1,16 +1,14 @@ -// Copyright (c) 2013-2015 The btcsuite developers +// Copyright (c) 2013-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package txscript_test +package txscript import ( "errors" "io" "os" "testing" - - "github.com/btcsuite/btcd/txscript" ) func TestSetLogWriter(t *testing.T) { @@ -48,7 +46,7 @@ func TestSetLogWriter(t *testing.T) { t.Logf("Running %d tests", len(tests)) for i, test := range tests { - err := txscript.SetLogWriter(test.w, test.level) + err := SetLogWriter(test.w, test.level) if err != nil { if err.Error() != test.expected.Error() { t.Errorf("SetLogWriter #%d (%s) wrong result\n"+ diff --git a/txscript/reference_test.go b/txscript/reference_test.go index 5d546e85..80dd484d 100644 --- a/txscript/reference_test.go +++ b/txscript/reference_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package txscript_test +package txscript import ( "bytes" @@ -16,7 +16,6 @@ import ( "testing" "github.com/btcsuite/btcd/chaincfg/chainhash" - . "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) @@ -102,7 +101,12 @@ func parseShortForm(script string) ([]byte, error) { builder.AddInt64(num) continue } else if bts, err := parseHex(tok); err == nil { - builder.TstConcatRawScript(bts) + // Concatenate the bytes manually since the test code + // intentionally creates scripts that are too large and + // would cause the builder to error otherwise. + if builder.err == nil { + builder.script = append(builder.script, bts...) + } } else if len(tok) >= 2 && tok[0] == '\'' && tok[len(tok)-1] == '\'' { builder.AddFullData([]byte(tok[1 : len(tok)-1])) @@ -648,7 +652,7 @@ func TestCalcSignatureHash(t *testing.T) { } subScript, _ := hex.DecodeString(test[1].(string)) - parsedScript, err := TstParseScript(subScript) + parsedScript, err := parseScript(subScript) if err != nil { t.Errorf("TestCalcSignatureHash failed test #%d: "+ "Failed to parse sub-script: %v", i, err) @@ -656,7 +660,7 @@ func TestCalcSignatureHash(t *testing.T) { } hashType := SigHashType(testVecF64ToUint32(test[3].(float64))) - hash := TstCalcSignatureHash(parsedScript, hashType, tx, + hash := calcSignatureHash(parsedScript, hashType, tx, int(test[2].(float64))) expectedHash, _ := chainhash.NewHashFromStr(test[4].(string)) diff --git a/txscript/script_test.go b/txscript/script_test.go index 012d07f8..d309d39a 100644 --- a/txscript/script_test.go +++ b/txscript/script_test.go @@ -1,17 +1,3682 @@ -// Copyright (c) 2013-2015 The btcsuite developers +// Copyright (c) 2013-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package txscript_test +package txscript import ( "bytes" "reflect" "testing" - - "github.com/btcsuite/btcd/txscript" ) +// TestParseOpcode tests for opcode parsing with bad data templates. +func TestParseOpcode(t *testing.T) { + // Deep copy the array and make one of the opcodes invalid by setting it + // to the wrong length. + fakeArray := opcodeArray + fakeArray[OP_PUSHDATA4] = opcode{value: OP_PUSHDATA4, + name: "OP_PUSHDATA4", length: -8, opfunc: opcodePushData} + + // This script would be fine if -8 was a valid length. + _, err := parseScriptTemplate([]byte{OP_PUSHDATA4, 0x1, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00}, &fakeArray) + if err == nil { + t.Errorf("no error with dodgy opcode array!") + } +} + +// TestUnparsingInvalidOpcodes tests for errors when unparsing invalid parsed +// opcodes. +func TestUnparsingInvalidOpcodes(t *testing.T) { + tests := []struct { + name string + pop *parsedOpcode + expectedErr error + }{ + { + name: "OP_FALSE", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_FALSE], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_FALSE long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_FALSE], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_1 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_1], + data: nil, + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_1", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_1], + data: make([]byte, 1), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_1 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_1], + data: make([]byte, 2), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_2 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_2], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_2", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_2], + data: make([]byte, 2), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_2 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_2], + data: make([]byte, 3), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_3 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_3], + data: make([]byte, 2), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_3", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_3], + data: make([]byte, 3), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_3 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_3], + data: make([]byte, 4), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_4 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_4], + data: make([]byte, 3), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_4", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_4], + data: make([]byte, 4), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_4 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_4], + data: make([]byte, 5), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_5 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_5], + data: make([]byte, 4), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_5", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_5], + data: make([]byte, 5), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_5 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_5], + data: make([]byte, 6), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_6 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_6], + data: make([]byte, 5), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_6", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_6], + data: make([]byte, 6), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_6 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_6], + data: make([]byte, 7), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_7 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_7], + data: make([]byte, 6), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_7", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_7], + data: make([]byte, 7), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_7 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_7], + data: make([]byte, 8), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_8 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_8], + data: make([]byte, 7), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_8", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_8], + data: make([]byte, 8), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_8 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_8], + data: make([]byte, 9), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_9 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_9], + data: make([]byte, 8), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_9", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_9], + data: make([]byte, 9), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_9 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_9], + data: make([]byte, 10), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_10 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_10], + data: make([]byte, 9), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_10", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_10], + data: make([]byte, 10), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_10 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_10], + data: make([]byte, 11), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_11 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_11], + data: make([]byte, 10), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_11", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_11], + data: make([]byte, 11), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_11 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_11], + data: make([]byte, 12), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_12 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_12], + data: make([]byte, 11), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_12", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_12], + data: make([]byte, 12), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_12 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_12], + data: make([]byte, 13), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_13 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_13], + data: make([]byte, 12), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_13", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_13], + data: make([]byte, 13), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_13 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_13], + data: make([]byte, 14), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_14 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_14], + data: make([]byte, 13), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_14", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_14], + data: make([]byte, 14), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_14 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_14], + data: make([]byte, 15), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_15 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_15], + data: make([]byte, 14), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_15", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_15], + data: make([]byte, 15), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_15 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_15], + data: make([]byte, 16), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_16 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_16], + data: make([]byte, 15), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_16", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_16], + data: make([]byte, 16), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_16 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_16], + data: make([]byte, 17), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_17 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_17], + data: make([]byte, 16), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_17", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_17], + data: make([]byte, 17), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_17 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_17], + data: make([]byte, 18), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_18 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_18], + data: make([]byte, 17), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_18", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_18], + data: make([]byte, 18), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_18 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_18], + data: make([]byte, 19), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_19 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_19], + data: make([]byte, 18), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_19", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_19], + data: make([]byte, 19), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_19 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_19], + data: make([]byte, 20), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_20 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_20], + data: make([]byte, 19), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_20", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_20], + data: make([]byte, 20), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_20 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_20], + data: make([]byte, 21), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_21 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_21], + data: make([]byte, 20), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_21", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_21], + data: make([]byte, 21), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_21 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_21], + data: make([]byte, 22), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_22 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_22], + data: make([]byte, 21), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_22", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_22], + data: make([]byte, 22), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_22 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_22], + data: make([]byte, 23), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_23 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_23], + data: make([]byte, 22), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_23", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_23], + data: make([]byte, 23), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_23 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_23], + data: make([]byte, 24), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_24 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_24], + data: make([]byte, 23), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_24", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_24], + data: make([]byte, 24), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_24 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_24], + data: make([]byte, 25), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_25 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_25], + data: make([]byte, 24), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_25", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_25], + data: make([]byte, 25), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_25 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_25], + data: make([]byte, 26), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_26 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_26], + data: make([]byte, 25), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_26", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_26], + data: make([]byte, 26), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_26 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_26], + data: make([]byte, 27), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_27 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_27], + data: make([]byte, 26), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_27", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_27], + data: make([]byte, 27), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_27 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_27], + data: make([]byte, 28), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_28 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_28], + data: make([]byte, 27), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_28", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_28], + data: make([]byte, 28), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_28 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_28], + data: make([]byte, 29), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_29 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_29], + data: make([]byte, 28), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_29", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_29], + data: make([]byte, 29), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_29 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_29], + data: make([]byte, 30), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_30 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_30], + data: make([]byte, 29), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_30", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_30], + data: make([]byte, 30), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_30 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_30], + data: make([]byte, 31), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_31 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_31], + data: make([]byte, 30), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_31", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_31], + data: make([]byte, 31), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_31 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_31], + data: make([]byte, 32), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_32 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_32], + data: make([]byte, 31), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_32", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_32], + data: make([]byte, 32), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_32 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_32], + data: make([]byte, 33), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_33 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_33], + data: make([]byte, 32), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_33", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_33], + data: make([]byte, 33), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_33 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_33], + data: make([]byte, 34), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_34 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_34], + data: make([]byte, 33), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_34", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_34], + data: make([]byte, 34), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_34 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_34], + data: make([]byte, 35), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_35 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_35], + data: make([]byte, 34), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_35", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_35], + data: make([]byte, 35), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_35 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_35], + data: make([]byte, 36), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_36 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_36], + data: make([]byte, 35), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_36", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_36], + data: make([]byte, 36), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_36 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_36], + data: make([]byte, 37), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_37 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_37], + data: make([]byte, 36), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_37", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_37], + data: make([]byte, 37), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_37 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_37], + data: make([]byte, 38), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_38 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_38], + data: make([]byte, 37), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_38", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_38], + data: make([]byte, 38), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_38 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_38], + data: make([]byte, 39), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_39 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_39], + data: make([]byte, 38), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_39", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_39], + data: make([]byte, 39), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_39 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_39], + data: make([]byte, 40), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_40 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_40], + data: make([]byte, 39), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_40", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_40], + data: make([]byte, 40), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_40 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_40], + data: make([]byte, 41), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_41 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_41], + data: make([]byte, 40), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_41", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_41], + data: make([]byte, 41), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_41 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_41], + data: make([]byte, 42), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_42 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_42], + data: make([]byte, 41), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_42", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_42], + data: make([]byte, 42), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_42 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_42], + data: make([]byte, 43), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_43 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_43], + data: make([]byte, 42), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_43", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_43], + data: make([]byte, 43), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_43 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_43], + data: make([]byte, 44), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_44 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_44], + data: make([]byte, 43), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_44", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_44], + data: make([]byte, 44), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_44 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_44], + data: make([]byte, 45), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_45 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_45], + data: make([]byte, 44), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_45", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_45], + data: make([]byte, 45), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_45 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_45], + data: make([]byte, 46), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_46 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_46], + data: make([]byte, 45), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_46", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_46], + data: make([]byte, 46), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_46 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_46], + data: make([]byte, 47), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_47 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_47], + data: make([]byte, 46), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_47", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_47], + data: make([]byte, 47), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_47 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_47], + data: make([]byte, 48), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_48 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_48], + data: make([]byte, 47), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_48", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_48], + data: make([]byte, 48), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_48 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_48], + data: make([]byte, 49), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_49 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_49], + data: make([]byte, 48), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_49", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_49], + data: make([]byte, 49), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_49 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_49], + data: make([]byte, 50), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_50 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_50], + data: make([]byte, 49), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_50", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_50], + data: make([]byte, 50), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_50 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_50], + data: make([]byte, 51), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_51 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_51], + data: make([]byte, 50), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_51", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_51], + data: make([]byte, 51), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_51 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_51], + data: make([]byte, 52), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_52 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_52], + data: make([]byte, 51), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_52", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_52], + data: make([]byte, 52), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_52 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_52], + data: make([]byte, 53), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_53 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_53], + data: make([]byte, 52), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_53", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_53], + data: make([]byte, 53), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_53 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_53], + data: make([]byte, 54), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_54 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_54], + data: make([]byte, 53), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_54", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_54], + data: make([]byte, 54), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_54 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_54], + data: make([]byte, 55), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_55 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_55], + data: make([]byte, 54), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_55", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_55], + data: make([]byte, 55), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_55 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_55], + data: make([]byte, 56), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_56 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_56], + data: make([]byte, 55), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_56", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_56], + data: make([]byte, 56), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_56 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_56], + data: make([]byte, 57), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_57 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_57], + data: make([]byte, 56), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_57", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_57], + data: make([]byte, 57), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_57 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_57], + data: make([]byte, 58), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_58 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_58], + data: make([]byte, 57), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_58", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_58], + data: make([]byte, 58), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_58 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_58], + data: make([]byte, 59), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_59 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_59], + data: make([]byte, 58), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_59", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_59], + data: make([]byte, 59), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_59 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_59], + data: make([]byte, 60), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_60 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_60], + data: make([]byte, 59), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_60", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_60], + data: make([]byte, 60), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_60 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_60], + data: make([]byte, 61), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_61 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_61], + data: make([]byte, 60), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_61", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_61], + data: make([]byte, 61), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_61 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_61], + data: make([]byte, 62), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_62 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_62], + data: make([]byte, 61), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_62", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_62], + data: make([]byte, 62), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_62 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_62], + data: make([]byte, 63), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_63 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_63], + data: make([]byte, 62), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_63", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_63], + data: make([]byte, 63), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_63 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_63], + data: make([]byte, 64), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_64 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_64], + data: make([]byte, 63), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_64", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_64], + data: make([]byte, 64), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_64 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_64], + data: make([]byte, 65), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_65 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_65], + data: make([]byte, 64), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_65", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_65], + data: make([]byte, 65), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_65 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_65], + data: make([]byte, 66), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_66 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_66], + data: make([]byte, 65), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_66", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_66], + data: make([]byte, 66), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_66 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_66], + data: make([]byte, 67), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_67 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_67], + data: make([]byte, 66), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_67", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_67], + data: make([]byte, 67), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_67 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_67], + data: make([]byte, 68), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_68 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_68], + data: make([]byte, 67), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_68", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_68], + data: make([]byte, 68), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_68 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_68], + data: make([]byte, 69), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_69 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_69], + data: make([]byte, 68), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_69", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_69], + data: make([]byte, 69), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_69 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_69], + data: make([]byte, 70), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_70 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_70], + data: make([]byte, 69), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_70", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_70], + data: make([]byte, 70), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_70 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_70], + data: make([]byte, 71), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_71 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_71], + data: make([]byte, 70), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_71", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_71], + data: make([]byte, 71), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_71 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_71], + data: make([]byte, 72), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_72 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_72], + data: make([]byte, 71), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_72", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_72], + data: make([]byte, 72), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_72 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_72], + data: make([]byte, 73), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_73 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_73], + data: make([]byte, 72), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_73", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_73], + data: make([]byte, 73), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_73 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_73], + data: make([]byte, 74), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_74 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_74], + data: make([]byte, 73), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_74", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_74], + data: make([]byte, 74), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_74 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_74], + data: make([]byte, 75), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_75 short", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_75], + data: make([]byte, 74), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DATA_75", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_75], + data: make([]byte, 75), + }, + expectedErr: nil, + }, + { + name: "OP_DATA_75 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DATA_75], + data: make([]byte, 76), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_PUSHDATA1", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PUSHDATA1], + data: []byte{0, 1, 2, 3, 4}, + }, + expectedErr: nil, + }, + { + name: "OP_PUSHDATA2", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PUSHDATA2], + data: []byte{0, 1, 2, 3, 4}, + }, + expectedErr: nil, + }, + { + name: "OP_PUSHDATA4", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PUSHDATA1], + data: []byte{0, 1, 2, 3, 4}, + }, + expectedErr: nil, + }, + { + name: "OP_1NEGATE", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_1NEGATE], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_1NEGATE long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_1NEGATE], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_RESERVED", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RESERVED], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_RESERVED long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RESERVED], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_TRUE", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_TRUE], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_TRUE long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_TRUE], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_3", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_3], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_3 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_3], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_4", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_4], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_4 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_4], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_5", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_5], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_5 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_5], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_6", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_6], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_6 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_6], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_7", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_7], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_7 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_7], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_8", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_8], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_8 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_8], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_9", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_9], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_9 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_9], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_10", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_10], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_10 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_10], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_11", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_11], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_11 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_11], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_12", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_12], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_12 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_12], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_13", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_13], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_13 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_13], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_14", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_14], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_14 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_14], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_15", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_15], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_15 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_15], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_16", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_16], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_16 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_16], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_VER", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_VER], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_VER long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_VER], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_IF", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_IF], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_IF long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_IF], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOTIF", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOTIF], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOTIF long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOTIF], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_VERIF", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_VERIF], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_VERIF long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_VERIF], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_VERNOTIF", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_VERNOTIF], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_VERNOTIF long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_VERNOTIF], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_ELSE", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ELSE], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_ELSE long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ELSE], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_ENDIF", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ENDIF], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_ENDIF long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ENDIF], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_VERIFY", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_VERIFY], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_VERIFY long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_VERIFY], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_RETURN", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RETURN], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_RETURN long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RETURN], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_TOALTSTACK", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_TOALTSTACK], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_TOALTSTACK long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_TOALTSTACK], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_FROMALTSTACK", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_FROMALTSTACK], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_FROMALTSTACK long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_FROMALTSTACK], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2DROP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2DROP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2DROP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2DROP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2DUP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2DUP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2DUP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2DUP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_3DUP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_3DUP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_3DUP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_3DUP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2OVER", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2OVER], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2OVER long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2OVER], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2ROT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2ROT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2ROT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2ROT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2SWAP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2SWAP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2SWAP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2SWAP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_IFDUP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_IFDUP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_IFDUP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_IFDUP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DEPTH", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DEPTH], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_DEPTH long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DEPTH], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DROP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DROP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_DROP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DROP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DUP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DUP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_DUP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DUP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NIP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NIP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NIP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NIP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_OVER", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_OVER], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_OVER long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_OVER], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_PICK", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PICK], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_PICK long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PICK], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_ROLL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ROLL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_ROLL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ROLL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_ROT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ROT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_ROT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ROT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_SWAP", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SWAP], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_SWAP long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SWAP], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_TUCK", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_TUCK], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_TUCK long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_TUCK], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_CAT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CAT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_CAT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CAT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_SUBSTR", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SUBSTR], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_SUBSTR long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SUBSTR], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_LEFT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LEFT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_LEFT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LEFT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_LEFT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LEFT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_LEFT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LEFT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_RIGHT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RIGHT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_RIGHT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RIGHT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_SIZE", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SIZE], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_SIZE long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SIZE], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_INVERT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_INVERT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_INVERT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_INVERT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_AND", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_AND], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_AND long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_AND], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_OR", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_OR], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_OR long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_OR], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_XOR", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_XOR], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_XOR long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_XOR], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_EQUAL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_EQUAL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_EQUAL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_EQUAL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_EQUALVERIFY", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_EQUALVERIFY], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_EQUALVERIFY long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_EQUALVERIFY], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_RESERVED1", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RESERVED1], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_RESERVED1 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RESERVED1], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_RESERVED2", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RESERVED2], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_RESERVED2 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RESERVED2], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_1ADD", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_1ADD], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_1ADD long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_1ADD], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_1SUB", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_1SUB], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_1SUB long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_1SUB], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2MUL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2MUL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2MUL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2MUL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_2DIV", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2DIV], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_2DIV long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_2DIV], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NEGATE", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NEGATE], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NEGATE long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NEGATE], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_ABS", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ABS], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_ABS long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ABS], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_0NOTEQUAL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_0NOTEQUAL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_0NOTEQUAL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_0NOTEQUAL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_ADD", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ADD], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_ADD long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_ADD], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_SUB", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SUB], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_SUB long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SUB], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_MUL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_MUL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_MUL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_MUL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_DIV", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DIV], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_DIV long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_DIV], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_MOD", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_MOD], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_MOD long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_MOD], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_LSHIFT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LSHIFT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_LSHIFT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LSHIFT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_RSHIFT", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RSHIFT], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_RSHIFT long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RSHIFT], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_BOOLAND", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_BOOLAND], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_BOOLAND long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_BOOLAND], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_BOOLOR", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_BOOLOR], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_BOOLOR long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_BOOLOR], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NUMEQUAL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NUMEQUAL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NUMEQUAL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NUMEQUAL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NUMEQUALVERIFY", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NUMEQUALVERIFY], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NUMEQUALVERIFY long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NUMEQUALVERIFY], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NUMNOTEQUAL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NUMNOTEQUAL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NUMNOTEQUAL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NUMNOTEQUAL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_LESSTHAN", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LESSTHAN], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_LESSTHAN long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LESSTHAN], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_GREATERTHAN", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_GREATERTHAN], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_GREATERTHAN long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_GREATERTHAN], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_LESSTHANOREQUAL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LESSTHANOREQUAL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_LESSTHANOREQUAL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_LESSTHANOREQUAL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_GREATERTHANOREQUAL", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_GREATERTHANOREQUAL], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_GREATERTHANOREQUAL long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_GREATERTHANOREQUAL], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_MIN", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_MIN], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_MIN long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_MIN], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_MAX", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_MAX], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_MAX long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_MAX], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_WITHIN", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_WITHIN], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_WITHIN long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_WITHIN], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_RIPEMD160", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RIPEMD160], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_RIPEMD160 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_RIPEMD160], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_SHA1", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SHA1], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_SHA1 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SHA1], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_SHA256", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SHA256], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_SHA256 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_SHA256], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_HASH160", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_HASH160], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_HASH160 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_HASH160], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_HASH256", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_HASH256], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_HASH256 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_HASH256], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_CODESAPERATOR", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CODESEPARATOR], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_CODESEPARATOR long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CODESEPARATOR], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_CHECKSIG", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CHECKSIG], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_CHECKSIG long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CHECKSIG], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_CHECKSIGVERIFY", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CHECKSIGVERIFY], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_CHECKSIGVERIFY long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CHECKSIGVERIFY], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_CHECKMULTISIG", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CHECKMULTISIG], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_CHECKMULTISIG long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CHECKMULTISIG], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_CHECKMULTISIGVERIFY", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CHECKMULTISIGVERIFY], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_CHECKMULTISIGVERIFY long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_CHECKMULTISIGVERIFY], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP1", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP1], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP1 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP1], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP2", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP2], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP2 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP2], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP3", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP3], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP3 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP3], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP4", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP4], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP4 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP4], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP5", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP5], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP5 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP5], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP6", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP6], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP6 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP6], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP7", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP7], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP7 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP7], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP8", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP8], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP8 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP8], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP9", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP9], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP9 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP9], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_NOP10", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP10], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_NOP10 long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_NOP10], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_PUBKEYHASH", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PUBKEYHASH], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_PUBKEYHASH long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PUBKEYHASH], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_PUBKEY", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PUBKEY], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_PUBKEY long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_PUBKEY], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + { + name: "OP_INVALIDOPCODE", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_INVALIDOPCODE], + data: nil, + }, + expectedErr: nil, + }, + { + name: "OP_INVALIDOPCODE long", + pop: &parsedOpcode{ + opcode: &opcodeArray[OP_INVALIDOPCODE], + data: make([]byte, 1), + }, + expectedErr: ErrStackInvalidOpcode, + }, + } + + for _, test := range tests { + _, err := test.pop.bytes() + if err != test.expectedErr { + t.Errorf("Parsed Opcode test '%s' failed", test.name) + t.Error(err, test.expectedErr) + } + } +} + // TestPushedData ensured the PushedData function extracts the expected data out // of various scripts. func TestPushedData(t *testing.T) { @@ -57,7 +3722,7 @@ func TestPushedData(t *testing.T) { for i, test := range tests { script := mustParseShortForm(test.script) - data, err := txscript.PushedData(script) + data, err := PushedData(script) if test.valid && err != nil { t.Errorf("TestPushedData failed test #%d: %v\n", i, err) continue @@ -78,51 +3743,49 @@ func TestHasCanonicalPush(t *testing.T) { t.Parallel() for i := 0; i < 65535; i++ { - builder := txscript.NewScriptBuilder() - builder.AddInt64(int64(i)) - script, err := builder.Script() + script, err := NewScriptBuilder().AddInt64(int64(i)).Script() if err != nil { t.Errorf("Script: test #%d unexpected error: %v\n", i, err) continue } - if result := txscript.IsPushOnlyScript(script); !result { + if result := IsPushOnlyScript(script); !result { t.Errorf("IsPushOnlyScript: test #%d failed: %x\n", i, script) continue } - pops, err := txscript.TstParseScript(script) + pops, err := parseScript(script) if err != nil { - t.Errorf("TstParseScript: #%d failed: %v", i, err) + t.Errorf("parseScript: #%d failed: %v", i, err) continue } for _, pop := range pops { - if result := txscript.TstHasCanonicalPushes(pop); !result { - t.Errorf("TstHasCanonicalPushes: test #%d "+ - "failed: %x\n", i, script) + if result := canonicalPush(pop); !result { + t.Errorf("canonicalPush: test #%d failed: %x\n", + i, script) break } } } - for i := 0; i <= txscript.MaxScriptElementSize; i++ { - builder := txscript.NewScriptBuilder() + for i := 0; i <= MaxScriptElementSize; i++ { + builder := NewScriptBuilder() builder.AddData(bytes.Repeat([]byte{0x49}, i)) script, err := builder.Script() if err != nil { t.Errorf("StandardPushesTests test #%d unexpected error: %v\n", i, err) continue } - if result := txscript.IsPushOnlyScript(script); !result { + if result := IsPushOnlyScript(script); !result { t.Errorf("StandardPushesTests IsPushOnlyScript test #%d failed: %x\n", i, script) continue } - pops, err := txscript.TstParseScript(script) + pops, err := parseScript(script) if err != nil { t.Errorf("StandardPushesTests #%d failed to TstParseScript: %v", i, err) continue } for _, pop := range pops { - if result := txscript.TstHasCanonicalPushes(pop); !result { + if result := canonicalPush(pop); !result { t.Errorf("StandardPushesTests TstHasCanonicalPushes test #%d failed: %x\n", i, script) break } @@ -143,12 +3806,12 @@ func TestGetPreciseSigOps(t *testing.T) { }{ { name: "scriptSig doesn't parse", - scriptSig: []byte{txscript.OP_PUSHDATA1, 2}, - err: txscript.ErrStackShortScript, + scriptSig: mustParseShortForm("PUSHDATA1 0x02"), + err: ErrStackShortScript, }, { name: "scriptSig isn't push only", - scriptSig: []byte{txscript.OP_1, txscript.OP_DUP}, + scriptSig: mustParseShortForm("1 DUP"), nSigOps: 0, }, { @@ -159,14 +3822,13 @@ func TestGetPreciseSigOps(t *testing.T) { { name: "No script at the end", // No script at end but still push only. - scriptSig: []byte{txscript.OP_1, txscript.OP_1}, + scriptSig: mustParseShortForm("1 1"), nSigOps: 0, }, { - name: "pushed script doesn't parse", - scriptSig: []byte{txscript.OP_DATA_2, - txscript.OP_PUSHDATA1, 2}, - err: txscript.ErrStackShortScript, + name: "pushed script doesn't parse", + scriptSig: mustParseShortForm("DATA_2 PUSHDATA1 0x02"), + err: ErrStackShortScript, }, } @@ -176,8 +3838,7 @@ func TestGetPreciseSigOps(t *testing.T) { pkScript := mustParseShortForm("HASH160 DATA_20 0x433ec2ac1ffa1b7b7d0" + "27f564529c57197f9ae88 EQUAL") for _, test := range tests { - count := txscript.GetPreciseSigOpCount(test.scriptSig, pkScript, - true) + count := GetPreciseSigOpCount(test.scriptSig, pkScript, true) if count != test.nSigOps { t.Errorf("%s: expected count of %d, got %d", test.name, test.nSigOps, count) @@ -202,14 +3863,14 @@ func TestRemoveOpcodes(t *testing.T) { // Nothing to remove. name: "nothing to remove", before: "NOP", - remove: txscript.OP_CODESEPARATOR, + remove: OP_CODESEPARATOR, after: "NOP", }, { // Test basic opcode removal. name: "codeseparator 1", before: "NOP CODESEPARATOR TRUE", - remove: txscript.OP_CODESEPARATOR, + remove: OP_CODESEPARATOR, after: "NOP TRUE", }, { @@ -217,33 +3878,45 @@ func TestRemoveOpcodes(t *testing.T) { // in a previous opcode. name: "codeseparator by coincidence", before: "NOP DATA_1 CODESEPARATOR TRUE", - remove: txscript.OP_CODESEPARATOR, + remove: OP_CODESEPARATOR, after: "NOP DATA_1 CODESEPARATOR TRUE", }, { name: "invalid opcode", before: "CAT", - remove: txscript.OP_CODESEPARATOR, + remove: OP_CODESEPARATOR, after: "CAT", }, { name: "invalid length (insruction)", before: "PUSHDATA1", - remove: txscript.OP_CODESEPARATOR, - err: txscript.ErrStackShortScript, + remove: OP_CODESEPARATOR, + err: ErrStackShortScript, }, { name: "invalid length (data)", before: "PUSHDATA1 0xff 0xfe", - remove: txscript.OP_CODESEPARATOR, - err: txscript.ErrStackShortScript, + remove: OP_CODESEPARATOR, + err: ErrStackShortScript, }, } + // tstRemoveOpcode is a convenience function to parse the provided + // raw script, remove the passed opcode, then unparse the result back + // into a raw script. + tstRemoveOpcode := func(script []byte, opcode byte) ([]byte, error) { + pops, err := parseScript(script) + if err != nil { + return nil, err + } + pops = removeOpcode(pops, opcode) + return unparseScript(pops) + } + for _, test := range tests { before := mustParseShortForm(test.before) after := mustParseShortForm(test.after) - result, err := txscript.TstRemoveOpcode(before, test.remove) + result, err := tstRemoveOpcode(before, test.remove) if test.err != nil { if err != test.err { t.Errorf("%s: got unexpected error. exp: \"%v\" "+ @@ -276,26 +3949,26 @@ func TestRemoveOpcodeByData(t *testing.T) { }{ { name: "nothing to do", - before: []byte{txscript.OP_NOP}, + before: []byte{OP_NOP}, remove: []byte{1, 2, 3, 4}, - after: []byte{txscript.OP_NOP}, + after: []byte{OP_NOP}, }, { name: "simple case", - before: []byte{txscript.OP_DATA_4, 1, 2, 3, 4}, + before: []byte{OP_DATA_4, 1, 2, 3, 4}, remove: []byte{1, 2, 3, 4}, after: nil, }, { name: "simple case (miss)", - before: []byte{txscript.OP_DATA_4, 1, 2, 3, 4}, + before: []byte{OP_DATA_4, 1, 2, 3, 4}, remove: []byte{1, 2, 3, 5}, - after: []byte{txscript.OP_DATA_4, 1, 2, 3, 4}, + after: []byte{OP_DATA_4, 1, 2, 3, 4}, }, { // padded to keep it canonical. name: "simple case (pushdata1)", - before: append(append([]byte{txscript.OP_PUSHDATA1, 76}, + before: append(append([]byte{OP_PUSHDATA1, 76}, bytes.Repeat([]byte{0}, 72)...), []byte{1, 2, 3, 4}...), remove: []byte{1, 2, 3, 4}, @@ -303,23 +3976,23 @@ func TestRemoveOpcodeByData(t *testing.T) { }, { name: "simple case (pushdata1 miss)", - before: append(append([]byte{txscript.OP_PUSHDATA1, 76}, + before: append(append([]byte{OP_PUSHDATA1, 76}, bytes.Repeat([]byte{0}, 72)...), []byte{1, 2, 3, 4}...), remove: []byte{1, 2, 3, 5}, - after: append(append([]byte{txscript.OP_PUSHDATA1, 76}, + after: append(append([]byte{OP_PUSHDATA1, 76}, bytes.Repeat([]byte{0}, 72)...), []byte{1, 2, 3, 4}...), }, { name: "simple case (pushdata1 miss noncanonical)", - before: []byte{txscript.OP_PUSHDATA1, 4, 1, 2, 3, 4}, + before: []byte{OP_PUSHDATA1, 4, 1, 2, 3, 4}, remove: []byte{1, 2, 3, 4}, - after: []byte{txscript.OP_PUSHDATA1, 4, 1, 2, 3, 4}, + after: []byte{OP_PUSHDATA1, 4, 1, 2, 3, 4}, }, { name: "simple case (pushdata2)", - before: append(append([]byte{txscript.OP_PUSHDATA2, 0, 1}, + before: append(append([]byte{OP_PUSHDATA2, 0, 1}, bytes.Repeat([]byte{0}, 252)...), []byte{1, 2, 3, 4}...), remove: []byte{1, 2, 3, 4}, @@ -327,24 +4000,24 @@ func TestRemoveOpcodeByData(t *testing.T) { }, { name: "simple case (pushdata2 miss)", - before: append(append([]byte{txscript.OP_PUSHDATA2, 0, 1}, + before: append(append([]byte{OP_PUSHDATA2, 0, 1}, bytes.Repeat([]byte{0}, 252)...), []byte{1, 2, 3, 4}...), remove: []byte{1, 2, 3, 4, 5}, - after: append(append([]byte{txscript.OP_PUSHDATA2, 0, 1}, + after: append(append([]byte{OP_PUSHDATA2, 0, 1}, bytes.Repeat([]byte{0}, 252)...), []byte{1, 2, 3, 4}...), }, { name: "simple case (pushdata2 miss noncanonical)", - before: []byte{txscript.OP_PUSHDATA2, 4, 0, 1, 2, 3, 4}, + before: []byte{OP_PUSHDATA2, 4, 0, 1, 2, 3, 4}, remove: []byte{1, 2, 3, 4}, - after: []byte{txscript.OP_PUSHDATA2, 4, 0, 1, 2, 3, 4}, + after: []byte{OP_PUSHDATA2, 4, 0, 1, 2, 3, 4}, }, { // This is padded to make the push canonical. name: "simple case (pushdata4)", - before: append(append([]byte{txscript.OP_PUSHDATA4, 0, 0, 1, 0}, + before: append(append([]byte{OP_PUSHDATA4, 0, 0, 1, 0}, bytes.Repeat([]byte{0}, 65532)...), []byte{1, 2, 3, 4}...), remove: []byte{1, 2, 3, 4}, @@ -352,42 +4025,53 @@ func TestRemoveOpcodeByData(t *testing.T) { }, { name: "simple case (pushdata4 miss noncanonical)", - before: []byte{txscript.OP_PUSHDATA4, 4, 0, 0, 0, 1, 2, 3, 4}, + before: []byte{OP_PUSHDATA4, 4, 0, 0, 0, 1, 2, 3, 4}, remove: []byte{1, 2, 3, 4}, - after: []byte{txscript.OP_PUSHDATA4, 4, 0, 0, 0, 1, 2, 3, 4}, + after: []byte{OP_PUSHDATA4, 4, 0, 0, 0, 1, 2, 3, 4}, }, { // This is padded to make the push canonical. name: "simple case (pushdata4 miss)", - before: append(append([]byte{txscript.OP_PUSHDATA4, 0, 0, 1, 0}, + before: append(append([]byte{OP_PUSHDATA4, 0, 0, 1, 0}, bytes.Repeat([]byte{0}, 65532)...), []byte{1, 2, 3, 4}...), remove: []byte{1, 2, 3, 4, 5}, - after: append(append([]byte{txscript.OP_PUSHDATA4, 0, 0, 1, 0}, + after: append(append([]byte{OP_PUSHDATA4, 0, 0, 1, 0}, bytes.Repeat([]byte{0}, 65532)...), []byte{1, 2, 3, 4}...), }, { name: "invalid opcode ", - before: []byte{txscript.OP_UNKNOWN187}, + before: []byte{OP_UNKNOWN187}, remove: []byte{1, 2, 3, 4}, - after: []byte{txscript.OP_UNKNOWN187}, + after: []byte{OP_UNKNOWN187}, }, { name: "invalid length (instruction)", - before: []byte{txscript.OP_PUSHDATA1}, + before: []byte{OP_PUSHDATA1}, remove: []byte{1, 2, 3, 4}, - err: txscript.ErrStackShortScript, + err: ErrStackShortScript, }, { name: "invalid length (data)", - before: []byte{txscript.OP_PUSHDATA1, 255, 254}, + before: []byte{OP_PUSHDATA1, 255, 254}, remove: []byte{1, 2, 3, 4}, - err: txscript.ErrStackShortScript, + err: ErrStackShortScript, }, } + // tstRemoveOpcodeByData is a convenience function to parse the provided + // raw script, remove the passed data, then unparse the result back + // into a raw script. + tstRemoveOpcodeByData := func(script []byte, data []byte) ([]byte, error) { + pops, err := parseScript(script) + if err != nil { + return nil, err + } + pops = removeOpcodeByData(pops, data) + return unparseScript(pops) + } + for _, test := range tests { - result, err := txscript.TstRemoveOpcodeByData(test.before, - test.remove) + result, err := tstRemoveOpcodeByData(test.before, test.remove) if test.err != nil { if err != test.err { t.Errorf("%s: got unexpected error. exp: \"%v\" "+ @@ -413,8 +4097,8 @@ func TestIsPayToScriptHash(t *testing.T) { for _, test := range scriptClassTests { script := mustParseShortForm(test.script) - shouldBe := (test.class == txscript.ScriptHashTy) - p2sh := txscript.IsPayToScriptHash(script) + shouldBe := (test.class == ScriptHashTy) + p2sh := IsPayToScriptHash(script) if p2sh != shouldBe { t.Errorf("%s: epxected p2sh %v, got %v", test.name, shouldBe, p2sh) @@ -447,7 +4131,7 @@ func TestHasCanonicalPushes(t *testing.T) { for i, test := range tests { script := mustParseShortForm(test.script) - pops, err := txscript.TstParseScript(script) + pops, err := parseScript(script) if err != nil { if test.expected { t.Errorf("TstParseScript #%d failed: %v", i, err) @@ -455,10 +4139,10 @@ func TestHasCanonicalPushes(t *testing.T) { continue } for _, pop := range pops { - if txscript.TstHasCanonicalPushes(pop) != test.expected { - t.Errorf("TstHasCanonicalPushes: #%d (%s) "+ - "wrong result\ngot: %v\nwant: %v", i, - test.name, true, test.expected) + if canonicalPush(pop) != test.expected { + t.Errorf("canonicalPush: #%d (%s) wrong result"+ + "\ngot: %v\nwant: %v", i, test.name, + true, test.expected) break } } @@ -481,7 +4165,7 @@ func TestIsPushOnlyScript(t *testing.T) { expected: false, } - if txscript.IsPushOnlyScript(test.script) != test.expected { + if IsPushOnlyScript(test.script) != test.expected { t.Errorf("IsPushOnlyScript (%s) wrong result\ngot: %v\nwant: "+ "%v", test.name, true, test.expected) } @@ -513,7 +4197,7 @@ func TestIsUnspendable(t *testing.T) { } for i, test := range tests { - res := txscript.IsUnspendable(test.pkScript) + res := IsUnspendable(test.pkScript) if res != test.expected { t.Errorf("TestIsUnspendable #%d failed: got %v want %v", i, res, test.expected) diff --git a/txscript/scriptbuilder_test.go b/txscript/scriptbuilder_test.go index 904fd79f..7e316c69 100644 --- a/txscript/scriptbuilder_test.go +++ b/txscript/scriptbuilder_test.go @@ -1,14 +1,12 @@ -// Copyright (c) 2013-2015 The btcsuite developers +// Copyright (c) 2013-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package txscript_test +package txscript import ( "bytes" "testing" - - "github.com/btcsuite/btcd/txscript" ) // TestScriptBuilderAddOp tests that pushing opcodes to a script via the @@ -23,23 +21,23 @@ func TestScriptBuilderAddOp(t *testing.T) { }{ { name: "push OP_0", - opcodes: []byte{txscript.OP_0}, - expected: []byte{txscript.OP_0}, + opcodes: []byte{OP_0}, + expected: []byte{OP_0}, }, { name: "push OP_1 OP_2", - opcodes: []byte{txscript.OP_1, txscript.OP_2}, - expected: []byte{txscript.OP_1, txscript.OP_2}, + opcodes: []byte{OP_1, OP_2}, + expected: []byte{OP_1, OP_2}, }, { name: "push OP_HASH160 OP_EQUAL", - opcodes: []byte{txscript.OP_HASH160, txscript.OP_EQUAL}, - expected: []byte{txscript.OP_HASH160, txscript.OP_EQUAL}, + opcodes: []byte{OP_HASH160, OP_EQUAL}, + expected: []byte{OP_HASH160, OP_EQUAL}, }, } // Run tests and individually add each op via AddOp. - builder := txscript.NewScriptBuilder() + builder := NewScriptBuilder() t.Logf("Running %d tests", len(tests)) for i, test := range tests { builder.Reset() @@ -90,47 +88,47 @@ func TestScriptBuilderAddInt64(t *testing.T) { val int64 expected []byte }{ - {name: "push -1", val: -1, expected: []byte{txscript.OP_1NEGATE}}, - {name: "push small int 0", val: 0, expected: []byte{txscript.OP_0}}, - {name: "push small int 1", val: 1, expected: []byte{txscript.OP_1}}, - {name: "push small int 2", val: 2, expected: []byte{txscript.OP_2}}, - {name: "push small int 3", val: 3, expected: []byte{txscript.OP_3}}, - {name: "push small int 4", val: 4, expected: []byte{txscript.OP_4}}, - {name: "push small int 5", val: 5, expected: []byte{txscript.OP_5}}, - {name: "push small int 6", val: 6, expected: []byte{txscript.OP_6}}, - {name: "push small int 7", val: 7, expected: []byte{txscript.OP_7}}, - {name: "push small int 8", val: 8, expected: []byte{txscript.OP_8}}, - {name: "push small int 9", val: 9, expected: []byte{txscript.OP_9}}, - {name: "push small int 10", val: 10, expected: []byte{txscript.OP_10}}, - {name: "push small int 11", val: 11, expected: []byte{txscript.OP_11}}, - {name: "push small int 12", val: 12, expected: []byte{txscript.OP_12}}, - {name: "push small int 13", val: 13, expected: []byte{txscript.OP_13}}, - {name: "push small int 14", val: 14, expected: []byte{txscript.OP_14}}, - {name: "push small int 15", val: 15, expected: []byte{txscript.OP_15}}, - {name: "push small int 16", val: 16, expected: []byte{txscript.OP_16}}, - {name: "push 17", val: 17, expected: []byte{txscript.OP_DATA_1, 0x11}}, - {name: "push 65", val: 65, expected: []byte{txscript.OP_DATA_1, 0x41}}, - {name: "push 127", val: 127, expected: []byte{txscript.OP_DATA_1, 0x7f}}, - {name: "push 128", val: 128, expected: []byte{txscript.OP_DATA_2, 0x80, 0}}, - {name: "push 255", val: 255, expected: []byte{txscript.OP_DATA_2, 0xff, 0}}, - {name: "push 256", val: 256, expected: []byte{txscript.OP_DATA_2, 0, 0x01}}, - {name: "push 32767", val: 32767, expected: []byte{txscript.OP_DATA_2, 0xff, 0x7f}}, - {name: "push 32768", val: 32768, expected: []byte{txscript.OP_DATA_3, 0, 0x80, 0}}, - {name: "push -2", val: -2, expected: []byte{txscript.OP_DATA_1, 0x82}}, - {name: "push -3", val: -3, expected: []byte{txscript.OP_DATA_1, 0x83}}, - {name: "push -4", val: -4, expected: []byte{txscript.OP_DATA_1, 0x84}}, - {name: "push -5", val: -5, expected: []byte{txscript.OP_DATA_1, 0x85}}, - {name: "push -17", val: -17, expected: []byte{txscript.OP_DATA_1, 0x91}}, - {name: "push -65", val: -65, expected: []byte{txscript.OP_DATA_1, 0xc1}}, - {name: "push -127", val: -127, expected: []byte{txscript.OP_DATA_1, 0xff}}, - {name: "push -128", val: -128, expected: []byte{txscript.OP_DATA_2, 0x80, 0x80}}, - {name: "push -255", val: -255, expected: []byte{txscript.OP_DATA_2, 0xff, 0x80}}, - {name: "push -256", val: -256, expected: []byte{txscript.OP_DATA_2, 0x00, 0x81}}, - {name: "push -32767", val: -32767, expected: []byte{txscript.OP_DATA_2, 0xff, 0xff}}, - {name: "push -32768", val: -32768, expected: []byte{txscript.OP_DATA_3, 0x00, 0x80, 0x80}}, + {name: "push -1", val: -1, expected: []byte{OP_1NEGATE}}, + {name: "push small int 0", val: 0, expected: []byte{OP_0}}, + {name: "push small int 1", val: 1, expected: []byte{OP_1}}, + {name: "push small int 2", val: 2, expected: []byte{OP_2}}, + {name: "push small int 3", val: 3, expected: []byte{OP_3}}, + {name: "push small int 4", val: 4, expected: []byte{OP_4}}, + {name: "push small int 5", val: 5, expected: []byte{OP_5}}, + {name: "push small int 6", val: 6, expected: []byte{OP_6}}, + {name: "push small int 7", val: 7, expected: []byte{OP_7}}, + {name: "push small int 8", val: 8, expected: []byte{OP_8}}, + {name: "push small int 9", val: 9, expected: []byte{OP_9}}, + {name: "push small int 10", val: 10, expected: []byte{OP_10}}, + {name: "push small int 11", val: 11, expected: []byte{OP_11}}, + {name: "push small int 12", val: 12, expected: []byte{OP_12}}, + {name: "push small int 13", val: 13, expected: []byte{OP_13}}, + {name: "push small int 14", val: 14, expected: []byte{OP_14}}, + {name: "push small int 15", val: 15, expected: []byte{OP_15}}, + {name: "push small int 16", val: 16, expected: []byte{OP_16}}, + {name: "push 17", val: 17, expected: []byte{OP_DATA_1, 0x11}}, + {name: "push 65", val: 65, expected: []byte{OP_DATA_1, 0x41}}, + {name: "push 127", val: 127, expected: []byte{OP_DATA_1, 0x7f}}, + {name: "push 128", val: 128, expected: []byte{OP_DATA_2, 0x80, 0}}, + {name: "push 255", val: 255, expected: []byte{OP_DATA_2, 0xff, 0}}, + {name: "push 256", val: 256, expected: []byte{OP_DATA_2, 0, 0x01}}, + {name: "push 32767", val: 32767, expected: []byte{OP_DATA_2, 0xff, 0x7f}}, + {name: "push 32768", val: 32768, expected: []byte{OP_DATA_3, 0, 0x80, 0}}, + {name: "push -2", val: -2, expected: []byte{OP_DATA_1, 0x82}}, + {name: "push -3", val: -3, expected: []byte{OP_DATA_1, 0x83}}, + {name: "push -4", val: -4, expected: []byte{OP_DATA_1, 0x84}}, + {name: "push -5", val: -5, expected: []byte{OP_DATA_1, 0x85}}, + {name: "push -17", val: -17, expected: []byte{OP_DATA_1, 0x91}}, + {name: "push -65", val: -65, expected: []byte{OP_DATA_1, 0xc1}}, + {name: "push -127", val: -127, expected: []byte{OP_DATA_1, 0xff}}, + {name: "push -128", val: -128, expected: []byte{OP_DATA_2, 0x80, 0x80}}, + {name: "push -255", val: -255, expected: []byte{OP_DATA_2, 0xff, 0x80}}, + {name: "push -256", val: -256, expected: []byte{OP_DATA_2, 0x00, 0x81}}, + {name: "push -32767", val: -32767, expected: []byte{OP_DATA_2, 0xff, 0xff}}, + {name: "push -32768", val: -32768, expected: []byte{OP_DATA_3, 0x00, 0x80, 0x80}}, } - builder := txscript.NewScriptBuilder() + builder := NewScriptBuilder() t.Logf("Running %d tests", len(tests)) for i, test := range tests { builder.Reset().AddInt64(test.val) @@ -161,70 +159,70 @@ func TestScriptBuilderAddData(t *testing.T) { useFull bool // use AddFullData instead of AddData. }{ // BIP0062: Pushing an empty byte sequence must use OP_0. - {name: "push empty byte sequence", data: nil, expected: []byte{txscript.OP_0}}, - {name: "push 1 byte 0x00", data: []byte{0x00}, expected: []byte{txscript.OP_0}}, + {name: "push empty byte sequence", data: nil, expected: []byte{OP_0}}, + {name: "push 1 byte 0x00", data: []byte{0x00}, expected: []byte{OP_0}}, // BIP0062: Pushing a 1-byte sequence of byte 0x01 through 0x10 must use OP_n. - {name: "push 1 byte 0x01", data: []byte{0x01}, expected: []byte{txscript.OP_1}}, - {name: "push 1 byte 0x02", data: []byte{0x02}, expected: []byte{txscript.OP_2}}, - {name: "push 1 byte 0x03", data: []byte{0x03}, expected: []byte{txscript.OP_3}}, - {name: "push 1 byte 0x04", data: []byte{0x04}, expected: []byte{txscript.OP_4}}, - {name: "push 1 byte 0x05", data: []byte{0x05}, expected: []byte{txscript.OP_5}}, - {name: "push 1 byte 0x06", data: []byte{0x06}, expected: []byte{txscript.OP_6}}, - {name: "push 1 byte 0x07", data: []byte{0x07}, expected: []byte{txscript.OP_7}}, - {name: "push 1 byte 0x08", data: []byte{0x08}, expected: []byte{txscript.OP_8}}, - {name: "push 1 byte 0x09", data: []byte{0x09}, expected: []byte{txscript.OP_9}}, - {name: "push 1 byte 0x0a", data: []byte{0x0a}, expected: []byte{txscript.OP_10}}, - {name: "push 1 byte 0x0b", data: []byte{0x0b}, expected: []byte{txscript.OP_11}}, - {name: "push 1 byte 0x0c", data: []byte{0x0c}, expected: []byte{txscript.OP_12}}, - {name: "push 1 byte 0x0d", data: []byte{0x0d}, expected: []byte{txscript.OP_13}}, - {name: "push 1 byte 0x0e", data: []byte{0x0e}, expected: []byte{txscript.OP_14}}, - {name: "push 1 byte 0x0f", data: []byte{0x0f}, expected: []byte{txscript.OP_15}}, - {name: "push 1 byte 0x10", data: []byte{0x10}, expected: []byte{txscript.OP_16}}, + {name: "push 1 byte 0x01", data: []byte{0x01}, expected: []byte{OP_1}}, + {name: "push 1 byte 0x02", data: []byte{0x02}, expected: []byte{OP_2}}, + {name: "push 1 byte 0x03", data: []byte{0x03}, expected: []byte{OP_3}}, + {name: "push 1 byte 0x04", data: []byte{0x04}, expected: []byte{OP_4}}, + {name: "push 1 byte 0x05", data: []byte{0x05}, expected: []byte{OP_5}}, + {name: "push 1 byte 0x06", data: []byte{0x06}, expected: []byte{OP_6}}, + {name: "push 1 byte 0x07", data: []byte{0x07}, expected: []byte{OP_7}}, + {name: "push 1 byte 0x08", data: []byte{0x08}, expected: []byte{OP_8}}, + {name: "push 1 byte 0x09", data: []byte{0x09}, expected: []byte{OP_9}}, + {name: "push 1 byte 0x0a", data: []byte{0x0a}, expected: []byte{OP_10}}, + {name: "push 1 byte 0x0b", data: []byte{0x0b}, expected: []byte{OP_11}}, + {name: "push 1 byte 0x0c", data: []byte{0x0c}, expected: []byte{OP_12}}, + {name: "push 1 byte 0x0d", data: []byte{0x0d}, expected: []byte{OP_13}}, + {name: "push 1 byte 0x0e", data: []byte{0x0e}, expected: []byte{OP_14}}, + {name: "push 1 byte 0x0f", data: []byte{0x0f}, expected: []byte{OP_15}}, + {name: "push 1 byte 0x10", data: []byte{0x10}, expected: []byte{OP_16}}, // BIP0062: Pushing the byte 0x81 must use OP_1NEGATE. - {name: "push 1 byte 0x81", data: []byte{0x81}, expected: []byte{txscript.OP_1NEGATE}}, + {name: "push 1 byte 0x81", data: []byte{0x81}, expected: []byte{OP_1NEGATE}}, // BIP0062: Pushing any other byte sequence up to 75 bytes must // use the normal data push (opcode byte n, with n the number of // bytes, followed n bytes of data being pushed). - {name: "push 1 byte 0x11", data: []byte{0x11}, expected: []byte{txscript.OP_DATA_1, 0x11}}, - {name: "push 1 byte 0x80", data: []byte{0x80}, expected: []byte{txscript.OP_DATA_1, 0x80}}, - {name: "push 1 byte 0x82", data: []byte{0x82}, expected: []byte{txscript.OP_DATA_1, 0x82}}, - {name: "push 1 byte 0xff", data: []byte{0xff}, expected: []byte{txscript.OP_DATA_1, 0xff}}, + {name: "push 1 byte 0x11", data: []byte{0x11}, expected: []byte{OP_DATA_1, 0x11}}, + {name: "push 1 byte 0x80", data: []byte{0x80}, expected: []byte{OP_DATA_1, 0x80}}, + {name: "push 1 byte 0x82", data: []byte{0x82}, expected: []byte{OP_DATA_1, 0x82}}, + {name: "push 1 byte 0xff", data: []byte{0xff}, expected: []byte{OP_DATA_1, 0xff}}, { name: "push data len 17", data: bytes.Repeat([]byte{0x49}, 17), - expected: append([]byte{txscript.OP_DATA_17}, bytes.Repeat([]byte{0x49}, 17)...), + expected: append([]byte{OP_DATA_17}, bytes.Repeat([]byte{0x49}, 17)...), }, { name: "push data len 75", data: bytes.Repeat([]byte{0x49}, 75), - expected: append([]byte{txscript.OP_DATA_75}, bytes.Repeat([]byte{0x49}, 75)...), + expected: append([]byte{OP_DATA_75}, bytes.Repeat([]byte{0x49}, 75)...), }, // BIP0062: Pushing 76 to 255 bytes must use OP_PUSHDATA1. { name: "push data len 76", data: bytes.Repeat([]byte{0x49}, 76), - expected: append([]byte{txscript.OP_PUSHDATA1, 76}, bytes.Repeat([]byte{0x49}, 76)...), + expected: append([]byte{OP_PUSHDATA1, 76}, bytes.Repeat([]byte{0x49}, 76)...), }, { name: "push data len 255", data: bytes.Repeat([]byte{0x49}, 255), - expected: append([]byte{txscript.OP_PUSHDATA1, 255}, bytes.Repeat([]byte{0x49}, 255)...), + expected: append([]byte{OP_PUSHDATA1, 255}, bytes.Repeat([]byte{0x49}, 255)...), }, // BIP0062: Pushing 256 to 520 bytes must use OP_PUSHDATA2. { name: "push data len 256", data: bytes.Repeat([]byte{0x49}, 256), - expected: append([]byte{txscript.OP_PUSHDATA2, 0, 1}, bytes.Repeat([]byte{0x49}, 256)...), + expected: append([]byte{OP_PUSHDATA2, 0, 1}, bytes.Repeat([]byte{0x49}, 256)...), }, { name: "push data len 520", data: bytes.Repeat([]byte{0x49}, 520), - expected: append([]byte{txscript.OP_PUSHDATA2, 0x08, 0x02}, bytes.Repeat([]byte{0x49}, 520)...), + expected: append([]byte{OP_PUSHDATA2, 0x08, 0x02}, bytes.Repeat([]byte{0x49}, 520)...), }, // BIP0062: OP_PUSHDATA4 can never be used, as pushes over 520 @@ -254,7 +252,7 @@ func TestScriptBuilderAddData(t *testing.T) { { name: "push data len 32767 (non-canonical)", data: bytes.Repeat([]byte{0x49}, 32767), - expected: append([]byte{txscript.OP_PUSHDATA2, 255, 127}, bytes.Repeat([]byte{0x49}, 32767)...), + expected: append([]byte{OP_PUSHDATA2, 255, 127}, bytes.Repeat([]byte{0x49}, 32767)...), useFull: true, }, @@ -262,12 +260,12 @@ func TestScriptBuilderAddData(t *testing.T) { { name: "push data len 65536 (non-canonical)", data: bytes.Repeat([]byte{0x49}, 65536), - expected: append([]byte{txscript.OP_PUSHDATA4, 0, 0, 1, 0}, bytes.Repeat([]byte{0x49}, 65536)...), + expected: append([]byte{OP_PUSHDATA4, 0, 0, 1, 0}, bytes.Repeat([]byte{0x49}, 65536)...), useFull: true, }, } - builder := txscript.NewScriptBuilder() + builder := NewScriptBuilder() t.Logf("Running %d tests", len(tests)) for i, test := range tests { if !test.useFull { @@ -292,8 +290,7 @@ func TestExceedMaxScriptSize(t *testing.T) { t.Parallel() // Start off by constructing a max size script. - maxScriptSize := txscript.TstMaxScriptSize - builder := txscript.NewScriptBuilder() + builder := NewScriptBuilder() builder.Reset().AddFullData(make([]byte, maxScriptSize-3)) origScript, err := builder.Script() if err != nil { @@ -303,7 +300,7 @@ func TestExceedMaxScriptSize(t *testing.T) { // Ensure adding data that would exceed the maximum size of the script // does not add the data. script, err := builder.AddData([]byte{0x00}).Script() - if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil { + if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil { t.Fatalf("ScriptBuilder.AddData allowed exceeding max script "+ "size: %v", len(script)) } @@ -315,8 +312,8 @@ func TestExceedMaxScriptSize(t *testing.T) { // Ensure adding an opcode that would exceed the maximum size of the // script does not add the data. builder.Reset().AddFullData(make([]byte, maxScriptSize-3)) - script, err = builder.AddOp(txscript.OP_0).Script() - if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil { + script, err = builder.AddOp(OP_0).Script() + if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil { t.Fatalf("ScriptBuilder.AddOp unexpected modified script - "+ "got len %d, want len %d", len(script), len(origScript)) } @@ -329,7 +326,7 @@ func TestExceedMaxScriptSize(t *testing.T) { // script does not add the data. builder.Reset().AddFullData(make([]byte, maxScriptSize-3)) script, err = builder.AddInt64(0).Script() - if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil { + if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil { t.Fatalf("ScriptBuilder.AddInt64 unexpected modified script - "+ "got len %d, want len %d", len(script), len(origScript)) } @@ -347,15 +344,14 @@ func TestErroredScript(t *testing.T) { // Start off by constructing a near max size script that has enough // space left to add each data type without an error and force an // initial error condition. - maxScriptSize := txscript.TstMaxScriptSize - builder := txscript.NewScriptBuilder() + builder := NewScriptBuilder() builder.Reset().AddFullData(make([]byte, maxScriptSize-8)) origScript, err := builder.Script() if err != nil { t.Fatalf("ScriptBuilder.AddFullData unexpected error: %v", err) } script, err := builder.AddData([]byte{0x00, 0x00, 0x00, 0x00, 0x00}).Script() - if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil { + if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil { t.Fatalf("ScriptBuilder.AddData allowed exceeding max script "+ "size: %v", len(script)) } @@ -367,7 +363,7 @@ func TestErroredScript(t *testing.T) { // Ensure adding data, even using the non-canonical path, to a script // that has errored doesn't succeed. script, err = builder.AddFullData([]byte{0x00}).Script() - if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil { + if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil { t.Fatal("ScriptBuilder.AddFullData succeeded on errored script") } if !bytes.Equal(script, origScript) { @@ -378,7 +374,7 @@ func TestErroredScript(t *testing.T) { // Ensure adding data to a script that has errored doesn't succeed. script, err = builder.AddData([]byte{0x00}).Script() - if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil { + if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil { t.Fatal("ScriptBuilder.AddData succeeded on errored script") } if !bytes.Equal(script, origScript) { @@ -388,8 +384,8 @@ func TestErroredScript(t *testing.T) { } // Ensure adding an opcode to a script that has errored doesn't succeed. - script, err = builder.AddOp(txscript.OP_0).Script() - if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil { + script, err = builder.AddOp(OP_0).Script() + if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil { t.Fatal("ScriptBuilder.AddOp succeeded on errored script") } if !bytes.Equal(script, origScript) { @@ -400,7 +396,7 @@ func TestErroredScript(t *testing.T) { // Ensure adding an integer to a script that has errored doesn't // succeed. script, err = builder.AddInt64(0).Script() - if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil { + if _, ok := err.(ErrScriptNotCanonical); !ok || err == nil { t.Fatal("ScriptBuilder.AddInt64 succeeded on errored script") } if !bytes.Equal(script, origScript) { diff --git a/txscript/sign_test.go b/txscript/sign_test.go index 9a192be9..09234dc7 100644 --- a/txscript/sign_test.go +++ b/txscript/sign_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package txscript_test +package txscript import ( "errors" @@ -12,7 +12,6 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" ) @@ -22,14 +21,14 @@ type addressToKey struct { compressed bool } -func mkGetKey(keys map[string]addressToKey) txscript.KeyDB { +func mkGetKey(keys map[string]addressToKey) KeyDB { if keys == nil { - return txscript.KeyClosure(func(addr btcutil.Address) (*btcec.PrivateKey, + return KeyClosure(func(addr btcutil.Address) (*btcec.PrivateKey, bool, error) { return nil, false, errors.New("nope") }) } - return txscript.KeyClosure(func(addr btcutil.Address) (*btcec.PrivateKey, + return KeyClosure(func(addr btcutil.Address) (*btcec.PrivateKey, bool, error) { a2k, ok := keys[addr.EncodeAddress()] if !ok { @@ -39,15 +38,13 @@ func mkGetKey(keys map[string]addressToKey) txscript.KeyDB { }) } -func mkGetScript(scripts map[string][]byte) txscript.ScriptDB { +func mkGetScript(scripts map[string][]byte) ScriptDB { if scripts == nil { - return txscript.ScriptClosure(func(addr btcutil.Address) ( - []byte, error) { + return ScriptClosure(func(addr btcutil.Address) ([]byte, error) { return nil, errors.New("nope") }) } - return txscript.ScriptClosure(func(addr btcutil.Address) ([]byte, - error) { + return ScriptClosure(func(addr btcutil.Address) ([]byte, error) { script, ok := scripts[addr.EncodeAddress()] if !ok { return nil, errors.New("nope") @@ -58,8 +55,8 @@ func mkGetScript(scripts map[string][]byte) txscript.ScriptDB { func checkScripts(msg string, tx *wire.MsgTx, idx int, sigScript, pkScript []byte) error { tx.TxIn[idx].SignatureScript = sigScript - vm, err := txscript.NewEngine(pkScript, tx, idx, - txscript.ScriptBip16|txscript.ScriptVerifyDERSignatures, nil) + vm, err := NewEngine(pkScript, tx, idx, + ScriptBip16|ScriptVerifyDERSignatures, nil) if err != nil { return fmt.Errorf("failed to make script engine for %s: %v", msg, err) @@ -75,11 +72,11 @@ func checkScripts(msg string, tx *wire.MsgTx, idx int, sigScript, pkScript []byt } func signAndCheck(msg string, tx *wire.MsgTx, idx int, pkScript []byte, - hashType txscript.SigHashType, kdb txscript.KeyDB, sdb txscript.ScriptDB, + hashType SigHashType, kdb KeyDB, sdb ScriptDB, previousScript []byte) error { - sigScript, err := txscript.SignTxOutput(&chaincfg.TestNet3Params, tx, - idx, pkScript, hashType, kdb, sdb, nil) + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, tx, idx, + pkScript, hashType, kdb, sdb, nil) if err != nil { return fmt.Errorf("failed to sign output %s: %v", msg, err) } @@ -93,14 +90,14 @@ func TestSignTxOutput(t *testing.T) { // make key // make script based on key. // sign with magic pixie dust. - hashTypes := []txscript.SigHashType{ - txscript.SigHashOld, // no longer used but should act like all - txscript.SigHashAll, - txscript.SigHashNone, - txscript.SigHashSingle, - txscript.SigHashAll | txscript.SigHashAnyOneCanPay, - txscript.SigHashNone | txscript.SigHashAnyOneCanPay, - txscript.SigHashSingle | txscript.SigHashAnyOneCanPay, + hashTypes := []SigHashType{ + SigHashOld, // no longer used but should act like all + SigHashAll, + SigHashNone, + SigHashSingle, + SigHashAll | SigHashAnyOneCanPay, + SigHashNone | SigHashAnyOneCanPay, + SigHashSingle | SigHashAnyOneCanPay, } tx := &wire.MsgTx{ Version: 1, @@ -162,7 +159,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -199,15 +196,15 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, pkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, pkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(nil), nil) if err != nil { @@ -218,9 +215,9 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, pkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, pkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(nil), sigScript) if err != nil { @@ -260,7 +257,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -298,15 +295,15 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, pkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, pkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(nil), nil) if err != nil { @@ -317,9 +314,9 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, pkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, pkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(nil), sigScript) if err != nil { @@ -359,7 +356,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -397,15 +394,15 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, pkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, pkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(nil), nil) if err != nil { @@ -416,9 +413,9 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, pkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, pkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(nil), sigScript) if err != nil { @@ -458,7 +455,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -496,15 +493,15 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, pkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, pkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(nil), nil) if err != nil { @@ -515,9 +512,9 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, pkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, pkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(nil), sigScript) if err != nil { @@ -557,7 +554,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -572,7 +569,7 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( + scriptPkScript, err := PayToAddrScript( scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ @@ -614,7 +611,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -629,7 +626,7 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( + scriptPkScript, err := PayToAddrScript( scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ @@ -637,9 +634,9 @@ func TestSignTxOutput(t *testing.T) { break } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -652,9 +649,9 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -696,7 +693,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -710,7 +707,7 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( + scriptPkScript, err := PayToAddrScript( scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ @@ -753,7 +750,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -767,7 +764,7 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( + scriptPkScript, err := PayToAddrScript( scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ @@ -775,9 +772,9 @@ func TestSignTxOutput(t *testing.T) { break } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -790,9 +787,9 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -834,7 +831,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -848,7 +845,7 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( + scriptPkScript, err := PayToAddrScript( scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ @@ -891,7 +888,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -905,17 +902,16 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( - scriptAddr) + scriptPkScript, err := PayToAddrScript(scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ "%s: %v", msg, err) break } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -928,9 +924,9 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, false}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -972,7 +968,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -986,8 +982,7 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( - scriptAddr) + scriptPkScript, err := PayToAddrScript(scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ "%s: %v", msg, err) @@ -1029,7 +1024,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.PayToAddrScript(address) + pkScript, err := PayToAddrScript(address) if err != nil { t.Errorf("failed to make pkscript "+ "for %s: %v", msg, err) @@ -1043,17 +1038,16 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( - scriptAddr) + scriptPkScript, err := PayToAddrScript(scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ "%s: %v", msg, err) break } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -1066,9 +1060,9 @@ func TestSignTxOutput(t *testing.T) { // by the above loop, this should be valid, now sign // again and merge. - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address.EncodeAddress(): {key, true}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -1127,7 +1121,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.MultiSigScript( + pkScript, err := MultiSigScript( []*btcutil.AddressPubKey{address1, address2}, 2) if err != nil { @@ -1143,8 +1137,7 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( - scriptAddr) + scriptPkScript, err := PayToAddrScript(scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ "%s: %v", msg, err) @@ -1204,7 +1197,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.MultiSigScript( + pkScript, err := MultiSigScript( []*btcutil.AddressPubKey{address1, address2}, 2) if err != nil { @@ -1220,17 +1213,16 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( - scriptAddr) + scriptPkScript, err := PayToAddrScript(scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ "%s: %v", msg, err) break } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address1.EncodeAddress(): {key1, true}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -1249,9 +1241,9 @@ func TestSignTxOutput(t *testing.T) { } // Sign with the other key and merge - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address2.EncodeAddress(): {key2, true}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -1311,7 +1303,7 @@ func TestSignTxOutput(t *testing.T) { break } - pkScript, err := txscript.MultiSigScript( + pkScript, err := MultiSigScript( []*btcutil.AddressPubKey{address1, address2}, 2) if err != nil { @@ -1327,17 +1319,16 @@ func TestSignTxOutput(t *testing.T) { break } - scriptPkScript, err := txscript.PayToAddrScript( - scriptAddr) + scriptPkScript, err := PayToAddrScript(scriptAddr) if err != nil { t.Errorf("failed to make script pkscript for "+ "%s: %v", msg, err) break } - sigScript, err := txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err := SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address1.EncodeAddress(): {key1, true}, }), mkGetScript(map[string][]byte{ scriptAddr.EncodeAddress(): pkScript, @@ -1356,9 +1347,9 @@ func TestSignTxOutput(t *testing.T) { } // Sign with the other key and merge - sigScript, err = txscript.SignTxOutput( - &chaincfg.TestNet3Params, tx, i, scriptPkScript, - hashType, mkGetKey(map[string]addressToKey{ + sigScript, err = SignTxOutput(&chaincfg.TestNet3Params, + tx, i, scriptPkScript, hashType, + mkGetKey(map[string]addressToKey{ address1.EncodeAddress(): {key1, true}, address2.EncodeAddress(): {key2, true}, }), mkGetScript(map[string][]byte{ @@ -1391,7 +1382,7 @@ type tstInput struct { type tstSigScript struct { name string inputs []tstInput - hashType txscript.SigHashType + hashType SigHashType compress bool scriptAtWrongIndex bool } @@ -1443,7 +1434,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAll, + hashType: SigHashAll, compress: false, scriptAtWrongIndex: false, }, @@ -1463,7 +1454,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAll, + hashType: SigHashAll, compress: false, scriptAtWrongIndex: false, }, @@ -1477,7 +1468,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAll, + hashType: SigHashAll, compress: true, scriptAtWrongIndex: false, }, @@ -1497,7 +1488,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAll, + hashType: SigHashAll, compress: true, scriptAtWrongIndex: false, }, @@ -1511,7 +1502,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashNone, + hashType: SigHashNone, compress: false, scriptAtWrongIndex: false, }, @@ -1525,7 +1516,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashSingle, + hashType: SigHashSingle, compress: false, scriptAtWrongIndex: false, }, @@ -1539,7 +1530,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAnyOneCanPay, + hashType: SigHashAnyOneCanPay, compress: false, scriptAtWrongIndex: false, }, @@ -1567,7 +1558,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAll, + hashType: SigHashAll, compress: true, scriptAtWrongIndex: false, }, @@ -1580,7 +1571,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAll, + hashType: SigHashAll, compress: false, scriptAtWrongIndex: false, }, @@ -1600,7 +1591,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAll, + hashType: SigHashAll, compress: false, scriptAtWrongIndex: true, }, @@ -1620,7 +1611,7 @@ var sigScriptTests = []tstSigScript{ indexOutOfRange: false, }, }, - hashType: txscript.SigHashAll, + hashType: SigHashAll, compress: false, scriptAtWrongIndex: true, }, @@ -1640,7 +1631,7 @@ nexttest: for i := range sigScriptTests { tx := wire.NewMsgTx() - output := wire.NewTxOut(500, []byte{txscript.OP_RETURN}) + output := wire.NewTxOut(500, []byte{OP_RETURN}) tx.AddTxOut(output) for range sigScriptTests[i].inputs { @@ -1658,7 +1649,7 @@ nexttest: } else { idx = j } - script, err = txscript.SignatureScript(tx, idx, + script, err = SignatureScript(tx, idx, sigScriptTests[i].inputs[j].txout.PkScript, sigScriptTests[i].hashType, privKey, sigScriptTests[i].compress) @@ -1690,10 +1681,10 @@ nexttest: } // Validate tx input scripts - scriptFlags := txscript.ScriptBip16 | txscript.ScriptVerifyDERSignatures + scriptFlags := ScriptBip16 | ScriptVerifyDERSignatures for j := range tx.TxIn { - vm, err := txscript.NewEngine(sigScriptTests[i]. - inputs[j].txout.PkScript, tx, j, scriptFlags, nil) + vm, err := NewEngine(sigScriptTests[i].inputs[j].txout. + PkScript, tx, j, scriptFlags, nil) if err != nil { t.Errorf("cannot create script vm for test %v: %v", sigScriptTests[i].name, err) diff --git a/txscript/standard_test.go b/txscript/standard_test.go index 09ab135a..3c199dd7 100644 --- a/txscript/standard_test.go +++ b/txscript/standard_test.go @@ -1,33 +1,18 @@ -// Copyright (c) 2013-2015 The btcsuite developers +// Copyright (c) 2013-2016 The btcsuite developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. -package txscript_test +package txscript import ( "bytes" - "encoding/hex" "reflect" "testing" "github.com/btcsuite/btcd/chaincfg" - "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcutil" ) -// decodeHex decodes the passed hex string and returns the resulting bytes. It -// panics if an error occurs. This is only used in the tests as a helper since -// the only way it can fail is if there is an error in the test source code. -func decodeHex(hexStr string) []byte { - b, err := hex.DecodeString(hexStr) - if err != nil { - panic("invalid hex string in test source: err " + err.Error() + - ", hex: " + hexStr) - } - - return b -} - // mustParseShortForm parses the passed short form script and returns the // resulting bytes. It panics if an error occurs. This is only used in the // tests as a helper since the only way it can fail is if there is an error in @@ -93,175 +78,175 @@ func TestExtractPkScriptAddrs(t *testing.T) { script []byte addrs []btcutil.Address reqSigs int - class txscript.ScriptClass + class ScriptClass }{ { name: "standard p2pk with compressed pubkey (0x02)", - script: decodeHex("2102192d74d0cb94344c9569c2e7790157" + - "3d8d7903c3ebec3a957724895dca52c6b4ac"), + script: hexToBytes("2102192d74d0cb94344c9569c2e779015" + + "73d8d7903c3ebec3a957724895dca52c6b4ac"), addrs: []btcutil.Address{ - newAddressPubKey(decodeHex("02192d74d0cb94344" + - "c9569c2e77901573d8d7903c3ebec3a95772" + - "4895dca52c6b4")), + newAddressPubKey(hexToBytes("02192d74d0cb9434" + + "4c9569c2e77901573d8d7903c3ebec3a9577" + + "24895dca52c6b4")), }, reqSigs: 1, - class: txscript.PubKeyTy, + class: PubKeyTy, }, { name: "standard p2pk with uncompressed pubkey (0x04)", - script: decodeHex("410411db93e1dcdb8a016b49840f8c53bc" + - "1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb" + - "84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643" + - "f656b412a3ac"), + script: hexToBytes("410411db93e1dcdb8a016b49840f8c53b" + + "c1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddf" + + "b84ccf9744464f82e160bfa9b8b64f9d4c03f999b864" + + "3f656b412a3ac"), addrs: []btcutil.Address{ - newAddressPubKey(decodeHex("0411db93e1dcdb8a0" + - "16b49840f8c53bc1eb68a382e97b1482ecad" + - "7b148a6909a5cb2e0eaddfb84ccf9744464f" + - "82e160bfa9b8b64f9d4c03f999b8643f656b" + - "412a3")), + newAddressPubKey(hexToBytes("0411db93e1dcdb8a" + + "016b49840f8c53bc1eb68a382e97b1482eca" + + "d7b148a6909a5cb2e0eaddfb84ccf9744464" + + "f82e160bfa9b8b64f9d4c03f999b8643f656" + + "b412a3")), }, reqSigs: 1, - class: txscript.PubKeyTy, + class: PubKeyTy, }, { name: "standard p2pk with hybrid pubkey (0x06)", - script: decodeHex("4106192d74d0cb94344c9569c2e7790157" + - "3d8d7903c3ebec3a957724895dca52c6b40d45264838" + - "c0bd96852662ce6a847b197376830160c6d2eb5e6a4c" + - "44d33f453eac"), + script: hexToBytes("4106192d74d0cb94344c9569c2e779015" + + "73d8d7903c3ebec3a957724895dca52c6b40d4526483" + + "8c0bd96852662ce6a847b197376830160c6d2eb5e6a4" + + "c44d33f453eac"), addrs: []btcutil.Address{ - newAddressPubKey(decodeHex("06192d74d0cb94344" + - "c9569c2e77901573d8d7903c3ebec3a95772" + - "4895dca52c6b40d45264838c0bd96852662c" + - "e6a847b197376830160c6d2eb5e6a4c44d33" + - "f453e")), + newAddressPubKey(hexToBytes("06192d74d0cb9434" + + "4c9569c2e77901573d8d7903c3ebec3a9577" + + "24895dca52c6b40d45264838c0bd96852662" + + "ce6a847b197376830160c6d2eb5e6a4c44d3" + + "3f453e")), }, reqSigs: 1, - class: txscript.PubKeyTy, + class: PubKeyTy, }, { name: "standard p2pk with compressed pubkey (0x03)", - script: decodeHex("2103b0bd634234abbb1ba1e986e884185c" + - "61cf43e001f9137f23c2c409273eb16e65ac"), + script: hexToBytes("2103b0bd634234abbb1ba1e986e884185" + + "c61cf43e001f9137f23c2c409273eb16e65ac"), addrs: []btcutil.Address{ - newAddressPubKey(decodeHex("03b0bd634234abbb1" + - "ba1e986e884185c61cf43e001f9137f23c2c" + - "409273eb16e65")), + newAddressPubKey(hexToBytes("03b0bd634234abbb" + + "1ba1e986e884185c61cf43e001f9137f23c2" + + "c409273eb16e65")), }, reqSigs: 1, - class: txscript.PubKeyTy, + class: PubKeyTy, }, { name: "2nd standard p2pk with uncompressed pubkey (0x04)", - script: decodeHex("4104b0bd634234abbb1ba1e986e884185c" + - "61cf43e001f9137f23c2c409273eb16e6537a576782e" + - "ba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c" + - "1e0908ef7bac"), + script: hexToBytes("4104b0bd634234abbb1ba1e986e884185" + + "c61cf43e001f9137f23c2c409273eb16e6537a576782" + + "eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3" + + "c1e0908ef7bac"), addrs: []btcutil.Address{ - newAddressPubKey(decodeHex("04b0bd634234abbb1" + - "ba1e986e884185c61cf43e001f9137f23c2c" + - "409273eb16e6537a576782eba668a7ef8bd3" + - "b3cfb1edb7117ab65129b8a2e681f3c1e090" + - "8ef7b")), + newAddressPubKey(hexToBytes("04b0bd634234abbb" + + "1ba1e986e884185c61cf43e001f9137f23c2" + + "c409273eb16e6537a576782eba668a7ef8bd" + + "3b3cfb1edb7117ab65129b8a2e681f3c1e09" + + "08ef7b")), }, reqSigs: 1, - class: txscript.PubKeyTy, + class: PubKeyTy, }, { name: "standard p2pk with hybrid pubkey (0x07)", - script: decodeHex("4107b0bd634234abbb1ba1e986e884185c" + - "61cf43e001f9137f23c2c409273eb16e6537a576782e" + - "ba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c" + - "1e0908ef7bac"), + script: hexToBytes("4107b0bd634234abbb1ba1e986e884185" + + "c61cf43e001f9137f23c2c409273eb16e6537a576782" + + "eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3" + + "c1e0908ef7bac"), addrs: []btcutil.Address{ - newAddressPubKey(decodeHex("07b0bd634234abbb1" + - "ba1e986e884185c61cf43e001f9137f23c2c" + - "409273eb16e6537a576782eba668a7ef8bd3" + - "b3cfb1edb7117ab65129b8a2e681f3c1e090" + - "8ef7b")), + newAddressPubKey(hexToBytes("07b0bd634234abbb" + + "1ba1e986e884185c61cf43e001f9137f23c2" + + "c409273eb16e6537a576782eba668a7ef8bd" + + "3b3cfb1edb7117ab65129b8a2e681f3c1e09" + + "08ef7b")), }, reqSigs: 1, - class: txscript.PubKeyTy, + class: PubKeyTy, }, { name: "standard p2pkh", - script: decodeHex("76a914ad06dd6ddee55cbca9a9e3713bd7" + - "587509a3056488ac"), + script: hexToBytes("76a914ad06dd6ddee55cbca9a9e3713bd" + + "7587509a3056488ac"), addrs: []btcutil.Address{ - newAddressPubKeyHash(decodeHex("ad06dd6ddee55" + - "cbca9a9e3713bd7587509a30564")), + newAddressPubKeyHash(hexToBytes("ad06dd6ddee5" + + "5cbca9a9e3713bd7587509a30564")), }, reqSigs: 1, - class: txscript.PubKeyHashTy, + class: PubKeyHashTy, }, { name: "standard p2sh", - script: decodeHex("a91463bcc565f9e68ee0189dd5cc67f1b0" + - "e5f02f45cb87"), + script: hexToBytes("a91463bcc565f9e68ee0189dd5cc67f1b" + + "0e5f02f45cb87"), addrs: []btcutil.Address{ - newAddressScriptHash(decodeHex("63bcc565f9e68" + - "ee0189dd5cc67f1b0e5f02f45cb")), + newAddressScriptHash(hexToBytes("63bcc565f9e6" + + "8ee0189dd5cc67f1b0e5f02f45cb")), }, reqSigs: 1, - class: txscript.ScriptHashTy, + class: ScriptHashTy, }, // from real tx 60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1, vout 0 { name: "standard 1 of 2 multisig", - script: decodeHex("514104cc71eb30d653c0c3163990c47b97" + - "6f3fb3f37cccdcbedb169a1dfef58bbfbfaff7d8a473" + - "e7e2e6d317b87bafe8bde97e3cf8f065dec022b51d11" + - "fcdd0d348ac4410461cbdcc5409fb4b4d42b51d33381" + - "354d80e550078cb532a34bfa2fcfdeb7d76519aecc62" + - "770f5b0e4ef8551946d8a540911abe3e7854a26f39f5" + - "8b25c15342af52ae"), + script: hexToBytes("514104cc71eb30d653c0c3163990c47b9" + + "76f3fb3f37cccdcbedb169a1dfef58bbfbfaff7d8a47" + + "3e7e2e6d317b87bafe8bde97e3cf8f065dec022b51d1" + + "1fcdd0d348ac4410461cbdcc5409fb4b4d42b51d3338" + + "1354d80e550078cb532a34bfa2fcfdeb7d76519aecc6" + + "2770f5b0e4ef8551946d8a540911abe3e7854a26f39f" + + "58b25c15342af52ae"), addrs: []btcutil.Address{ - newAddressPubKey(decodeHex("04cc71eb30d653c0c" + - "3163990c47b976f3fb3f37cccdcbedb169a1" + - "dfef58bbfbfaff7d8a473e7e2e6d317b87ba" + - "fe8bde97e3cf8f065dec022b51d11fcdd0d3" + - "48ac4")), - newAddressPubKey(decodeHex("0461cbdcc5409fb4b" + - "4d42b51d33381354d80e550078cb532a34bf" + - "a2fcfdeb7d76519aecc62770f5b0e4ef8551" + - "946d8a540911abe3e7854a26f39f58b25c15" + - "342af")), + newAddressPubKey(hexToBytes("04cc71eb30d653c0" + + "c3163990c47b976f3fb3f37cccdcbedb169a" + + "1dfef58bbfbfaff7d8a473e7e2e6d317b87b" + + "afe8bde97e3cf8f065dec022b51d11fcdd0d" + + "348ac4")), + newAddressPubKey(hexToBytes("0461cbdcc5409fb4" + + "b4d42b51d33381354d80e550078cb532a34b" + + "fa2fcfdeb7d76519aecc62770f5b0e4ef855" + + "1946d8a540911abe3e7854a26f39f58b25c1" + + "5342af")), }, reqSigs: 1, - class: txscript.MultiSigTy, + class: MultiSigTy, }, // from real tx d646f82bd5fbdb94a36872ce460f97662b80c3050ad3209bef9d1e398ea277ab, vin 1 { name: "standard 2 of 3 multisig", - script: decodeHex("524104cb9c3c222c5f7a7d3b9bd152f363" + - "a0b6d54c9eb312c4d4f9af1e8551b6c421a6a4ab0e29" + - "105f24de20ff463c1c91fcf3bf662cdde4783d4799f7" + - "87cb7c08869b4104ccc588420deeebea22a7e900cc8b" + - "68620d2212c374604e3487ca08f1ff3ae12bdc639514" + - "d0ec8612a2d3c519f084d9a00cbbe3b53d071e9b09e7" + - "1e610b036aa24104ab47ad1939edcb3db65f7fedea62" + - "bbf781c5410d3f22a7a3a56ffefb2238af8627363bdf" + - "2ed97c1f89784a1aecdb43384f11d2acc64443c7fc29" + - "9cef0400421a53ae"), + script: hexToBytes("524104cb9c3c222c5f7a7d3b9bd152f36" + + "3a0b6d54c9eb312c4d4f9af1e8551b6c421a6a4ab0e2" + + "9105f24de20ff463c1c91fcf3bf662cdde4783d4799f" + + "787cb7c08869b4104ccc588420deeebea22a7e900cc8" + + "b68620d2212c374604e3487ca08f1ff3ae12bdc63951" + + "4d0ec8612a2d3c519f084d9a00cbbe3b53d071e9b09e" + + "71e610b036aa24104ab47ad1939edcb3db65f7fedea6" + + "2bbf781c5410d3f22a7a3a56ffefb2238af8627363bd" + + "f2ed97c1f89784a1aecdb43384f11d2acc64443c7fc2" + + "99cef0400421a53ae"), addrs: []btcutil.Address{ - newAddressPubKey(decodeHex("04cb9c3c222c5f7a7" + - "d3b9bd152f363a0b6d54c9eb312c4d4f9af1" + - "e8551b6c421a6a4ab0e29105f24de20ff463" + - "c1c91fcf3bf662cdde4783d4799f787cb7c0" + - "8869b")), - newAddressPubKey(decodeHex("04ccc588420deeebe" + - "a22a7e900cc8b68620d2212c374604e3487c" + - "a08f1ff3ae12bdc639514d0ec8612a2d3c51" + - "9f084d9a00cbbe3b53d071e9b09e71e610b0" + - "36aa2")), - newAddressPubKey(decodeHex("04ab47ad1939edcb3" + - "db65f7fedea62bbf781c5410d3f22a7a3a56" + - "ffefb2238af8627363bdf2ed97c1f89784a1" + - "aecdb43384f11d2acc64443c7fc299cef040" + - "0421a")), + newAddressPubKey(hexToBytes("04cb9c3c222c5f7a" + + "7d3b9bd152f363a0b6d54c9eb312c4d4f9af" + + "1e8551b6c421a6a4ab0e29105f24de20ff46" + + "3c1c91fcf3bf662cdde4783d4799f787cb7c" + + "08869b")), + newAddressPubKey(hexToBytes("04ccc588420deeeb" + + "ea22a7e900cc8b68620d2212c374604e3487" + + "ca08f1ff3ae12bdc639514d0ec8612a2d3c5" + + "19f084d9a00cbbe3b53d071e9b09e71e610b" + + "036aa2")), + newAddressPubKey(hexToBytes("04ab47ad1939edcb" + + "3db65f7fedea62bbf781c5410d3f22a7a3a5" + + "6ffefb2238af8627363bdf2ed97c1f89784a" + + "1aecdb43384f11d2acc64443c7fc299cef04" + + "00421a")), }, reqSigs: 2, - class: txscript.MultiSigTy, + class: MultiSigTy, }, // The below are nonstandard script due to things such as @@ -270,23 +255,23 @@ func TestExtractPkScriptAddrs(t *testing.T) { { name: "p2pk with uncompressed pk missing OP_CHECKSIG", - script: decodeHex("410411db93e1dcdb8a016b49840f8c53bc" + - "1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb" + - "84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643" + - "f656b412a3"), + script: hexToBytes("410411db93e1dcdb8a016b49840f8c53b" + + "c1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddf" + + "b84ccf9744464f82e160bfa9b8b64f9d4c03f999b864" + + "3f656b412a3"), addrs: nil, reqSigs: 0, - class: txscript.NonStandardTy, + class: NonStandardTy, }, { name: "valid signature from a sigscript - no addresses", - script: decodeHex("47304402204e45e16932b8af514961a1d3" + - "a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220" + - "181522ec8eca07de4860a4acdd12909d831cc56cbbac" + - "4622082221a8768d1d0901"), + script: hexToBytes("47304402204e45e16932b8af514961a1d" + + "3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd41022" + + "0181522ec8eca07de4860a4acdd12909d831cc56cbba" + + "c4622082221a8768d1d0901"), addrs: nil, reqSigs: 0, - class: txscript.NonStandardTy, + class: NonStandardTy, }, // Note the technically the pubkey is the second item on the // stack, but since the address extraction intentionally only @@ -294,70 +279,70 @@ func TestExtractPkScriptAddrs(t *testing.T) { // addresses. { name: "valid sigscript to reedeem p2pk - no addresses", - script: decodeHex("493046022100ddc69738bf2336318e4e04" + - "1a5a77f305da87428ab1606f023260017854350ddc02" + - "2100817af09d2eec36862d16009852b7e3a0f6dd7659" + - "8290b7834e1453660367e07a014104cd4240c198e125" + - "23b6f9cb9f5bed06de1ba37e96a1bbd13745fcf9d11c" + - "25b1dff9a519675d198804ba9962d3eca2d5937d58e5" + - "a75a71042d40388a4d307f887d"), + script: hexToBytes("493046022100ddc69738bf2336318e4e0" + + "41a5a77f305da87428ab1606f023260017854350ddc0" + + "22100817af09d2eec36862d16009852b7e3a0f6dd765" + + "98290b7834e1453660367e07a014104cd4240c198e12" + + "523b6f9cb9f5bed06de1ba37e96a1bbd13745fcf9d11" + + "c25b1dff9a519675d198804ba9962d3eca2d5937d58e" + + "5a75a71042d40388a4d307f887d"), addrs: nil, reqSigs: 0, - class: txscript.NonStandardTy, + class: NonStandardTy, }, // from real tx 691dd277dc0e90a462a3d652a1171686de49cf19067cd33c7df0392833fb986a, vout 0 // invalid public keys { name: "1 of 3 multisig with invalid pubkeys", - script: decodeHex("51411c2200007353455857696b696c6561" + - "6b73204361626c6567617465204261636b75700a0a63" + - "61626c65676174652d3230313031323034313831312e" + - "377a0a0a446f41776e6c6f61642074686520666f6c6c" + - "6f77696e67207472616e73616374696f6e7320776974" + - "68205361746f736869204e616b616d6f746f27732064" + - "6f776e6c6f61416420746f6f6c2077686963680a6361" + - "6e20626520666f756e6420696e207472616e73616374" + - "696f6e20366335336364393837313139656637393764" + - "35616463636453ae"), + script: hexToBytes("51411c2200007353455857696b696c656" + + "16b73204361626c6567617465204261636b75700a0a6" + + "361626c65676174652d3230313031323034313831312" + + "e377a0a0a446f41776e6c6f61642074686520666f6c6" + + "c6f77696e67207472616e73616374696f6e732077697" + + "468205361746f736869204e616b616d6f746f2773206" + + "46f776e6c6f61416420746f6f6c2077686963680a636" + + "16e20626520666f756e6420696e207472616e7361637" + + "4696f6e2036633533636439383731313965663739376" + + "435616463636453ae"), addrs: []btcutil.Address{}, reqSigs: 1, - class: txscript.MultiSigTy, + class: MultiSigTy, }, // from real tx: 691dd277dc0e90a462a3d652a1171686de49cf19067cd33c7df0392833fb986a, vout 44 // invalid public keys { name: "1 of 3 multisig with invalid pubkeys 2", - script: decodeHex("5141346333656332353963373464616365" + - "36666430383862343463656638630a63363662633139" + - "39366338623934613338313162333635363138666531" + - "65396231623541366361636365393933613339383861" + - "34363966636336643664616266640a32363633636661" + - "39636634633033633630396335393363336539316665" + - "64653730323921313233646434326432353633396433" + - "38613663663530616234636434340a00000053ae"), + script: hexToBytes("514134633365633235396337346461636" + + "536666430383862343463656638630a6336366263313" + + "93936633862393461333831316233363536313866653" + + "16539623162354136636163636539393361333938386" + + "134363966636336643664616266640a3236363363666" + + "13963663463303363363039633539336333653931666" + + "56465373032392131323364643432643235363339643" + + "338613663663530616234636434340a00000053ae"), addrs: []btcutil.Address{}, reqSigs: 1, - class: txscript.MultiSigTy, + class: MultiSigTy, }, { name: "empty script", script: []byte{}, addrs: nil, reqSigs: 0, - class: txscript.NonStandardTy, + class: NonStandardTy, }, { name: "script that does not parse", - script: []byte{txscript.OP_DATA_45}, + script: []byte{OP_DATA_45}, addrs: nil, reqSigs: 0, - class: txscript.NonStandardTy, + class: NonStandardTy, }, } t.Logf("Running %d tests.", len(tests)) for i, test := range tests { - class, addrs, reqSigs, err := txscript.ExtractPkScriptAddrs( + class, addrs, reqSigs, err := ExtractPkScriptAddrs( test.script, &chaincfg.MainNetParams) if err != nil { } @@ -395,7 +380,7 @@ func TestCalcScriptInfo(t *testing.T) { sigScript string pkScript string bip16 bool - scriptInfo txscript.ScriptInfo + scriptInfo ScriptInfo scriptInfoErr error }{ { @@ -407,7 +392,7 @@ func TestCalcScriptInfo(t *testing.T) { pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" + "3152205ec4f59c", bip16: true, - scriptInfoErr: txscript.ErrStackShortScript, + scriptInfoErr: ErrStackShortScript, }, { name: "sigScript doesn't parse", @@ -417,7 +402,7 @@ func TestCalcScriptInfo(t *testing.T) { pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" + "3152205ec4f59c74 EQUAL", bip16: true, - scriptInfoErr: txscript.ErrStackShortScript, + scriptInfoErr: ErrStackShortScript, }, { // Invented scripts, the hashes do not match @@ -428,8 +413,8 @@ func TestCalcScriptInfo(t *testing.T) { pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" + "3152205ec4f59c74 EQUAL", bip16: true, - scriptInfo: txscript.ScriptInfo{ - PkScriptClass: txscript.ScriptHashTy, + scriptInfo: ScriptInfo{ + PkScriptClass: ScriptHashTy, NumInputs: 3, ExpectedInputs: 3, // nonstandard p2sh. SigOps: 1, @@ -444,8 +429,8 @@ func TestCalcScriptInfo(t *testing.T) { pkScript: "HASH160 DATA_20 0xfe441065b6532231de2fac56" + "3152205ec4f59c74 EQUAL", bip16: true, - scriptInfo: txscript.ScriptInfo{ - PkScriptClass: txscript.ScriptHashTy, + scriptInfo: ScriptInfo{ + PkScriptClass: ScriptHashTy, NumInputs: 3, ExpectedInputs: -1, // nonstandard p2sh. SigOps: 0, @@ -464,8 +449,8 @@ func TestCalcScriptInfo(t *testing.T) { "5060708090a0b0c0d0e0f101112131415161718191a1" + "b1c1d1e1f2021 3 CHECKMULTISIG", bip16: true, - scriptInfo: txscript.ScriptInfo{ - PkScriptClass: txscript.MultiSigTy, + scriptInfo: ScriptInfo{ + PkScriptClass: MultiSigTy, NumInputs: 4, ExpectedInputs: 4, SigOps: 3, @@ -476,7 +461,7 @@ func TestCalcScriptInfo(t *testing.T) { for _, test := range tests { sigScript := mustParseShortForm(test.sigScript) pkScript := mustParseShortForm(test.pkScript) - si, err := txscript.CalcScriptInfo(sigScript, pkScript, + si, err := CalcScriptInfo(sigScript, pkScript, test.bip16) if err != nil { if err != test.scriptInfoErr { @@ -533,8 +518,8 @@ func TestPayToAddrScript(t *testing.T) { t.Parallel() // 1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX - p2pkhMain, err := btcutil.NewAddressPubKeyHash(decodeHex("e34cce70c863"+ - "73273efcc54ce7d2a491bb4a0e84"), &chaincfg.MainNetParams) + p2pkhMain, err := btcutil.NewAddressPubKeyHash(hexToBytes("e34cce70c86"+ + "373273efcc54ce7d2a491bb4a0e84"), &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create public key hash address: %v", err) return @@ -542,7 +527,7 @@ func TestPayToAddrScript(t *testing.T) { // Taken from transaction: // b0539a45de13b3e0403909b8bd1a555b8cbe45fd4e3f3fda76f3a5f52835c29d - p2shMain, _ := btcutil.NewAddressScriptHashFromHash(decodeHex("e8c300"+ + p2shMain, _ := btcutil.NewAddressScriptHashFromHash(hexToBytes("e8c300"+ "c87986efa84c37c0519929019ef86eb5b4"), &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create script hash address: %v", err) @@ -550,16 +535,16 @@ func TestPayToAddrScript(t *testing.T) { } // mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg - p2pkCompressedMain, err := btcutil.NewAddressPubKey(decodeHex("02192d74"+ - "d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"), + p2pkCompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("02192d"+ + "74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"), &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (compressed): %v", err) return } - p2pkCompressed2Main, err := btcutil.NewAddressPubKey(decodeHex("03b0bd"+ - "634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"), + p2pkCompressed2Main, err := btcutil.NewAddressPubKey(hexToBytes("03b0b"+ + "d634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"), &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (compressed 2): %v", @@ -567,10 +552,10 @@ func TestPayToAddrScript(t *testing.T) { return } - p2pkUncompressedMain, err := btcutil.NewAddressPubKey(decodeHex("0411db"+ - "93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2"+ - "e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3"), - &chaincfg.MainNetParams) + p2pkUncompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("0411"+ + "db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5"+ + "cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b4"+ + "12a3"), &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (uncompressed): %v", err) @@ -621,17 +606,17 @@ func TestPayToAddrScript(t *testing.T) { }, // Supported address types with nil pointers. - {(*btcutil.AddressPubKeyHash)(nil), "", txscript.ErrUnsupportedAddress}, - {(*btcutil.AddressScriptHash)(nil), "", txscript.ErrUnsupportedAddress}, - {(*btcutil.AddressPubKey)(nil), "", txscript.ErrUnsupportedAddress}, + {(*btcutil.AddressPubKeyHash)(nil), "", ErrUnsupportedAddress}, + {(*btcutil.AddressScriptHash)(nil), "", ErrUnsupportedAddress}, + {(*btcutil.AddressPubKey)(nil), "", ErrUnsupportedAddress}, // Unsupported address type. - {&bogusAddress{}, "", txscript.ErrUnsupportedAddress}, + {&bogusAddress{}, "", ErrUnsupportedAddress}, } t.Logf("Running %d tests", len(tests)) for i, test := range tests { - pkScript, err := txscript.PayToAddrScript(test.in) + pkScript, err := PayToAddrScript(test.in) if err != test.err { t.Errorf("PayToAddrScript #%d unexpected error - "+ "got %v, want %v", i, err, test.err) @@ -653,16 +638,16 @@ func TestMultiSigScript(t *testing.T) { t.Parallel() // mainnet p2pk 13CG6SJ3yHUXo4Cr2RY4THLLJrNFuG3gUg - p2pkCompressedMain, err := btcutil.NewAddressPubKey(decodeHex("02192d7"+ - "4d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"), + p2pkCompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("02192d"+ + "74d0cb94344c9569c2e77901573d8d7903c3ebec3a957724895dca52c6b4"), &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (compressed): %v", err) return } - p2pkCompressed2Main, err := btcutil.NewAddressPubKey(decodeHex("03b0bd"+ - "634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"), + p2pkCompressed2Main, err := btcutil.NewAddressPubKey(hexToBytes("03b0b"+ + "d634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e65"), &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (compressed 2): %v", @@ -670,10 +655,10 @@ func TestMultiSigScript(t *testing.T) { return } - p2pkUncompressedMain, err := btcutil.NewAddressPubKey(decodeHex("0411d"+ - "b93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5c"+ - "b2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b41"+ - "2a3"), &chaincfg.MainNetParams) + p2pkUncompressedMain, err := btcutil.NewAddressPubKey(hexToBytes("0411"+ + "db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5"+ + "cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b4"+ + "12a3"), &chaincfg.MainNetParams) if err != nil { t.Errorf("Unable to create pubkey address (uncompressed): %v", err) @@ -717,7 +702,7 @@ func TestMultiSigScript(t *testing.T) { }, 3, "", - txscript.ErrBadNumRequired, + ErrBadNumRequired, }, { []*btcutil.AddressPubKey{ @@ -736,14 +721,13 @@ func TestMultiSigScript(t *testing.T) { }, 2, "", - txscript.ErrBadNumRequired, + ErrBadNumRequired, }, } t.Logf("Running %d tests", len(tests)) for i, test := range tests { - script, err := txscript.MultiSigScript(test.keys, - test.nrequired) + script, err := MultiSigScript(test.keys, test.nrequired) if err != test.err { t.Errorf("MultiSigScript #%d unexpected error - "+ "got %v, want %v", i, err, test.err) @@ -773,14 +757,14 @@ func TestCalcMultiSigStats(t *testing.T) { name: "short script", script: "0x046708afdb0fe5548271967f1a67130b7105cd6a828" + "e03909a67962e0ea1f61d", - err: txscript.ErrStackShortScript, + err: ErrStackShortScript, }, { name: "stack underflow", script: "RETURN DATA_41 0x046708afdb0fe5548271967f1a" + "67130b7105cd6a828e03909a67962e0ea1f61deb649f6" + "bc3f4cef308", - err: txscript.ErrStackUnderflow, + err: ErrStackUnderflow, }, { name: "multisig script", @@ -796,7 +780,7 @@ func TestCalcMultiSigStats(t *testing.T) { for i, test := range tests { script := mustParseShortForm(test.script) - if _, _, err := txscript.CalcMultiSigStats(script); err != test.err { + if _, _, err := CalcMultiSigStats(script); err != test.err { t.Errorf("CalcMultiSigStats #%d (%s) unexpected "+ "error\ngot: %v\nwant: %v", i, test.name, err, test.err) @@ -811,21 +795,21 @@ func TestCalcMultiSigStats(t *testing.T) { var scriptClassTests = []struct { name string script string - class txscript.ScriptClass + class ScriptClass }{ { name: "Pay Pubkey", script: "DATA_65 0x0411db93e1dcdb8a016b49840f8c53bc1eb68a382e" + "97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e16" + "0bfa9b8b64f9d4c03f999b8643f656b412a3 CHECKSIG", - class: txscript.PubKeyTy, + class: PubKeyTy, }, // tx 599e47a8114fe098103663029548811d2651991b62397e057f0c863c2bc9f9ea { name: "Pay PubkeyHash", script: "DUP HASH160 DATA_20 0x660d4ef3a743e3e696ad990364e555" + "c271ad504b EQUALVERIFY CHECKSIG", - class: txscript.PubKeyHashTy, + class: PubKeyHashTy, }, // part of tx 6d36bc17e947ce00bb6f12f8e7a56a1585c5a36188ffa2b05e10b4743273a74b // codeseparator parts have been elided. (bitcoin core's checks for @@ -834,45 +818,45 @@ var scriptClassTests = []struct { name: "multisig", script: "1 DATA_33 0x0232abdc893e7f0631364d7fd01cb33d24da4" + "5329a00357b3a7886211ab414d55a 1 CHECKMULTISIG", - class: txscript.MultiSigTy, + class: MultiSigTy, }, // tx e5779b9e78f9650debc2893fd9636d827b26b4ddfa6a8172fe8708c924f5c39d { name: "P2SH", script: "HASH160 DATA_20 0x433ec2ac1ffa1b7b7d027f564529c57197f" + "9ae88 EQUAL", - class: txscript.ScriptHashTy, + class: ScriptHashTy, }, { // Nulldata with no data at all. name: "nulldata no data", script: "RETURN", - class: txscript.NullDataTy, + class: NullDataTy, }, { // Nulldata with single zero push. name: "nulldata zero", script: "RETURN 0", - class: txscript.NullDataTy, + class: NullDataTy, }, { // Nulldata with small integer push. name: "nulldata small int", script: "RETURN 1", - class: txscript.NullDataTy, + class: NullDataTy, }, { // Nulldata with max small integer push. name: "nulldata max small int", script: "RETURN 16", - class: txscript.NullDataTy, + class: NullDataTy, }, { // Nulldata with small data push. name: "nulldata small data", script: "RETURN DATA_8 0x046708afdb0fe554", - class: txscript.NullDataTy, + class: NullDataTy, }, { // Canonical nulldata with 60-byte data push. @@ -880,7 +864,7 @@ var scriptClassTests = []struct { script: "RETURN 0x3c 0x046708afdb0fe5548271967f1a67130b7105cd" + "6a828e03909a67962e0ea1f61deb649f6bc3f4cef3046708afdb" + "0fe5548271967f1a67130b7105cd6a", - class: txscript.NullDataTy, + class: NullDataTy, }, { // Non-canonical nulldata with 60-byte data push. @@ -888,7 +872,7 @@ var scriptClassTests = []struct { script: "RETURN PUSHDATA1 0x3c 0x046708afdb0fe5548271967f1a67" + "130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3" + "046708afdb0fe5548271967f1a67130b7105cd6a", - class: txscript.NullDataTy, + class: NullDataTy, }, { // Nulldata with max allowed data to be considered standard. @@ -897,7 +881,7 @@ var scriptClassTests = []struct { "130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3" + "046708afdb0fe5548271967f1a67130b7105cd6a828e03909a67" + "962e0ea1f61deb649f6bc3f4cef3", - class: txscript.NullDataTy, + class: NullDataTy, }, { // Nulldata with more than max allowed data to be considered @@ -907,14 +891,14 @@ var scriptClassTests = []struct { "130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3" + "046708afdb0fe5548271967f1a67130b7105cd6a828e03909a67" + "962e0ea1f61deb649f6bc3f4cef308", - class: txscript.NonStandardTy, + class: NonStandardTy, }, { // Almost nulldata, but add an additional opcode after the data // to make it nonstandard. name: "almost nulldata", script: "RETURN 4 TRUE", - class: txscript.NonStandardTy, + class: NonStandardTy, }, // The next few are almost multisig (it is the more complex script type) @@ -924,13 +908,13 @@ var scriptClassTests = []struct { name: "strange 1", script: "DUP DATA_33 0x0232abdc893e7f0631364d7fd01cb33d24da45" + "329a00357b3a7886211ab414d55a 1 CHECKMULTISIG", - class: txscript.NonStandardTy, + class: NonStandardTy, }, { // Multisig but invalid pubkey. name: "strange 2", script: "1 1 1 CHECKMULTISIG", - class: txscript.NonStandardTy, + class: NonStandardTy, }, { // Multisig but no matching npubkeys opcode. @@ -939,25 +923,25 @@ var scriptClassTests = []struct { "9a00357b3a7886211ab414d55a DATA_33 0x0232abdc893e7f0" + "631364d7fd01cb33d24da45329a00357b3a7886211ab414d55a " + "CHECKMULTISIG", - class: txscript.NonStandardTy, + class: NonStandardTy, }, { // Multisig but with multisigverify. name: "strange 4", script: "1 DATA_33 0x0232abdc893e7f0631364d7fd01cb33d24da4532" + "9a00357b3a7886211ab414d55a 1 CHECKMULTISIGVERIFY", - class: txscript.NonStandardTy, + class: NonStandardTy, }, { // Multisig but wrong length. name: "strange 5", script: "1 CHECKMULTISIG", - class: txscript.NonStandardTy, + class: NonStandardTy, }, { name: "doesn't parse", script: "DATA_5 0x01020304", - class: txscript.NonStandardTy, + class: NonStandardTy, }, { name: "multisig script with wrong number of pubkeys", @@ -969,7 +953,7 @@ var scriptClassTests = []struct { "0x02c08f3de8ee2de9be7bd770f4c10eb0" + "d6ff1dd81ee96eedd3a9d4aeaf86695e80 " + "3 CHECKMULTISIG", - class: txscript.NonStandardTy, + class: NonStandardTy, }, } @@ -980,7 +964,7 @@ func TestScriptClass(t *testing.T) { for _, test := range scriptClassTests { script := mustParseShortForm(test.script) - class := txscript.GetScriptClass(script) + class := GetScriptClass(script) if class != test.class { t.Errorf("%s: expected %s got %s (script %x)", test.name, test.class, class, script) @@ -996,42 +980,42 @@ func TestStringifyClass(t *testing.T) { tests := []struct { name string - class txscript.ScriptClass + class ScriptClass stringed string }{ { name: "nonstandardty", - class: txscript.NonStandardTy, + class: NonStandardTy, stringed: "nonstandard", }, { name: "pubkey", - class: txscript.PubKeyTy, + class: PubKeyTy, stringed: "pubkey", }, { name: "pubkeyhash", - class: txscript.PubKeyHashTy, + class: PubKeyHashTy, stringed: "pubkeyhash", }, { name: "scripthash", - class: txscript.ScriptHashTy, + class: ScriptHashTy, stringed: "scripthash", }, { name: "multisigty", - class: txscript.MultiSigTy, + class: MultiSigTy, stringed: "multisig", }, { name: "nulldataty", - class: txscript.NullDataTy, + class: NullDataTy, stringed: "nulldata", }, { name: "broken", - class: txscript.ScriptClass(255), + class: ScriptClass(255), stringed: "Invalid", }, }