bitcore-lib-zcash/test/test.SIN.js

79 lines
2.5 KiB
JavaScript
Raw Normal View History

2014-02-17 12:55:56 -08:00
'use strict';
var chai = chai || require('chai');
var bitcore = bitcore || require('../bitcore');
2014-02-17 12:55:56 -08:00
var should = chai.should();
2014-07-10 13:17:24 -07:00
var SIN = bitcore.SIN;
2014-02-17 12:55:56 -08:00
2014-02-19 11:07:50 -08:00
describe('SIN', function() {
2014-02-17 12:55:56 -08:00
it('should be able to create class', function() {
2014-02-19 11:07:50 -08:00
should.exist(SIN);
2014-02-17 12:55:56 -08:00
});
it('should be able to create instance', function() {
2014-02-19 11:07:50 -08:00
var s = new SIN();
should.exist(s);
2014-02-17 12:55:56 -08:00
});
2014-07-10 13:17:24 -07:00
it('should be able to convert to string', function() {
var s = new SIN('6bqov85Hsatqb8eLtwLW1PBQLWVNJkzPwgdAT3SYNkB6X2aF2n');
s.toString.bind(s).should.not.throw();
});
var data = [
['6bqov85Hsatqb8eLtwLW1PBQLWVNJkzPwgdAT3SYNkB6X2aF2n', false],
2014-07-23 14:53:57 -07:00
['TfGPWmEYZCTr1FHqinjoGxnYAxdBhsta4qR', true],
['TexvSXam8vtoUviGajQyDuYdPSAEtwTNyZg', true]
2014-07-10 13:17:24 -07:00
];
data.forEach(function(datum) {
var sin = datum[0];
var result = datum[1];
it('should validate correctly ' + sin, function() {
var a = new SIN(sin);
var s = a.toString();
a.isValid().should.equal(result);
s.should.equal(a.toString()); // check that validation doesn't change data
});
});
describe('#SIN', function() {
it('should be able to create a new SIN with a version byte', function() {
2014-07-23 21:52:17 -07:00
var myhash = new Buffer('1ab59a0fd1d5fc446d38746ee033c8af57ed6bc0', 'hex');
var sin = new SIN(SIN.SIN_EPHEM, myhash);
should.exist(sin);
});
2014-07-23 21:40:13 -07:00
it('should fail with param version, string', function() {
var hash = '1ab59a0fd1d5fc446d38746ee033c8af57ed6bc0';
2014-07-24 12:47:50 -07:00
(function() {
2014-07-23 21:40:13 -07:00
var sin = new SIN(SIN.SIN_EPHEM, hash);
}).should.throw();
});
2014-07-24 12:47:50 -07:00
2014-07-23 21:52:17 -07:00
it('should fail with wrong sized hash', function() {
var myhash = new Buffer('111ab59a0fd1d5fc446d38746ee033c8af57ed6bc0', 'hex');
2014-07-24 12:47:50 -07:00
(function() {
2014-07-23 21:52:17 -07:00
var sin = new SIN(SIN.SIN_EPHEM, myhash);
}).should.throw();
});
2014-07-24 12:47:50 -07:00
});
2014-07-23 14:53:57 -07:00
describe('#fromPubKey', function() {
it('should fail to create a new SIN not using a pub key', function() {
2014-07-24 12:47:50 -07:00
(function() {
SIN.fromPubKey('1234')
}).should.throw();
2014-07-23 14:53:57 -07:00
});
it('should fail to create a new SIN not using a pub key case 2', function() {
2014-07-24 12:47:50 -07:00
(function() {
SIN.fromPubKey('03e0973263b4e0d5f5f56d25d430e777ab3838ff644db972c0bf32c31da5686c27')
}).should.throw();
2014-07-23 14:53:57 -07:00
});
it('should be able to create a new SIN using a pub key', function() {
var pubkey1 = new Buffer('03e0973263b4e0d5f5f56d25d430e777ab3838ff644db972c0bf32c31da5686c27', 'hex');
var sin = SIN.fromPubKey(pubkey1);
should.exist(sin);
sin.toString().should.equal('FrCfKjSFN1Ubp3x6AD6au8M5LTaNAEN8b');
});
2014-07-24 12:47:50 -07:00
2014-07-23 14:53:57 -07:00
});
2014-02-17 12:55:56 -08:00
});