From 17459dd7c2e3a7537a935a2c0c6b9f31b6c30991 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 16 Dec 2014 13:23:12 -0300 Subject: [PATCH] added sig_canonical tests --- test/crypto/signature.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/crypto/signature.js b/test/crypto/signature.js index f9f3da5..f1eb13a 100644 --- a/test/crypto/signature.js +++ b/test/crypto/signature.js @@ -4,6 +4,10 @@ var should = require('chai').should(); var bitcore = require('../..'); var BN = bitcore.crypto.BN; var Signature = bitcore.crypto.Signature; +var JSUtil = bitcore.util.js; + +var sig_canonical = require('../data/bitcoind/sig_canonical'); +var sig_noncanonical = require('../data/bitcoind/sig_noncanonical'); describe('Signature', function() { @@ -201,6 +205,26 @@ describe('Signature', function() { sigbuf[0] = 0x31; Signature.isTxDER(sigbuf).should.equal(false); }); + + describe('bitcoind fixtures', function() { + var test_sigs = function(set, expected) { + var i = 0; + set.forEach(function(vector) { + if (!JSUtil.isHexa(vector)) { + // non-hex strings are ignored + return; + } + it('should be ' + (expected ? '' : 'in') + 'valid for fixture #' + i, function() { + var sighex = vector; + Signature.isTxDER(new Buffer(sighex, 'hex')).should.equal(expected); + }); + i++; + }); + }; + test_sigs(sig_canonical, true); + //test_sigs(sig_noncanonical, false); + }); + }); describe('#hasLowS', function() { it('should detect high and low S', function() {