fixing stuff
This commit is contained in:
parent
7dc37a272a
commit
48dd8549ef
3 changed files with 17 additions and 134 deletions
|
|
@ -54,105 +54,6 @@ describe('Network / Async', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('#_setupPeerHandlers', function() {
|
||||
var n = new Async();
|
||||
n.peer = {};
|
||||
var spy = n.peer.on = sinon.spy();
|
||||
it('should setup handlers', function() {
|
||||
n._setupPeerHandlers();
|
||||
spy.calledWith('connection').should.equal(true);
|
||||
spy.calledWith('open').should.equal(true);
|
||||
spy.calledWith('error').should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#_handlePeerOpen', function() {
|
||||
var n = new Async();
|
||||
it('should call openCallback handler', function(done) {
|
||||
n.peerId = 1;
|
||||
n.copayerId = 2;
|
||||
n._handlePeerOpen(function() {
|
||||
n.connectedPeers.should.deep.equal([1]);
|
||||
n.copayerForPeer.should.deep.equal({
|
||||
1: 2
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#_handlePeerError', function() {
|
||||
var log = console.log;
|
||||
var n = new Async();
|
||||
it('should call _checkAnyPeer on could not connect error', function() {
|
||||
var save = n._checkAnyPeer;
|
||||
var spy = n._checkAnyPeer = sinon.spy();
|
||||
var logSpy = console.log = sinon.spy();
|
||||
n._handlePeerError({
|
||||
message: 'Could not connect to peer xxx'
|
||||
});
|
||||
console.log = log;
|
||||
spy.called.should.equal(true);
|
||||
logSpy.called.should.equal(true);
|
||||
n._checkAnyPeer = save;
|
||||
});
|
||||
|
||||
it('should call not call _checkAnyPeer other error', function() {
|
||||
var save = n._checkAnyPeer;
|
||||
var spy = n._checkAnyPeer = sinon.spy();
|
||||
var otherMessage = 'Could connect to peer xxx';
|
||||
var logSpy = console.log = sinon.spy();
|
||||
n._handlePeerError({
|
||||
message: otherMessage,
|
||||
});
|
||||
console.log = log;
|
||||
spy.called.should.equal(false);
|
||||
n.criticalError.should.equal(otherMessage);
|
||||
logSpy.called.should.equal(true);
|
||||
n._checkAnyPeer = save;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('#_encode', function() {
|
||||
|
||||
it('should encode data successfully', function() {
|
||||
var n = new Async();
|
||||
var data = new bitcore.Buffer('my data to encode');
|
||||
var privkeystr = new bitcore.Buffer('test privkey');
|
||||
var privkey = bitcore.util.sha256(privkeystr);
|
||||
var key = new bitcore.Key();
|
||||
key.private = privkey;
|
||||
key.regenerateSync();
|
||||
var encoded = n._encode(key.public, key, data);
|
||||
should.exist(encoded);
|
||||
encoded.sig.length.should.not.equal(0);
|
||||
encoded.pubkey.length.should.not.equal(0);
|
||||
encoded.encrypted.length.should.not.equal(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#_decode', function() {
|
||||
|
||||
it('should decode that which was encoded', function() {
|
||||
var n = new Async();
|
||||
var data = new bitcore.Buffer('my data to encrypt');
|
||||
var privkeystr = new bitcore.Buffer('test privkey');
|
||||
var privkey = bitcore.util.sha256(privkeystr);
|
||||
var key = new bitcore.Key();
|
||||
key.private = privkey;
|
||||
key.regenerateSync();
|
||||
var encoded = n._encode(key.public, key, data);
|
||||
var decoded = n._decode(key, encoded);
|
||||
encoded.sig.should.not.equal(0);
|
||||
decoded.payload.toString().should.equal('my data to encrypt');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#send', function() {
|
||||
|
||||
it('should call _sendToOne for a copayer', function(done) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue