Commit graph

29 commits

Author SHA1 Message Date
Owain G. Ainsworth
40c75b27ac Add CalcScriptInfo entrypoint to return info about scriptpairs.
Specficially the class of the pkScript, the  expected numbers of
arguments and the number of sigops.
2013-10-17 17:07:39 +01:00
Owain G. Ainsworth
53ca29efad fix multi-byte bug in previous.
Use the right offset when working out if we should mask off the sign bit.
Add more tests that would have caught this case.
2013-10-10 00:20:14 +01:00
Josh Rickmar
8a743c344a Update all comments and test coverage with new func name 2013-10-08 13:12:24 -04:00
Josh Rickmar
a5f81fc545 Add PayToPubKeyHashScript and SignatureScript functions.
PayToPubKeyHashScript generates a new pay to pubkey hash script to use
as the pkScript when creating new transactions.  If the passed pubkey
hash is an invalid size, StackErrInvalidOpcode will be returned as an
error.

SignatureScript returns the signature script necessary to validate a
single input of a transaction.

This also adds sanity checking for serializing scripts into byte
slices.  If the length of a serialized opcode does not equal the
expected length, StackErrInvalidOpcode will be returned when unparsing
a []parsedOpcode.

New internal tests were added to verify checks for valid and invalid
parsed opcodes.
2013-10-01 12:50:22 -04:00
Dave Collins
29ed09cc98 Add IsPushOnlyScript.
This commit adds an exported function, IsPushOnlyScript, which can be used
to tell whether or not a script only pushes data (only contains opcodes
that push data).
2013-09-30 16:54:54 -05:00
Owain G. Ainsworth
a63edcd2dc preallocate a few arrays.
When we do append loops, make an educated guess as to the size and make an array
with that capacity to avoid extra copying.

Doesn't affect the speed of the tests, over 4 runs the difference was lost in
the noise.
2013-09-25 17:38:20 +01:00
Owain G. Ainsworth
22c29c4316 Perform pushed length checks at exec time, not parse.
To match bitcoind behaviour. Fix tests to agree with this direction.
2013-07-29 22:00:57 +01:00
Owain G. Ainsworth
bedaddb790 add GetScriptClass to return the internal script type of a script.
To be used to tell which class a script is (multisig, scripthash, pubkey,
pkhash, or nonstandard)
2013-07-05 15:23:02 +01:00
Owain G. Ainsworth
c41330e772 Add basic test for if internal opcode definitions are buggy. 2013-06-28 00:46:34 +01:00
Owain G. Ainsworth
89578c985a add basic test for OP_SHA1
yup, it produces the sha of the data.
2013-06-27 16:15:32 +01:00
Owain G. Ainsworth
e5a2756795 Test empty scripts and out of bounds for DisasmScript()
give disasmscript a defined error return for out of bounds.
2013-06-27 15:07:37 +01:00
Owain G. Ainsworth
244ce4b96e add IsPayToScriptHash api
To tell ifa bytestream matches teh p2sh pattern.
2013-06-27 14:20:08 +01:00
Owain G. Ainsworth
dd216cef29 Test pushing at and beyond the boundary for largest stack item. 2013-06-26 23:57:49 +01:00
Owain G. Ainsworth
df898ae1dd test a few non-standards script types to hit some edge cases. 2013-06-26 23:28:44 +01:00
Owain G. Ainsworth
d6161f0d41 fix ScriptToAddress when called with 0 length script.
It did work by luck before, but now it works no matter what the template
tables say. Add tests for the other error cases and internal data
assertions.
2013-06-26 22:11:54 +01:00
Owain G. Ainsworth
7ae307abfd Fix case where we have an empty script that isn't the first.
Silly check needed to confirm it was the first script. Add test for this case.
2013-06-26 14:16:00 +01:00
Owain G. Ainsworth
7e937fae75 testing for the case where a p2sh sigscript isn't pushonly.
Also providing a defined error (from NewScript) for that case.
2013-06-25 13:12:15 +01:00
Owain G. Ainsworth
4a87e6e3a7 Test a few failure cases of p2sh txs. 2013-06-25 00:12:08 +01:00
Owain G. Ainsworth
2bdaebfa74 some more tests for GetPreciseSigOpsCount. total coverage now. 2013-06-24 16:32:41 +01:00
Owain G. Ainsworth
8fe24958bb Test the unfinished condition of CheckErrorCondition 2013-06-21 01:33:38 +01:00
Owain G. Ainsworth
03696a8874 Add functions to count the number of signature operations in a script.
To be usd for validation. Most of the codepaths teste, a few tests
missing for cases needed tests in the validation codepaths too. To be
worked on in tree.
2013-06-20 20:10:30 +01:00
Owain G. Ainsworth
25624bc6a7 check that OP_CHECK_MULTISIG also triggers on too many ops 2013-06-20 01:21:12 +01:00
Owain G. Ainsworth
bac455cdd2 Fix reversed test bug with the max operations handling
We were counting the number of push ops instead of the number of non
push ops.  Add tests that found this (checking tha the max operations
check fires).
2013-06-20 00:30:34 +01:00
Owain G. Ainsworth
8035de426b Check that the pc validation code works ok.
Add a testing only interface to set the pc and set it to a few invalid
settings to check that step and disasmPC all blow up correctly.
2013-06-19 23:31:44 +01:00
Owain G. Ainsworth
625541e202 add some testing for byte format in stack.PushInt()
should verify all the formats now.

pain causes endian little.
2013-06-19 01:06:02 +01:00
Owain G. Ainsworth
501b711301 int.Sign() in go will never return negative for zero.
So remove the -0 handling in fromInt, only toInt needs it.
2013-06-19 00:51:48 +01:00
Owain G. Ainsworth
4692d64f68 permit tests expect fail for nonspecified return code.
Use this to test the pubkey paths in checksig which return btcec errors
which we don't define. all of the other active tests know the return
code we need.
2013-06-18 23:36:44 +01:00
Owain G. Ainsworth
df0c0b27d1 Factor the end-of-script error handling into a function.
Use it to reduce code dpulication in the bip16 case.

In addition we export it so that that a user could run:
for !done && err == nil {
	done, err = s.Step()
}
err = s.CheckErrorCondition()

manually instead of having to run Execute().
2013-06-18 17:44:29 +01:00
Dave Collins
1197770159 Initial implementation. 2013-06-13 14:59:46 -05:00