Skip to content

Conversation

@dcousens
Copy link
Contributor

This pull request primarily adds a large portion of the core Bitcoin tests (aka, test data from the reference client), and makes some minor changes to Transaction.hashForSignature to ensure it can pass these tests.
To do this, some new functionality was added:

  • Script.fromChunks, required only by without for now, this function will likely be the backbone behind the entire of Script, avoiding the necessity to parse scripts, and removing all mutable functionality within Script.
  • Script.prototype.without, similar in functionality to CScript.findAndDelete in the reference client, however fundamentally just a filter over the script.chunks. This was made easy by Script.fromChunks.
  • bufferutils.readPushDataInt
  • bufferutils.writePushDataInt
  • bufferutils.pushDataSize

All with appropriate tests. (Script.fromChunks will be receiving more, but it covers the basics for now).

Finally, a change required to pass the tests was the fix up of the Transaction constant SIGHASH_ANYONECANPAY, which appears to have been incorrect since the 0.1.3 tag (and no doubt since this libraries creation).

edit: It also fixes many of the tests which had incorrect exception handling, or tests that were throwing on the wrong exceptions etc.

@dcousens
Copy link
Contributor Author

Given that Script.prototype.without is essentially just a filter over the chunks, perhaps it might be better to instead provide it as such? Script.prototype.filter?
Thoughts?

The use case is selectively removing either an opcode or (eventually, not supported for now) a data block.

dcousens added 2 commits May 29, 2014 14:43
All the `invalid2` tests have been removed as they were not invalid
base58check.  They were actually valid in some cases.
They will be re-integrated in more specific bitcoin core tests in
relation to Address/ECKey respectively.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.38%) when pulling 35486ca on dcousens:btccoretests into c9ad359 on bitcoinjs:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.39%) when pulling 6d08362 on dcousens:btccoretests into c9ad359 on bitcoinjs:master.

dcousens added 11 commits May 29, 2014 16:01
These weren't broken as such, but they weren't distinctly checking that
the right exception was thrown either.
Also fixes the bug when the sequence number is 0 and
`TransactionIn.defaultSequence` is used; resulting in an undefined
sequence number as it is undefined.
To save on us building a hash map with which to check the inputs,
instead I just ensure that the order of the inputs is the same as it is
in the serialized transaction.
Adds asserts to ensure only valid hashes are created (until the
implementation is complete).

Also uses `Script.without` to remove OP_CODESEPARATOR from the Scripts
as required by the protocol.
Not all tests are added yet, but this represents a significant portion.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.39%) when pulling f7a2bb6 on dcousens:btccoretests into c9ad359 on bitcoinjs:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.39%) when pulling 1406915 on dcousens:btccoretests into c9ad359 on bitcoinjs:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.39%) when pulling 6f3d829 on dcousens:btccoretests into c9ad359 on bitcoinjs:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.66%) when pulling bda1a83 on dcousens:btccoretests into c9ad359 on bitcoinjs:master.

@kyledrake
Copy link
Contributor

+1. Awesome getting some of the Bitcoin Core tests in!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just convert every array-like chunk in chunks into a buffer after line 372? then the type check won't be necessary here and below. And when chunks are fully bufferified, just remove the conversion code we are good to go. minor point given that this is still WIP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly what will happen, just avoided for now because this would require changing a lot more code.
In fact, the conversion won't even be necessary, we'll never accept Arrays in the first place once Script is "bufferified".

@weilu
Copy link
Contributor

weilu commented May 30, 2014

LGTM

weilu added a commit that referenced this pull request May 30, 2014
Bitcoin core tests and fixed exception testing
@weilu weilu merged commit 13f95d4 into bitcoinjs:master May 30, 2014
@dcousens dcousens deleted the btccoretests branch May 30, 2014 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants