Commit graph

425 commits

Author SHA1 Message Date
Daniel Cousens
9a72c7437b Script: adds Script.EMPTY constant 2014-06-13 10:49:08 +10:00
Wei Lu
f53e35ed28 wallet: delete utxo instead of marking it as spend 2014-06-12 16:48:01 +08:00
Wei Lu
d265b53b03 wallet: processTx -> processConfirmedTx, processPendingTx 2014-06-12 16:47:46 +08:00
Wei Lu
e064e9d29d wallet.createTx ignores pending utxo 2014-06-12 13:11:28 +08:00
Wei Lu
660c95483d wallet.processTx accepts isPending flag and passes it on to output 2014-06-12 12:56:50 +08:00
Daniel Cousens
e21939bad5 ecpubkey: removed unnecessary alias 2014-06-10 18:36:00 +10:00
Daniel Cousens
4ce9015f3b use ecurve instead of custom ec 2014-06-10 17:58:13 +10:00
Daniel Cousens
f20ffec8b3 tests: always use for, it testing style 2014-06-07 19:46:06 +10:00
Daniel Cousens
61b4216afb script: fix capitalization in test fixture 2014-06-07 19:34:09 +10:00
Daniel Cousens
eb3a6bcb31 all: rename D to d as per SEC convention 2014-06-07 18:24:16 +10:00
Kyle Drake
6b55ab4d04 Merge pull request #189 from coinpunk/remove-untested-curves
Remove untested EC curves
2014-06-06 14:58:12 -07:00
Kyle Drake
9b5dfbd865 Merge pull request #206 from dcousens/base58rework
Base58 Check rework
2014-06-04 16:54:18 -07:00
Daniel Cousens
4c6385e0d2 integration: use ScriptPubKey for Address 2014-06-05 00:06:28 +10:00
Daniel Cousens
2b563ec55a integration: fix invalid use of network object 2014-06-05 00:06:07 +10:00
Daniel Cousens
943621f466 Address/HDNode: fix test descriptions 2014-06-04 15:46:40 +10:00
Daniel Cousens
27f9e7dc1e convert: remove reverseEndian 2014-06-04 15:46:40 +10:00
Daniel Cousens
8433d73d06 convert: use Buffers and add more tests 2014-06-04 15:46:40 +10:00
Daniel Cousens
28dc390377 EC/Key: use network object consistently 2014-06-04 15:23:40 +10:00
Daniel Cousens
d39662e375 Base58check: no longer encodes version separately 2014-06-04 15:23:37 +10:00
Wei Lu
63e6cf987f Merge pull request #203 from dcousens/hdwallettests
HDWallet tests and strict constructor
2014-06-04 13:05:15 +08:00
Daniel Cousens
6a73bc02f5 HDNode: rename priv/pub to privKey/pubKey 2014-06-03 19:54:58 +10:00
Daniel Cousens
dca193be4e HDNode: adds neutered test examples 2014-06-03 19:54:15 +10:00
Daniel Cousens
64e307b13f HDWallet: rename to HDNode 2014-06-03 17:08:42 +10:00
Daniel Cousens
c340f5cf83 HDWallet: now export all information by default 2014-06-03 17:04:05 +10:00
Daniel Cousens
dca284a131 HDWallet: rename derivePrivate to deriveHardened 2014-06-03 17:04:05 +10:00
Daniel Cousens
29fbbaa58d HDWallet: adds Public -> public tests 2014-06-03 16:21:20 +10:00
Daniel Cousens
99bb69bf20 HDWallet: moves hardened info to test data more explicitly 2014-06-03 16:12:36 +10:00
Wei Lu
c76d3cef37 Merge pull request #202 from dcousens/ecneg
ECKey -D test and light cleanup
2014-06-03 13:38:25 +08:00
Daniel Cousens
938c43649d HDWallet: remove unnecessary Base58 context on fromBuffer tests 2014-06-01 16:48:41 +10:00
Daniel Cousens
4cec42a8d8 HDWallet: add to/fromHex tests 2014-06-01 16:42:54 +10:00
Daniel Cousens
260705a24a HDWallet: consistent test data ordering
Also adds network parameter for later moving the network specific tests
to be data driven.
2014-06-01 16:42:01 +10:00
Daniel Cousens
0e61f41a52 HDWallet: fix test data descriptions 2014-06-01 16:41:44 +10:00
Daniel Cousens
533d61380a HDWallet: improve testing coverage 2014-06-01 16:41:42 +10:00
Daniel Cousens
e8e862f632 HDWallet: adds PubKey validation 2014-05-31 20:40:57 +10:00
Daniel Cousens
759aeb9abc HDWallet: remove repeated assertion 2014-05-31 20:40:57 +10:00
Daniel Cousens
c0006c299f HDWallet: use new constructor 2014-05-31 20:40:57 +10:00
Daniel Cousens
58dd86bda1 HDWallet: moves fromBuffer tests to data driven style 2014-05-31 15:44:06 +10:00
Daniel Cousens
799b69eb1e HDWallet: use assert.throws 2014-05-31 15:44:06 +10:00
Daniel Cousens
749943cb4e HDWallet: clarify test intention 2014-05-31 15:21:18 +10:00
Daniel Cousens
2b2081bed9 base58check: buffers only, remove explicit 0
Undefined is treated as zero if it ever gets to this point anyway, so no
value is added by having this default param here.

