Fix conflicts:
index.html
This commit is contained in:
commit
bc5c473752
26 changed files with 715 additions and 252 deletions
|
|
@ -15,6 +15,7 @@
|
|||
<script src="../lib/bitcore/browser/bundle.js"></script>
|
||||
<script src="../js/copayBundle.js"></script>
|
||||
<script src="test.blockchain.Insight.js"></script>
|
||||
<script src="test.Message.js"></script>
|
||||
<script src="test.network.WebRTC.js"></script>
|
||||
<script src="test.PrivateKey.js"></script>
|
||||
<script src="test.PublicKeyRing.js"></script>
|
||||
|
|
|
|||
103
test/test.Message.js
Normal file
103
test/test.Message.js
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var sinon = require('sinon');
|
||||
var Message = require('../js/models/core/Message');
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var Buffer = bitcore.Buffer;
|
||||
|
||||
describe('Message model', function() {
|
||||
var key = new bitcore.Key();
|
||||
key.private = bitcore.util.sha256(new Buffer('test'));
|
||||
key.regenerateSync();
|
||||
|
||||
var key2 = new bitcore.Key();
|
||||
key2.private = bitcore.util.sha256(new Buffer('test 2'));
|
||||
key2.regenerateSync();
|
||||
|
||||
describe('#encode', function() {
|
||||
|
||||
it('should encode a message', function() {
|
||||
var message = new Buffer('message');
|
||||
var encoded = Message.encode(key2.public, key, message);
|
||||
should.exist(encoded.pubkey);
|
||||
should.exist(encoded.sig);
|
||||
should.exist(encoded.encrypted);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#decode', function() {
|
||||
|
||||
it('should decode an encoded message', function() {
|
||||
var message = new Buffer('message');
|
||||
var messagehex = message.toString('hex');
|
||||
var encoded = Message.encode(key2.public, key, message);
|
||||
|
||||
var decoded = Message.decode(key2, encoded);
|
||||
decoded.toString('hex').should.equal(messagehex);
|
||||
});
|
||||
|
||||
it('should fail if the version number is incorrect', function() {
|
||||
var payload = new Buffer('message');
|
||||
var fromkey = key;
|
||||
var topubkey = key2.public;
|
||||
var version = new Buffer([1]);
|
||||
var toencrypt = Buffer.concat([version, payload]);
|
||||
var encrypted = Message._encrypt(topubkey, toencrypt);
|
||||
var sig = Message._sign(fromkey, encrypted);
|
||||
var encoded = {
|
||||
pubkey: fromkey.public.toString('hex'),
|
||||
sig: sig.toString('hex'),
|
||||
encrypted: encrypted.toString('hex')
|
||||
};
|
||||
|
||||
(function() {Message.decode(key2, encoded);}).should.throw('Invalid version number');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#_encrypt', function() {
|
||||
|
||||
it('should encrypt data', function() {
|
||||
var payload = new Buffer('payload');
|
||||
var encrypted = Message._encrypt(key.public, payload);
|
||||
encrypted.length.should.equal(129);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#_decrypt', function() {
|
||||
var payload = new Buffer('payload');
|
||||
var payloadhex = payload.toString('hex');
|
||||
|
||||
it('should decrypt encrypted data', function() {
|
||||
var encrypted = Message._encrypt(key.public, payload);
|
||||
var decrypted = Message._decrypt(key.private, encrypted);
|
||||
decrypted.toString('hex').should.equal(payloadhex);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#_sign', function() {
|
||||
|
||||
it('should sign data', function() {
|
||||
var payload = new Buffer('payload');
|
||||
var sig = Message._sign(key, payload);
|
||||
sig.length.should.be.greaterThan(60);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#_verify', function() {
|
||||
var payload = new Buffer('payload');
|
||||
var sig = Message._sign(key, payload);
|
||||
|
||||
it('should verify signed data', function() {
|
||||
Message._verify(key.public, sig, payload).should.equal(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -331,7 +331,6 @@ describe('Wallet model', function() {
|
|||
var w = cachedCreateW2();
|
||||
var spy = sinon.spy(w, 'scheduleConnect');
|
||||
var callCount = 3;
|
||||
w.reconnectDelay = 25;
|
||||
w.netStart();
|
||||
setTimeout(function() {
|
||||
sinon.assert.callCount(spy, callCount);
|
||||
|
|
@ -534,11 +533,12 @@ describe('Wallet model', function() {
|
|||
},
|
||||
|
||||
];
|
||||
var roundWallet = cachedCreateW2();
|
||||
|
||||
roundErrorChecks.forEach(function(c) {
|
||||
it('check rounding errors ' + c.unspent[0], function(done) {
|
||||
var w = cachedCreateW2();
|
||||
w.generateAddress();
|
||||
it('#getBalance should handle rounding errors: ' + c.unspent[0], function(done) {
|
||||
var w = roundWallet;
|
||||
//w.generateAddress();
|
||||
w.blockchain.fixUnspent(c.unspent.map(function(u) {
|
||||
return {
|
||||
amount: u
|
||||
|
|
@ -743,7 +743,7 @@ describe('Wallet model', function() {
|
|||
var spyEmit = sinon.spy(w, 'emit');
|
||||
w.updateIndexes(function(err) {
|
||||
sinon.assert.callCount(spyStore, 1);
|
||||
sinon.assert.callCount(spyEmit, 1);
|
||||
sinon.assert.callCount(spyEmit, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
@ -826,7 +826,6 @@ describe('Wallet model', function() {
|
|||
|
||||
describe('#getMyCopayerId', function() {
|
||||
it('should call getCopayerId', function() {
|
||||
//this.timeout(10000);
|
||||
var w = cachedCreateW2();
|
||||
w.getCopayerId = sinon.spy();
|
||||
w.getMyCopayerId();
|
||||
|
|
@ -836,7 +835,6 @@ describe('Wallet model', function() {
|
|||
|
||||
describe('#getMyCopayerIdPriv', function() {
|
||||
it('should call privateKey.getIdPriv', function() {
|
||||
//this.timeout(10000);
|
||||
var w = cachedCreateW2();
|
||||
w.privateKey.getIdPriv = sinon.spy();
|
||||
w.getMyCopayerIdPriv();
|
||||
|
|
@ -845,9 +843,7 @@ describe('Wallet model', function() {
|
|||
});
|
||||
|
||||
describe('#netStart', function() {
|
||||
|
||||
it('should call Network.start', function() {
|
||||
//this.timeout(10000);
|
||||
var w = cachedCreateW2();
|
||||
w.network.start = sinon.spy();
|
||||
w.netStart();
|
||||
|
|
@ -855,13 +851,21 @@ describe('Wallet model', function() {
|
|||
});
|
||||
|
||||
it('should call Network.start with a private key', function() {
|
||||
//this.timeout(10000);
|
||||
var w = cachedCreateW2();
|
||||
w.network.start = sinon.spy();
|
||||
w.netStart();
|
||||
w.network.start.getCall(0).args[0].privkey.length.should.equal(64);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#offerBackup', function() {
|
||||
it('should work', function() {
|
||||
var w = cachedCreateW2();
|
||||
w.store = sinon.spy();
|
||||
w.offerBackup();
|
||||
w.backupOffered.should.equal(true);
|
||||
w.store.calledOnce.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ describe('WalletFactory model', function() {
|
|||
});
|
||||
|
||||
it('#fromObj #toObj round trip', function() {
|
||||
var o = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"version":"0.0.5"},"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":{"changeIndex":0,"receiveIndex":0},"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{},"publicKeysCache":{"m/0/1/0":["0314368b8efa07e8c7dad30498d0a7e3aa575db1fef833347c6d381c1a33a17b17","02cfd95f89ab46bd3bd86954dd9f83dbab0cd2e4466dee587e8e4d8d733fc0d748","02568969eb6212fe946450be6c5b3353fc754a40b2cdc4aed501a8976fec371da8","0360f870a088ae0ef1c37035a9b6a462ca8dcdd5da275f4e2dcd19f44b81d3e7e4","0300ad8f1bded838b02e127bb25961fbcee718db2df81f680f889692acdcbdd73d"],"m/0/1/1":["024f97a9adb2fa9306c4e3d9244f5e5355c7e2c6b3dd4122ba804e17dc9729df5d","0214834a5adcbc4ad0f3bbbc1c280b8ac480387fcc9a1fd988c1526ed496d923c4","024e72338bd5e976375d076bd71a9649e9141b4cbfc9e16cb7109b354b3e913a05","0322045ea35c3118aa7ab9f2c9f182b0120956b0aa65cc72b9d093f145327a4b17","030dc2450c72df366c1960739c577a2efd4451070bd78effcb6f71d1bcd7dfc7a8"],"m/0/1/2":["0247de59deb66783b8f9b0c326234a9569d00866c2a73f599e77a4d0cab5cbce8f","0376e49f0ac3647404034aae0dc8dd927c34a634ef24ea36f56a272f75fce9539b","032fbaa2593bd1eea4a46e7ac15f15802cdd1eb65a7d5bc4364ddd9d52f0838234","03a81f2a7e1f7191aa0b0c6e0a4ccefc71edd3564e86014972fe338045f68d5a5a","02eb8a012ea9a709392502cacda6ef5115d6d2319ab470d546d9068ab941621a99"],"m/0/0/0":["036dcbd378b4352120d6b720b6294dd2d0dd02801fcf010bb69dadbec1f3999279","022089eedb85dc45d1efa418e1ea226588deedebc1d85acca15ff72783e33636c0","0388aa5fd432b74c56427396f350d236c3ca8f7b2f62da513ce4c2e6ff04a67e9c","02fc4caa7449db7483d2e1fccdacac6fa2f736278c758af9966402589b5632f13e","02e4a15b885d8b2d586f82fa85d16179644e60a154674bde0ec3004810b1bdab99"],"m/0/0/1":["039afa26b2f341c76c7b3c3d0672438f35ac6ebb67b1ddfefac9cd79b7b24418c1","021acaaf500d431ebc396f50630767b01c91ce98ae48e968775ceaad932b7e3b8e","022a947259c4a9f76d5e95c0849df31d01233df41d0d75d631b89317a48d8cddce","03d38d9f94217da780303d9a8987c86d737ef39683febc0cd6632cddbfa62186fd","0394d2581b307fe2af19721888d922aab58ab198ef88cedf9506177e30d807811e"],"m/0/0/2":["037825ffce15d34f9bd6c02bcda7701826706471a4d6ab5004eb965f98811c2098","023768dd6d3c71b7df5733ccda5b2d8b454d5b4c4179d91a6fda74db8b869a2406","021a79e91f003f308764d43039e9b5d56bc8f33ca2f4d30ec6cc5a37c0d09dc273","02437f1e388b273936319f79a5d22958ef5ebff9c8cd7b6f6f72518445b1e30867","0373b0881cb4fd02baa62589023fdfe9739c6148cf104d907549f2528eb80146f5"]}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet","privateKeyCache":{}},"addressBook":{}}';
|
||||
var o = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"version":"0.0.5"},"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":{"changeIndex":0,"receiveIndex":0},"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{},"publicKeysCache":{"m/0/1/0":["0314368b8efa07e8c7dad30498d0a7e3aa575db1fef833347c6d381c1a33a17b17","02cfd95f89ab46bd3bd86954dd9f83dbab0cd2e4466dee587e8e4d8d733fc0d748","02568969eb6212fe946450be6c5b3353fc754a40b2cdc4aed501a8976fec371da8","0360f870a088ae0ef1c37035a9b6a462ca8dcdd5da275f4e2dcd19f44b81d3e7e4","0300ad8f1bded838b02e127bb25961fbcee718db2df81f680f889692acdcbdd73d"],"m/0/1/1":["024f97a9adb2fa9306c4e3d9244f5e5355c7e2c6b3dd4122ba804e17dc9729df5d","0214834a5adcbc4ad0f3bbbc1c280b8ac480387fcc9a1fd988c1526ed496d923c4","024e72338bd5e976375d076bd71a9649e9141b4cbfc9e16cb7109b354b3e913a05","0322045ea35c3118aa7ab9f2c9f182b0120956b0aa65cc72b9d093f145327a4b17","030dc2450c72df366c1960739c577a2efd4451070bd78effcb6f71d1bcd7dfc7a8"],"m/0/1/2":["0247de59deb66783b8f9b0c326234a9569d00866c2a73f599e77a4d0cab5cbce8f","0376e49f0ac3647404034aae0dc8dd927c34a634ef24ea36f56a272f75fce9539b","032fbaa2593bd1eea4a46e7ac15f15802cdd1eb65a7d5bc4364ddd9d52f0838234","03a81f2a7e1f7191aa0b0c6e0a4ccefc71edd3564e86014972fe338045f68d5a5a","02eb8a012ea9a709392502cacda6ef5115d6d2319ab470d546d9068ab941621a99"],"m/0/0/0":["036dcbd378b4352120d6b720b6294dd2d0dd02801fcf010bb69dadbec1f3999279","022089eedb85dc45d1efa418e1ea226588deedebc1d85acca15ff72783e33636c0","0388aa5fd432b74c56427396f350d236c3ca8f7b2f62da513ce4c2e6ff04a67e9c","02fc4caa7449db7483d2e1fccdacac6fa2f736278c758af9966402589b5632f13e","02e4a15b885d8b2d586f82fa85d16179644e60a154674bde0ec3004810b1bdab99"],"m/0/0/1":["039afa26b2f341c76c7b3c3d0672438f35ac6ebb67b1ddfefac9cd79b7b24418c1","021acaaf500d431ebc396f50630767b01c91ce98ae48e968775ceaad932b7e3b8e","022a947259c4a9f76d5e95c0849df31d01233df41d0d75d631b89317a48d8cddce","03d38d9f94217da780303d9a8987c86d737ef39683febc0cd6632cddbfa62186fd","0394d2581b307fe2af19721888d922aab58ab198ef88cedf9506177e30d807811e"],"m/0/0/2":["037825ffce15d34f9bd6c02bcda7701826706471a4d6ab5004eb965f98811c2098","023768dd6d3c71b7df5733ccda5b2d8b454d5b4c4179d91a6fda74db8b869a2406","021a79e91f003f308764d43039e9b5d56bc8f33ca2f4d30ec6cc5a37c0d09dc273","02437f1e388b273936319f79a5d22958ef5ebff9c8cd7b6f6f72518445b1e30867","0373b0881cb4fd02baa62589023fdfe9739c6148cf104d907549f2528eb80146f5"]}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet","privateKeyCache":{}},"addressBook":{},"backupOffered":false}';
|
||||
|
||||
var wf = new WalletFactory(config, '0.0.5');
|
||||
var w = wf.fromObj(JSON.parse(o));
|
||||
|
|
@ -94,6 +94,29 @@ describe('WalletFactory model', function() {
|
|||
JSON.stringify(w.toObj()).should.equal(o);
|
||||
});
|
||||
|
||||
it('should create wallet from encrypted object', function() {
|
||||
var wf = new WalletFactory(config, '0.0.1');
|
||||
wf.storage._setPassphrase = sinon.spy();
|
||||
wf.storage.import = sinon.spy();
|
||||
|
||||
var w = wf.fromEncryptedObj("encrypted object", "password");
|
||||
should.exist(w);
|
||||
wf.storage._setPassphrase.called.should.be.true;
|
||||
wf.storage.import.called.should.be.true;
|
||||
});
|
||||
|
||||
it('should import and update indexes', function() {
|
||||
var wf = new WalletFactory(config, '0.0.1');
|
||||
var wallet = {id: "fake wallet", updateIndexes: function(cb) { cb(); }};
|
||||
wf.fromEncryptedObj = sinon.stub().returns(wallet);
|
||||
var callback = sinon.spy();
|
||||
|
||||
var w = wf.import("encrypted", "password", callback);
|
||||
|
||||
should.exist(w);
|
||||
wallet.should.equal(w);
|
||||
sinon.assert.callCount(callback, 1);
|
||||
});
|
||||
|
||||
it('BIP32 length problem', function() {
|
||||
var sconfig = {
|
||||
|
|
|
|||
|
|
@ -46,26 +46,28 @@ describe('Network / WebRTC', function() {
|
|||
|
||||
});
|
||||
|
||||
describe('#_encrypt', function() {
|
||||
describe('#_encode', function() {
|
||||
|
||||
it('should encrypt data successfully', function() {
|
||||
it('should encode data successfully', function() {
|
||||
var n = new WebRTC();
|
||||
var data = new bitcore.Buffer('my data to encrypt');
|
||||
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 encrypted = n._encrypt(key.public, data);
|
||||
encrypted.length.should.not.equal(0);
|
||||
encrypted.length.should.equal(145);
|
||||
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('#_decrypt', function() {
|
||||
describe('#_decode', function() {
|
||||
|
||||
it('should decrypt that which was encrypted', function() {
|
||||
it('should decode that which was encoded', function() {
|
||||
var n = new WebRTC();
|
||||
var data = new bitcore.Buffer('my data to encrypt');
|
||||
var privkeystr = new bitcore.Buffer('test privkey');
|
||||
|
|
@ -73,10 +75,10 @@ describe('Network / WebRTC', function() {
|
|||
var key = new bitcore.Key();
|
||||
key.private = privkey;
|
||||
key.regenerateSync();
|
||||
var encrypted = n._encrypt(key.public, data);
|
||||
var decrypted = n._decrypt(key.private, encrypted);
|
||||
encrypted.length.should.not.equal(0);
|
||||
decrypted.toString().should.equal('my data to encrypt');
|
||||
var encoded = n._encode(key.public, key, data);
|
||||
var decoded = n._decode(key, encoded);
|
||||
encoded.sig.should.not.equal(0);
|
||||
decoded.toString().should.equal('my data to encrypt');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -85,6 +87,7 @@ describe('Network / WebRTC', function() {
|
|||
|
||||
it('should call _sendToOne for a copayer', function(done) {
|
||||
var n = new WebRTC();
|
||||
n.privkey = bitcore.util.sha256('test');
|
||||
|
||||
var data = new bitcore.Buffer('my data to send');
|
||||
|
||||
|
|
@ -95,7 +98,7 @@ describe('Network / WebRTC', function() {
|
|||
key.regenerateSync();
|
||||
|
||||
var copayerId = key.public.toString('hex');
|
||||
n._sendToOne = function(a1, a2, a3, cb) {
|
||||
n._sendToOne = function(a1, a2, cb) {
|
||||
cb();
|
||||
};
|
||||
var sig = undefined;
|
||||
|
|
@ -107,6 +110,7 @@ describe('Network / WebRTC', function() {
|
|||
|
||||
it('should call _sendToOne with encrypted data for a copayer', function(done) {
|
||||
var n = new WebRTC();
|
||||
n.privkey = bitcore.util.sha256('test');
|
||||
|
||||
var data = new bitcore.Buffer('my data to send');
|
||||
|
||||
|
|
@ -117,8 +121,9 @@ describe('Network / WebRTC', function() {
|
|||
key.regenerateSync();
|
||||
|
||||
var copayerId = key.public.toString('hex');
|
||||
n._sendToOne = function(a1, encPayload, a3, cb) {
|
||||
encPayload.length.should.be.greaterThan(0);
|
||||
n._sendToOne = function(a1, enc, cb) {
|
||||
var encPayload = JSON.parse(enc.toString());
|
||||
encPayload.sig.length.should.be.greaterThan(0);
|
||||
cb();
|
||||
};
|
||||
var sig = undefined;
|
||||
|
|
@ -130,6 +135,7 @@ describe('Network / WebRTC', function() {
|
|||
|
||||
it('should call _sendToOne for a list of copayers', function(done) {
|
||||
var n = new WebRTC();
|
||||
n.privkey = bitcore.util.sha256('test');
|
||||
|
||||
var data = new bitcore.Buffer('my data to send');
|
||||
|
||||
|
|
@ -140,7 +146,7 @@ describe('Network / WebRTC', function() {
|
|||
key.regenerateSync();
|
||||
|
||||
var copayerIds = [key.public.toString('hex')];
|
||||
n._sendToOne = function(a1, a2, a3, cb) {
|
||||
n._sendToOne = function(a1, a2, cb) {
|
||||
cb();
|
||||
};
|
||||
var sig = undefined;
|
||||
|
|
@ -151,4 +157,73 @@ describe('Network / WebRTC', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#_onData', function() {
|
||||
var privkey1 = bitcore.util.sha256('test privkey 1');
|
||||
var privkey2 = bitcore.util.sha256('test privkey 2');
|
||||
var privkey3 = bitcore.util.sha256('test privkey 2');
|
||||
|
||||
var key1 = new bitcore.Key();
|
||||
key1.private = privkey1;
|
||||
key1.regenerateSync();
|
||||
|
||||
var key2 = new bitcore.Key();
|
||||
key2.private = privkey2;
|
||||
key2.regenerateSync();
|
||||
|
||||
var key3 = new bitcore.Key();
|
||||
key3.private = privkey3;
|
||||
key3.regenerateSync();
|
||||
|
||||
it('should not reject data sent from a peer with hijacked pubkey', function() {
|
||||
var n = new WebRTC();
|
||||
n.privkey = key2.private.toString('hex');
|
||||
|
||||
var message = {
|
||||
type: 'hello',
|
||||
copayerId: key1.public.toString('hex')
|
||||
};
|
||||
var messagestr = JSON.stringify(message);
|
||||
var messagebuf = new Buffer(messagestr);
|
||||
|
||||
var encoded = n._encode(key2.public, key1, messagebuf);
|
||||
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._onData(encodeduint, isInbound, peerId);
|
||||
n._deletePeer.calledOnce.should.equal(false);
|
||||
});
|
||||
|
||||
it('should reject data sent from a peer with hijacked pubkey', function() {
|
||||
var n = new WebRTC();
|
||||
n.privkey = key2.private.toString('hex');
|
||||
|
||||
var message = {
|
||||
type: 'hello',
|
||||
copayerId: key3.public.toString('hex') //MITM pubkey 3
|
||||
};
|
||||
var messagestr = JSON.stringify(message);
|
||||
var messagebuf = new Buffer(messagestr);
|
||||
|
||||
var encoded = n._encode(key2.public, key1, messagebuf);
|
||||
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._onData(encodeduint, isInbound, peerId);
|
||||
n._deletePeer.calledOnce.should.equal(true);
|
||||
n._deletePeer.getCall(0).args[0].should.equal(peerId);
|
||||
n._deletePeer.getCall(0).args[1].should.equal('incorrect pubkey for peerId');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ saveAs = function(o) {
|
|||
|
||||
|
||||
describe("Unit: Controllers", function() {
|
||||
var invalidForm = {
|
||||
$invalid: true
|
||||
};
|
||||
|
||||
var scope;
|
||||
|
||||
|
|
@ -73,6 +76,11 @@ describe("Unit: Controllers", function() {
|
|||
expect(array.length).equal(n);
|
||||
});
|
||||
});
|
||||
describe('#create', function() {
|
||||
it('should work with invalid form', function() {
|
||||
scope.create(invalidForm);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -237,7 +245,6 @@ describe("Unit: Controllers", function() {
|
|||
});
|
||||
}));
|
||||
|
||||
|
||||
afterEach(function() {
|
||||
$httpBackend.verifyNoOutstandingExpectation();
|
||||
$httpBackend.verifyNoOutstandingRequest();
|
||||
|
|
@ -283,10 +290,23 @@ describe("Unit: Controllers", function() {
|
|||
});
|
||||
|
||||
describe('Send Controller', function() {
|
||||
var sendCtrl;
|
||||
beforeEach(inject(function($controller, $rootScope) {
|
||||
var sendCtrl, form;
|
||||
beforeEach(inject(function($compile, $rootScope, $controller) {
|
||||
scope = $rootScope.$new();
|
||||
$rootScope.availableBalance = 123456;
|
||||
|
||||
var element = angular.element(
|
||||
'<form name="form">' +
|
||||
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
||||
'</form>'
|
||||
);
|
||||
scope.model = {
|
||||
amount: null
|
||||
};
|
||||
$compile(element)(scope);
|
||||
scope.$digest();
|
||||
form = scope.form;
|
||||
|
||||
sendCtrl = $controller('SendController', {
|
||||
$scope: scope,
|
||||
$modal: {},
|
||||
|
|
@ -297,8 +317,53 @@ describe("Unit: Controllers", function() {
|
|||
expect(scope.isMobile).not.to.equal(null);
|
||||
});
|
||||
it('should autotop balance correctly', function() {
|
||||
scope.topAmount();
|
||||
scope.topAmount(form);
|
||||
form.amount.$setViewValue(123356);
|
||||
expect(scope.amount).to.equal(123356);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
expect(form.amount.$pristine).to.equal(false);
|
||||
});
|
||||
it('should return available amount', function() {
|
||||
var amount = scope.getAvailableAmount();
|
||||
expect(amount).to.equal(123356);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Import Controller', function() {
|
||||
var what;
|
||||
beforeEach(inject(function($controller, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
what = $controller('ImportController', {
|
||||
$scope: scope,
|
||||
});
|
||||
}));
|
||||
|
||||
it('should exist', function() {
|
||||
should.exist(what);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Signin Controller', function() {
|
||||
var what;
|
||||
beforeEach(inject(function($controller, $rootScope) {
|
||||
scope = $rootScope.$new();
|
||||
what = $controller('SigninController', {
|
||||
$scope: scope,
|
||||
});
|
||||
}));
|
||||
|
||||
it('should exist', function() {
|
||||
should.exist(what);
|
||||
});
|
||||
describe('#open', function() {
|
||||
it('should work with invalid form', function() {
|
||||
scope.open(invalidForm);
|
||||
});
|
||||
});
|
||||
describe('#join', function() {
|
||||
it('should work with invalid form', function() {
|
||||
scope.join(invalidForm);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ describe("Unit: Testing Directives", function() {
|
|||
|
||||
beforeEach(module('copayApp.directives'));
|
||||
|
||||
beforeEach(function() {
|
||||
config.unitToSatoshi = 100;
|
||||
config.unitName = 'bits';
|
||||
});
|
||||
|
||||
describe('Check config', function() {
|
||||
it('unit should be set to BITS in config.js', function() {
|
||||
|
|
@ -43,41 +47,89 @@ describe("Unit: Testing Directives", function() {
|
|||
});
|
||||
|
||||
describe('Validate Amount', function() {
|
||||
beforeEach(inject(function($compile, $rootScope) {
|
||||
$scope = $rootScope;
|
||||
$rootScope.availableBalance = 1000;
|
||||
var element = angular.element(
|
||||
'<form name="form">' +
|
||||
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
||||
'</form>'
|
||||
);
|
||||
$scope.model = {
|
||||
amount: null
|
||||
};
|
||||
$compile(element)($scope);
|
||||
$scope.$digest();
|
||||
form = $scope.form;
|
||||
}));
|
||||
describe('Unit: bits', function() {
|
||||
beforeEach(inject(function($compile, $rootScope) {
|
||||
$scope = $rootScope;
|
||||
$rootScope.availableBalance = 1000;
|
||||
var element = angular.element(
|
||||
'<form name="form">' +
|
||||
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
||||
'</form>'
|
||||
);
|
||||
$scope.model = {
|
||||
amount: null
|
||||
};
|
||||
$compile(element)($scope);
|
||||
$scope.$digest();
|
||||
form = $scope.form;
|
||||
}));
|
||||
it('should validate', function() {
|
||||
form.amount.$setViewValue(100);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
form.amount.$setViewValue(800);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
form.amount.$setViewValue(900);
|
||||
expect($scope.notEnoughAmount).to.equal(null);
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('should validate', function() {
|
||||
form.amount.$setViewValue(100);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
form.amount.$setViewValue(900);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
it('should not validate', function() {
|
||||
form.amount.$setViewValue(0);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(9999999999);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(901);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(1000);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(901);
|
||||
expect($scope.notEnoughAmount).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not validate', function() {
|
||||
form.amount.$setViewValue(0);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(9999999999);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(901);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(1000);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
describe('Unit: BTC', function() {
|
||||
beforeEach(inject(function($compile, $rootScope) {
|
||||
config.unitToSatoshi = 100000000;
|
||||
config.unitName = 'BTC';
|
||||
$scope = $rootScope;
|
||||
$rootScope.availableBalance = 0.04;
|
||||
var element = angular.element(
|
||||
'<form name="form">' +
|
||||
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
||||
'</form>'
|
||||
);
|
||||
$scope.model = {
|
||||
amount: null
|
||||
};
|
||||
$compile(element)($scope);
|
||||
$scope.$digest();
|
||||
form = $scope.form;
|
||||
}));
|
||||
|
||||
it('should validate', function() {
|
||||
form.amount.$setViewValue(0.01);
|
||||
expect($scope.notEnoughAmount).to.equal(null);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
form.amount.$setViewValue(0.039);
|
||||
expect($scope.notEnoughAmount).to.equal(null);
|
||||
expect(form.amount.$invalid).to.equal(false);
|
||||
});
|
||||
|
||||
it('should not validate', function() {
|
||||
form.amount.$setViewValue(0.03999);
|
||||
expect($scope.notEnoughAmount).to.equal(true);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(0);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(0.0);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
form.amount.$setViewValue(0.05);
|
||||
expect($scope.notEnoughAmount).to.equal(true);
|
||||
expect(form.amount.$invalid).to.equal(true);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Contact directive', function() {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@
|
|||
//
|
||||
var sinon = require('sinon');
|
||||
|
||||
beforeEach(function() {
|
||||
config.unitToSatoshi = 100;
|
||||
config.unitName = 'bits';
|
||||
});
|
||||
|
||||
describe('Check config', function() {
|
||||
|
||||
it('unit should be set to BITS in config.js', function() {
|
||||
expect(config.unitToSatoshi).to.equal(100);
|
||||
expect(config.unitName).to.equal('bits');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue