Commit graph

18 commits

Author SHA1 Message Date
Owain G. Ainsworth
52a1488eaf bitcoind only fails on invalid (undefined) opcodes when they are executed.
So add entries for them that disassemble and parse ok, but will fail
when executed with the appropriate error. Add a full suite of tests to confirm
that this happens.

Found by a strange transaction in testnet.
2013-10-08 00:16:23 +01: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
26fb20e4ed Remove need for protocol version.
This commit modifies the code to no longer require a protocol version.  It
does this by making use of the new Serialize function in btcwire.

Unfortuantely this does entail a public API change which I generally don't
like to do, but eliminating the usage of the protocol version throughout
the codebase was important enough to warrant the change.
2013-08-05 18:11:34 -05:00
Owain G. Ainsworth
118014a5b4 gofmt. 2013-07-31 01:31:27 +01:00
Owain G. Ainsworth
e7f9415e4f Return 0 for bad scripts from sigops code instead of an error.
matches how bitcoind behaves.
2013-07-25 14:27:58 +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
244ce4b96e add IsPayToScriptHash api
To tell ifa bytestream matches teh p2sh pattern.
2013-06-27 14:20:08 +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
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
53ba8fb834 gofmt 2013-06-21 01:33:56 +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
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
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
Dave Collins
1197770159 Initial implementation. 2013-06-13 14:59:46 -05:00