A test fixture to verify this behaviour is added.
2014-05-31 15:05:33 +10:00
Daniel Cousens
77ed66b24d ECKey: ensure throw is from ECKey 2014-05-31 15:05:33 +10:00
Daniel Cousens
978f0c5406 ECKey: adds test to ensure throws on negative D 2014-05-31 15:05:33 +10:00
Daniel Cousens
3bce535e36 Wallet: use assert for consistency 2014-05-31 14:28:16 +10:00
Daniel Cousens
5b7873d05b bufferutils: test fixture filename copies parent 2014-05-31 14:24:43 +10:00
Daniel Cousens
b9bdf21cbe bufferutils: use verifuint for 64 bit integers
Taken from browserify-buffer.

Also adds a few more tests to assert this is working correctly from both
read and write perspectives.
The assertion in for writePushDataInt in the 32 bit case was
unnecessary as that is handled by buffer.writeUInt32LE anyway.
2014-05-31 14:24:43 +10:00
Daniel Cousens
80da2ed2d5 HDWallet: add fromBase58 exception checks 2014-05-30 19:01:03 +10:00
Daniel Cousens
cde285ccfc Wallet: enforce operator new 2014-05-30 19:01:03 +10:00
Daniel Cousens
4952c5f4e7 HD/Wallet: use network objects, not strings 2014-05-30 19:01:02 +10:00
Daniel Cousens
2df790e2ab Wallet: remove use of hashLittleEndian 2014-05-30 18:17:32 +10:00
Daniel Cousens
bd3690bdc0 Wallet: remove async interface 2014-05-30 18:17:32 +10:00
Daniel Cousens
50e9a09a8c Wallet: cleanup createTx control flow
Unknowingly this also revealed a subtle bug in the previous
implementation which allowed the creation of transactions even
when no UTXOs existed.
2014-05-30 18:17:18 +10:00
Daniel Cousens
7e9b5d8584 bufferutils: return opcode for use 2014-05-30 17:54:33 +10:00
Daniel Cousens
bda1a8321c bufferutils: unrolls tests and adds more 16 bit test fixtures 2014-05-29 16:26:15 +10:00
Daniel Cousens
14069155b0 tests: adds bitcoin core tests
Not all tests are added yet, but this represents a significant portion.
2014-05-29 16:06:19 +10:00
Daniel Cousens
7d94d1b068 Script: add fromChunks and without 2014-05-29 16:06:19 +10:00
Daniel Cousens
d18f2dba00 bufferutils: add PUSHDATA implementation 2014-05-29 16:06:19 +10:00
Daniel Cousens
36a1d579f8 coretests: reverse inputs for simplicity of testing
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.
2014-05-29 16:06:19 +10:00
Daniel Cousens
12a2dc3cc2 tests: adds Bitcoin core test data 2014-05-29 16:06:19 +10:00
Daniel Cousens
b05d17f904 Script: adds missing exception regex 2014-05-29 16:06:18 +10:00
Daniel Cousens
8b3634c866 HDWallet: adds missing exception regex 2014-05-29 16:06:18 +10:00
Daniel Cousens
7494a146a6 ECKey: fix exception tests
These weren't broken as such, but they weren't distinctly checking that
the right exception was thrown either.
2014-05-29 16:01:04 +10:00
Daniel Cousens
6cfa729dae ecdsa: fix missing exceptions 2014-05-29 15:42:52 +10:00
Daniel Cousens
2fc69b0834 address/base58check: fix missing exceptions/tests
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.
2014-05-29 14:43:44 +10:00
Daniel Cousens
47ae862ae9 base58: fix missing exceptions 2014-05-29 14:43:29 +10:00
Daniel Cousens
326cda63c0 integration: use Script.getHash 2014-05-29 02:06:49 +10:00
Daniel Cousens
c9f9d86cb4 integration: stop async tests causing wrong balance 2014-05-29 02:06:49 +10:00
Daniel Cousens
778aab104e tests: fix #198 indentation 2014-05-28 19:02:57 +10:00
John Russell
343289229e ensures that pubKey length is greater than m
ensure that pubKey length is greater than m

