Comparing version 0.12.11 to 0.12.12
@@ -19,2 +19,61 @@ 'use strict'; | ||
var buffers = []; | ||
var hashBuffers = []; | ||
console.log('Generating Random Test Data...'); | ||
for (var i = 0; i < 100; i++) { | ||
// uint64le | ||
var br = new bitcore.encoding.BufferWriter(); | ||
var num = Math.round(Math.random() * 10000000000000); | ||
br.writeUInt64LEBN(new bitcore.crypto.BN(num)); | ||
buffers.push(br.toBuffer()); | ||
// hashes | ||
var data = bitcore.crypto.Hash.sha256sha256(new Buffer(32)); | ||
hashBuffers.push(data); | ||
} | ||
var c = 0; | ||
var bn; | ||
function readUInt64LEBN() { | ||
if (c >= buffers.length) { | ||
c = 0; | ||
} | ||
var buf = buffers[c]; | ||
var br = new bitcore.encoding.BufferReader(buf); | ||
bn = br.readUInt64LEBN(); | ||
c++; | ||
} | ||
var reversed; | ||
function readReverse() { | ||
if (c >= hashBuffers.length) { | ||
c = 0; | ||
} | ||
var buf = hashBuffers[c]; | ||
var br = new bitcore.encoding.BufferReader(buf); | ||
reversed = br.readReverse(); | ||
c++; | ||
} | ||
console.log('Starting benchmark...'); | ||
var suite = new benchmark.Suite(); | ||
suite.add('bufferReader.readUInt64LEBN()', readUInt64LEBN, {maxTime: maxTime}); | ||
suite.add('bufferReader.readReverse()', readReverse, {maxTime: maxTime}); | ||
suite | ||
.on('cycle', function(event) { | ||
console.log(String(event.target)); | ||
}) | ||
.on('complete', function() { | ||
console.log('Done'); | ||
console.log('----------------------------------------------------------------------'); | ||
next(); | ||
}) | ||
.run(); | ||
}, | ||
function(next) { | ||
var block1; | ||
@@ -21,0 +80,0 @@ var block2; |
{ | ||
"name": "bitcore", | ||
"main": "./bitcore.min.js", | ||
"version": "0.12.11", | ||
"version": "0.12.12", | ||
"homepage": "http://bitcore.io", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -134,6 +134,7 @@ 'use strict'; | ||
* bignum. Instead, an error is thrown if trying to input a number bigger than | ||
* 4 bytes. We copy that behavior here. | ||
* 4 bytes. We copy that behavior here. A third argument, `size`, is provided to | ||
* extend the hard limit of 4 bytes, as some usages require more than 4 bytes. | ||
*/ | ||
BN.fromScriptNumBuffer = function(buf, fRequireMinimal) { | ||
var nMaxNumSize = 4; | ||
BN.fromScriptNumBuffer = function(buf, fRequireMinimal, size) { | ||
var nMaxNumSize = size || 4; | ||
$.checkArgument(buf.length <= nMaxNumSize, new Error('script number overflow')); | ||
@@ -179,2 +180,6 @@ if (fRequireMinimal && buf.length > 0) { | ||
BN.prototype.gte = function(b) { | ||
return this.cmp(b) >= 0; | ||
}; | ||
BN.prototype.lt = function(b) { | ||
@@ -181,0 +186,0 @@ return this.cmp(b) < 0; |
@@ -94,7 +94,18 @@ 'use strict'; | ||
BufferReader.prototype.readUInt64LEBN = function() { | ||
var buf = this.buf.slice(this.pos, this.pos + 8); | ||
var reversebuf = BufferReader({ | ||
buf: buf | ||
}).readReverse(); | ||
var bn = BN.fromBuffer(reversebuf); | ||
var second = this.buf.readUInt32LE(this.pos); | ||
var first = this.buf.readUInt32LE(this.pos + 4); | ||
var combined = (first * 0x100000000) + second; | ||
// Instantiating an instance of BN with a number is faster than with an | ||
// array or string. However, the maximum safe number for a double precision | ||
// floating point is 2 ^ 52 - 1 (0x1fffffffffffff), thus we can safely use | ||
// non-floating point numbers less than this amount (52 bits). And in the case | ||
// that the number is larger, we can instatiate an instance of BN by passing | ||
// an array from the buffer (slower) and specifying the endianness. | ||
var bn; | ||
if (combined <= 0x1fffffffffffff) { | ||
bn = new BN(combined); | ||
} else { | ||
var data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8); | ||
bn = new BN(data, 10, 'le'); | ||
} | ||
this.pos = this.pos + 8; | ||
@@ -101,0 +112,0 @@ return bn; |
@@ -198,2 +198,4 @@ 'use strict'; | ||
OP_CHECKLOCKTIMEVERIFY: 177, | ||
// expansion | ||
@@ -200,0 +202,0 @@ OP_NOP1: 176, |
@@ -187,2 +187,5 @@ 'use strict'; | ||
Interpreter.LOCKTIME_THRESHOLD = 500000000; | ||
Interpreter.LOCKTIME_THRESHOLD_BN = new BN(Interpreter.LOCKTIME_THRESHOLD); | ||
// flags taken from bitcoind | ||
@@ -230,2 +233,5 @@ // bitcoind commit: b5d1b1092998bc95313856d535c632ea5a8f9104 | ||
// CLTV See BIP65 for details. | ||
Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1 << 9); | ||
Interpreter.castToBool = function(buf) { | ||
@@ -316,2 +322,49 @@ for (var i = 0; i < buf.length; i++) { | ||
/** | ||
* Checks a locktime parameter with the transaction's locktime. | ||
* There are two times of nLockTime: lock-by-blockheight and lock-by-blocktime, | ||
* distinguished by whether nLockTime < LOCKTIME_THRESHOLD = 500000000 | ||
* | ||
* See the corresponding code on bitcoin core: | ||
* https://github.com/bitcoin/bitcoin/blob/ffd75adce01a78b3461b3ff05bcc2b530a9ce994/src/script/interpreter.cpp#L1129 | ||
* | ||
* @param {BN} nLockTime the locktime read from the script | ||
* @return {boolean} true if the transaction's locktime is less than or equal to | ||
* the transaction's locktime | ||
*/ | ||
Interpreter.prototype.checkLockTime = function(nLockTime) { | ||
// We want to compare apples to apples, so fail the script | ||
// unless the type of nLockTime being tested is the same as | ||
// the nLockTime in the transaction. | ||
if (!( | ||
(this.tx.nLockTime < Interpreter.LOCKTIME_THRESHOLD && nLockTime.lt(Interpreter.LOCKTIME_THRESHOLD_BN)) || | ||
(this.tx.nLockTime >= Interpreter.LOCKTIME_THRESHOLD && nLockTime.gte(Interpreter.LOCKTIME_THRESHOLD_BN)) | ||
)) { | ||
return false; | ||
} | ||
// Now that we know we're comparing apples-to-apples, the | ||
// comparison is a simple numeric one. | ||
if (nLockTime.gt(new BN(this.tx.nLockTime))) { | ||
return false; | ||
} | ||
// Finally the nLockTime feature can be disabled and thus | ||
// CHECKLOCKTIMEVERIFY bypassed if every txin has been | ||
// finalized by setting nSequence to maxint. The | ||
// transaction would be allowed into the blockchain, making | ||
// the opcode ineffective. | ||
// | ||
// Testing if this vin is not final is sufficient to | ||
// prevent this condition. Alternatively we could test all | ||
// inputs, but testing just this input minimizes the data | ||
// required to prove correct CHECKLOCKTIMEVERIFY execution. | ||
if (!this.tx.inputs[this.nin].isFinal()) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
/** | ||
@@ -420,4 +473,51 @@ * Based on the inner loop of bitcoind's EvalScript function | ||
case Opcode.OP_NOP2: | ||
case Opcode.OP_CHECKLOCKTIMEVERIFY: | ||
if (!(this.flags & Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY)) { | ||
// not enabled; treat as a NOP2 | ||
if (this.flags & Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS) { | ||
this.errstr = 'SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS'; | ||
return false; | ||
} | ||
break; | ||
} | ||
if (this.stack.length < 1) { | ||
this.errstr = 'SCRIPT_ERR_INVALID_STACK_OPERATION'; | ||
return false; | ||
} | ||
// Note that elsewhere numeric opcodes are limited to | ||
// operands in the range -2**31+1 to 2**31-1, however it is | ||
// legal for opcodes to produce results exceeding that | ||
// range. This limitation is implemented by CScriptNum's | ||
// default 4-byte limit. | ||
// | ||
// If we kept to that limit we'd have a year 2038 problem, | ||
// even though the nLockTime field in transactions | ||
// themselves is uint32 which only becomes meaningless | ||
// after the year 2106. | ||
// | ||
// Thus as a special case we tell CScriptNum to accept up | ||
// to 5-byte bignums, which are good until 2**39-1, well | ||
// beyond the 2**32-1 limit of the nLockTime field itself. | ||
var nLockTime = BN.fromScriptNumBuffer(this.stack[this.stack.length - 1], fRequireMinimal, 5); | ||
// In the rare event that the argument may be < 0 due to | ||
// some arithmetic being done first, you can always use | ||
// 0 MAX CHECKLOCKTIMEVERIFY. | ||
if (nLockTime.lt(new BN(0))) { | ||
this.errstr = 'SCRIPT_ERR_NEGATIVE_LOCKTIME'; | ||
return false; | ||
} | ||
// Actually compare the specified lock time with the transaction. | ||
if (!this.checkLockTime(nLockTime)) { | ||
this.errstr = 'SCRIPT_ERR_UNSATISFIED_LOCKTIME'; | ||
return false; | ||
} | ||
break; | ||
case Opcode.OP_NOP1: | ||
case Opcode.OP_NOP2: | ||
case Opcode.OP_NOP3: | ||
@@ -424,0 +524,0 @@ case Opcode.OP_NOP4: |
@@ -251,6 +251,22 @@ 'use strict'; | ||
Script.prototype.isPublicKeyHashIn = function() { | ||
return this.chunks.length === 2 && | ||
this.chunks[0].buf && | ||
this.chunks[0].buf.length <= 0x49 && | ||
PublicKey.isValid(this.chunks[1].buf); | ||
if (this.chunks.length === 2) { | ||
var signatureBuf = this.chunks[0].buf; | ||
var pubkeyBuf = this.chunks[1].buf; | ||
if (signatureBuf && | ||
signatureBuf.length && | ||
signatureBuf[0] === 0x30 && | ||
pubkeyBuf && | ||
pubkeyBuf.length | ||
) { | ||
var version = pubkeyBuf[0]; | ||
if ((version === 0x04 || | ||
version === 0x06 || | ||
version === 0x07) && pubkeyBuf.length === 65) { | ||
return true; | ||
} else if ((version === 0x03 || version === 0x02) && pubkeyBuf.length === 33) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
@@ -257,0 +273,0 @@ |
@@ -158,2 +158,6 @@ 'use strict'; | ||
Input.prototype.isFinal = function() { | ||
return this.sequenceNumber !== 4294967295; | ||
}; | ||
Input.prototype.addSignature = function() { | ||
@@ -160,0 +164,0 @@ throw new errors.AbstractMethodInvoked('Input#addSignature'); |
@@ -155,3 +155,2 @@ 'use strict'; | ||
reverse: function reverse(param) { | ||
$.checkArgumentType(param, 'Buffer', 'param'); | ||
var ret = new buffer.Buffer(param.length); | ||
@@ -158,0 +157,0 @@ for (var i = 0; i < param.length; i++) { |
{ | ||
"name": "bitcore", | ||
"version": "0.12.10", | ||
"version": "0.12.11", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "bn.js": { |
{ | ||
"name": "bitcore", | ||
"version": "0.12.11", | ||
"version": "0.12.12", | ||
"description": "A pure and powerful JavaScript Bitcoin library.", | ||
@@ -5,0 +5,0 @@ "author": "BitPay <dev@bitpay.com>", |
@@ -93,4 +93,10 @@ Bitcore | ||
## Tests | ||
## Development & Tests | ||
```sh | ||
git clone https://github.com/bitpay/bitcore | ||
cd bitcore | ||
npm install | ||
``` | ||
Run all the tests: | ||
@@ -97,0 +103,0 @@ |
@@ -106,3 +106,73 @@ [ | ||
["CHECKLOCKTIMEVERIFY tests"], | ||
["By-height locks, with argument just beyond tx nLockTime"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "1 NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "499999999 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000fe64cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["By-time locks, with argument just beyond tx nLockTime (but within numerical boundries)"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "500000001 NOP2 1"]], | ||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000065cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "4294967295 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000feffffff", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Argument missing"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Argument negative with by-blockheight nLockTime=0"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "-1 NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Argument negative with by-blocktime nLockTime=500,000,000"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "-1 NOP2 1"]], | ||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000065cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Input locked"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0 NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Another input being unlocked isn't sufficient; the CHECKLOCKTIMEVERIFY-using input must be unlocked"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0 NOP2 1"] , | ||
["0000000000000000000000000000000000000000000000000000000000000200", 1, "1"]], | ||
"010000000200010000000000000000000000000000000000000000000000000000000000000000000000ffffffff00020000000000000000000000000000000000000000000000000000000000000100000000000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Argument/tx height/time mismatch, both versions"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0 NOP2 1"]], | ||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000065cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "499999999 NOP2 1"]], | ||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000065cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "500000000 NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "500000000 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000ff64cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Argument 2^32 with nLockTime=2^32-1"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "4294967296 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000ffffffff", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Same, but with nLockTime=2^31-1"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "2147483648 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000ffffff7f", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["6 byte non-minimally-encoded arguments are invalid even in their contents are valid"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0x06 0x000000000000 NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Failure due to failing CHECKLOCKTIMEVERIFY in scriptSig"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "1"]], | ||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000251b1000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Failure due to failing CHECKLOCKTIMEVERIFY in redeemScript"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xc5b93064159b3b2d6ab506a41b1f50463771b988 EQUAL"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000030251b1000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Failure due to empty stack before CHECKLOCKTIMEVERIFY in redeemScript"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xc5b93064159b3b2d6ab506a41b1f50463771b988 EQUAL"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000001b1010000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Make diffs cleaner by leaving a comment here without comma at the end"] | ||
] |
@@ -180,4 +180,46 @@ [ | ||
["CHECKLOCKTIMEVERIFY tests"], | ||
["By-height locks, with argument == 0 and == tx nLockTime"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0 NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "499999999 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000ff64cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000ff64cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["By-time locks, with argument just beyond tx nLockTime (but within numerical boundries)"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "500000000 NOP2 1"]], | ||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000065cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "4294967295 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000ffffffff", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "500000000 NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000ffffffff", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Any non-maxint nSequence is fine"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0 NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000feffffff0100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["The argument can be calculated rather than created directly by a PUSHDATA"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "499999999 1ADD NOP2 1"]], | ||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000065cd1d", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Perhaps even by an ADD producing a 5-byte result that is out of bounds for other opcodes"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "2147483647 2147483647 ADD NOP2 1"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000feffffff", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["5 byte non-minimally-encoded arguments are valid"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0x05 0x0000000000 NOP2 1"]], | ||
"010000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Valid CHECKLOCKTIMEVERIFY in scriptSig"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "1"]], | ||
"01000000010001000000000000000000000000000000000000000000000000000000000000000000000251b1000000000100000000000000000001000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Valid CHECKLOCKTIMEVERIFY in redeemScript"], | ||
[[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0xc5b93064159b3b2d6ab506a41b1f50463771b988 EQUAL"]], | ||
"0100000001000100000000000000000000000000000000000000000000000000000000000000000000030251b1000000000100000000000000000001000000", "P2SH,CHECKLOCKTIMEVERIFY"], | ||
["Make diffs cleaner by leaving a comment here without comma at the end"] | ||
] |
@@ -193,2 +193,9 @@ 'use strict'; | ||
it('should return 10BTC', function() { | ||
var tenbtc = 10 * 1e8; | ||
var tenbtcBuffer = new Buffer('00ca9a3b00000000', 'hex'); | ||
var br = new BufferReader(tenbtcBuffer); | ||
br.readUInt64LEBN().toNumber().should.equal(tenbtc); | ||
}); | ||
it('should return 2^30', function() { | ||
@@ -202,2 +209,31 @@ var buf = new Buffer(8); | ||
it('should return 2^32 + 1', function() { | ||
var num = Math.pow(2, 32) + 1; | ||
var numBuffer = new Buffer('0100000001000000', 'hex'); | ||
var br = new BufferReader(numBuffer); | ||
br.readUInt64LEBN().toNumber().should.equal(num); | ||
}); | ||
it('should return max number of satoshis', function() { | ||
var maxSatoshis = 21000000 * 1e8; | ||
var maxSatoshisBuffer = new Buffer('0040075af0750700', 'hex'); | ||
var br = new BufferReader(maxSatoshisBuffer); | ||
br.readUInt64LEBN().toNumber().should.equal(maxSatoshis); | ||
}); | ||
it('should return 2^53 - 1', function() { | ||
var maxSafe = Math.pow(2, 53) - 1; | ||
var maxSafeBuffer = new Buffer('ffffffffffff1f00', 'hex'); | ||
var br = new BufferReader(maxSafeBuffer); | ||
br.readUInt64LEBN().toNumber().should.equal(maxSafe); | ||
}); | ||
it('should return 2^53', function() { | ||
var bn = new BN('20000000000000', 16); | ||
var bnBuffer = new Buffer('0000000000002000', 'hex'); | ||
var br = new BufferReader(bnBuffer); | ||
var readbn = br.readUInt64LEBN(); | ||
readbn.cmp(bn).should.equal(0); | ||
}); | ||
it('should return 0', function() { | ||
@@ -204,0 +240,0 @@ var buf = new Buffer(8); |
@@ -88,4 +88,4 @@ 'use strict'; | ||
describe('@map', function() { | ||
it('should have a map containing 116 elements', function() { | ||
_.size(Opcode.map).should.equal(116); | ||
it('should have a map containing 117 elements', function() { | ||
_.size(Opcode.map).should.equal(117); | ||
}); | ||
@@ -92,0 +92,0 @@ }); |
@@ -185,2 +185,5 @@ 'use strict'; | ||
} | ||
if (flagstr.indexOf('CHECKLOCKTIMEVERIFY') !== -1) { | ||
flags = flags | Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; | ||
} | ||
return flags; | ||
@@ -187,0 +190,0 @@ }; |
@@ -236,15 +236,23 @@ 'use strict'; | ||
it('should identify this known pubkeyhashin', function() { | ||
it('should identify this known pubkeyhashin (uncompressed pubkey version)', function() { | ||
Script('73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 65 0x04e365859b3c78a8b7c202412b949ebca58e147dba297be29eee53cd3e1d300a6419bc780cc9aec0dc94ed194e91c8f6433f1b781ee00eac0ead2aae1e8e0712c6').isPublicKeyHashIn().should.equal(true); | ||
}); | ||
it('should identify this known pubkeyhashin starting with 0x02', function() { | ||
it('should identify this known pubkeyhashin (hybrid pubkey version w/06)', function() { | ||
Script('73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 65 0x06e365859b3c78a8b7c202412b949ebca58e147dba297be29eee53cd3e1d300a6419bc780cc9aec0dc94ed194e91c8f6433f1b781ee00eac0ead2aae1e8e0712c6').isPublicKeyHashIn().should.equal(true); | ||
}); | ||
it('should identify this known pubkeyhashin (hybrid pubkey version w/07)', function() { | ||
Script('73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 65 0x07e365859b3c78a8b7c202412b949ebca58e147dba297be29eee53cd3e1d300a6419bc780cc9aec0dc94ed194e91c8f6433f1b781ee00eac0ead2aae1e8e0712c6').isPublicKeyHashIn().should.equal(true); | ||
}); | ||
it('should identify this known pubkeyhashin (compressed pubkey w/ 0x02)', function() { | ||
Script('73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 21 0x02aec6b86621e7fef63747fbfd6a6e7d54c8e1052044ef2dd2c5e46656ef1194d4').isPublicKeyHashIn().should.equal(true); | ||
}); | ||
it('should identify this known pubkeyhashin starting with 0x03', function() { | ||
it('should identify this known pubkeyhashin (compressed pubkey w/ 0x03)', function() { | ||
Script('73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 21 0x03e724d93c4fda5f1236c525de7ffac6c5f1f72b0f5cdd1fc4b4f5642b6d055fcc').isPublicKeyHashIn().should.equal(true); | ||
}); | ||
it('should identify this known non-pubkeyhashin', function() { | ||
it('should identify this known non-pubkeyhashin (bad ops length)', function() { | ||
Script('73 0x3046022100bb3c194a30e460d81d34be0a230179c043a656f67e3c5c8bf47eceae7c4042ee0221008bf54ca11b2985285be0fd7a212873d243e6e73f5fad57e8eb14c4f39728b8c601 65 0x04e365859b3c78a8b7c202412b949ebca58e147dba297be29eee53cd3e1d300a6419bc780cc9aec0dc94ed194e91c8f6433f1b781ee00eac0ead2aae1e8e0712c6 OP_CHECKSIG').isPublicKeyHashIn().should.equal(false); | ||
@@ -257,2 +265,18 @@ }); | ||
it('should identify this known non-pubkeyhashin (bad version)', function() { | ||
Script('70 0x3043021f336721e4343f67c835cbfd465477db09073dc38a936f9c445d573c1c8a7fdf022064b0e3cb6892a9ecf870030e3066bc259e1f24841c9471d97f9be08b73f6530701 33 0x1270b2e1dcaa8f51cb0ead1221dd8cb31721502b3b5b7d4b374d263dfec63a4369').isPublicKeyHashIn().should.equal(false); | ||
}); | ||
it('should identify this known non-pubkeyhashin (bad signature version)', function() { | ||
Script('70 0x4043021f336721e4343f67c835cbfd465477db09073dc38a936f9c445d573c1c8a7fdf022064b0e3cb6892a9ecf870030e3066bc259e1f24841c9471d97f9be08b73f6530701 33 0x0370b2e1dcaa8f51cb0ead1221dd8cb31721502b3b5b7d4b374d263dfec63a4369').isPublicKeyHashIn().should.equal(false); | ||
}); | ||
it('should identify this known non-pubkeyhashin (no public key)', function() { | ||
Script('70 0x3043021f336721e4343f67c835cbfd465477db09073dc38a936f9c445d573c1c8a7fdf022064b0e3cb6892a9ecf870030e3066bc259e1f24841c9471d97f9be08b73f6530701 OP_CHECKSIG').isPublicKeyHashIn().should.equal(false); | ||
}); | ||
it('should identify this known non-pubkeyhashin (no signature)', function() { | ||
Script('OP_DROP OP_CHECKSIG').isPublicKeyHashIn().should.equal(false); | ||
}); | ||
}); | ||
@@ -259,0 +283,0 @@ |
@@ -155,8 +155,3 @@ 'use strict'; | ||
}); | ||
it('checks the argument type', function() { | ||
expect(function() { | ||
BufferUtil.reverse('invalid'); | ||
}).to.throw(errors.InvalidArgumentType); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
324654
115
12493324
151