fix tests for keypair
This commit is contained in:
parent
24b16fc126
commit
40d308748f
|
@ -1,12 +1,14 @@
|
||||||
|
'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() {
|
||||||
|
|
||||||
it('should make a blank key', function() {
|
it('should make a blank key', function() {
|
||||||
var key = new Keypair();
|
var key = new Keypair();
|
||||||
should.exist(key);
|
should.exist(key);
|
||||||
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -58,7 +65,7 @@ describe('Keypair', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#fromPrivkey", function() {
|
describe("#fromPrivkey", function() {
|
||||||
|
|
||||||
it('should make a new key from a privkey', function() {
|
it('should make a new key from a privkey', function() {
|
||||||
should.exist(Keypair().fromPrivkey(Privkey().fromRandom()).pubkey);
|
should.exist(Keypair().fromPrivkey(Privkey().fromRandom()).pubkey);
|
||||||
});
|
});
|
||||||
|
@ -66,7 +73,7 @@ describe('Keypair', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#fromRandom", function() {
|
describe("#fromRandom", function() {
|
||||||
|
|
||||||
it('should make a new priv and pub, should be compressed, mainnet', function() {
|
it('should make a new priv and pub, should be compressed, mainnet', function() {
|
||||||
var key = new Keypair();
|
var key = new Keypair();
|
||||||
key.fromRandom();
|
key.fromRandom();
|
||||||
|
@ -83,7 +90,7 @@ describe('Keypair', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#fromString()", function() {
|
describe("#fromString()", function() {
|
||||||
|
|
||||||
it('should recover a key creating with toString', function() {
|
it('should recover a key creating with toString', function() {
|
||||||
var key = new Keypair();
|
var key = new Keypair();
|
||||||
key.fromRandom();
|
key.fromRandom();
|
||||||
|
@ -122,12 +129,14 @@ describe('Keypair', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#privkey2pubkey", function() {
|
describe("#privkey2pubkey", function() {
|
||||||
|
|
||||||
it('should convert this known Privkey to known Pubkey', function() {
|
it('should convert this known Privkey to known Pubkey', 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);
|
||||||
|
@ -153,7 +166,7 @@ describe('Keypair', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#toString()", function() {
|
describe("#toString()", function() {
|
||||||
|
|
||||||
it('should exist', function() {
|
it('should exist', function() {
|
||||||
var key = new Keypair();
|
var key = new Keypair();
|
||||||
key.fromRandom();
|
key.fromRandom();
|
||||||
|
|
Loading…
Reference in New Issue