use Array.isArray over instanceof

error message
2014-05-28 01:48:17 -07:00
Daniel Cousens
4dd617d5ca wallet: fix address description typo 2014-05-28 13:25:37 +10:00
Daniel Cousens
8514bbfabd Address: remove Address.Error
By removing Address.Error, we remove a code smell.
This part of the code base was also not under any form of test.
Test data and tests have therefore been added verifying its behaviour in
both Wallet and Address tests.
2014-05-28 13:17:07 +10:00
Kyle Drake
33e5883be1 sec: remove untested alt curves not used by bitcoin 2014-05-25 14:30:34 +10:00
Wei Lu
c962d0c9b7 Merge pull request #194 from coinpunk/hdcleanups
Remove fromHex, tests for edge case fromBuffer errors
2014-05-25 03:09:55 +00:00
Kyle Drake
600209b1a6 hdwallet: remove fromHex, add better tests for edge cases 2014-05-25 12:26:29 +10:00
Wei Lu
c5704cfd44 Merge pull request #193 from dcousens/hdtests
HDWallet: move test vectors to fixtures
2014-05-25 02:09:31 +00:00
Kyle Drake
dd3e171212 Merge pull request #188 from dcousens/ecsig
ecdsa: always use signature object
2014-05-25 11:57:09 +10:00
Daniel Cousens
d2e921fce6 HDWallet: move test vectors to fixtures 2014-05-25 11:48:34 +10:00
Daniel Cousens
08951be66f Script: add createPubKeyScriptPubKey 2014-05-25 10:21:06 +10:00
Kyle Drake
4e3cb6762b fix for hash160 in integration test 2014-05-25 09:55:56 +10:00
Kyle Drake
f545ed1279 remove crypto hash transition code 2014-05-25 09:46:06 +10:00
Daniel Cousens
58fd12e66d ecdsa: always use signature object 2014-05-24 16:25:38 +10:00
Daniel Cousens
37d5147cac ecdsa: add invalid tests for verifyRaw 2014-05-24 14:33:25 +10:00
Daniel Cousens
1d6b1fe58b message: better variable names 2014-05-24 14:33:24 +10:00
Daniel Cousens
2114deba95 message: data-driven tests 2014-05-24 13:50:27 +10:00
Daniel Cousens
b2351f9026 tests: use JSON fixtures exclusively 2014-05-24 00:52:24 +10:00
Daniel Cousens
0fcda5835e tests: remove bigi test fixture 2014-05-24 00:52:24 +10:00
Daniel Cousens
bcfd62fdb5 ecdsa: remove implicit ecparams 2014-05-24 00:48:31 +10:00
Daniel Cousens
ab2ca395ac ecdsa: remove ECKey dependency in tests 2014-05-24 00:48:31 +10:00
Daniel Cousens
2dec1375a1 ecdsa: use (r, s) values directly 2014-05-24 00:48:31 +10:00
Daniel Cousens
8d7408202f ecdsa: consistent parameter ordering 2014-05-24 00:48:31 +10:00
Daniel Cousens
a17a5b23d9 ec: fix point decoding for other curves 2014-05-22 12:33:47 +10:00
Daniel Cousens
5ec9504ed6 ecdsa: opt for shiftRight, pow and square
In the given situations, these offer better readability, or in the case
of shiftRight, a substantial performance increase.
2014-05-22 12:33:47 +10:00
Daniel Cousens
24371425f9 ec: decodeFrom now uses Buffers and handles errors 2014-05-18 17:52:49 +10:00
Daniel Cousens
a3f691bf7c ecdsa: parseSigCompact use Buffer API
parseSigCompact also now returns the correct recovert parameter without
the need to subtract the compression bit.
This makes it easier to use.
2014-05-18 17:52:49 +10:00
Daniel Cousens
ccca6989b5 ec: getEncoded now uses Buffer API 2014-05-18 17:52:49 +10:00
Daniel Cousens
1c76bdf9c3 ec: add better test vectors for ECPointFp encode/decode
These test vectors were generated internally.
2014-05-18 17:52:49 +10:00
Daniel Cousens
4c7108d561 ecdsa: add serializeSigCompact and tests
This also adds tests for all other ECDSA serialize/parsing functions.
The k, r, s and D values were sourced from test vectors on
https://bitcointalk.org/index.php?topic=285142.40 .

