add tests to EncodedData and fix hex conversion bug
...making sure the new changes to __proto__ are working correctly.
This commit is contained in:
parent
cfa0c11983
commit
71f181efee
|
@ -5,21 +5,56 @@ var bitcore = bitcore || require('../bitcore');
|
||||||
|
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
|
|
||||||
var EncodedDataModule = bitcore.EncodedData;
|
var EncodedData = bitcore.EncodedData;
|
||||||
var EncodedData;
|
|
||||||
|
|
||||||
describe('EncodedData', function() {
|
describe('EncodedData', function() {
|
||||||
it('should initialze the main object', function() {
|
|
||||||
should.exist(EncodedDataModule);
|
it('should initialize the main object', function() {
|
||||||
});
|
|
||||||
it('should be able to create class', function() {
|
|
||||||
EncodedData = EncodedDataModule;
|
|
||||||
should.exist(EncodedData);
|
should.exist(EncodedData);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to create an instance', function() {
|
it('should be able to create an instance', function() {
|
||||||
var ed = new EncodedData('1GMx4HdDmN78xzGvdQYkwrVqkmLDG1aMNT');
|
var ed = new EncodedData('1GMx4HdDmN78xzGvdQYkwrVqkmLDG1aMNT');
|
||||||
should.exist(ed);
|
should.exist(ed);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#as', function() {
|
||||||
|
var buf = bitcore.util.sha256('test');
|
||||||
|
var hex = buf.toString('hex');
|
||||||
|
var b58 = '2DFtpKRbW2nfrzgAgE25onW3vwCQwM7S1iHk34LW9cwH1kzmHp';
|
||||||
|
|
||||||
|
it('should convert from binary -> base58', function() {
|
||||||
|
var ed = new EncodedData(buf);
|
||||||
|
ed.as('base58').should.equal(bitcore.Base58.base58Check.encode(buf));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert from binary -> hex', function() {
|
||||||
|
var ed = new EncodedData(buf);
|
||||||
|
ed.as('hex').should.equal(hex);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert from base58 -> binary', function() {
|
||||||
|
var ed = new EncodedData(b58);
|
||||||
|
ed.as('binary').toString('hex').should.equal(hex);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert from base58 -> hex', function() {
|
||||||
|
var ed = new EncodedData(b58);
|
||||||
|
ed.as('hex').should.equal(hex);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert from hex -> binary', function() {
|
||||||
|
var ed = new EncodedData(hex, 'hex');
|
||||||
|
ed.as('binary').toString('hex').should.equal(hex);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert from hex -> base58', function() {
|
||||||
|
var ed = new EncodedData(hex, 'hex');
|
||||||
|
ed.as('base58').should.equal(b58);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ function EncodedData(data, encoding) {
|
||||||
} else {
|
} else {
|
||||||
if (typeof this.encodings[encoding] === 'undefined')
|
if (typeof this.encodings[encoding] === 'undefined')
|
||||||
encoding = 'binary';
|
encoding = 'binary';
|
||||||
this.converters = this.encodings['binary'].converters;
|
this.converters = this.encodings[encoding].converters;
|
||||||
this._encoding = this.encodings['binary']._encoding;
|
this._encoding = this.encodings[encoding]._encoding;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue