Import btcscript repo into txscript directory.
This commit contains the entire btcscript repository along with several changes needed to move all of the files into the txscript directory in order to prepare it for merging. This does NOT update btcd or any of the other packages to use the new location as that will be done separately. - All import paths in the old btcscript test files have been changed to the new location - All references to btcscript as the package name have been chagned to txscript This is ongoing work toward #214.
This commit is contained in:
parent
115cea2109
commit
cbda064842
26 changed files with 2242 additions and 2498 deletions
28
.gitignore
vendored
28
.gitignore
vendored
|
@ -1,28 +0,0 @@
|
||||||
# Temp files
|
|
||||||
*~
|
|
||||||
|
|
||||||
# Log files
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
|
||||||
*.o
|
|
||||||
*.a
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Folders
|
|
||||||
_obj
|
|
||||||
_test
|
|
||||||
|
|
||||||
# Architecture specific extensions/prefixes
|
|
||||||
*.[568vq]
|
|
||||||
[568vq].out
|
|
||||||
|
|
||||||
*.cgo1.go
|
|
||||||
*.cgo2.c
|
|
||||||
_cgo_defun.c
|
|
||||||
_cgo_gotypes.go
|
|
||||||
_cgo_export.*
|
|
||||||
|
|
||||||
_testmain.go
|
|
||||||
|
|
||||||
*.exe
|
|
|
@ -1,3 +0,0 @@
|
||||||
language: go
|
|
||||||
go: release
|
|
||||||
install: go get -d -t -v ./...
|
|
13
LICENSE
13
LICENSE
|
@ -1,13 +0,0 @@
|
||||||
Copyright (c) 2013-2014 Conformal Systems LLC.
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
@ -1,17 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# This script uses gocov to generate a test coverage report.
|
|
||||||
# The gocov tool my be obtained with the following command:
|
|
||||||
# go get github.com/axw/gocov/gocov
|
|
||||||
#
|
|
||||||
# It will be installed to $GOPATH/bin, so ensure that location is in your $PATH.
|
|
||||||
|
|
||||||
# Check for gocov.
|
|
||||||
type gocov >/dev/null 2>&1
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo >&2 "This script requires the gocov tool."
|
|
||||||
echo >&2 "You may obtain it with the following command:"
|
|
||||||
echo >&2 "go get github.com/axw/gocov/gocov"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
gocov test | gocov report
|
|
|
@ -1,186 +0,0 @@
|
||||||
|
|
||||||
github.com/btcsuite/btcscript/script.go calcScriptHash 100.00% (39/39)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.Step 100.00% (37/37)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeCheckSig 100.00% (29/29)
|
|
||||||
github.com/btcsuite/btcscript/script.go parseScriptTemplate 100.00% (29/29)
|
|
||||||
github.com/btcsuite/btcscript/script.go NewScript 100.00% (29/29)
|
|
||||||
github.com/btcsuite/btcscript/address.go ExtractPkScriptAddrs 100.00% (27/27)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ScriptBuilder.addData 100.00% (25/25)
|
|
||||||
github.com/btcsuite/btcscript/script.go CalcScriptInfo 100.00% (25/25)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go parsedOpcode.bytes 100.00% (23/23)
|
|
||||||
github.com/btcsuite/btcscript/stack.go asInt 100.00% (23/23)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go parsedOpcode.disabled 100.00% (17/17)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go parsedOpcode.print 100.00% (16/16)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.nipN 100.00% (15/15)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go canonicalDataSize 100.00% (14/14)
|
|
||||||
github.com/btcsuite/btcscript/stack.go fromInt 100.00% (14/14)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ScriptBuilder.AddUint64 100.00% (13/13)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ScriptBuilder.AddData 100.00% (13/13)
|
|
||||||
github.com/btcsuite/btcscript/script.go isMultiSig 100.00% (13/13)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeWithin 100.00% (13/13)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ScriptBuilder.AddInt64 100.00% (13/13)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go parsedOpcode.exec 100.00% (13/13)
|
|
||||||
github.com/btcsuite/btcscript/script.go GetPreciseSigOpCount 100.00% (13/13)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeIf 100.00% (11/11)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeNotIf 100.00% (11/11)
|
|
||||||
github.com/btcsuite/btcscript/script.go PayToAddrScript 100.00% (11/11)
|
|
||||||
github.com/btcsuite/btcscript/script.go typeOfScript 100.00% (11/11)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeMax 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeLessThan 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeBoolAnd 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/log.go SetLogWriter 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeGreaterThanOrEqual 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeMin 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeBoolOr 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeLessThanOrEqual 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.Tuck 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/script.go getSigOpCount 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/script.go PushedData 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeNumEqual 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeNumNotEqual 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeGreaterThan 100.00% (10/10)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.RotN 100.00% (9/9)
|
|
||||||
github.com/btcsuite/btcscript/script.go SignatureScript 100.00% (9/9)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.OverN 100.00% (9/9)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.SwapN 100.00% (9/9)
|
|
||||||
github.com/btcsuite/btcscript/script.go DisasmString 100.00% (9/9)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.CheckErrorCondition 100.00% (9/9)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.Execute 100.00% (8/8)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.DupN 100.00% (8/8)
|
|
||||||
github.com/btcsuite/btcscript/script.go CalcMultiSigStats 100.00% (8/8)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ScriptBuilder.AddOp 100.00% (8/8)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeAdd 100.00% (8/8)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeSub 100.00% (8/8)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeEqual 100.00% (8/8)
|
|
||||||
github.com/btcsuite/btcscript/script.go MultiSigScript 100.00% (8/8)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode0NotEqual 100.00% (7/7)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeNot 100.00% (7/7)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.DropN 100.00% (7/7)
|
|
||||||
github.com/btcsuite/btcscript/script.go HasCanonicalPushes 100.00% (7/7)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeVerify 100.00% (6/6)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeIfDup 100.00% (6/6)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go parsedOpcode.conditional 100.00% (6/6)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeElse 100.00% (6/6)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeEndif 100.00% (6/6)
|
|
||||||
github.com/btcsuite/btcscript/script.go removeOpcode 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeToAltStack 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeFromAltStack 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodePick 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeRoll 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeSize 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode1Add 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode1Sub 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeNegate 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeAbs 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeRipemd160 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeSha1 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeSha256 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeHash160 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeHash256 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.validPC 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.DisasmScript 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/script.go removeOpcodeByData 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PickN 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.RollN 100.00% (5/5)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeCheckMultiSigVerify 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go IsPayToScriptHash 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go isNullData 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go IsPushOnlyScript 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeNumEqualVerify 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go GetScriptClass 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeEqualVerify 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.DisasmPC 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go isPushOnly 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go @1346:17 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go getStack 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.curPC 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeNop 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/stack.go asBool 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PopInt 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PopBool 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PeekByteArray 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PeekInt 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PeekBool 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go parsedOpcode.alwaysIllegal 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeCheckSigVerify 100.00% (4/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go asSmallInt 100.00% (3/3)
|
|
||||||
github.com/btcsuite/btcscript/script.go ScriptClass.String 100.00% (3/3)
|
|
||||||
github.com/btcsuite/btcscript/stack.go fromBool 100.00% (3/3)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ScriptBuilder.Reset 100.00% (3/3)
|
|
||||||
github.com/btcsuite/btcscript/script.go isSmallInt 100.00% (3/3)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ScriptBuilder.AddFullData 100.00% (3/3)
|
|
||||||
github.com/btcsuite/btcscript/script.go setStack 100.00% (3/3)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeN 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.Depth 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go calcHash 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode1Negate 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeCodeSeparator 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.NipN 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/script.go GetSigOpCount 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeFalse 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeDepth 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodePushData 100.00% (2/2)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode2Rot 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode2Over 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode3Dup 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go init 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go KeyClosure.GetKey 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go ScriptClosure.GetScript 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode2Dup 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeOver 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeNip 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/log.go DisableLog 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/log.go init 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.disasm 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.subScript 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode2Drop 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeDup 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeDrop 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.GetStack 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.SetStack 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.GetAltStack 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go Script.SetAltStack 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcode2Swap 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go payToPubKeyHashScript 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go payToScriptHashScript 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go payToPubKeyScript 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeInvalid 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ScriptBuilder.Script 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go NewScriptBuilder 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeReserved 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/log.go newLogClosure 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PushByteArray 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go isPubkeyHash 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go isScriptHash 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PushInt 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go calcHash160 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PushBool 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.PopByteArray 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go isPubkey 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/log.go UseLogger 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/script.go parseScript 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeTuck 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeSwap 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeRot 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeReturn 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/scriptbuilder.go ErrScriptNotCanonical.Error 100.00% (1/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeCheckMultiSig 98.48% (65/66)
|
|
||||||
github.com/btcsuite/btcscript/script.go mergeScripts 95.24% (20/21)
|
|
||||||
github.com/btcsuite/btcscript/script.go signMultiSig 93.33% (14/15)
|
|
||||||
github.com/btcsuite/btcscript/script.go canonicalPush 92.86% (13/14)
|
|
||||||
github.com/btcsuite/btcscript/script.go mergeMultiSig 88.37% (38/43)
|
|
||||||
github.com/btcsuite/btcscript/script.go RawTxInSignature 87.50% (7/8)
|
|
||||||
github.com/btcsuite/btcscript/script.go expectedInputs 85.71% (6/7)
|
|
||||||
github.com/btcsuite/btcscript/script.go unparseScript 85.71% (6/7)
|
|
||||||
github.com/btcsuite/btcscript/script.go SignTxOutput 80.00% (12/15)
|
|
||||||
github.com/btcsuite/btcscript/script.go p2pkSignatureScript 75.00% (3/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go sign 69.23% (18/26)
|
|
||||||
github.com/btcsuite/btcscript/script.go @606:34 0.00% (0/6)
|
|
||||||
github.com/btcsuite/btcscript/script.go @594:34 0.00% (0/4)
|
|
||||||
github.com/btcsuite/btcscript/stack.go Stack.String 0.00% (0/4)
|
|
||||||
github.com/btcsuite/btcscript/script.go @639:34 0.00% (0/3)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go opcodeDisabled 0.00% (0/1)
|
|
||||||
github.com/btcsuite/btcscript/log.go logClosure.String 0.00% (0/1)
|
|
||||||
github.com/btcsuite/btcscript/opcode.go @1810:33 0.00% (0/1)
|
|
||||||
github.com/btcsuite/btcscript --------------------------- 96.69% (1284/1328)
|
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
btcscript
|
txscript
|
||||||
=========
|
========
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/btcsuite/btcscript.png?branch=master)]
|
[![Build Status](https://travis-ci.org/btcsuite/btcd.png?branch=master)]
|
||||||
(https://travis-ci.org/btcsuite/btcscript)
|
(https://travis-ci.org/btcsuite/btcd)
|
||||||
|
|
||||||
Package btcscript implements the bitcoin transaction scripts. There is
|
Package txscript implements the bitcoin transaction script language. There is
|
||||||
a comprehensive test suite. `test_coverage.txt` contains the current
|
a comprehensive test suite. Package txscript is licensed under the liberal ISC
|
||||||
coverage statistics (generated using gocov). On a UNIX-like OS, the
|
license.
|
||||||
script `cov_report.sh` can be used to generate the report. Package
|
|
||||||
btcscript is licensed under the liberal ISC license.
|
|
||||||
|
|
||||||
This package is one of the core packages from btcd, an alternative full-node
|
This package has intentionally been designed so it can be used as a standalone
|
||||||
implementation of bitcoin which is under active development by Conformal.
|
package for any projects needing to use or validate bitcoin transaction scripts.
|
||||||
Although it was primarily written for btcd, this package has intentionally been
|
|
||||||
designed so it can be used as a standalone package for any projects needing to
|
|
||||||
use or validate bitcoin transaction scripts.
|
|
||||||
|
|
||||||
## Bitcoin Scripts
|
## Bitcoin Scripts
|
||||||
|
|
||||||
|
@ -25,39 +20,35 @@ can be found at https://en.bitcoin.it/wiki/Script
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
[![GoDoc](https://godoc.org/github.com/btcsuite/btcscript?status.png)]
|
[![GoDoc](https://godoc.org/github.com/btcsuite/btcd/txscript?status.png)]
|
||||||
(http://godoc.org/github.com/btcsuite/btcscript)
|
(http://godoc.org/github.com/btcsuite/btcd/txscript)
|
||||||
|
|
||||||
Full `go doc` style documentation for the project can be viewed online without
|
Full `go doc` style documentation for the project can be viewed online without
|
||||||
installing this package by using the GoDoc site
|
installing this package by using the GoDoc site
|
||||||
[here](http://godoc.org/github.com/btcsuite/btcscript).
|
[here](http://godoc.org/github.com/btcsuite/btcd/txscript).
|
||||||
|
|
||||||
You can also view the documentation locally once the package is installed with
|
You can also view the documentation locally once the package is installed with
|
||||||
the `godoc` tool by running `godoc -http=":6060"` and pointing your browser to
|
the `godoc` tool by running `godoc -http=":6060"` and pointing your browser to
|
||||||
http://localhost:6060/pkg/github.com/btcsuite/btcscript
|
http://localhost:6060/pkg/github.com/btcsuite/btcd/txscript
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ go get github.com/btcsuite/btcscript
|
$ go get github.com/btcsuite/btcd/txscript
|
||||||
```
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
* [Standard Pay-to-pubkey-hash Script]
|
* [Standard Pay-to-pubkey-hash Script]
|
||||||
(http://godoc.org/github.com/btcsuite/btcscript#example-PayToAddrScript)
|
(http://godoc.org/github.com/btcsuite/btcd/txscript#example-PayToAddrScript)
|
||||||
Demonstrates creating a script which pays to a bitcoin address. It also
|
Demonstrates creating a script which pays to a bitcoin address. It also
|
||||||
prints the created script hex and uses the DisasmString function to display
|
prints the created script hex and uses the DisasmString function to display
|
||||||
the disassembled script.
|
the disassembled script.
|
||||||
|
|
||||||
* [Extracting Details from Standard Scripts]
|
* [Extracting Details from Standard Scripts]
|
||||||
(http://godoc.org/github.com/btcsuite/btcscript#example-ExtractPkScriptAddrs)
|
(http://godoc.org/github.com/btcsuite/btcd/txscript#example-ExtractPkScriptAddrs)
|
||||||
Demonstrates extracting information from a standard public key script.
|
Demonstrates extracting information from a standard public key script.
|
||||||
|
|
||||||
## TODO
|
|
||||||
|
|
||||||
- Increase test coverage to 100%
|
|
||||||
|
|
||||||
## GPG Verification Key
|
## GPG Verification Key
|
||||||
|
|
||||||
All official release tags are signed by Conformal so users can ensure the code
|
All official release tags are signed by Conformal so users can ensure the code
|
||||||
|
@ -80,4 +71,4 @@ signature perform the following:
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Package btcscript is licensed under the liberal ISC License.
|
Package txscript is licensed under the liberal ISC License.
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript
|
package txscript
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
|
@ -1,15 +1,15 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
package btcscript_test
|
package txscript_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcscript"
|
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
script []byte
|
script []byte
|
||||||
addrs []btcutil.Address
|
addrs []btcutil.Address
|
||||||
reqSigs int
|
reqSigs int
|
||||||
class btcscript.ScriptClass
|
class txscript.ScriptClass
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "standard p2pk with compressed pubkey (0x02)",
|
name: "standard p2pk with compressed pubkey (0x02)",
|
||||||
|
@ -87,7 +87,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"4895dca52c6b4")),
|
"4895dca52c6b4")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.PubKeyTy,
|
class: txscript.PubKeyTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "standard p2pk with uncompressed pubkey (0x04)",
|
name: "standard p2pk with uncompressed pubkey (0x04)",
|
||||||
|
@ -103,7 +103,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"412a3")),
|
"412a3")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.PubKeyTy,
|
class: txscript.PubKeyTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "standard p2pk with hybrid pubkey (0x06)",
|
name: "standard p2pk with hybrid pubkey (0x06)",
|
||||||
|
@ -119,7 +119,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"f453e")),
|
"f453e")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.PubKeyTy,
|
class: txscript.PubKeyTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "standard p2pk with compressed pubkey (0x03)",
|
name: "standard p2pk with compressed pubkey (0x03)",
|
||||||
|
@ -131,7 +131,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"409273eb16e65")),
|
"409273eb16e65")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.PubKeyTy,
|
class: txscript.PubKeyTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "2nd standard p2pk with uncompressed pubkey (0x04)",
|
name: "2nd standard p2pk with uncompressed pubkey (0x04)",
|
||||||
|
@ -147,7 +147,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"8ef7b")),
|
"8ef7b")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.PubKeyTy,
|
class: txscript.PubKeyTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "standard p2pk with hybrid pubkey (0x07)",
|
name: "standard p2pk with hybrid pubkey (0x07)",
|
||||||
|
@ -163,7 +163,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"8ef7b")),
|
"8ef7b")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.PubKeyTy,
|
class: txscript.PubKeyTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "standard p2pkh",
|
name: "standard p2pkh",
|
||||||
|
@ -174,7 +174,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"cbca9a9e3713bd7587509a30564")),
|
"cbca9a9e3713bd7587509a30564")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.PubKeyHashTy,
|
class: txscript.PubKeyHashTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "standard p2sh",
|
name: "standard p2sh",
|
||||||
|
@ -185,7 +185,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"ee0189dd5cc67f1b0e5f02f45cb")),
|
"ee0189dd5cc67f1b0e5f02f45cb")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.ScriptHashTy,
|
class: txscript.ScriptHashTy,
|
||||||
},
|
},
|
||||||
// from real tx 60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1, vout 0
|
// from real tx 60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1, vout 0
|
||||||
{
|
{
|
||||||
|
@ -210,7 +210,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"342af")),
|
"342af")),
|
||||||
},
|
},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.MultiSigTy,
|
class: txscript.MultiSigTy,
|
||||||
},
|
},
|
||||||
// from real tx d646f82bd5fbdb94a36872ce460f97662b80c3050ad3209bef9d1e398ea277ab, vin 1
|
// from real tx d646f82bd5fbdb94a36872ce460f97662b80c3050ad3209bef9d1e398ea277ab, vin 1
|
||||||
{
|
{
|
||||||
|
@ -243,7 +243,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"0421a")),
|
"0421a")),
|
||||||
},
|
},
|
||||||
reqSigs: 2,
|
reqSigs: 2,
|
||||||
class: btcscript.MultiSigTy,
|
class: txscript.MultiSigTy,
|
||||||
},
|
},
|
||||||
|
|
||||||
// The below are nonstandard script due to things such as
|
// The below are nonstandard script due to things such as
|
||||||
|
@ -258,7 +258,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"f656b412a3"),
|
"f656b412a3"),
|
||||||
addrs: nil,
|
addrs: nil,
|
||||||
reqSigs: 0,
|
reqSigs: 0,
|
||||||
class: btcscript.NonStandardTy,
|
class: txscript.NonStandardTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid signature from a sigscript - no addresses",
|
name: "valid signature from a sigscript - no addresses",
|
||||||
|
@ -268,7 +268,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"4622082221a8768d1d0901"),
|
"4622082221a8768d1d0901"),
|
||||||
addrs: nil,
|
addrs: nil,
|
||||||
reqSigs: 0,
|
reqSigs: 0,
|
||||||
class: btcscript.NonStandardTy,
|
class: txscript.NonStandardTy,
|
||||||
},
|
},
|
||||||
// Note the technically the pubkey is the second item on the
|
// Note the technically the pubkey is the second item on the
|
||||||
// stack, but since the address extraction intentionally only
|
// stack, but since the address extraction intentionally only
|
||||||
|
@ -285,7 +285,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"a75a71042d40388a4d307f887d"),
|
"a75a71042d40388a4d307f887d"),
|
||||||
addrs: nil,
|
addrs: nil,
|
||||||
reqSigs: 0,
|
reqSigs: 0,
|
||||||
class: btcscript.NonStandardTy,
|
class: txscript.NonStandardTy,
|
||||||
},
|
},
|
||||||
// from real tx 691dd277dc0e90a462a3d652a1171686de49cf19067cd33c7df0392833fb986a, vout 0
|
// from real tx 691dd277dc0e90a462a3d652a1171686de49cf19067cd33c7df0392833fb986a, vout 0
|
||||||
// invalid public keys
|
// invalid public keys
|
||||||
|
@ -303,7 +303,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"35616463636453ae"),
|
"35616463636453ae"),
|
||||||
addrs: []btcutil.Address{},
|
addrs: []btcutil.Address{},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.MultiSigTy,
|
class: txscript.MultiSigTy,
|
||||||
},
|
},
|
||||||
// from real tx: 691dd277dc0e90a462a3d652a1171686de49cf19067cd33c7df0392833fb986a, vout 44
|
// from real tx: 691dd277dc0e90a462a3d652a1171686de49cf19067cd33c7df0392833fb986a, vout 44
|
||||||
// invalid public keys
|
// invalid public keys
|
||||||
|
@ -319,27 +319,27 @@ func TestExtractPkScriptAddrs(t *testing.T) {
|
||||||
"38613663663530616234636434340a00000053ae"),
|
"38613663663530616234636434340a00000053ae"),
|
||||||
addrs: []btcutil.Address{},
|
addrs: []btcutil.Address{},
|
||||||
reqSigs: 1,
|
reqSigs: 1,
|
||||||
class: btcscript.MultiSigTy,
|
class: txscript.MultiSigTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "empty script",
|
name: "empty script",
|
||||||
script: []byte{},
|
script: []byte{},
|
||||||
addrs: nil,
|
addrs: nil,
|
||||||
reqSigs: 0,
|
reqSigs: 0,
|
||||||
class: btcscript.NonStandardTy,
|
class: txscript.NonStandardTy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "script that does not parse",
|
name: "script that does not parse",
|
||||||
script: []byte{btcscript.OP_DATA_45},
|
script: []byte{txscript.OP_DATA_45},
|
||||||
addrs: nil,
|
addrs: nil,
|
||||||
reqSigs: 0,
|
reqSigs: 0,
|
||||||
class: btcscript.NonStandardTy,
|
class: txscript.NonStandardTy,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Running %d tests.", len(tests))
|
t.Logf("Running %d tests.", len(tests))
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
class, addrs, reqSigs, err := btcscript.ExtractPkScriptAddrs(
|
class, addrs, reqSigs, err := txscript.ExtractPkScriptAddrs(
|
||||||
test.script, &btcnet.MainNetParams)
|
test.script, &btcnet.MainNetParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Package btcscript implements bitcoin transaction scripts.
|
Package txscript implements the bitcoin transaction script language.
|
||||||
|
|
||||||
A complete description of the script language used by bitcoin can be found at
|
A complete description of the script language used by bitcoin can be found at
|
||||||
https://en.bitcoin.it/wiki/Script. The following only serves as a quick
|
https://en.bitcoin.it/wiki/Script. The following only serves as a quick
|
||||||
|
@ -32,8 +32,8 @@ what conditions must be met in order to spend bitcoins.
|
||||||
|
|
||||||
Errors
|
Errors
|
||||||
|
|
||||||
Errors returned by this package are of the form btcscript.ErrStackX where X
|
Errors returned by this package are of the form txscript.ErrStackX where X
|
||||||
indicates the specific error. See Variables in the package documentation for a
|
indicates the specific error. See Variables in the package documentation for a
|
||||||
full list.
|
full list.
|
||||||
*/
|
*/
|
||||||
package btcscript
|
package txscript
|
|
@ -1,15 +1,15 @@
|
||||||
// Copyright (c) 2014 Conformal Systems LLC.
|
// Copyright (c) 2014-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript_test
|
package txscript_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcnet"
|
"github.com/btcsuite/btcnet"
|
||||||
"github.com/btcsuite/btcscript"
|
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,14 +29,14 @@ func ExamplePayToAddrScript() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a public key script that pays to the address.
|
// Create a public key script that pays to the address.
|
||||||
script, err := btcscript.PayToAddrScript(address)
|
script, err := txscript.PayToAddrScript(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("Script Hex: %x\n", script)
|
fmt.Printf("Script Hex: %x\n", script)
|
||||||
|
|
||||||
disasm, err := btcscript.DisasmString(script)
|
disasm, err := txscript.DisasmString(script)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -60,7 +60,7 @@ func ExampleExtractPkScriptAddrs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract and print details from the script.
|
// Extract and print details from the script.
|
||||||
scriptClass, addresses, reqSigs, err := btcscript.ExtractPkScriptAddrs(
|
scriptClass, addresses, reqSigs, err := txscript.ExtractPkScriptAddrs(
|
||||||
script, &btcnet.MainNetParams)
|
script, &btcnet.MainNetParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript
|
package txscript
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript
|
package txscript
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript_test
|
package txscript_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetLogWriter(t *testing.T) {
|
func TestSetLogWriter(t *testing.T) {
|
||||||
|
@ -48,7 +48,7 @@ func TestSetLogWriter(t *testing.T) {
|
||||||
|
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
err := btcscript.SetLogWriter(test.w, test.level)
|
err := txscript.SetLogWriter(test.w, test.level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() != test.expected.Error() {
|
if err.Error() != test.expected.Error() {
|
||||||
t.Errorf("SetLogWriter #%d (%s) wrong result\n"+
|
t.Errorf("SetLogWriter #%d (%s) wrong result\n"+
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript
|
package txscript
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -20,7 +20,7 @@ import (
|
||||||
"github.com/btcsuite/fastsha256"
|
"github.com/btcsuite/fastsha256"
|
||||||
)
|
)
|
||||||
|
|
||||||
// An opcode defines the information related to a btcscript opcode.
|
// An opcode defines the information related to a txscript opcode.
|
||||||
// opfunc if present is the function to call to perform the opcode on
|
// opfunc if present is the function to call to perform the opcode on
|
||||||
// the script. The current script is passed in as a slice with the firs
|
// the script. The current script is passed in as a slice with the firs
|
||||||
// member being the opcode itself.
|
// member being the opcode itself.
|
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript
|
package txscript
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -193,7 +193,7 @@ func (t ScriptClass) String() string {
|
||||||
return scriptClassToName[t]
|
return scriptClassToName[t]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Script is the virtual machine that executes btcscripts.
|
// Script is the virtual machine that executes scripts.
|
||||||
type Script struct {
|
type Script struct {
|
||||||
scripts [][]parsedOpcode
|
scripts [][]parsedOpcode
|
||||||
scriptidx int
|
scriptidx int
|
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript
|
package txscript
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
@ -38,10 +38,10 @@ func (e ErrScriptNotCanonical) Error() string {
|
||||||
// For example, the following would build a 2-of-3 multisig script for usage in
|
// For example, the following would build a 2-of-3 multisig script for usage in
|
||||||
// a pay-to-script-hash (although in this situation MultiSigScript() would be a
|
// a pay-to-script-hash (although in this situation MultiSigScript() would be a
|
||||||
// better choice to generate the script):
|
// better choice to generate the script):
|
||||||
// builder := btcscript.NewScriptBuilder()
|
// builder := txscript.NewScriptBuilder()
|
||||||
// builder.AddOp(btcscript.OP_2).AddData(pubKey1).AddData(pubKey2)
|
// builder.AddOp(txscript.OP_2).AddData(pubKey1).AddData(pubKey2)
|
||||||
// builder.AddData(pubKey3).AddOp(btcscript.OP_3)
|
// builder.AddData(pubKey3).AddOp(txscript.OP_3)
|
||||||
// builder.AddOp(btcscript.OP_CHECKMULTISIG)
|
// builder.AddOp(txscript.OP_CHECKMULTISIG)
|
||||||
// script, err := builder.Script()
|
// script, err := builder.Script()
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// // Handle the error.
|
// // Handle the error.
|
|
@ -1,14 +1,14 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript_test
|
package txscript_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestScriptBuilderAddOp tests that pushing opcodes to a script via the
|
// TestScriptBuilderAddOp tests that pushing opcodes to a script via the
|
||||||
|
@ -23,22 +23,22 @@ func TestScriptBuilderAddOp(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "push OP_0",
|
name: "push OP_0",
|
||||||
opcodes: []byte{btcscript.OP_0},
|
opcodes: []byte{txscript.OP_0},
|
||||||
expected: []byte{btcscript.OP_0},
|
expected: []byte{txscript.OP_0},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "push OP_1 OP_2",
|
name: "push OP_1 OP_2",
|
||||||
opcodes: []byte{btcscript.OP_1, btcscript.OP_2},
|
opcodes: []byte{txscript.OP_1, txscript.OP_2},
|
||||||
expected: []byte{btcscript.OP_1, btcscript.OP_2},
|
expected: []byte{txscript.OP_1, txscript.OP_2},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "push OP_HASH160 OP_EQUAL",
|
name: "push OP_HASH160 OP_EQUAL",
|
||||||
opcodes: []byte{btcscript.OP_HASH160, btcscript.OP_EQUAL},
|
opcodes: []byte{txscript.OP_HASH160, txscript.OP_EQUAL},
|
||||||
expected: []byte{btcscript.OP_HASH160, btcscript.OP_EQUAL},
|
expected: []byte{txscript.OP_HASH160, txscript.OP_EQUAL},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := btcscript.NewScriptBuilder()
|
builder := txscript.NewScriptBuilder()
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
builder.Reset()
|
builder.Reset()
|
||||||
|
@ -70,47 +70,47 @@ func TestScriptBuilderAddInt64(t *testing.T) {
|
||||||
val int64
|
val int64
|
||||||
expected []byte
|
expected []byte
|
||||||
}{
|
}{
|
||||||
{name: "push -1", val: -1, expected: []byte{btcscript.OP_1NEGATE}},
|
{name: "push -1", val: -1, expected: []byte{txscript.OP_1NEGATE}},
|
||||||
{name: "push small int 0", val: 0, expected: []byte{btcscript.OP_0}},
|
{name: "push small int 0", val: 0, expected: []byte{txscript.OP_0}},
|
||||||
{name: "push small int 1", val: 1, expected: []byte{btcscript.OP_1}},
|
{name: "push small int 1", val: 1, expected: []byte{txscript.OP_1}},
|
||||||
{name: "push small int 2", val: 2, expected: []byte{btcscript.OP_2}},
|
{name: "push small int 2", val: 2, expected: []byte{txscript.OP_2}},
|
||||||
{name: "push small int 3", val: 3, expected: []byte{btcscript.OP_3}},
|
{name: "push small int 3", val: 3, expected: []byte{txscript.OP_3}},
|
||||||
{name: "push small int 4", val: 4, expected: []byte{btcscript.OP_4}},
|
{name: "push small int 4", val: 4, expected: []byte{txscript.OP_4}},
|
||||||
{name: "push small int 5", val: 5, expected: []byte{btcscript.OP_5}},
|
{name: "push small int 5", val: 5, expected: []byte{txscript.OP_5}},
|
||||||
{name: "push small int 6", val: 6, expected: []byte{btcscript.OP_6}},
|
{name: "push small int 6", val: 6, expected: []byte{txscript.OP_6}},
|
||||||
{name: "push small int 7", val: 7, expected: []byte{btcscript.OP_7}},
|
{name: "push small int 7", val: 7, expected: []byte{txscript.OP_7}},
|
||||||
{name: "push small int 8", val: 8, expected: []byte{btcscript.OP_8}},
|
{name: "push small int 8", val: 8, expected: []byte{txscript.OP_8}},
|
||||||
{name: "push small int 9", val: 9, expected: []byte{btcscript.OP_9}},
|
{name: "push small int 9", val: 9, expected: []byte{txscript.OP_9}},
|
||||||
{name: "push small int 10", val: 10, expected: []byte{btcscript.OP_10}},
|
{name: "push small int 10", val: 10, expected: []byte{txscript.OP_10}},
|
||||||
{name: "push small int 11", val: 11, expected: []byte{btcscript.OP_11}},
|
{name: "push small int 11", val: 11, expected: []byte{txscript.OP_11}},
|
||||||
{name: "push small int 12", val: 12, expected: []byte{btcscript.OP_12}},
|
{name: "push small int 12", val: 12, expected: []byte{txscript.OP_12}},
|
||||||
{name: "push small int 13", val: 13, expected: []byte{btcscript.OP_13}},
|
{name: "push small int 13", val: 13, expected: []byte{txscript.OP_13}},
|
||||||
{name: "push small int 14", val: 14, expected: []byte{btcscript.OP_14}},
|
{name: "push small int 14", val: 14, expected: []byte{txscript.OP_14}},
|
||||||
{name: "push small int 15", val: 15, expected: []byte{btcscript.OP_15}},
|
{name: "push small int 15", val: 15, expected: []byte{txscript.OP_15}},
|
||||||
{name: "push small int 16", val: 16, expected: []byte{btcscript.OP_16}},
|
{name: "push small int 16", val: 16, expected: []byte{txscript.OP_16}},
|
||||||
{name: "push 17", val: 17, expected: []byte{btcscript.OP_DATA_1, 0x11}},
|
{name: "push 17", val: 17, expected: []byte{txscript.OP_DATA_1, 0x11}},
|
||||||
{name: "push 65", val: 65, expected: []byte{btcscript.OP_DATA_1, 0x41}},
|
{name: "push 65", val: 65, expected: []byte{txscript.OP_DATA_1, 0x41}},
|
||||||
{name: "push 127", val: 127, expected: []byte{btcscript.OP_DATA_1, 0x7f}},
|
{name: "push 127", val: 127, expected: []byte{txscript.OP_DATA_1, 0x7f}},
|
||||||
{name: "push 128", val: 128, expected: []byte{btcscript.OP_DATA_2, 0x80, 0}},
|
{name: "push 128", val: 128, expected: []byte{txscript.OP_DATA_2, 0x80, 0}},
|
||||||
{name: "push 255", val: 255, expected: []byte{btcscript.OP_DATA_2, 0xff, 0}},
|
{name: "push 255", val: 255, expected: []byte{txscript.OP_DATA_2, 0xff, 0}},
|
||||||
{name: "push 256", val: 256, expected: []byte{btcscript.OP_DATA_2, 0, 0x01}},
|
{name: "push 256", val: 256, expected: []byte{txscript.OP_DATA_2, 0, 0x01}},
|
||||||
{name: "push 32767", val: 32767, expected: []byte{btcscript.OP_DATA_2, 0xff, 0x7f}},
|
{name: "push 32767", val: 32767, expected: []byte{txscript.OP_DATA_2, 0xff, 0x7f}},
|
||||||
{name: "push 32768", val: 32768, expected: []byte{btcscript.OP_DATA_3, 0, 0x80, 0}},
|
{name: "push 32768", val: 32768, expected: []byte{txscript.OP_DATA_3, 0, 0x80, 0}},
|
||||||
{name: "push -2", val: -2, expected: []byte{btcscript.OP_DATA_1, 0x82}},
|
{name: "push -2", val: -2, expected: []byte{txscript.OP_DATA_1, 0x82}},
|
||||||
{name: "push -3", val: -3, expected: []byte{btcscript.OP_DATA_1, 0x83}},
|
{name: "push -3", val: -3, expected: []byte{txscript.OP_DATA_1, 0x83}},
|
||||||
{name: "push -4", val: -4, expected: []byte{btcscript.OP_DATA_1, 0x84}},
|
{name: "push -4", val: -4, expected: []byte{txscript.OP_DATA_1, 0x84}},
|
||||||
{name: "push -5", val: -5, expected: []byte{btcscript.OP_DATA_1, 0x85}},
|
{name: "push -5", val: -5, expected: []byte{txscript.OP_DATA_1, 0x85}},
|
||||||
{name: "push -17", val: -17, expected: []byte{btcscript.OP_DATA_1, 0x91}},
|
{name: "push -17", val: -17, expected: []byte{txscript.OP_DATA_1, 0x91}},
|
||||||
{name: "push -65", val: -65, expected: []byte{btcscript.OP_DATA_1, 0xc1}},
|
{name: "push -65", val: -65, expected: []byte{txscript.OP_DATA_1, 0xc1}},
|
||||||
{name: "push -127", val: -127, expected: []byte{btcscript.OP_DATA_1, 0xff}},
|
{name: "push -127", val: -127, expected: []byte{txscript.OP_DATA_1, 0xff}},
|
||||||
{name: "push -128", val: -128, expected: []byte{btcscript.OP_DATA_2, 0x80, 0x80}},
|
{name: "push -128", val: -128, expected: []byte{txscript.OP_DATA_2, 0x80, 0x80}},
|
||||||
{name: "push -255", val: -255, expected: []byte{btcscript.OP_DATA_2, 0xff, 0x80}},
|
{name: "push -255", val: -255, expected: []byte{txscript.OP_DATA_2, 0xff, 0x80}},
|
||||||
{name: "push -256", val: -256, expected: []byte{btcscript.OP_DATA_2, 0x00, 0x81}},
|
{name: "push -256", val: -256, expected: []byte{txscript.OP_DATA_2, 0x00, 0x81}},
|
||||||
{name: "push -32767", val: -32767, expected: []byte{btcscript.OP_DATA_2, 0xff, 0xff}},
|
{name: "push -32767", val: -32767, expected: []byte{txscript.OP_DATA_2, 0xff, 0xff}},
|
||||||
{name: "push -32768", val: -32768, expected: []byte{btcscript.OP_DATA_3, 0x00, 0x80, 0x80}},
|
{name: "push -32768", val: -32768, expected: []byte{txscript.OP_DATA_3, 0x00, 0x80, 0x80}},
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := btcscript.NewScriptBuilder()
|
builder := txscript.NewScriptBuilder()
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
builder.Reset().AddInt64(test.val)
|
builder.Reset().AddInt64(test.val)
|
||||||
|
@ -139,34 +139,34 @@ func TestScriptBuilderAddUint64(t *testing.T) {
|
||||||
val uint64
|
val uint64
|
||||||
expected []byte
|
expected []byte
|
||||||
}{
|
}{
|
||||||
{name: "push small int 0", val: 0, expected: []byte{btcscript.OP_0}},
|
{name: "push small int 0", val: 0, expected: []byte{txscript.OP_0}},
|
||||||
{name: "push small int 1", val: 1, expected: []byte{btcscript.OP_1}},
|
{name: "push small int 1", val: 1, expected: []byte{txscript.OP_1}},
|
||||||
{name: "push small int 2", val: 2, expected: []byte{btcscript.OP_2}},
|
{name: "push small int 2", val: 2, expected: []byte{txscript.OP_2}},
|
||||||
{name: "push small int 3", val: 3, expected: []byte{btcscript.OP_3}},
|
{name: "push small int 3", val: 3, expected: []byte{txscript.OP_3}},
|
||||||
{name: "push small int 4", val: 4, expected: []byte{btcscript.OP_4}},
|
{name: "push small int 4", val: 4, expected: []byte{txscript.OP_4}},
|
||||||
{name: "push small int 5", val: 5, expected: []byte{btcscript.OP_5}},
|
{name: "push small int 5", val: 5, expected: []byte{txscript.OP_5}},
|
||||||
{name: "push small int 6", val: 6, expected: []byte{btcscript.OP_6}},
|
{name: "push small int 6", val: 6, expected: []byte{txscript.OP_6}},
|
||||||
{name: "push small int 7", val: 7, expected: []byte{btcscript.OP_7}},
|
{name: "push small int 7", val: 7, expected: []byte{txscript.OP_7}},
|
||||||
{name: "push small int 8", val: 8, expected: []byte{btcscript.OP_8}},
|
{name: "push small int 8", val: 8, expected: []byte{txscript.OP_8}},
|
||||||
{name: "push small int 9", val: 9, expected: []byte{btcscript.OP_9}},
|
{name: "push small int 9", val: 9, expected: []byte{txscript.OP_9}},
|
||||||
{name: "push small int 10", val: 10, expected: []byte{btcscript.OP_10}},
|
{name: "push small int 10", val: 10, expected: []byte{txscript.OP_10}},
|
||||||
{name: "push small int 11", val: 11, expected: []byte{btcscript.OP_11}},
|
{name: "push small int 11", val: 11, expected: []byte{txscript.OP_11}},
|
||||||
{name: "push small int 12", val: 12, expected: []byte{btcscript.OP_12}},
|
{name: "push small int 12", val: 12, expected: []byte{txscript.OP_12}},
|
||||||
{name: "push small int 13", val: 13, expected: []byte{btcscript.OP_13}},
|
{name: "push small int 13", val: 13, expected: []byte{txscript.OP_13}},
|
||||||
{name: "push small int 14", val: 14, expected: []byte{btcscript.OP_14}},
|
{name: "push small int 14", val: 14, expected: []byte{txscript.OP_14}},
|
||||||
{name: "push small int 15", val: 15, expected: []byte{btcscript.OP_15}},
|
{name: "push small int 15", val: 15, expected: []byte{txscript.OP_15}},
|
||||||
{name: "push small int 16", val: 16, expected: []byte{btcscript.OP_16}},
|
{name: "push small int 16", val: 16, expected: []byte{txscript.OP_16}},
|
||||||
{name: "push 17", val: 17, expected: []byte{btcscript.OP_DATA_1, 0x11}},
|
{name: "push 17", val: 17, expected: []byte{txscript.OP_DATA_1, 0x11}},
|
||||||
{name: "push 65", val: 65, expected: []byte{btcscript.OP_DATA_1, 0x41}},
|
{name: "push 65", val: 65, expected: []byte{txscript.OP_DATA_1, 0x41}},
|
||||||
{name: "push 127", val: 127, expected: []byte{btcscript.OP_DATA_1, 0x7f}},
|
{name: "push 127", val: 127, expected: []byte{txscript.OP_DATA_1, 0x7f}},
|
||||||
{name: "push 128", val: 128, expected: []byte{btcscript.OP_DATA_2, 0x80, 0}},
|
{name: "push 128", val: 128, expected: []byte{txscript.OP_DATA_2, 0x80, 0}},
|
||||||
{name: "push 255", val: 255, expected: []byte{btcscript.OP_DATA_2, 0xff, 0}},
|
{name: "push 255", val: 255, expected: []byte{txscript.OP_DATA_2, 0xff, 0}},
|
||||||
{name: "push 256", val: 256, expected: []byte{btcscript.OP_DATA_2, 0, 0x01}},
|
{name: "push 256", val: 256, expected: []byte{txscript.OP_DATA_2, 0, 0x01}},
|
||||||
{name: "push 32767", val: 32767, expected: []byte{btcscript.OP_DATA_2, 0xff, 0x7f}},
|
{name: "push 32767", val: 32767, expected: []byte{txscript.OP_DATA_2, 0xff, 0x7f}},
|
||||||
{name: "push 32768", val: 32768, expected: []byte{btcscript.OP_DATA_3, 0, 0x80, 0}},
|
{name: "push 32768", val: 32768, expected: []byte{txscript.OP_DATA_3, 0, 0x80, 0}},
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := btcscript.NewScriptBuilder()
|
builder := txscript.NewScriptBuilder()
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
builder.Reset().AddUint64(test.val)
|
builder.Reset().AddUint64(test.val)
|
||||||
|
@ -197,70 +197,70 @@ func TestScriptBuilderAddData(t *testing.T) {
|
||||||
useFull bool // use AddFullData instead of AddData.
|
useFull bool // use AddFullData instead of AddData.
|
||||||
}{
|
}{
|
||||||
// BIP0062: Pushing an empty byte sequence must use OP_0.
|
// BIP0062: Pushing an empty byte sequence must use OP_0.
|
||||||
{name: "push empty byte sequence", data: []byte{}, expected: []byte{btcscript.OP_0}},
|
{name: "push empty byte sequence", data: []byte{}, expected: []byte{txscript.OP_0}},
|
||||||
{name: "push 1 byte 0x00", data: []byte{0x00}, expected: []byte{btcscript.OP_0}},
|
{name: "push 1 byte 0x00", data: []byte{0x00}, expected: []byte{txscript.OP_0}},
|
||||||
|
|
||||||
// BIP0062: Pushing a 1-byte sequence of byte 0x01 through 0x10 must use OP_n.
|
// 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{btcscript.OP_1}},
|
{name: "push 1 byte 0x01", data: []byte{0x01}, expected: []byte{txscript.OP_1}},
|
||||||
{name: "push 1 byte 0x02", data: []byte{0x02}, expected: []byte{btcscript.OP_2}},
|
{name: "push 1 byte 0x02", data: []byte{0x02}, expected: []byte{txscript.OP_2}},
|
||||||
{name: "push 1 byte 0x03", data: []byte{0x03}, expected: []byte{btcscript.OP_3}},
|
{name: "push 1 byte 0x03", data: []byte{0x03}, expected: []byte{txscript.OP_3}},
|
||||||
{name: "push 1 byte 0x04", data: []byte{0x04}, expected: []byte{btcscript.OP_4}},
|
{name: "push 1 byte 0x04", data: []byte{0x04}, expected: []byte{txscript.OP_4}},
|
||||||
{name: "push 1 byte 0x05", data: []byte{0x05}, expected: []byte{btcscript.OP_5}},
|
{name: "push 1 byte 0x05", data: []byte{0x05}, expected: []byte{txscript.OP_5}},
|
||||||
{name: "push 1 byte 0x06", data: []byte{0x06}, expected: []byte{btcscript.OP_6}},
|
{name: "push 1 byte 0x06", data: []byte{0x06}, expected: []byte{txscript.OP_6}},
|
||||||
{name: "push 1 byte 0x07", data: []byte{0x07}, expected: []byte{btcscript.OP_7}},
|
{name: "push 1 byte 0x07", data: []byte{0x07}, expected: []byte{txscript.OP_7}},
|
||||||
{name: "push 1 byte 0x08", data: []byte{0x08}, expected: []byte{btcscript.OP_8}},
|
{name: "push 1 byte 0x08", data: []byte{0x08}, expected: []byte{txscript.OP_8}},
|
||||||
{name: "push 1 byte 0x09", data: []byte{0x09}, expected: []byte{btcscript.OP_9}},
|
{name: "push 1 byte 0x09", data: []byte{0x09}, expected: []byte{txscript.OP_9}},
|
||||||
{name: "push 1 byte 0x0a", data: []byte{0x0a}, expected: []byte{btcscript.OP_10}},
|
{name: "push 1 byte 0x0a", data: []byte{0x0a}, expected: []byte{txscript.OP_10}},
|
||||||
{name: "push 1 byte 0x0b", data: []byte{0x0b}, expected: []byte{btcscript.OP_11}},
|
{name: "push 1 byte 0x0b", data: []byte{0x0b}, expected: []byte{txscript.OP_11}},
|
||||||
{name: "push 1 byte 0x0c", data: []byte{0x0c}, expected: []byte{btcscript.OP_12}},
|
{name: "push 1 byte 0x0c", data: []byte{0x0c}, expected: []byte{txscript.OP_12}},
|
||||||
{name: "push 1 byte 0x0d", data: []byte{0x0d}, expected: []byte{btcscript.OP_13}},
|
{name: "push 1 byte 0x0d", data: []byte{0x0d}, expected: []byte{txscript.OP_13}},
|
||||||
{name: "push 1 byte 0x0e", data: []byte{0x0e}, expected: []byte{btcscript.OP_14}},
|
{name: "push 1 byte 0x0e", data: []byte{0x0e}, expected: []byte{txscript.OP_14}},
|
||||||
{name: "push 1 byte 0x0f", data: []byte{0x0f}, expected: []byte{btcscript.OP_15}},
|
{name: "push 1 byte 0x0f", data: []byte{0x0f}, expected: []byte{txscript.OP_15}},
|
||||||
{name: "push 1 byte 0x10", data: []byte{0x10}, expected: []byte{btcscript.OP_16}},
|
{name: "push 1 byte 0x10", data: []byte{0x10}, expected: []byte{txscript.OP_16}},
|
||||||
|
|
||||||
// BIP0062: Pushing the byte 0x81 must use OP_1NEGATE.
|
// BIP0062: Pushing the byte 0x81 must use OP_1NEGATE.
|
||||||
{name: "push 1 byte 0x81", data: []byte{0x81}, expected: []byte{btcscript.OP_1NEGATE}},
|
{name: "push 1 byte 0x81", data: []byte{0x81}, expected: []byte{txscript.OP_1NEGATE}},
|
||||||
|
|
||||||
// BIP0062: Pushing any other byte sequence up to 75 bytes must
|
// BIP0062: Pushing any other byte sequence up to 75 bytes must
|
||||||
// use the normal data push (opcode byte n, with n the number of
|
// use the normal data push (opcode byte n, with n the number of
|
||||||
// bytes, followed n bytes of data being pushed).
|
// bytes, followed n bytes of data being pushed).
|
||||||
{name: "push 1 byte 0x11", data: []byte{0x11}, expected: []byte{btcscript.OP_DATA_1, 0x11}},
|
{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{btcscript.OP_DATA_1, 0x80}},
|
{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{btcscript.OP_DATA_1, 0x82}},
|
{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{btcscript.OP_DATA_1, 0xff}},
|
{name: "push 1 byte 0xff", data: []byte{0xff}, expected: []byte{txscript.OP_DATA_1, 0xff}},
|
||||||
{
|
{
|
||||||
name: "push data len 17",
|
name: "push data len 17",
|
||||||
data: bytes.Repeat([]byte{0x49}, 17),
|
data: bytes.Repeat([]byte{0x49}, 17),
|
||||||
expected: append([]byte{btcscript.OP_DATA_17}, bytes.Repeat([]byte{0x49}, 17)...),
|
expected: append([]byte{txscript.OP_DATA_17}, bytes.Repeat([]byte{0x49}, 17)...),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "push data len 75",
|
name: "push data len 75",
|
||||||
data: bytes.Repeat([]byte{0x49}, 75),
|
data: bytes.Repeat([]byte{0x49}, 75),
|
||||||
expected: append([]byte{btcscript.OP_DATA_75}, bytes.Repeat([]byte{0x49}, 75)...),
|
expected: append([]byte{txscript.OP_DATA_75}, bytes.Repeat([]byte{0x49}, 75)...),
|
||||||
},
|
},
|
||||||
|
|
||||||
// BIP0062: Pushing 76 to 255 bytes must use OP_PUSHDATA1.
|
// BIP0062: Pushing 76 to 255 bytes must use OP_PUSHDATA1.
|
||||||
{
|
{
|
||||||
name: "push data len 76",
|
name: "push data len 76",
|
||||||
data: bytes.Repeat([]byte{0x49}, 76),
|
data: bytes.Repeat([]byte{0x49}, 76),
|
||||||
expected: append([]byte{btcscript.OP_PUSHDATA1, 76}, bytes.Repeat([]byte{0x49}, 76)...),
|
expected: append([]byte{txscript.OP_PUSHDATA1, 76}, bytes.Repeat([]byte{0x49}, 76)...),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "push data len 255",
|
name: "push data len 255",
|
||||||
data: bytes.Repeat([]byte{0x49}, 255),
|
data: bytes.Repeat([]byte{0x49}, 255),
|
||||||
expected: append([]byte{btcscript.OP_PUSHDATA1, 255}, bytes.Repeat([]byte{0x49}, 255)...),
|
expected: append([]byte{txscript.OP_PUSHDATA1, 255}, bytes.Repeat([]byte{0x49}, 255)...),
|
||||||
},
|
},
|
||||||
|
|
||||||
// BIP0062: Pushing 256 to 520 bytes must use OP_PUSHDATA2.
|
// BIP0062: Pushing 256 to 520 bytes must use OP_PUSHDATA2.
|
||||||
{
|
{
|
||||||
name: "push data len 256",
|
name: "push data len 256",
|
||||||
data: bytes.Repeat([]byte{0x49}, 256),
|
data: bytes.Repeat([]byte{0x49}, 256),
|
||||||
expected: append([]byte{btcscript.OP_PUSHDATA2, 0, 1}, bytes.Repeat([]byte{0x49}, 256)...),
|
expected: append([]byte{txscript.OP_PUSHDATA2, 0, 1}, bytes.Repeat([]byte{0x49}, 256)...),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "push data len 520",
|
name: "push data len 520",
|
||||||
data: bytes.Repeat([]byte{0x49}, 520),
|
data: bytes.Repeat([]byte{0x49}, 520),
|
||||||
expected: append([]byte{btcscript.OP_PUSHDATA2, 0x08, 0x02}, bytes.Repeat([]byte{0x49}, 520)...),
|
expected: append([]byte{txscript.OP_PUSHDATA2, 0x08, 0x02}, bytes.Repeat([]byte{0x49}, 520)...),
|
||||||
},
|
},
|
||||||
|
|
||||||
// BIP0062: OP_PUSHDATA4 can never be used, as pushes over 520
|
// BIP0062: OP_PUSHDATA4 can never be used, as pushes over 520
|
||||||
|
@ -290,7 +290,7 @@ func TestScriptBuilderAddData(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "push data len 32767 (non-canonical)",
|
name: "push data len 32767 (non-canonical)",
|
||||||
data: bytes.Repeat([]byte{0x49}, 32767),
|
data: bytes.Repeat([]byte{0x49}, 32767),
|
||||||
expected: append([]byte{btcscript.OP_PUSHDATA2, 255, 127}, bytes.Repeat([]byte{0x49}, 32767)...),
|
expected: append([]byte{txscript.OP_PUSHDATA2, 255, 127}, bytes.Repeat([]byte{0x49}, 32767)...),
|
||||||
useFull: true,
|
useFull: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -298,12 +298,12 @@ func TestScriptBuilderAddData(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "push data len 65536 (non-canonical)",
|
name: "push data len 65536 (non-canonical)",
|
||||||
data: bytes.Repeat([]byte{0x49}, 65536),
|
data: bytes.Repeat([]byte{0x49}, 65536),
|
||||||
expected: append([]byte{btcscript.OP_PUSHDATA4, 0, 0, 1, 0}, bytes.Repeat([]byte{0x49}, 65536)...),
|
expected: append([]byte{txscript.OP_PUSHDATA4, 0, 0, 1, 0}, bytes.Repeat([]byte{0x49}, 65536)...),
|
||||||
useFull: true,
|
useFull: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := btcscript.NewScriptBuilder()
|
builder := txscript.NewScriptBuilder()
|
||||||
t.Logf("Running %d tests", len(tests))
|
t.Logf("Running %d tests", len(tests))
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
if !test.useFull {
|
if !test.useFull {
|
||||||
|
@ -328,8 +328,8 @@ func TestExceedMaxScriptSize(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
// Start off by constructing a max size script.
|
// Start off by constructing a max size script.
|
||||||
maxScriptSize := btcscript.TstMaxScriptSize
|
maxScriptSize := txscript.TstMaxScriptSize
|
||||||
builder := btcscript.NewScriptBuilder()
|
builder := txscript.NewScriptBuilder()
|
||||||
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
|
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
|
||||||
origScript, err := builder.Script()
|
origScript, err := builder.Script()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -339,7 +339,7 @@ func TestExceedMaxScriptSize(t *testing.T) {
|
||||||
// Ensure adding data that would exceed the maximum size of the script
|
// Ensure adding data that would exceed the maximum size of the script
|
||||||
// does not add the data.
|
// does not add the data.
|
||||||
script, err := builder.AddData([]byte{0x00}).Script()
|
script, err := builder.AddData([]byte{0x00}).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatalf("ScriptBuilder.AddData allowed exceeding max script "+
|
t.Fatalf("ScriptBuilder.AddData allowed exceeding max script "+
|
||||||
"size: %v", len(script))
|
"size: %v", len(script))
|
||||||
}
|
}
|
||||||
|
@ -351,8 +351,8 @@ func TestExceedMaxScriptSize(t *testing.T) {
|
||||||
// Ensure adding an opcode that would exceed the maximum size of the
|
// Ensure adding an opcode that would exceed the maximum size of the
|
||||||
// script does not add the data.
|
// script does not add the data.
|
||||||
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
|
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
|
||||||
script, err = builder.AddOp(btcscript.OP_0).Script()
|
script, err = builder.AddOp(txscript.OP_0).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatalf("ScriptBuilder.AddOp unexpected modified script - "+
|
t.Fatalf("ScriptBuilder.AddOp unexpected modified script - "+
|
||||||
"got len %d, want len %d", len(script), len(origScript))
|
"got len %d, want len %d", len(script), len(origScript))
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ func TestExceedMaxScriptSize(t *testing.T) {
|
||||||
// script does not add the data.
|
// script does not add the data.
|
||||||
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
|
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
|
||||||
script, err = builder.AddInt64(0).Script()
|
script, err = builder.AddInt64(0).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatalf("ScriptBuilder.AddInt64 unexpected modified script - "+
|
t.Fatalf("ScriptBuilder.AddInt64 unexpected modified script - "+
|
||||||
"got len %d, want len %d", len(script), len(origScript))
|
"got len %d, want len %d", len(script), len(origScript))
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,7 @@ func TestExceedMaxScriptSize(t *testing.T) {
|
||||||
// of the script does not add the data.
|
// of the script does not add the data.
|
||||||
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
|
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
|
||||||
script, err = builder.AddUint64(0).Script()
|
script, err = builder.AddUint64(0).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatalf("ScriptBuilder.AddUint64 unexpected modified script - "+
|
t.Fatalf("ScriptBuilder.AddUint64 unexpected modified script - "+
|
||||||
"got len %d, want len %d", len(script), len(origScript))
|
"got len %d, want len %d", len(script), len(origScript))
|
||||||
}
|
}
|
||||||
|
@ -396,15 +396,15 @@ func TestErroredScript(t *testing.T) {
|
||||||
// Start off by constructing a near max size script that has enough
|
// 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
|
// space left to add each data type without an error and force an
|
||||||
// initial error condition.
|
// initial error condition.
|
||||||
maxScriptSize := btcscript.TstMaxScriptSize
|
maxScriptSize := txscript.TstMaxScriptSize
|
||||||
builder := btcscript.NewScriptBuilder()
|
builder := txscript.NewScriptBuilder()
|
||||||
builder.Reset().AddFullData(make([]byte, maxScriptSize-8))
|
builder.Reset().AddFullData(make([]byte, maxScriptSize-8))
|
||||||
origScript, err := builder.Script()
|
origScript, err := builder.Script()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ScriptBuilder.AddFullData unexpected error: %v", err)
|
t.Fatalf("ScriptBuilder.AddFullData unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
script, err := builder.AddData([]byte{0x00, 0x00, 0x00, 0x00, 0x00}).Script()
|
script, err := builder.AddData([]byte{0x00, 0x00, 0x00, 0x00, 0x00}).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatalf("ScriptBuilder.AddData allowed exceeding max script "+
|
t.Fatalf("ScriptBuilder.AddData allowed exceeding max script "+
|
||||||
"size: %v", len(script))
|
"size: %v", len(script))
|
||||||
}
|
}
|
||||||
|
@ -416,7 +416,7 @@ func TestErroredScript(t *testing.T) {
|
||||||
// Ensure adding data, even using the non-canonical path, to a script
|
// Ensure adding data, even using the non-canonical path, to a script
|
||||||
// that has errored doesn't succeed.
|
// that has errored doesn't succeed.
|
||||||
script, err = builder.AddFullData([]byte{0x00}).Script()
|
script, err = builder.AddFullData([]byte{0x00}).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatal("ScriptBuilder.AddFullData succeeded on errored script")
|
t.Fatal("ScriptBuilder.AddFullData succeeded on errored script")
|
||||||
}
|
}
|
||||||
if !bytes.Equal(script, origScript) {
|
if !bytes.Equal(script, origScript) {
|
||||||
|
@ -427,7 +427,7 @@ func TestErroredScript(t *testing.T) {
|
||||||
|
|
||||||
// Ensure adding data to a script that has errored doesn't succeed.
|
// Ensure adding data to a script that has errored doesn't succeed.
|
||||||
script, err = builder.AddData([]byte{0x00}).Script()
|
script, err = builder.AddData([]byte{0x00}).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatal("ScriptBuilder.AddData succeeded on errored script")
|
t.Fatal("ScriptBuilder.AddData succeeded on errored script")
|
||||||
}
|
}
|
||||||
if !bytes.Equal(script, origScript) {
|
if !bytes.Equal(script, origScript) {
|
||||||
|
@ -437,8 +437,8 @@ func TestErroredScript(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure adding an opcode to a script that has errored doesn't succeed.
|
// Ensure adding an opcode to a script that has errored doesn't succeed.
|
||||||
script, err = builder.AddOp(btcscript.OP_0).Script()
|
script, err = builder.AddOp(txscript.OP_0).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatal("ScriptBuilder.AddOp succeeded on errored script")
|
t.Fatal("ScriptBuilder.AddOp succeeded on errored script")
|
||||||
}
|
}
|
||||||
if !bytes.Equal(script, origScript) {
|
if !bytes.Equal(script, origScript) {
|
||||||
|
@ -449,7 +449,7 @@ func TestErroredScript(t *testing.T) {
|
||||||
// Ensure adding an integer to a script that has errored doesn't
|
// Ensure adding an integer to a script that has errored doesn't
|
||||||
// succeed.
|
// succeed.
|
||||||
script, err = builder.AddInt64(0).Script()
|
script, err = builder.AddInt64(0).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatal("ScriptBuilder.AddInt64 succeeded on errored script")
|
t.Fatal("ScriptBuilder.AddInt64 succeeded on errored script")
|
||||||
}
|
}
|
||||||
if !bytes.Equal(script, origScript) {
|
if !bytes.Equal(script, origScript) {
|
||||||
|
@ -460,7 +460,7 @@ func TestErroredScript(t *testing.T) {
|
||||||
// Ensure adding an unsigned integer to a script that has errored
|
// Ensure adding an unsigned integer to a script that has errored
|
||||||
// doesn't succeed.
|
// doesn't succeed.
|
||||||
script, err = builder.AddUint64(0).Script()
|
script, err = builder.AddUint64(0).Script()
|
||||||
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
|
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
|
||||||
t.Fatal("ScriptBuilder.AddUint64 succeeded on errored script")
|
t.Fatal("ScriptBuilder.AddUint64 succeeded on errored script")
|
||||||
}
|
}
|
||||||
if !bytes.Equal(script, origScript) {
|
if !bytes.Equal(script, origScript) {
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript
|
package txscript
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
// Copyright (c) 2013-2015 Conformal Systems LLC.
|
||||||
// Use of this source code is governed by an ISC
|
// Use of this source code is governed by an ISC
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package btcscript_test
|
package txscript_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -11,7 +11,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestStack tests that all of the stack operations work as expected.
|
// TestStack tests that all of the stack operations work as expected.
|
||||||
|
@ -21,14 +21,14 @@ func TestStack(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
before [][]byte
|
before [][]byte
|
||||||
operation func(*btcscript.Stack) error
|
operation func(*txscript.Stack) error
|
||||||
expectedReturn error
|
expectedReturn error
|
||||||
after [][]byte
|
after [][]byte
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"noop",
|
"noop",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -37,37 +37,37 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"peek underflow (byte)",
|
"peek underflow (byte)",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
_, err := stack.PeekByteArray(5)
|
_, err := stack.PeekByteArray(5)
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"peek underflow (int)",
|
"peek underflow (int)",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
_, err := stack.PeekInt(5)
|
_, err := stack.PeekInt(5)
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"peek underflow (bool)",
|
"peek underflow (bool)",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
_, err := stack.PeekBool(5)
|
_, err := stack.PeekBool(5)
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pop",
|
"pop",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
val, err := stack.PopByteArray()
|
val, err := stack.PopByteArray()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -83,7 +83,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"pop",
|
"pop",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
val, err := stack.PopByteArray()
|
val, err := stack.PopByteArray()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -99,7 +99,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"pop everything",
|
"pop everything",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
_, err := stack.PopByteArray()
|
_, err := stack.PopByteArray()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -114,7 +114,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"pop underflow",
|
"pop underflow",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
for i := 0; i < 6; i++ {
|
for i := 0; i < 6; i++ {
|
||||||
_, err := stack.PopByteArray()
|
_, err := stack.PopByteArray()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -123,13 +123,13 @@ func TestStack(t *testing.T) {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"pop bool",
|
"pop bool",
|
||||||
[][]byte{{0}},
|
[][]byte{{0}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
val, err := stack.PopBool()
|
val, err := stack.PopBool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -146,7 +146,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"pop bool",
|
"pop bool",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
val, err := stack.PopBool()
|
val, err := stack.PopBool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -163,7 +163,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"pop bool",
|
"pop bool",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
_, err := stack.PopBool()
|
_, err := stack.PopBool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -171,13 +171,13 @@ func TestStack(t *testing.T) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"popInt 0",
|
"popInt 0",
|
||||||
[][]byte{{0x0}},
|
[][]byte{{0x0}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
v, err := stack.PopInt()
|
v, err := stack.PopInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -193,7 +193,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"popInt -0",
|
"popInt -0",
|
||||||
[][]byte{{0x80}},
|
[][]byte{{0x80}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
v, err := stack.PopInt()
|
v, err := stack.PopInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -209,7 +209,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"popInt 1",
|
"popInt 1",
|
||||||
[][]byte{{0x01}},
|
[][]byte{{0x01}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
v, err := stack.PopInt()
|
v, err := stack.PopInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -225,7 +225,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"popInt 1 leading 0",
|
"popInt 1 leading 0",
|
||||||
[][]byte{{0x01, 0x00, 0x00, 0x00}},
|
[][]byte{{0x01, 0x00, 0x00, 0x00}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
v, err := stack.PopInt()
|
v, err := stack.PopInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -242,7 +242,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"popInt -1",
|
"popInt -1",
|
||||||
[][]byte{{0x81}},
|
[][]byte{{0x81}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
v, err := stack.PopInt()
|
v, err := stack.PopInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -258,7 +258,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"popInt -1 leading 0",
|
"popInt -1 leading 0",
|
||||||
[][]byte{{0x01, 0x00, 0x00, 0x80}},
|
[][]byte{{0x01, 0x00, 0x00, 0x80}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
v, err := stack.PopInt()
|
v, err := stack.PopInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -276,7 +276,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"popInt -513",
|
"popInt -513",
|
||||||
[][]byte{{0x1, 0x82}},
|
[][]byte{{0x1, 0x82}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
v, err := stack.PopInt()
|
v, err := stack.PopInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -294,7 +294,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"peekint nomodify -1",
|
"peekint nomodify -1",
|
||||||
[][]byte{{0x01, 0x00, 0x00, 0x80}},
|
[][]byte{{0x01, 0x00, 0x00, 0x80}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
v, err := stack.PeekInt(0)
|
v, err := stack.PeekInt(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -311,7 +311,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushInt 0",
|
"PushInt 0",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(0))
|
stack.PushInt(big.NewInt(0))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -321,7 +321,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushInt 1",
|
"PushInt 1",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(1))
|
stack.PushInt(big.NewInt(1))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -331,7 +331,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushInt -1",
|
"PushInt -1",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(-1))
|
stack.PushInt(big.NewInt(-1))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -341,7 +341,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushInt two bytes",
|
"PushInt two bytes",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(256))
|
stack.PushInt(big.NewInt(256))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -352,7 +352,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushInt leading zeros",
|
"PushInt leading zeros",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
// this will have the highbit set
|
// this will have the highbit set
|
||||||
stack.PushInt(big.NewInt(128))
|
stack.PushInt(big.NewInt(128))
|
||||||
return nil
|
return nil
|
||||||
|
@ -363,7 +363,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"dup",
|
"dup",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
err := stack.DupN(1)
|
err := stack.DupN(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -377,7 +377,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"dup2",
|
"dup2",
|
||||||
[][]byte{{1}, {2}},
|
[][]byte{{1}, {2}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
err := stack.DupN(2)
|
err := stack.DupN(2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -391,7 +391,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"dup3",
|
"dup3",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
err := stack.DupN(3)
|
err := stack.DupN(3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -405,7 +405,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"dup0",
|
"dup0",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
err := stack.DupN(0)
|
err := stack.DupN(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -413,13 +413,13 @@ func TestStack(t *testing.T) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
btcscript.ErrStackInvalidArgs,
|
txscript.ErrStackInvalidArgs,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dup-1",
|
"dup-1",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
err := stack.DupN(-1)
|
err := stack.DupN(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -427,13 +427,13 @@ func TestStack(t *testing.T) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
btcscript.ErrStackInvalidArgs,
|
txscript.ErrStackInvalidArgs,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dup too much",
|
"dup too much",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
err := stack.DupN(2)
|
err := stack.DupN(2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -441,13 +441,13 @@ func TestStack(t *testing.T) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dup-1",
|
"dup-1",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
err := stack.DupN(-1)
|
err := stack.DupN(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -455,13 +455,13 @@ func TestStack(t *testing.T) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
btcscript.ErrStackInvalidArgs,
|
txscript.ErrStackInvalidArgs,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"PushBool true",
|
"PushBool true",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushBool(true)
|
stack.PushBool(true)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -472,7 +472,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushBool false",
|
"PushBool false",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushBool(false)
|
stack.PushBool(false)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -483,7 +483,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushBool PopBool",
|
"PushBool PopBool",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushBool(true)
|
stack.PushBool(true)
|
||||||
val, err := stack.PopBool()
|
val, err := stack.PopBool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -501,7 +501,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushBool PopBool 2",
|
"PushBool PopBool 2",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushBool(false)
|
stack.PushBool(false)
|
||||||
val, err := stack.PopBool()
|
val, err := stack.PopBool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -519,7 +519,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushInt PopBool",
|
"PushInt PopBool",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(1))
|
stack.PushInt(big.NewInt(1))
|
||||||
val, err := stack.PopBool()
|
val, err := stack.PopBool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -537,7 +537,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushInt PopBool 2",
|
"PushInt PopBool 2",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(0))
|
stack.PushInt(big.NewInt(0))
|
||||||
val, err := stack.PopBool()
|
val, err := stack.PopBool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -555,7 +555,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"PushInt PopBool 2",
|
"PushInt PopBool 2",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(0))
|
stack.PushInt(big.NewInt(0))
|
||||||
val, err := stack.PopBool()
|
val, err := stack.PopBool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -573,7 +573,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Nip top",
|
"Nip top",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.NipN(0)
|
return stack.NipN(0)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -582,7 +582,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Nip middle",
|
"Nip middle",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.NipN(1)
|
return stack.NipN(1)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -591,7 +591,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Nip low",
|
"Nip low",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.NipN(2)
|
return stack.NipN(2)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -600,27 +600,27 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Nip too much",
|
"Nip too much",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
// bite off more than we can chew
|
// bite off more than we can chew
|
||||||
return stack.NipN(3)
|
return stack.NipN(3)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{{2}, {3}},
|
[][]byte{{2}, {3}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Nip too much",
|
"Nip too much",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
// bite off more than we can chew
|
// bite off more than we can chew
|
||||||
return stack.NipN(3)
|
return stack.NipN(3)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{{2}, {3}},
|
[][]byte{{2}, {3}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"keep on tucking",
|
"keep on tucking",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.Tuck()
|
return stack.Tuck()
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -629,25 +629,25 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"a little tucked up",
|
"a little tucked up",
|
||||||
[][]byte{{1}}, // too few arguments for tuck
|
[][]byte{{1}}, // too few arguments for tuck
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.Tuck()
|
return stack.Tuck()
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"all tucked up",
|
"all tucked up",
|
||||||
[][]byte{}, // too few arguments for tuck
|
[][]byte{}, // too few arguments for tuck
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.Tuck()
|
return stack.Tuck()
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"drop 1",
|
"drop 1",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.DropN(1)
|
return stack.DropN(1)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -656,7 +656,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"drop 2",
|
"drop 2",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.DropN(2)
|
return stack.DropN(2)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -665,7 +665,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"drop 3",
|
"drop 3",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.DropN(3)
|
return stack.DropN(3)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -674,7 +674,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"drop 4",
|
"drop 4",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.DropN(4)
|
return stack.DropN(4)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -683,25 +683,25 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"drop 4/5",
|
"drop 4/5",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.DropN(5)
|
return stack.DropN(5)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"drop invalid",
|
"drop invalid",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.DropN(0)
|
return stack.DropN(0)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackInvalidArgs,
|
txscript.ErrStackInvalidArgs,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Rot1",
|
"Rot1",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.RotN(1)
|
return stack.RotN(1)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -710,7 +710,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Rot2",
|
"Rot2",
|
||||||
[][]byte{{1}, {2}, {3}, {4}, {5}, {6}},
|
[][]byte{{1}, {2}, {3}, {4}, {5}, {6}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.RotN(2)
|
return stack.RotN(2)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -719,25 +719,25 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Rot too little",
|
"Rot too little",
|
||||||
[][]byte{{1}, {2}},
|
[][]byte{{1}, {2}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.RotN(1)
|
return stack.RotN(1)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Rot0",
|
"Rot0",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.RotN(0)
|
return stack.RotN(0)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackInvalidArgs,
|
txscript.ErrStackInvalidArgs,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Swap1",
|
"Swap1",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.SwapN(1)
|
return stack.SwapN(1)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -746,7 +746,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Swap2",
|
"Swap2",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.SwapN(2)
|
return stack.SwapN(2)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -755,25 +755,25 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Swap too little",
|
"Swap too little",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.SwapN(1)
|
return stack.SwapN(1)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Swap0",
|
"Swap0",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.SwapN(0)
|
return stack.SwapN(0)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackInvalidArgs,
|
txscript.ErrStackInvalidArgs,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Over1",
|
"Over1",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.OverN(1)
|
return stack.OverN(1)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -782,7 +782,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Over2",
|
"Over2",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.OverN(2)
|
return stack.OverN(2)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -791,25 +791,25 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Over too little",
|
"Over too little",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.OverN(1)
|
return stack.OverN(1)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Over0",
|
"Over0",
|
||||||
[][]byte{{1}, {2}, {3}},
|
[][]byte{{1}, {2}, {3}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.OverN(0)
|
return stack.OverN(0)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackInvalidArgs,
|
txscript.ErrStackInvalidArgs,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Pick1",
|
"Pick1",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.PickN(1)
|
return stack.PickN(1)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -818,7 +818,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Pick2",
|
"Pick2",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.PickN(2)
|
return stack.PickN(2)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -827,16 +827,16 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Pick too little",
|
"Pick too little",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.PickN(1)
|
return stack.PickN(1)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Roll1",
|
"Roll1",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.RollN(1)
|
return stack.RollN(1)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -845,7 +845,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Roll2",
|
"Roll2",
|
||||||
[][]byte{{1}, {2}, {3}, {4}},
|
[][]byte{{1}, {2}, {3}, {4}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.RollN(2)
|
return stack.RollN(2)
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
|
@ -854,16 +854,16 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Roll too little",
|
"Roll too little",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
return stack.RollN(1)
|
return stack.RollN(1)
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Peek bool",
|
"Peek bool",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
// Peek bool is otherwise pretty well tested,
|
// Peek bool is otherwise pretty well tested,
|
||||||
// just check it works.
|
// just check it works.
|
||||||
val, err := stack.PeekBool(0)
|
val, err := stack.PeekBool(0)
|
||||||
|
@ -881,7 +881,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Peek bool 2",
|
"Peek bool 2",
|
||||||
[][]byte{{0}},
|
[][]byte{{0}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
// Peek bool is otherwise pretty well tested,
|
// Peek bool is otherwise pretty well tested,
|
||||||
// just check it works.
|
// just check it works.
|
||||||
val, err := stack.PeekBool(0)
|
val, err := stack.PeekBool(0)
|
||||||
|
@ -899,7 +899,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Peek int",
|
"Peek int",
|
||||||
[][]byte{{1}},
|
[][]byte{{1}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
// Peek int is otherwise pretty well tested,
|
// Peek int is otherwise pretty well tested,
|
||||||
// just check it works.
|
// just check it works.
|
||||||
val, err := stack.PeekInt(0)
|
val, err := stack.PeekInt(0)
|
||||||
|
@ -917,7 +917,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Peek int 2",
|
"Peek int 2",
|
||||||
[][]byte{{0}},
|
[][]byte{{0}},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
// Peek int is otherwise pretty well tested,
|
// Peek int is otherwise pretty well tested,
|
||||||
// just check it works.
|
// just check it works.
|
||||||
val, err := stack.PeekInt(0)
|
val, err := stack.PeekInt(0)
|
||||||
|
@ -935,7 +935,7 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"pop int",
|
"pop int",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
stack.PushInt(big.NewInt(1))
|
stack.PushInt(big.NewInt(1))
|
||||||
// Peek int is otherwise pretty well tested,
|
// Peek int is otherwise pretty well tested,
|
||||||
// just check it works.
|
// just check it works.
|
||||||
|
@ -954,19 +954,19 @@ func TestStack(t *testing.T) {
|
||||||
{
|
{
|
||||||
"pop empty",
|
"pop empty",
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
func(stack *btcscript.Stack) error {
|
func(stack *txscript.Stack) error {
|
||||||
// Peek int is otherwise pretty well tested,
|
// Peek int is otherwise pretty well tested,
|
||||||
// just check it works.
|
// just check it works.
|
||||||
_, err := stack.PopInt()
|
_, err := stack.PopInt()
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
btcscript.ErrStackUnderflow,
|
txscript.ErrStackUnderflow,
|
||||||
[][]byte{},
|
[][]byte{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
stack := btcscript.Stack{}
|
stack := txscript.Stack{}
|
||||||
|
|
||||||
for i := range test.before {
|
for i := range test.before {
|
||||||
stack.PushByteArray(test.before[i])
|
stack.PushByteArray(test.before[i])
|
Loading…
Reference in a new issue