Browse Source

add check in constructor

patch-2
Matias Alejo Garcia 11 years ago
parent
commit
19584e1f26
  1. 3
      lib/SIN.js
  2. 7
      test/test.SIN.js

3
lib/SIN.js

@ -9,6 +9,9 @@ function SIN(type, payload) {
SIN.super_.call(this, type, payload); SIN.super_.call(this, type, payload);
return; return;
} }
if ( !Buffer.isBuffer(payload) || payload.length != 20)
throw new Error('Payload must be 20 bytes');
this.data = new Buffer(1 + 1 + payload.length); this.data = new Buffer(1 + 1 + payload.length);
this.converters = this.encodings['binary'].converters; this.converters = this.encodings['binary'].converters;
this._encoding = this.encodings['binary']._encoding; this._encoding = this.encodings['binary']._encoding;

7
test/test.SIN.js

@ -41,6 +41,13 @@ describe('SIN', function() {
var sin = new SIN(SIN.SIN_EPHEM, myhash); var sin = new SIN(SIN.SIN_EPHEM, myhash);
should.exist(sin); should.exist(sin);
}); });
it('should fail with param version, string', function() {
var hash = '1ab59a0fd1d5fc446d38746ee033c8af57ed6bc0';
( function (){
var sin = new SIN(SIN.SIN_EPHEM, hash);
}).should.throw();
});
}); });
describe('#fromPubKey', function() { describe('#fromPubKey', function() {
it('should fail to create a new SIN not using a pub key', function() { it('should fail to create a new SIN not using a pub key', function() {

Loading…
Cancel
Save