fix test 13
This commit is contained in:
parent
5ace0c7e46
commit
50348a171f
2 changed files with 11 additions and 22 deletions
|
|
@ -370,10 +370,10 @@ Network.prototype.send = function(dest, payload, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Network.prototype.encode = function(copayerId, payload) {
|
Network.prototype.encode = function(copayerId, payload, nonce) {
|
||||||
this.iterateNonce();
|
this.iterateNonce();
|
||||||
var opts = {
|
var opts = {
|
||||||
nonce: this.networkNonce
|
nonce: nonce || this.networkNonce
|
||||||
};
|
};
|
||||||
var copayerIdBuf = new Buffer(copayerId, 'hex');
|
var copayerIdBuf = new Buffer(copayerId, 'hex');
|
||||||
var message = AuthMessage.encode(copayerIdBuf, this.getKey(), payload, opts);
|
var message = AuthMessage.encode(copayerIdBuf, this.getKey(), payload, opts);
|
||||||
|
|
|
||||||
|
|
@ -154,30 +154,19 @@ describe('Network / Async', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not reject data sent from a peer with no previously set nonce but who is setting one now', function() {
|
it('should not reject data sent from a peer with no previously set nonce but who is setting one now', function() {
|
||||||
var n = createN(pk2);
|
var n1 = createN(pk1);
|
||||||
|
var n2 = createN(pk2);
|
||||||
|
n2._deletePeer = sinon.spy();
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
type: 'hello',
|
type: 'hello',
|
||||||
copayerId: key1.public.toString('hex')
|
copayerId: cid1
|
||||||
};
|
};
|
||||||
var messagestr = JSON.stringify(message);
|
var nonce = new Buffer('0000000000000001', 'hex');
|
||||||
var messagebuf = new Buffer(messagestr);
|
var enc = n1.encode(cid2, message, nonce);
|
||||||
|
n2._onMessage(enc);
|
||||||
var opts = {
|
n2._deletePeer.calledOnce.should.equal(false);
|
||||||
nonce: new Buffer('0000000000000001', 'hex')
|
n2.getHexNonces()[cid1].toString('hex').should.equal('0000000000000001');
|
||||||
}; //message send with new nonce
|
|
||||||
var encoded = n._encode(key2.public, key1, messagebuf, opts);
|
|
||||||
var encodedstr = JSON.stringify(encoded);
|
|
||||||
var encodeduint = new Buffer(encodedstr);
|
|
||||||
|
|
||||||
var isInbound = true;
|
|
||||||
var peerId = new bitcore.SIN(key1.public);
|
|
||||||
|
|
||||||
n._deletePeer = sinon.spy();
|
|
||||||
|
|
||||||
n._onMessage(encodeduint, isInbound, peerId);
|
|
||||||
n._deletePeer.calledOnce.should.equal(false);
|
|
||||||
n.getHexNonces()[(new bitcore.SIN(key1.public)).toString()].toString('hex').should.equal('0000000000000001');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not reject data sent from a peer with a really big new nonce', function() {
|
it('should not reject data sent from a peer with a really big new nonce', function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue