Browse Source

fix tests for keypair

patch-2
Manuel Araoz 10 years ago
parent
commit
40d308748f
  1. 35
      test/keypair.js

35
test/keypair.js

@ -1,9 +1,11 @@
'use strict';
var should = require('chai').should(); var should = require('chai').should();
var bn = require('../lib/bn'); var bitcore = require('..');
var point = require('../lib/point'); var bn = bitcore.BN;
var Privkey = require('../lib/privkey'); var Privkey = bitcore.Privkey;
var Pubkey = require('../lib/pubkey'); var Pubkey = bitcore.Pubkey;
var Keypair = require('../lib/keypair'); var Keypair = bitcore.Keypair;
describe('Keypair', function() { describe('Keypair', function() {
@ -15,16 +17,21 @@ describe('Keypair', function() {
it('should make a key with a priv and pub', function() { it('should make a key with a priv and pub', function() {
var priv = new Privkey(); var priv = new Privkey();
var pub = new Pubkey(); var pub = new Pubkey();
var key = new Keypair({privkey: priv, pubkey: pub}); var key = new Keypair({
privkey: priv,
pubkey: pub
});
should.exist(key); should.exist(key);
should.exist(key.privkey); should.exist(key.privkey);
should.exist(key.pubkey); should.exist(key.pubkey);
}); });
describe("#set", function() { describe('#set', function() {
it('should make a new priv and pub', function() { it('should make a new priv and pub', function() {
should.exist(Keypair().set({privkey: Privkey()}).privkey); should.exist(new Keypair().set({
privkey: new Privkey()
}).privkey);
}); });
}); });
@ -127,7 +134,9 @@ describe('Keypair', function() {
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff'; var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff';
var pubhex = '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc'; var pubhex = '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc';
var key = new Keypair(); var key = new Keypair();
key.privkey = new Privkey({bn: bn(new Buffer(privhex, 'hex'))}); key.privkey = new Privkey({
bn: bn(new Buffer(privhex, 'hex'))
});
key.privkey2pubkey(); key.privkey2pubkey();
key.pubkey.toString().should.equal(pubhex); key.pubkey.toString().should.equal(pubhex);
}); });
@ -135,7 +144,9 @@ describe('Keypair', function() {
it('should convert this known Privkey to known Pubkey and preserve compressed=true', function() { it('should convert this known Privkey to known Pubkey and preserve compressed=true', function() {
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff'; var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff';
var key = new Keypair(); var key = new Keypair();
key.privkey = new Privkey({bn: bn(new Buffer(privhex, 'hex'))}); key.privkey = new Privkey({
bn: bn(new Buffer(privhex, 'hex'))
});
key.privkey.compressed = true; key.privkey.compressed = true;
key.privkey2pubkey(); key.privkey2pubkey();
key.pubkey.compressed.should.equal(true); key.pubkey.compressed.should.equal(true);
@ -144,7 +155,9 @@ describe('Keypair', function() {
it('should convert this known Privkey to known Pubkey and preserve compressed=true', function() { it('should convert this known Privkey to known Pubkey and preserve compressed=true', function() {
var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff'; var privhex = '906977a061af29276e40bf377042ffbde414e496ae2260bbf1fa9d085637bfff';
var key = new Keypair(); var key = new Keypair();
key.privkey = new Privkey({bn: bn(new Buffer(privhex, 'hex'))}); key.privkey = new Privkey({
bn: bn(new Buffer(privhex, 'hex'))
});
key.privkey.compressed = false; key.privkey.compressed = false;
key.privkey2pubkey(); key.privkey2pubkey();
key.pubkey.compressed.should.equal(false); key.pubkey.compressed.should.equal(false);

Loading…
Cancel
Save