Base58Check.prototype.set

This commit is contained in:
Ryan X. Charles 2014-08-28 15:31:06 -07:00
parent da8989b649
commit d50d766352
2 changed files with 19 additions and 5 deletions

View File

@ -1,10 +1,16 @@
var base58 = require('./base58'); var base58 = require('./base58');
var sha256sha256 = require('./hash').sha256sha256; var sha256sha256 = require('./hash').sha256sha256;
var Base58Check = function Base58Check(buf) { var Base58Check = function Base58Check(obj) {
if (!(this instanceof Base58Check)) if (!(this instanceof Base58Check))
return new Base58Check(buf); return new Base58Check(obj);
this.buf = buf; if (obj)
this.set(obj);
};
Base58Check.prototype.set = function(obj) {
this.buf = obj.buf || this.buf || undefined;
return this;
}; };
Base58Check.decode = function(s) { Base58Check.decode = function(s) {

View File

@ -16,6 +16,14 @@ describe('Base58Check', function() {
should.exist(b58); should.exist(b58);
}); });
describe('#set', function() {
it('should set a buf', function() {
should.exist(Base58Check().set({buf: buf}).buf);
});
});
describe('@encode', function() { describe('@encode', function() {
it('should encode the buffer accurately', function() { it('should encode the buffer accurately', function() {
@ -83,7 +91,7 @@ describe('Base58Check', function() {
describe('#toBuffer', function() { describe('#toBuffer', function() {
it('should return the buffer', function() { it('should return the buffer', function() {
var b58 = Base58Check(buf); var b58 = Base58Check({buf: buf});
b58.buf.toString('hex').should.equal(buf.toString('hex')); b58.buf.toString('hex').should.equal(buf.toString('hex'));
}); });
@ -92,7 +100,7 @@ describe('Base58Check', function() {
describe('#toString', function() { describe('#toString', function() {
it('should return the buffer', function() { it('should return the buffer', function() {
var b58 = Base58Check(buf); var b58 = Base58Check({buf: buf});
b58.toString().should.equal(enc); b58.toString().should.equal(enc);
}); });