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:
Dave Collins 2015-01-30 00:03:01 -06:00
parent 115cea2109
commit cbda064842
26 changed files with 2242 additions and 2498 deletions

28
.gitignore vendored
View file

@ -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

View file

@ -1,3 +0,0 @@
language: go
go: release
install: go get -d -t -v ./...

13
LICENSE
View file

@ -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.

View file

@ -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

View file

@ -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)

View file

@ -1,20 +1,15 @@
btcscript
=========
txscript
========
[![Build Status](https://travis-ci.org/btcsuite/btcscript.png?branch=master)]
(https://travis-ci.org/btcsuite/btcscript)
[![Build Status](https://travis-ci.org/btcsuite/btcd.png?branch=master)]
(https://travis-ci.org/btcsuite/btcd)
Package btcscript implements the bitcoin transaction scripts. There is
a comprehensive test suite. `test_coverage.txt` contains the current
coverage statistics (generated using gocov). On a UNIX-like OS, the
script `cov_report.sh` can be used to generate the report. Package
btcscript is licensed under the liberal ISC license.
Package txscript implements the bitcoin transaction script language. There is
a comprehensive test suite. Package txscript is licensed under the liberal ISC
license.
This package is one of the core packages from btcd, an alternative full-node
implementation of bitcoin which is under active development by Conformal.
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.
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
@ -25,39 +20,35 @@ can be found at https://en.bitcoin.it/wiki/Script
## Documentation
[![GoDoc](https://godoc.org/github.com/btcsuite/btcscript?status.png)]
(http://godoc.org/github.com/btcsuite/btcscript)
[![GoDoc](https://godoc.org/github.com/btcsuite/btcd/txscript?status.png)]
(http://godoc.org/github.com/btcsuite/btcd/txscript)
Full `go doc` style documentation for the project can be viewed online without
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
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
```bash
$ go get github.com/btcsuite/btcscript
$ go get github.com/btcsuite/btcd/txscript
```
## Examples
* [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
prints the created script hex and uses the DisasmString function to display
the disassembled script.
* [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.
## TODO
- Increase test coverage to 100%
## GPG Verification Key
All official release tags are signed by Conformal so users can ensure the code
@ -80,4 +71,4 @@ signature perform the following:
## License
Package btcscript is licensed under the liberal ISC License.
Package txscript is licensed under the liberal ISC License.

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript
package txscript
import (
"github.com/btcsuite/btcnet"

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript_test
package txscript_test
import (
"encoding/hex"
"reflect"
"testing"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcscript"
"github.com/btcsuite/btcutil"
)
@ -75,7 +75,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
script []byte
addrs []btcutil.Address
reqSigs int
class btcscript.ScriptClass
class txscript.ScriptClass
}{
{
name: "standard p2pk with compressed pubkey (0x02)",
@ -87,7 +87,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"4895dca52c6b4")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
class: txscript.PubKeyTy,
},
{
name: "standard p2pk with uncompressed pubkey (0x04)",
@ -103,7 +103,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"412a3")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
class: txscript.PubKeyTy,
},
{
name: "standard p2pk with hybrid pubkey (0x06)",
@ -119,7 +119,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"f453e")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
class: txscript.PubKeyTy,
},
{
name: "standard p2pk with compressed pubkey (0x03)",
@ -131,7 +131,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"409273eb16e65")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
class: txscript.PubKeyTy,
},
{
name: "2nd standard p2pk with uncompressed pubkey (0x04)",
@ -147,7 +147,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"8ef7b")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
class: txscript.PubKeyTy,
},
{
name: "standard p2pk with hybrid pubkey (0x07)",
@ -163,7 +163,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"8ef7b")),
},
reqSigs: 1,
class: btcscript.PubKeyTy,
class: txscript.PubKeyTy,
},
{
name: "standard p2pkh",
@ -174,7 +174,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"cbca9a9e3713bd7587509a30564")),
},
reqSigs: 1,
class: btcscript.PubKeyHashTy,
class: txscript.PubKeyHashTy,
},
{
name: "standard p2sh",
@ -185,7 +185,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"ee0189dd5cc67f1b0e5f02f45cb")),
},
reqSigs: 1,
class: btcscript.ScriptHashTy,
class: txscript.ScriptHashTy,
},
// from real tx 60a20bd93aa49ab4b28d514ec10b06e1829ce6818ec06cd3aabd013ebcdc4bb1, vout 0
{
@ -210,7 +210,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"342af")),
},
reqSigs: 1,
class: btcscript.MultiSigTy,
class: txscript.MultiSigTy,
},
// from real tx d646f82bd5fbdb94a36872ce460f97662b80c3050ad3209bef9d1e398ea277ab, vin 1
{
@ -243,7 +243,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"0421a")),
},
reqSigs: 2,
class: btcscript.MultiSigTy,
class: txscript.MultiSigTy,
},
// The below are nonstandard script due to things such as
@ -258,7 +258,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"f656b412a3"),
addrs: nil,
reqSigs: 0,
class: btcscript.NonStandardTy,
class: txscript.NonStandardTy,
},
{
name: "valid signature from a sigscript - no addresses",
@ -268,7 +268,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"4622082221a8768d1d0901"),
addrs: nil,
reqSigs: 0,
class: btcscript.NonStandardTy,
class: txscript.NonStandardTy,
},
// Note the technically the pubkey is the second item on the
// stack, but since the address extraction intentionally only
@ -285,7 +285,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"a75a71042d40388a4d307f887d"),
addrs: nil,
reqSigs: 0,
class: btcscript.NonStandardTy,
class: txscript.NonStandardTy,
},
// from real tx 691dd277dc0e90a462a3d652a1171686de49cf19067cd33c7df0392833fb986a, vout 0
// invalid public keys
@ -303,7 +303,7 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"35616463636453ae"),
addrs: []btcutil.Address{},
reqSigs: 1,
class: btcscript.MultiSigTy,
class: txscript.MultiSigTy,
},
// from real tx: 691dd277dc0e90a462a3d652a1171686de49cf19067cd33c7df0392833fb986a, vout 44
// invalid public keys
@ -319,27 +319,27 @@ func TestExtractPkScriptAddrs(t *testing.T) {
"38613663663530616234636434340a00000053ae"),
addrs: []btcutil.Address{},
reqSigs: 1,
class: btcscript.MultiSigTy,
class: txscript.MultiSigTy,
},
{
name: "empty script",
script: []byte{},
addrs: nil,
reqSigs: 0,
class: btcscript.NonStandardTy,
class: txscript.NonStandardTy,
},
{
name: "script that does not parse",
script: []byte{btcscript.OP_DATA_45},
script: []byte{txscript.OP_DATA_45},
addrs: nil,
reqSigs: 0,
class: btcscript.NonStandardTy,
class: txscript.NonStandardTy,
},
}
t.Logf("Running %d tests.", len(tests))
for i, test := range tests {
class, addrs, reqSigs, err := btcscript.ExtractPkScriptAddrs(
class, addrs, reqSigs, err := txscript.ExtractPkScriptAddrs(
test.script, &btcnet.MainNetParams)
if err != nil {
}

View file

@ -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
// 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
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 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
full list.
*/
package btcscript
package txscript

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript_test
package txscript_test
import (
"encoding/hex"
"fmt"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcnet"
"github.com/btcsuite/btcscript"
"github.com/btcsuite/btcutil"
)
@ -29,14 +29,14 @@ func ExamplePayToAddrScript() {
}
// Create a public key script that pays to the address.
script, err := btcscript.PayToAddrScript(address)
script, err := txscript.PayToAddrScript(address)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Script Hex: %x\n", script)
disasm, err := btcscript.DisasmString(script)
disasm, err := txscript.DisasmString(script)
if err != nil {
fmt.Println(err)
return
@ -60,7 +60,7 @@ func ExampleExtractPkScriptAddrs() {
}
// Extract and print details from the script.
scriptClass, addresses, reqSigs, err := btcscript.ExtractPkScriptAddrs(
scriptClass, addresses, reqSigs, err := txscript.ExtractPkScriptAddrs(
script, &btcnet.MainNetParams)
if err != nil {
fmt.Println(err)

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript
package txscript
import (
"encoding/hex"

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript
package txscript
import (
"errors"

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript_test
package txscript_test
import (
"errors"
@ -10,7 +10,7 @@ import (
"os"
"testing"
"github.com/btcsuite/btcscript"
"github.com/btcsuite/btcd/txscript"
)
func TestSetLogWriter(t *testing.T) {
@ -48,7 +48,7 @@ func TestSetLogWriter(t *testing.T) {
t.Logf("Running %d tests", len(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.Error() != test.expected.Error() {
t.Errorf("SetLogWriter #%d (%s) wrong result\n"+

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript
package txscript
import (
"bytes"
@ -20,7 +20,7 @@ import (
"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
// the script. The current script is passed in as a slice with the firs
// member being the opcode itself.

File diff suppressed because it is too large Load diff

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript
package txscript
import (
"bytes"
@ -193,7 +193,7 @@ func (t ScriptClass) String() string {
return scriptClassToName[t]
}
// Script is the virtual machine that executes btcscripts.
// Script is the virtual machine that executes scripts.
type Script struct {
scripts [][]parsedOpcode
scriptidx int

File diff suppressed because it is too large Load diff

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript
package txscript
import (
"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
// a pay-to-script-hash (although in this situation MultiSigScript() would be a
// better choice to generate the script):
// builder := btcscript.NewScriptBuilder()
// builder.AddOp(btcscript.OP_2).AddData(pubKey1).AddData(pubKey2)
// builder.AddData(pubKey3).AddOp(btcscript.OP_3)
// builder.AddOp(btcscript.OP_CHECKMULTISIG)
// builder := txscript.NewScriptBuilder()
// builder.AddOp(txscript.OP_2).AddData(pubKey1).AddData(pubKey2)
// builder.AddData(pubKey3).AddOp(txscript.OP_3)
// builder.AddOp(txscript.OP_CHECKMULTISIG)
// script, err := builder.Script()
// if err != nil {
// // Handle the error.

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript_test
package txscript_test
import (
"bytes"
"testing"
"github.com/btcsuite/btcscript"
"github.com/btcsuite/btcd/txscript"
)
// TestScriptBuilderAddOp tests that pushing opcodes to a script via the
@ -23,22 +23,22 @@ func TestScriptBuilderAddOp(t *testing.T) {
}{
{
name: "push OP_0",
opcodes: []byte{btcscript.OP_0},
expected: []byte{btcscript.OP_0},
opcodes: []byte{txscript.OP_0},
expected: []byte{txscript.OP_0},
},
{
name: "push OP_1 OP_2",
opcodes: []byte{btcscript.OP_1, btcscript.OP_2},
expected: []byte{btcscript.OP_1, btcscript.OP_2},
opcodes: []byte{txscript.OP_1, txscript.OP_2},
expected: []byte{txscript.OP_1, txscript.OP_2},
},
{
name: "push OP_HASH160 OP_EQUAL",
opcodes: []byte{btcscript.OP_HASH160, btcscript.OP_EQUAL},
expected: []byte{btcscript.OP_HASH160, btcscript.OP_EQUAL},
opcodes: []byte{txscript.OP_HASH160, txscript.OP_EQUAL},
expected: []byte{txscript.OP_HASH160, txscript.OP_EQUAL},
},
}
builder := btcscript.NewScriptBuilder()
builder := txscript.NewScriptBuilder()
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
builder.Reset()
@ -70,47 +70,47 @@ func TestScriptBuilderAddInt64(t *testing.T) {
val int64
expected []byte
}{
{name: "push -1", val: -1, expected: []byte{btcscript.OP_1NEGATE}},
{name: "push small int 0", val: 0, expected: []byte{btcscript.OP_0}},
{name: "push small int 1", val: 1, expected: []byte{btcscript.OP_1}},
{name: "push small int 2", val: 2, expected: []byte{btcscript.OP_2}},
{name: "push small int 3", val: 3, expected: []byte{btcscript.OP_3}},
{name: "push small int 4", val: 4, expected: []byte{btcscript.OP_4}},
{name: "push small int 5", val: 5, expected: []byte{btcscript.OP_5}},
{name: "push small int 6", val: 6, expected: []byte{btcscript.OP_6}},
{name: "push small int 7", val: 7, expected: []byte{btcscript.OP_7}},
{name: "push small int 8", val: 8, expected: []byte{btcscript.OP_8}},
{name: "push small int 9", val: 9, expected: []byte{btcscript.OP_9}},
{name: "push small int 10", val: 10, expected: []byte{btcscript.OP_10}},
{name: "push small int 11", val: 11, expected: []byte{btcscript.OP_11}},
{name: "push small int 12", val: 12, expected: []byte{btcscript.OP_12}},
{name: "push small int 13", val: 13, expected: []byte{btcscript.OP_13}},
{name: "push small int 14", val: 14, expected: []byte{btcscript.OP_14}},
{name: "push small int 15", val: 15, expected: []byte{btcscript.OP_15}},
{name: "push small int 16", val: 16, expected: []byte{btcscript.OP_16}},
{name: "push 17", val: 17, expected: []byte{btcscript.OP_DATA_1, 0x11}},
{name: "push 65", val: 65, expected: []byte{btcscript.OP_DATA_1, 0x41}},
{name: "push 127", val: 127, expected: []byte{btcscript.OP_DATA_1, 0x7f}},
{name: "push 128", val: 128, expected: []byte{btcscript.OP_DATA_2, 0x80, 0}},
{name: "push 255", val: 255, expected: []byte{btcscript.OP_DATA_2, 0xff, 0}},
{name: "push 256", val: 256, expected: []byte{btcscript.OP_DATA_2, 0, 0x01}},
{name: "push 32767", val: 32767, expected: []byte{btcscript.OP_DATA_2, 0xff, 0x7f}},
{name: "push 32768", val: 32768, expected: []byte{btcscript.OP_DATA_3, 0, 0x80, 0}},
{name: "push -2", val: -2, expected: []byte{btcscript.OP_DATA_1, 0x82}},
{name: "push -3", val: -3, expected: []byte{btcscript.OP_DATA_1, 0x83}},
{name: "push -4", val: -4, expected: []byte{btcscript.OP_DATA_1, 0x84}},
{name: "push -5", val: -5, expected: []byte{btcscript.OP_DATA_1, 0x85}},
{name: "push -17", val: -17, expected: []byte{btcscript.OP_DATA_1, 0x91}},
{name: "push -65", val: -65, expected: []byte{btcscript.OP_DATA_1, 0xc1}},
{name: "push -127", val: -127, expected: []byte{btcscript.OP_DATA_1, 0xff}},
{name: "push -128", val: -128, expected: []byte{btcscript.OP_DATA_2, 0x80, 0x80}},
{name: "push -255", val: -255, expected: []byte{btcscript.OP_DATA_2, 0xff, 0x80}},
{name: "push -256", val: -256, expected: []byte{btcscript.OP_DATA_2, 0x00, 0x81}},
{name: "push -32767", val: -32767, expected: []byte{btcscript.OP_DATA_2, 0xff, 0xff}},
{name: "push -32768", val: -32768, expected: []byte{btcscript.OP_DATA_3, 0x00, 0x80, 0x80}},
{name: "push -1", val: -1, expected: []byte{txscript.OP_1NEGATE}},
{name: "push small int 0", val: 0, expected: []byte{txscript.OP_0}},
{name: "push small int 1", val: 1, expected: []byte{txscript.OP_1}},
{name: "push small int 2", val: 2, expected: []byte{txscript.OP_2}},
{name: "push small int 3", val: 3, expected: []byte{txscript.OP_3}},
{name: "push small int 4", val: 4, expected: []byte{txscript.OP_4}},
{name: "push small int 5", val: 5, expected: []byte{txscript.OP_5}},
{name: "push small int 6", val: 6, expected: []byte{txscript.OP_6}},
{name: "push small int 7", val: 7, expected: []byte{txscript.OP_7}},
{name: "push small int 8", val: 8, expected: []byte{txscript.OP_8}},
{name: "push small int 9", val: 9, expected: []byte{txscript.OP_9}},
{name: "push small int 10", val: 10, expected: []byte{txscript.OP_10}},
{name: "push small int 11", val: 11, expected: []byte{txscript.OP_11}},
{name: "push small int 12", val: 12, expected: []byte{txscript.OP_12}},
{name: "push small int 13", val: 13, expected: []byte{txscript.OP_13}},
{name: "push small int 14", val: 14, expected: []byte{txscript.OP_14}},
{name: "push small int 15", val: 15, expected: []byte{txscript.OP_15}},
{name: "push small int 16", val: 16, expected: []byte{txscript.OP_16}},
{name: "push 17", val: 17, expected: []byte{txscript.OP_DATA_1, 0x11}},
{name: "push 65", val: 65, expected: []byte{txscript.OP_DATA_1, 0x41}},
{name: "push 127", val: 127, expected: []byte{txscript.OP_DATA_1, 0x7f}},
{name: "push 128", val: 128, expected: []byte{txscript.OP_DATA_2, 0x80, 0}},
{name: "push 255", val: 255, expected: []byte{txscript.OP_DATA_2, 0xff, 0}},
{name: "push 256", val: 256, expected: []byte{txscript.OP_DATA_2, 0, 0x01}},
{name: "push 32767", val: 32767, expected: []byte{txscript.OP_DATA_2, 0xff, 0x7f}},
{name: "push 32768", val: 32768, expected: []byte{txscript.OP_DATA_3, 0, 0x80, 0}},
{name: "push -2", val: -2, expected: []byte{txscript.OP_DATA_1, 0x82}},
{name: "push -3", val: -3, expected: []byte{txscript.OP_DATA_1, 0x83}},
{name: "push -4", val: -4, expected: []byte{txscript.OP_DATA_1, 0x84}},
{name: "push -5", val: -5, expected: []byte{txscript.OP_DATA_1, 0x85}},
{name: "push -17", val: -17, expected: []byte{txscript.OP_DATA_1, 0x91}},
{name: "push -65", val: -65, expected: []byte{txscript.OP_DATA_1, 0xc1}},
{name: "push -127", val: -127, expected: []byte{txscript.OP_DATA_1, 0xff}},
{name: "push -128", val: -128, expected: []byte{txscript.OP_DATA_2, 0x80, 0x80}},
{name: "push -255", val: -255, expected: []byte{txscript.OP_DATA_2, 0xff, 0x80}},
{name: "push -256", val: -256, expected: []byte{txscript.OP_DATA_2, 0x00, 0x81}},
{name: "push -32767", val: -32767, expected: []byte{txscript.OP_DATA_2, 0xff, 0xff}},
{name: "push -32768", val: -32768, expected: []byte{txscript.OP_DATA_3, 0x00, 0x80, 0x80}},
}
builder := btcscript.NewScriptBuilder()
builder := txscript.NewScriptBuilder()
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
builder.Reset().AddInt64(test.val)
@ -139,34 +139,34 @@ func TestScriptBuilderAddUint64(t *testing.T) {
val uint64
expected []byte
}{
{name: "push small int 0", val: 0, expected: []byte{btcscript.OP_0}},
{name: "push small int 1", val: 1, expected: []byte{btcscript.OP_1}},
{name: "push small int 2", val: 2, expected: []byte{btcscript.OP_2}},
{name: "push small int 3", val: 3, expected: []byte{btcscript.OP_3}},
{name: "push small int 4", val: 4, expected: []byte{btcscript.OP_4}},
{name: "push small int 5", val: 5, expected: []byte{btcscript.OP_5}},
{name: "push small int 6", val: 6, expected: []byte{btcscript.OP_6}},
{name: "push small int 7", val: 7, expected: []byte{btcscript.OP_7}},
{name: "push small int 8", val: 8, expected: []byte{btcscript.OP_8}},
{name: "push small int 9", val: 9, expected: []byte{btcscript.OP_9}},
{name: "push small int 10", val: 10, expected: []byte{btcscript.OP_10}},
{name: "push small int 11", val: 11, expected: []byte{btcscript.OP_11}},
{name: "push small int 12", val: 12, expected: []byte{btcscript.OP_12}},
{name: "push small int 13", val: 13, expected: []byte{btcscript.OP_13}},
{name: "push small int 14", val: 14, expected: []byte{btcscript.OP_14}},
{name: "push small int 15", val: 15, expected: []byte{btcscript.OP_15}},
{name: "push small int 16", val: 16, expected: []byte{btcscript.OP_16}},
{name: "push 17", val: 17, expected: []byte{btcscript.OP_DATA_1, 0x11}},
{name: "push 65", val: 65, expected: []byte{btcscript.OP_DATA_1, 0x41}},
{name: "push 127", val: 127, expected: []byte{btcscript.OP_DATA_1, 0x7f}},
{name: "push 128", val: 128, expected: []byte{btcscript.OP_DATA_2, 0x80, 0}},
{name: "push 255", val: 255, expected: []byte{btcscript.OP_DATA_2, 0xff, 0}},
{name: "push 256", val: 256, expected: []byte{btcscript.OP_DATA_2, 0, 0x01}},
{name: "push 32767", val: 32767, expected: []byte{btcscript.OP_DATA_2, 0xff, 0x7f}},
{name: "push 32768", val: 32768, expected: []byte{btcscript.OP_DATA_3, 0, 0x80, 0}},
{name: "push small int 0", val: 0, expected: []byte{txscript.OP_0}},
{name: "push small int 1", val: 1, expected: []byte{txscript.OP_1}},
{name: "push small int 2", val: 2, expected: []byte{txscript.OP_2}},
{name: "push small int 3", val: 3, expected: []byte{txscript.OP_3}},
{name: "push small int 4", val: 4, expected: []byte{txscript.OP_4}},
{name: "push small int 5", val: 5, expected: []byte{txscript.OP_5}},
{name: "push small int 6", val: 6, expected: []byte{txscript.OP_6}},
{name: "push small int 7", val: 7, expected: []byte{txscript.OP_7}},
{name: "push small int 8", val: 8, expected: []byte{txscript.OP_8}},
{name: "push small int 9", val: 9, expected: []byte{txscript.OP_9}},
{name: "push small int 10", val: 10, expected: []byte{txscript.OP_10}},
{name: "push small int 11", val: 11, expected: []byte{txscript.OP_11}},
{name: "push small int 12", val: 12, expected: []byte{txscript.OP_12}},
{name: "push small int 13", val: 13, expected: []byte{txscript.OP_13}},
{name: "push small int 14", val: 14, expected: []byte{txscript.OP_14}},
{name: "push small int 15", val: 15, expected: []byte{txscript.OP_15}},
{name: "push small int 16", val: 16, expected: []byte{txscript.OP_16}},
{name: "push 17", val: 17, expected: []byte{txscript.OP_DATA_1, 0x11}},
{name: "push 65", val: 65, expected: []byte{txscript.OP_DATA_1, 0x41}},
{name: "push 127", val: 127, expected: []byte{txscript.OP_DATA_1, 0x7f}},
{name: "push 128", val: 128, expected: []byte{txscript.OP_DATA_2, 0x80, 0}},
{name: "push 255", val: 255, expected: []byte{txscript.OP_DATA_2, 0xff, 0}},
{name: "push 256", val: 256, expected: []byte{txscript.OP_DATA_2, 0, 0x01}},
{name: "push 32767", val: 32767, expected: []byte{txscript.OP_DATA_2, 0xff, 0x7f}},
{name: "push 32768", val: 32768, expected: []byte{txscript.OP_DATA_3, 0, 0x80, 0}},
}
builder := btcscript.NewScriptBuilder()
builder := txscript.NewScriptBuilder()
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
builder.Reset().AddUint64(test.val)
@ -197,70 +197,70 @@ func TestScriptBuilderAddData(t *testing.T) {
useFull bool // use AddFullData instead of AddData.
}{
// BIP0062: Pushing an empty byte sequence must use OP_0.
{name: "push empty byte sequence", data: []byte{}, expected: []byte{btcscript.OP_0}},
{name: "push 1 byte 0x00", data: []byte{0x00}, 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{txscript.OP_0}},
// BIP0062: Pushing a 1-byte sequence of byte 0x01 through 0x10 must use OP_n.
{name: "push 1 byte 0x01", data: []byte{0x01}, expected: []byte{btcscript.OP_1}},
{name: "push 1 byte 0x02", data: []byte{0x02}, expected: []byte{btcscript.OP_2}},
{name: "push 1 byte 0x03", data: []byte{0x03}, expected: []byte{btcscript.OP_3}},
{name: "push 1 byte 0x04", data: []byte{0x04}, expected: []byte{btcscript.OP_4}},
{name: "push 1 byte 0x05", data: []byte{0x05}, expected: []byte{btcscript.OP_5}},
{name: "push 1 byte 0x06", data: []byte{0x06}, expected: []byte{btcscript.OP_6}},
{name: "push 1 byte 0x07", data: []byte{0x07}, expected: []byte{btcscript.OP_7}},
{name: "push 1 byte 0x08", data: []byte{0x08}, expected: []byte{btcscript.OP_8}},
{name: "push 1 byte 0x09", data: []byte{0x09}, expected: []byte{btcscript.OP_9}},
{name: "push 1 byte 0x0a", data: []byte{0x0a}, expected: []byte{btcscript.OP_10}},
{name: "push 1 byte 0x0b", data: []byte{0x0b}, expected: []byte{btcscript.OP_11}},
{name: "push 1 byte 0x0c", data: []byte{0x0c}, expected: []byte{btcscript.OP_12}},
{name: "push 1 byte 0x0d", data: []byte{0x0d}, expected: []byte{btcscript.OP_13}},
{name: "push 1 byte 0x0e", data: []byte{0x0e}, expected: []byte{btcscript.OP_14}},
{name: "push 1 byte 0x0f", data: []byte{0x0f}, expected: []byte{btcscript.OP_15}},
{name: "push 1 byte 0x10", data: []byte{0x10}, expected: []byte{btcscript.OP_16}},
{name: "push 1 byte 0x01", data: []byte{0x01}, expected: []byte{txscript.OP_1}},
{name: "push 1 byte 0x02", data: []byte{0x02}, expected: []byte{txscript.OP_2}},
{name: "push 1 byte 0x03", data: []byte{0x03}, expected: []byte{txscript.OP_3}},
{name: "push 1 byte 0x04", data: []byte{0x04}, expected: []byte{txscript.OP_4}},
{name: "push 1 byte 0x05", data: []byte{0x05}, expected: []byte{txscript.OP_5}},
{name: "push 1 byte 0x06", data: []byte{0x06}, expected: []byte{txscript.OP_6}},
{name: "push 1 byte 0x07", data: []byte{0x07}, expected: []byte{txscript.OP_7}},
{name: "push 1 byte 0x08", data: []byte{0x08}, expected: []byte{txscript.OP_8}},
{name: "push 1 byte 0x09", data: []byte{0x09}, expected: []byte{txscript.OP_9}},
{name: "push 1 byte 0x0a", data: []byte{0x0a}, expected: []byte{txscript.OP_10}},
{name: "push 1 byte 0x0b", data: []byte{0x0b}, expected: []byte{txscript.OP_11}},
{name: "push 1 byte 0x0c", data: []byte{0x0c}, expected: []byte{txscript.OP_12}},
{name: "push 1 byte 0x0d", data: []byte{0x0d}, expected: []byte{txscript.OP_13}},
{name: "push 1 byte 0x0e", data: []byte{0x0e}, expected: []byte{txscript.OP_14}},
{name: "push 1 byte 0x0f", data: []byte{0x0f}, expected: []byte{txscript.OP_15}},
{name: "push 1 byte 0x10", data: []byte{0x10}, expected: []byte{txscript.OP_16}},
// 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
// use the normal data push (opcode byte n, with n the number of
// bytes, followed n bytes of data being pushed).
{name: "push 1 byte 0x11", data: []byte{0x11}, expected: []byte{btcscript.OP_DATA_1, 0x11}},
{name: "push 1 byte 0x80", data: []byte{0x80}, expected: []byte{btcscript.OP_DATA_1, 0x80}},
{name: "push 1 byte 0x82", data: []byte{0x82}, expected: []byte{btcscript.OP_DATA_1, 0x82}},
{name: "push 1 byte 0xff", data: []byte{0xff}, expected: []byte{btcscript.OP_DATA_1, 0xff}},
{name: "push 1 byte 0x11", data: []byte{0x11}, expected: []byte{txscript.OP_DATA_1, 0x11}},
{name: "push 1 byte 0x80", data: []byte{0x80}, expected: []byte{txscript.OP_DATA_1, 0x80}},
{name: "push 1 byte 0x82", data: []byte{0x82}, expected: []byte{txscript.OP_DATA_1, 0x82}},
{name: "push 1 byte 0xff", data: []byte{0xff}, expected: []byte{txscript.OP_DATA_1, 0xff}},
{
name: "push data len 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",
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.
{
name: "push data len 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",
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.
{
name: "push data len 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",
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
@ -290,7 +290,7 @@ func TestScriptBuilderAddData(t *testing.T) {
{
name: "push data len 32767 (non-canonical)",
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,
},
@ -298,12 +298,12 @@ func TestScriptBuilderAddData(t *testing.T) {
{
name: "push data len 65536 (non-canonical)",
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,
},
}
builder := btcscript.NewScriptBuilder()
builder := txscript.NewScriptBuilder()
t.Logf("Running %d tests", len(tests))
for i, test := range tests {
if !test.useFull {
@ -328,8 +328,8 @@ func TestExceedMaxScriptSize(t *testing.T) {
t.Parallel()
// Start off by constructing a max size script.
maxScriptSize := btcscript.TstMaxScriptSize
builder := btcscript.NewScriptBuilder()
maxScriptSize := txscript.TstMaxScriptSize
builder := txscript.NewScriptBuilder()
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
origScript, err := builder.Script()
if err != nil {
@ -339,7 +339,7 @@ func TestExceedMaxScriptSize(t *testing.T) {
// Ensure adding data that would exceed the maximum size of the script
// does not add the data.
script, err := builder.AddData([]byte{0x00}).Script()
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
t.Fatalf("ScriptBuilder.AddData allowed exceeding max 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
// script does not add the data.
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
script, err = builder.AddOp(btcscript.OP_0).Script()
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
script, err = builder.AddOp(txscript.OP_0).Script()
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
t.Fatalf("ScriptBuilder.AddOp unexpected modified script - "+
"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.
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
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 - "+
"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.
builder.Reset().AddFullData(make([]byte, maxScriptSize-3))
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 - "+
"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
// space left to add each data type without an error and force an
// initial error condition.
maxScriptSize := btcscript.TstMaxScriptSize
builder := btcscript.NewScriptBuilder()
maxScriptSize := txscript.TstMaxScriptSize
builder := txscript.NewScriptBuilder()
builder.Reset().AddFullData(make([]byte, maxScriptSize-8))
origScript, err := builder.Script()
if err != nil {
t.Fatalf("ScriptBuilder.AddFullData unexpected error: %v", err)
}
script, err := builder.AddData([]byte{0x00, 0x00, 0x00, 0x00, 0x00}).Script()
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
t.Fatalf("ScriptBuilder.AddData allowed exceeding max 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
// that has errored doesn't succeed.
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")
}
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.
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")
}
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.
script, err = builder.AddOp(btcscript.OP_0).Script()
if _, ok := err.(btcscript.ErrScriptNotCanonical); !ok || err == nil {
script, err = builder.AddOp(txscript.OP_0).Script()
if _, ok := err.(txscript.ErrScriptNotCanonical); !ok || err == nil {
t.Fatal("ScriptBuilder.AddOp succeeded on errored script")
}
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
// succeed.
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")
}
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
// doesn't succeed.
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")
}
if !bytes.Equal(script, origScript) {

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript
package txscript
import (
"encoding/hex"

View file

@ -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
// license that can be found in the LICENSE file.
package btcscript_test
package txscript_test
import (
"bytes"
@ -11,7 +11,7 @@ import (
"math/big"
"testing"
"github.com/btcsuite/btcscript"
"github.com/btcsuite/btcd/txscript"
)
// TestStack tests that all of the stack operations work as expected.
@ -21,14 +21,14 @@ func TestStack(t *testing.T) {
tests := []struct {
name string
before [][]byte
operation func(*btcscript.Stack) error
operation func(*txscript.Stack) error
expectedReturn error
after [][]byte
}{
{
"noop",
[][]byte{{1}, {2}, {3}, {4}, {5}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return nil
},
nil,
@ -37,37 +37,37 @@ func TestStack(t *testing.T) {
{
"peek underflow (byte)",
[][]byte{{1}, {2}, {3}, {4}, {5}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
_, err := stack.PeekByteArray(5)
return err
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"peek underflow (int)",
[][]byte{{1}, {2}, {3}, {4}, {5}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
_, err := stack.PeekInt(5)
return err
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"peek underflow (bool)",
[][]byte{{1}, {2}, {3}, {4}, {5}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
_, err := stack.PeekBool(5)
return err
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"pop",
[][]byte{{1}, {2}, {3}, {4}, {5}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
val, err := stack.PopByteArray()
if err != nil {
return err
@ -83,7 +83,7 @@ func TestStack(t *testing.T) {
{
"pop",
[][]byte{{1}, {2}, {3}, {4}, {5}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
val, err := stack.PopByteArray()
if err != nil {
return err
@ -99,7 +99,7 @@ func TestStack(t *testing.T) {
{
"pop everything",
[][]byte{{1}, {2}, {3}, {4}, {5}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
for i := 0; i < 5; i++ {
_, err := stack.PopByteArray()
if err != nil {
@ -114,7 +114,7 @@ func TestStack(t *testing.T) {
{
"pop underflow",
[][]byte{{1}, {2}, {3}, {4}, {5}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
for i := 0; i < 6; i++ {
_, err := stack.PopByteArray()
if err != nil {
@ -123,13 +123,13 @@ func TestStack(t *testing.T) {
}
return nil
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"pop bool",
[][]byte{{0}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
val, err := stack.PopBool()
if err != nil {
return err
@ -146,7 +146,7 @@ func TestStack(t *testing.T) {
{
"pop bool",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
val, err := stack.PopBool()
if err != nil {
return err
@ -163,7 +163,7 @@ func TestStack(t *testing.T) {
{
"pop bool",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
_, err := stack.PopBool()
if err != nil {
return err
@ -171,13 +171,13 @@ func TestStack(t *testing.T) {
return nil
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"popInt 0",
[][]byte{{0x0}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
v, err := stack.PopInt()
if err != nil {
return err
@ -193,7 +193,7 @@ func TestStack(t *testing.T) {
{
"popInt -0",
[][]byte{{0x80}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
v, err := stack.PopInt()
if err != nil {
return err
@ -209,7 +209,7 @@ func TestStack(t *testing.T) {
{
"popInt 1",
[][]byte{{0x01}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
v, err := stack.PopInt()
if err != nil {
return err
@ -225,7 +225,7 @@ func TestStack(t *testing.T) {
{
"popInt 1 leading 0",
[][]byte{{0x01, 0x00, 0x00, 0x00}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
v, err := stack.PopInt()
if err != nil {
return err
@ -242,7 +242,7 @@ func TestStack(t *testing.T) {
{
"popInt -1",
[][]byte{{0x81}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
v, err := stack.PopInt()
if err != nil {
return err
@ -258,7 +258,7 @@ func TestStack(t *testing.T) {
{
"popInt -1 leading 0",
[][]byte{{0x01, 0x00, 0x00, 0x80}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
v, err := stack.PopInt()
if err != nil {
return err
@ -276,7 +276,7 @@ func TestStack(t *testing.T) {
{
"popInt -513",
[][]byte{{0x1, 0x82}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
v, err := stack.PopInt()
if err != nil {
return err
@ -294,7 +294,7 @@ func TestStack(t *testing.T) {
{
"peekint nomodify -1",
[][]byte{{0x01, 0x00, 0x00, 0x80}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
v, err := stack.PeekInt(0)
if err != nil {
return err
@ -311,7 +311,7 @@ func TestStack(t *testing.T) {
{
"PushInt 0",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushInt(big.NewInt(0))
return nil
},
@ -321,7 +321,7 @@ func TestStack(t *testing.T) {
{
"PushInt 1",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushInt(big.NewInt(1))
return nil
},
@ -331,7 +331,7 @@ func TestStack(t *testing.T) {
{
"PushInt -1",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushInt(big.NewInt(-1))
return nil
},
@ -341,7 +341,7 @@ func TestStack(t *testing.T) {
{
"PushInt two bytes",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushInt(big.NewInt(256))
return nil
},
@ -352,7 +352,7 @@ func TestStack(t *testing.T) {
{
"PushInt leading zeros",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
// this will have the highbit set
stack.PushInt(big.NewInt(128))
return nil
@ -363,7 +363,7 @@ func TestStack(t *testing.T) {
{
"dup",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
err := stack.DupN(1)
if err != nil {
return err
@ -377,7 +377,7 @@ func TestStack(t *testing.T) {
{
"dup2",
[][]byte{{1}, {2}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
err := stack.DupN(2)
if err != nil {
return err
@ -391,7 +391,7 @@ func TestStack(t *testing.T) {
{
"dup3",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
err := stack.DupN(3)
if err != nil {
return err
@ -405,7 +405,7 @@ func TestStack(t *testing.T) {
{
"dup0",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
err := stack.DupN(0)
if err != nil {
return err
@ -413,13 +413,13 @@ func TestStack(t *testing.T) {
return nil
},
btcscript.ErrStackInvalidArgs,
txscript.ErrStackInvalidArgs,
[][]byte{},
},
{
"dup-1",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
err := stack.DupN(-1)
if err != nil {
return err
@ -427,13 +427,13 @@ func TestStack(t *testing.T) {
return nil
},
btcscript.ErrStackInvalidArgs,
txscript.ErrStackInvalidArgs,
[][]byte{},
},
{
"dup too much",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
err := stack.DupN(2)
if err != nil {
return err
@ -441,13 +441,13 @@ func TestStack(t *testing.T) {
return nil
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"dup-1",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
err := stack.DupN(-1)
if err != nil {
return err
@ -455,13 +455,13 @@ func TestStack(t *testing.T) {
return nil
},
btcscript.ErrStackInvalidArgs,
txscript.ErrStackInvalidArgs,
[][]byte{},
},
{
"PushBool true",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushBool(true)
return nil
@ -472,7 +472,7 @@ func TestStack(t *testing.T) {
{
"PushBool false",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushBool(false)
return nil
@ -483,7 +483,7 @@ func TestStack(t *testing.T) {
{
"PushBool PopBool",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushBool(true)
val, err := stack.PopBool()
if err != nil {
@ -501,7 +501,7 @@ func TestStack(t *testing.T) {
{
"PushBool PopBool 2",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushBool(false)
val, err := stack.PopBool()
if err != nil {
@ -519,7 +519,7 @@ func TestStack(t *testing.T) {
{
"PushInt PopBool",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushInt(big.NewInt(1))
val, err := stack.PopBool()
if err != nil {
@ -537,7 +537,7 @@ func TestStack(t *testing.T) {
{
"PushInt PopBool 2",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushInt(big.NewInt(0))
val, err := stack.PopBool()
if err != nil {
@ -555,7 +555,7 @@ func TestStack(t *testing.T) {
{
"PushInt PopBool 2",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushInt(big.NewInt(0))
val, err := stack.PopBool()
if err != nil {
@ -573,7 +573,7 @@ func TestStack(t *testing.T) {
{
"Nip top",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.NipN(0)
},
nil,
@ -582,7 +582,7 @@ func TestStack(t *testing.T) {
{
"Nip middle",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.NipN(1)
},
nil,
@ -591,7 +591,7 @@ func TestStack(t *testing.T) {
{
"Nip low",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.NipN(2)
},
nil,
@ -600,27 +600,27 @@ func TestStack(t *testing.T) {
{
"Nip too much",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
// bite off more than we can chew
return stack.NipN(3)
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{{2}, {3}},
},
{
"Nip too much",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
// bite off more than we can chew
return stack.NipN(3)
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{{2}, {3}},
},
{
"keep on tucking",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.Tuck()
},
nil,
@ -629,25 +629,25 @@ func TestStack(t *testing.T) {
{
"a little tucked up",
[][]byte{{1}}, // too few arguments for tuck
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.Tuck()
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"all tucked up",
[][]byte{}, // too few arguments for tuck
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.Tuck()
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"drop 1",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.DropN(1)
},
nil,
@ -656,7 +656,7 @@ func TestStack(t *testing.T) {
{
"drop 2",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.DropN(2)
},
nil,
@ -665,7 +665,7 @@ func TestStack(t *testing.T) {
{
"drop 3",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.DropN(3)
},
nil,
@ -674,7 +674,7 @@ func TestStack(t *testing.T) {
{
"drop 4",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.DropN(4)
},
nil,
@ -683,25 +683,25 @@ func TestStack(t *testing.T) {
{
"drop 4/5",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.DropN(5)
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"drop invalid",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.DropN(0)
},
btcscript.ErrStackInvalidArgs,
txscript.ErrStackInvalidArgs,
[][]byte{},
},
{
"Rot1",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.RotN(1)
},
nil,
@ -710,7 +710,7 @@ func TestStack(t *testing.T) {
{
"Rot2",
[][]byte{{1}, {2}, {3}, {4}, {5}, {6}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.RotN(2)
},
nil,
@ -719,25 +719,25 @@ func TestStack(t *testing.T) {
{
"Rot too little",
[][]byte{{1}, {2}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.RotN(1)
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"Rot0",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.RotN(0)
},
btcscript.ErrStackInvalidArgs,
txscript.ErrStackInvalidArgs,
[][]byte{},
},
{
"Swap1",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.SwapN(1)
},
nil,
@ -746,7 +746,7 @@ func TestStack(t *testing.T) {
{
"Swap2",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.SwapN(2)
},
nil,
@ -755,25 +755,25 @@ func TestStack(t *testing.T) {
{
"Swap too little",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.SwapN(1)
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"Swap0",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.SwapN(0)
},
btcscript.ErrStackInvalidArgs,
txscript.ErrStackInvalidArgs,
[][]byte{},
},
{
"Over1",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.OverN(1)
},
nil,
@ -782,7 +782,7 @@ func TestStack(t *testing.T) {
{
"Over2",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.OverN(2)
},
nil,
@ -791,25 +791,25 @@ func TestStack(t *testing.T) {
{
"Over too little",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.OverN(1)
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"Over0",
[][]byte{{1}, {2}, {3}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.OverN(0)
},
btcscript.ErrStackInvalidArgs,
txscript.ErrStackInvalidArgs,
[][]byte{},
},
{
"Pick1",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.PickN(1)
},
nil,
@ -818,7 +818,7 @@ func TestStack(t *testing.T) {
{
"Pick2",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.PickN(2)
},
nil,
@ -827,16 +827,16 @@ func TestStack(t *testing.T) {
{
"Pick too little",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.PickN(1)
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"Roll1",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.RollN(1)
},
nil,
@ -845,7 +845,7 @@ func TestStack(t *testing.T) {
{
"Roll2",
[][]byte{{1}, {2}, {3}, {4}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.RollN(2)
},
nil,
@ -854,16 +854,16 @@ func TestStack(t *testing.T) {
{
"Roll too little",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
return stack.RollN(1)
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
{
"Peek bool",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
// Peek bool is otherwise pretty well tested,
// just check it works.
val, err := stack.PeekBool(0)
@ -881,7 +881,7 @@ func TestStack(t *testing.T) {
{
"Peek bool 2",
[][]byte{{0}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
// Peek bool is otherwise pretty well tested,
// just check it works.
val, err := stack.PeekBool(0)
@ -899,7 +899,7 @@ func TestStack(t *testing.T) {
{
"Peek int",
[][]byte{{1}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
// Peek int is otherwise pretty well tested,
// just check it works.
val, err := stack.PeekInt(0)
@ -917,7 +917,7 @@ func TestStack(t *testing.T) {
{
"Peek int 2",
[][]byte{{0}},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
// Peek int is otherwise pretty well tested,
// just check it works.
val, err := stack.PeekInt(0)
@ -935,7 +935,7 @@ func TestStack(t *testing.T) {
{
"pop int",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
stack.PushInt(big.NewInt(1))
// Peek int is otherwise pretty well tested,
// just check it works.
@ -954,19 +954,19 @@ func TestStack(t *testing.T) {
{
"pop empty",
[][]byte{},
func(stack *btcscript.Stack) error {
func(stack *txscript.Stack) error {
// Peek int is otherwise pretty well tested,
// just check it works.
_, err := stack.PopInt()
return err
},
btcscript.ErrStackUnderflow,
txscript.ErrStackUnderflow,
[][]byte{},
},
}
for _, test := range tests {
stack := btcscript.Stack{}
stack := txscript.Stack{}
for i := range test.before {
stack.PushByteArray(test.before[i])