Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sin03 #450

Merged
merged 4 commits into from
Jul 24, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var Script = require('./Script');
var util = require('util');

function Address(version, hash) {
if (hash && hash.length && hash.length != 20)
if (hash && hash.length && (!Buffer.isBuffer(hash) || hash.length != 20))
throw new Error('Hash must be 20 bytes');
Address.super_.call(this, version, hash);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/SIN.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ function SIN(type, payload) {
SIN.super_.call(this, type, payload);
return;
}
if ( !Buffer.isBuffer(payload) || payload.length != 20)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no space before !Buffer

throw new Error('Payload must be 20 bytes');

this.data = new Buffer(1 + 1 + payload.length);
this.converters = this.encodings['binary'].converters;
this._encoding = this.encodings['binary']._encoding;
Expand Down
15 changes: 15 additions & 0 deletions test/test.Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ describe('Address', function() {
});
});

describe('constructor, 2 params', function() {
it('should make an address from a version, hash', function() {
var hash = new Buffer('1ab59a0fd1d5fc446d38746ee033c8af57ed6bc0', 'hex');
var addr = new Address(0, hash);
addr.toString().should.equal('13SE7uKmnQwGA8X1A8WcZnX2ceQRDEzsAd');
});
it('should fail with param version, string', function() {
var hash = '1ab59a0fd1d5fc446d38746ee033c8af57ed6bc0';
( function (){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"( function (){" should be "(function() {"

var addr = new Address(0, hash);
}).should.throw();
});
});


describe('#fromPubKey', function() {
it('should make pubkeyhash address from an uncompressed public key', function() {
var pubkey = new Buffer('04fa05ce8b25010cb6e17a30e0b66668bf083c40687547748ec330ee77adf53a42abd3d26148cbacfcf79c907ddefeb2c37f8bebc0a695ba79d634449d871de218', 'hex');
Expand Down
7 changes: 7 additions & 0 deletions test/test.SIN.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ describe('SIN', function() {
var sin = new SIN(SIN.SIN_EPHEM, myhash);
should.exist(sin);
});
it('should fail with param version, string', function() {
var hash = '1ab59a0fd1d5fc446d38746ee033c8af57ed6bc0';
( function (){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"( function (){" should be "(function() {"

var sin = new SIN(SIN.SIN_EPHEM, hash);
}).should.throw();
});

});
describe('#fromPubKey', function() {
it('should fail to create a new SIN not using a pub key', function() {
Expand Down