The compact signatures (aka, i values) were generated from bitcoinjslib, but they
are straight forward anyway.
2014-05-18 17:52:49 +10:00
Daniel Cousens
b208a6ab78 crypto/ecdsa: moves HmacSHA256 to crypto 2014-05-18 17:52:49 +10:00
Daniel Cousens
6eb167b2c8 message: remove unnecessary tests 2014-05-18 17:51:36 +10:00
Daniel Cousens
87567e008a message: use base64 for signature data 2014-05-18 17:51:36 +10:00
Daniel Cousens
6b5990c6e2 message: support alternate networks 2014-05-18 17:51:36 +10:00
Daniel Cousens
dc69162757 message: remove signing verification
The signature verifications here are unnecessary, as this
is not what is under test.
2014-05-18 17:51:36 +10:00
Daniel Cousens
10fe4474d1 ECKey: remove *Buffer/*Hex functions
An ECKey is a composition of a private key (D), a public key (Q) and its
compression flag.

These functions gave the impression of serialization of this
composition, when really they only serialized `D`.
They have therefore been removed in favour of always using a sane
serialization format (WIF) that matches the needed behaviour.

If a user needs the previous functionality, simply use `privKey.D.*`
instead of `privKey.*`, as BigInteger supports `*Buffer/*Hex` functions
as expected.
2014-05-18 17:50:10 +10:00
Daniel Cousens
bf109f32a9 ECPubKey: improve tests and extract test data to fixtures
The use of fixtures allows for more behavioural driven tests and simpler
addition of more test cases in future.

However, as ECPubKey is just a wrapper around other strenuously tested
modules, the test data is currently limited to testing a subset of the
total wrapper.

This should probably be done better by using mocked out modules instead.
2014-05-18 17:50:10 +10:00
Daniel Cousens
0468c4710c Transaction: rename (de)serialize to [to/from]Buffer 2014-05-17 00:09:13 +10:00
Daniel Cousens
55681e7e5d Script: use PubKey objects not prebuilt Buffers 2014-05-17 00:09:13 +10:00
Daniel Cousens
54cc123d31 Address/Script: consistent function ordering 2014-05-17 00:09:13 +10:00
Daniel Cousens
842b075e75 Address: consistent json formatting 2014-05-17 00:09:13 +10:00
Daniel Cousens
39d042d058 syncscript: general cleanup 2014-05-17 00:09:12 +10:00
Wei Lu
8063979d99 fix integration test 2014-05-13 22:03:11 +08:00
Daniel Cousens
6c0eebe94b tests: use filepaths directly
After a long IRC discussion, it was decided that the use of direct
filepaths instead of the module is a more pure form of testing ,
although it may provide less overall coverage than the mixed integration
style imports used previously.

This will need to be remedied by further integration testing in
/test/integration.
2014-05-13 18:05:56 +10:00
Daniel Cousens
e27c97a791 ECPubKey/ECKey: separate to two files 2014-05-13 16:51:06 +10:00
Daniel Cousens
05e0d08098 BufferExt: rename to bufferutils 2014-05-13 16:46:12 +10:00
Daniel Cousens
7a740c2e7b tests: forces consistent import syntax 2014-05-13 16:46:08 +10:00
Daniel Cousens
276a339d60 crypto: HMACSHA512 into crypto and add tests 2014-05-12 10:18:39 +10:00
Daniel Cousens
f70ccc9215 convert: remove hex functions 2014-05-12 10:17:38 +10:00
Daniel Cousens
f18c5e4c1e Script: removes Script.createP2SHMultiSigScriptSig
It is favoured to compose the scriptSig manually using
Script.createP2SHScriptSig and Script.createMultisigScriptSig.

Added a test to verify that createMultisigScriptSig throws when not
enough signatures a provided and the redeemScript is given.
2014-05-09 16:26:35 +10:00
Daniel Cousens
f8e662e495 Script: rename toScriptHash to getHash and add tests 2014-05-09 13:07:06 +10:00
Daniel Cousens
cace8316e4 Script: extract test data to fixture 2014-05-09 12:56:35 +10:00
Daniel Cousens
708aa03390 Transaction/Script: bitcoin network no longer implied
A Transaction (and its subsequent scripts) do not carry any network
specific information in the Bitcoin protocol.
Therefore they can not (without further context) produce the network
specific constants for the generation of the base58 Addresses.

As TransactionOut.address is used heavily throughout Wallet and other
areas of the library, this could not be entirely removed without a large
number of changes.
For now, TransactionOut.address is only defined in the case of
Tx.addOutput being used directly:

      Transaction.addOutput(address, value)
2014-05-08 10:59:58 +10:00
Daniel Cousens
5e0d38ba54 Address: add Address.*ScriptPubKey and tests
The introduction of these two functions allow for the all the network
related code to be eventually removed from Transaction and Script.

Previously the result for non-standard transactions was undefined
behaviour.  This change mandates that an exception is thrown if a
non-standard transaction is input.
2014-05-08 10:59:58 +10:00
Daniel Cousens
0822def7e0 Script: add standard Script.create*ScriptPubKey
Extracts the two Script types out of Script.createOutputScript, and puts
them both under test.

Also renames Script.createMultiSigOutputScript to adhere to the same
convention.
2014-05-08 10:59:58 +10:00
Daniel Cousens
d0f684844c Script: add toHex, fromHex
Script.fromHex previously existed, but was not under any kind of test.
This commit adds tests (despite being a little circular in nature) to
check that the output is as expected.
2014-05-08 10:59:58 +10:00
Daniel Cousens
57b8afbdab Network: rename Network to Networks
This change removes the most common ambiguities.
As the network module is not representative of a class, the lower case
has been used.
2014-05-08 10:59:58 +10:00
Daniel Cousens
76323a07d0 Transaction: restrict TxIn/TxOut constructor params
To keep this change minimal, both TxIn/TxOut still use the parameter
object for initialization.  TxOut accepts only the types it uses
internally, and not hex or byte arrays for scripts.

The clone is unnecessary as a TransactionOut is never mutated after its
creation.

This resulted in TransactionOut.scriptPubKey no longer being needed,
and was removed.  To access the scriptPubKey as a byte buffer, a user
can simply use:

	TransactionOut.script.toBuffer()

Unfortunately, this leaves TransactionOut in a sorry state of test.
Something that needs to be fixed.
2014-05-08 10:59:58 +10:00
Daniel Cousens
63231fb67d Extends test for custom Wallet change addresses 2014-05-06 15:40:40 +10:00
Daniel Cousens
a77846701f Fixes network support for TxOut 2014-05-06 15:40:40 +10:00
Daniel Cousens
4012b82bec Fixes Transaction.addOutput(Address, Number) 2014-05-06 15:40:40 +10:00
Daniel Cousens
eba08fa761 Fixes indentation for assertions 2014-05-06 15:40:40 +10:00
Daniel Cousens
d65a3c36e2 Merge pull request #159 from williamcotton/master
fixed issues with testnet and createTx
2014-05-06 08:04:02 +10:00
Wei Lu
e59f824c3a move fixture sync script into fixtures folder
Also fixes require paths & dev dependency
2014-05-05 13:46:00 +08:00
Wei Lu
5deab5188f Merge pull request #170 from dcousens/bufferx
BufferExt and Transaction serialization to use Buffers
2014-05-05 12:40:51 +08:00
Daniel Cousens
baa568697b Transaction.deserialize no longer mutates input 2014-05-05 09:11:37 +10:00
Daniel Cousens
4716eb29bf Removes redundant convert functions 2014-05-04 17:31:47 +10:00
Daniel Cousens
a8cf2fdd9e Changes internal serialization to use Buffers instead 2014-05-04 17:31:22 +10:00
Daniel Cousens
c8bda6dde6 Adds Buffer extensions 2014-05-04 17:30:59 +10:00
Wei Lu
33b73517fe fixes integration test dependency paths 2014-05-04 14:23:40 +08:00
Daniel Cousens
10ee5532c3 Serialize now returns a buffer 2014-05-04 15:37:25 +10:00
Daniel Cousens
d17f85f5a6 Changes fakeTxHash to actual hex 2014-05-04 15:37:25 +10:00
Daniel Cousens
09c6a787d9 Changes sequence number to an actual Number 2014-05-04 15:37:25 +10:00
Wei Lu
752aeae0d3 update integration test descriptions 2014-05-04 13:35:11 +08:00
Wei Lu
2affeda3f4 Restructure integration and coretests
Also update test script to pick up only tests directly under /test
2014-05-04 13:30:11 +08:00
Daniel Cousens
633b8f28d2 Fixes incorrect PubKey hex constant 2014-05-04 15:15:22 +10:00
Wei Lu
ba273db70f Merge pull request #162 from sidazhang/master
Adding integration tests
2014-05-04 13:05:04 +08:00
Daniel Cousens
02691098de Stretches test for derive m/0 from xpub 2014-05-04 12:14:33 +10:00
Daniel Cousens
ff08c2eec3 Fixes #167 and adds temporary test 2014-05-04 12:07:05 +10:00
Wei Lu
af1f121fd4 upgrade bigi & remove monkey patching 2014-05-03 10:04:54 +08:00
Daniel Cousens
77747241d4 Fixes exception typo 2014-04-30 05:10:02 +10:00
Daniel Cousens
b09dd73cbe Enforces bytesToWordArray only operates on byte arrays 2014-04-30 05:07:41 +10:00
sidazhang
fe4332bfbd integration tests for scripthash transcations 2014-04-27 10:50:39 -07:00
Wei Lu
70219c877b Fixes signScriptSig test 2014-04-26 13:39:26 +08:00