|
@ -1,5 +1,6 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var _ = require('lodash'); |
|
|
var should = require('chai').should(); |
|
|
var should = require('chai').should(); |
|
|
var bitcore = require('../..'); |
|
|
var bitcore = require('../..'); |
|
|
var BN = bitcore.crypto.BN; |
|
|
var BN = bitcore.crypto.BN; |
|
@ -293,4 +294,35 @@ describe('Signature', function() { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
describe('#hasDefinedHashtype', function() { |
|
|
|
|
|
it('should reject invalid sighash types and accept valid ones', function() { |
|
|
|
|
|
var sig = new Signature(); |
|
|
|
|
|
sig.hasDefinedHashtype().should.equal(false); |
|
|
|
|
|
var testCases = [ |
|
|
|
|
|
[undefined, false], |
|
|
|
|
|
[null, false], |
|
|
|
|
|
[0, false], |
|
|
|
|
|
[1.1, false], |
|
|
|
|
|
[-1, false], |
|
|
|
|
|
[-1.1, false], |
|
|
|
|
|
['', false], |
|
|
|
|
|
['1', false], |
|
|
|
|
|
[Signature.SIGHASH_ANYONECANPAY, false], |
|
|
|
|
|
[Signature.SIGHASH_ANYONECANPAY | Signature.SIGHASH_ALL, true], |
|
|
|
|
|
[Signature.SIGHASH_ANYONECANPAY | Signature.SIGHASH_NONE, true], |
|
|
|
|
|
[Signature.SIGHASH_ANYONECANPAY | Signature.SIGHASH_SINGLE, true], |
|
|
|
|
|
[Signature.SIGHASH_ALL, true], |
|
|
|
|
|
[Signature.SIGHASH_NONE, true], |
|
|
|
|
|
[Signature.SIGHASH_SINGLE, true], |
|
|
|
|
|
[Signature.SIGHASH_SINGLE + 1, false], |
|
|
|
|
|
[(Signature.SIGHASH_ANYONECANPAY | Signature.SIGHASH_SINGLE) + 1, false], |
|
|
|
|
|
[(Signature.SIGHASH_ANYONECANPAY | Signature.SIGHASH_ALL) - 1, false], |
|
|
|
|
|
]; |
|
|
|
|
|
_.each(testCases, function(testCase) { |
|
|
|
|
|
sig.nhashtype = testCase[0]; |
|
|
|
|
|
sig.hasDefinedHashtype().should.equal(testCase[1]); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|