Merge pull request #247 from maraoz/test/Buffers.monkey.js
Buffers.monkey now at 100% coverage
This commit is contained in:
commit
51ad6b4b3b
|
@ -9,8 +9,7 @@ exports.patch = function(Buffers) {
|
||||||
}
|
}
|
||||||
var pos = this.pos(i);
|
var pos = this.pos(i);
|
||||||
this.buffers = this.buffers.slice(pos.buf);
|
this.buffers = this.buffers.slice(pos.buf);
|
||||||
this.buffers[0].length -= pos.offset;
|
this.buffers[0] = new Buffer(this.buffers[0].slice(pos.offset));
|
||||||
this.buffers[0].offset += pos.offset;
|
|
||||||
this.length -= i;
|
this.length -= i;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,6 +14,7 @@ requireWhenAccessed('bignum', 'bignum');
|
||||||
requireWhenAccessed('base58', 'base58-native');
|
requireWhenAccessed('base58', 'base58-native');
|
||||||
requireWhenAccessed('bufferput', 'bufferput');
|
requireWhenAccessed('bufferput', 'bufferput');
|
||||||
requireWhenAccessed('buffertools', 'buffertools');
|
requireWhenAccessed('buffertools', 'buffertools');
|
||||||
|
requireWhenAccessed('Buffers.monkey', './Buffers.monkey');
|
||||||
requireWhenAccessed('config', './config');
|
requireWhenAccessed('config', './config');
|
||||||
requireWhenAccessed('const', './const');
|
requireWhenAccessed('const', './const');
|
||||||
requireWhenAccessed('Deserialize', './Deserialize');
|
requireWhenAccessed('Deserialize', './Deserialize');
|
||||||
|
|
|
@ -101,6 +101,9 @@ var createBitcore = function(opts) {
|
||||||
b.require(opts.dir + 'base58-native', {
|
b.require(opts.dir + 'base58-native', {
|
||||||
expose: 'base58-native'
|
expose: 'base58-native'
|
||||||
});
|
});
|
||||||
|
b.require(opts.dir + 'buffers', {
|
||||||
|
expose: 'buffers'
|
||||||
|
});
|
||||||
b.require('./' + opts.dir + 'bitcore', {
|
b.require('./' + opts.dir + 'bitcore', {
|
||||||
expose: 'bitcore'
|
expose: 'bitcore'
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
var bitcore = bitcore || require('../bitcore');
|
var bitcore = bitcore || require('../bitcore');
|
||||||
var buffertools = require('buffertools');
|
var buffertools = require('buffertools');
|
||||||
|
buffertools.extend();
|
||||||
|
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
|
|
||||||
|
@ -15,6 +16,9 @@ var base58Check = base58.base58Check;
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
var networks = bitcore.networks;
|
var networks = bitcore.networks;
|
||||||
var WalletKey = bitcore.WalletKey;
|
var WalletKey = bitcore.WalletKey;
|
||||||
|
var Buffers = require('buffers');
|
||||||
|
var m = bitcore['Buffers.monkey'] || require('../Buffers.monkey');
|
||||||
|
m.patch(Buffers);
|
||||||
|
|
||||||
describe('Miscelaneous stuff', function() {
|
describe('Miscelaneous stuff', function() {
|
||||||
it('should initialze the config object', function() {
|
it('should initialze the config object', function() {
|
||||||
|
@ -26,7 +30,7 @@ describe('Miscelaneous stuff', function() {
|
||||||
it('should initialze the network object', function() {
|
it('should initialze the network object', function() {
|
||||||
should.exist(networks);
|
should.exist(networks);
|
||||||
var nets = [networks.livenet, networks.testnet];
|
var nets = [networks.livenet, networks.testnet];
|
||||||
for (var i=0; i<2; i++) {
|
for (var i = 0; i < 2; i++) {
|
||||||
var net = nets[i];
|
var net = nets[i];
|
||||||
should.exist(net.addressVersion);
|
should.exist(net.addressVersion);
|
||||||
should.exist(net.privKeyVersion);
|
should.exist(net.privKeyVersion);
|
||||||
|
@ -42,8 +46,39 @@ describe('Miscelaneous stuff', function() {
|
||||||
should.exist(bitcore.Deserialize);
|
should.exist(bitcore.Deserialize);
|
||||||
should.exist(bitcore.Deserialize.intFromCompact);
|
should.exist(bitcore.Deserialize.intFromCompact);
|
||||||
});
|
});
|
||||||
|
it('should initialze the Buffer class', function() {
|
||||||
|
should.exist(bitcore.Buffer);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('Buffers monkey patch', function() {
|
||||||
|
var bufs;
|
||||||
|
beforeEach(function() {
|
||||||
|
bufs = new Buffers();
|
||||||
|
bufs.push(new Buffer('aaaaaa', 'hex'));
|
||||||
|
bufs.push(new Buffer('bbbb', 'hex'));
|
||||||
|
bufs.push(new Buffer('cc', 'hex'));
|
||||||
|
});
|
||||||
|
it('should monkey patch the Buffers class', function() {
|
||||||
|
should.exist(bufs.skip);
|
||||||
|
});
|
||||||
|
it('should work for 0', function() {
|
||||||
|
bufs.skip(0);
|
||||||
|
bufs.toBuffer().toHex().should.equal('aaaaaabbbbcc');
|
||||||
|
});
|
||||||
|
it('should work for length', function() {
|
||||||
|
bufs.skip(bufs.length);
|
||||||
|
bufs.toBuffer().toHex().should.equal('');
|
||||||
|
});
|
||||||
|
it('should work for middle values', function() {
|
||||||
|
bufs.skip(4);
|
||||||
|
bufs.toBuffer().toHex().should.equal('bbcc');
|
||||||
|
bufs.skip(1);
|
||||||
|
bufs.toBuffer().toHex().should.equal('cc');
|
||||||
|
bufs.skip(1);
|
||||||
|
bufs.toBuffer().toHex().should.equal('');
|
||||||
|
});
|
||||||
|
});
|
||||||
// bignum
|
// bignum
|
||||||
it('should initialze the bignum object', function() {
|
it('should initialze the bignum object', function() {
|
||||||
should.exist(bitcore.bignum);
|
should.exist(bitcore.bignum);
|
||||||
|
|
Loading…
Reference in New Issue