run js-beautify on everything
...with two spaces. Command: js-beautify -s 2 -r [filename]
This commit is contained in:
parent
da445e7c69
commit
ea2e2d4e19
49 changed files with 859 additions and 682 deletions
|
|
@ -1,3 +1,5 @@
|
|||
if (typeof window != 'undefined') {
|
||||
window.mocha.setup({ timeout: 5000 });
|
||||
window.mocha.setup({
|
||||
timeout: 5000
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
var imports = require('soop').imports();
|
||||
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
||||
|
||||
var imports = require('soop').imports();
|
||||
var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
|
||||
function Network(opts) {}
|
||||
|
||||
function Network(opts) {
|
||||
}
|
||||
|
||||
Network.parent=EventEmitter;
|
||||
Network.parent = EventEmitter;
|
||||
|
||||
Network.prototype.start = function(opts, cb) {
|
||||
// start! :D
|
||||
|
|
@ -34,10 +32,8 @@ Network.prototype.lockIncommingConnections = function() {
|
|||
|
||||
};
|
||||
|
||||
Network.prototype.getPeer = function() {
|
||||
};
|
||||
Network.prototype.connectToCopayers = function(cps) {
|
||||
};
|
||||
Network.prototype.getPeer = function() {};
|
||||
Network.prototype.connectToCopayers = function(cps) {};
|
||||
Network.prototype.isOnline = function() {
|
||||
return true;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ var FakeWallet = function() {
|
|||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000
|
||||
};
|
||||
this.name = 'myTESTwullet';
|
||||
this.addressBook = {
|
||||
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ' : {
|
||||
this.addressBook = {
|
||||
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ': {
|
||||
label: 'John',
|
||||
copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03',
|
||||
createdTs: 1403102115,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
try {
|
||||
var copay = require('copay'); //browser
|
||||
} catch (e) {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var API = API || copay.API;
|
||||
var Storage = Storage || require('../test/mocks/FakeStorage');
|
||||
var API = API || copay.API;
|
||||
var Storage = Storage || require('../test/mocks/FakeStorage');
|
||||
|
||||
var blanket = require("blanket")({
|
||||
"pattern": "/js/"
|
||||
|
|
@ -17,8 +17,10 @@ var blanket = require("blanket")({
|
|||
describe('API', function() {
|
||||
|
||||
it('should have a command called "echo"', function() {
|
||||
|
||||
var api = new API({Storage: Storage});
|
||||
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
should.exist(api.echo);
|
||||
});
|
||||
|
||||
|
|
@ -32,7 +34,9 @@ describe('API', function() {
|
|||
})
|
||||
|
||||
it('should throw an error for all commands when called with wrong number of arguments', function() {
|
||||
var api = new API({Storage: Storage});
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
for (var i in API.prototype) {
|
||||
var f = API.prototype[i];
|
||||
if (i[0] != '_' && typeof f == 'function') {
|
||||
|
|
@ -51,15 +55,17 @@ describe('API', function() {
|
|||
for (var i in API.prototype) {
|
||||
var f = API.prototype[i];
|
||||
if (i[0] != '_' && typeof f == 'function') {
|
||||
f.argTypes[f.argTypes.length-1][0].should.equal('callback');
|
||||
f.argTypes[f.argTypes.length-1][1].should.equal('function');
|
||||
f.argTypes[f.argTypes.length - 1][0].should.equal('callback');
|
||||
f.argTypes[f.argTypes.length - 1][1].should.equal('function');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe('#echo', function() {
|
||||
it('should echo a string', function(done) {
|
||||
var api = new API({Storage: Storage});
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
var str = 'mystr';
|
||||
api.echo(str, function(err, result) {
|
||||
result.should.equal(str);
|
||||
|
|
@ -70,7 +76,9 @@ describe('API', function() {
|
|||
|
||||
describe('#echoNumber', function() {
|
||||
it('should echo a number', function(done) {
|
||||
var api = new API({Storage: Storage});
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
var num = 500;
|
||||
api.echoNumber(num, function(err, result) {
|
||||
result.should.equal(num);
|
||||
|
|
@ -82,8 +90,12 @@ describe('API', function() {
|
|||
|
||||
describe('#echoObject', function() {
|
||||
it('should echo an object', function(done) {
|
||||
var api = new API({Storage: Storage});
|
||||
var obj = {test:'test'};
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
var obj = {
|
||||
test: 'test'
|
||||
};
|
||||
api.echoObject(obj, function(err, result) {
|
||||
result.test.should.equal(obj.test);
|
||||
(typeof result).should.equal('object');
|
||||
|
|
@ -94,7 +106,9 @@ describe('API', function() {
|
|||
|
||||
describe('#getArgTypes', function() {
|
||||
it('should get the argTypes of echo', function(done) {
|
||||
var api = new API({Storage: Storage});
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
api.getArgTypes('echo', function(err, result) {
|
||||
result[0][1].should.equal('string');
|
||||
done();
|
||||
|
|
@ -104,7 +118,9 @@ describe('API', function() {
|
|||
|
||||
describe('#getCommands', function() {
|
||||
it('should get all the commands', function(done) {
|
||||
var api = new API({Storage: Storage});
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
var n = 0;
|
||||
|
||||
for (var i in api)
|
||||
|
|
@ -120,7 +136,9 @@ describe('API', function() {
|
|||
|
||||
describe('#getWallets', function() {
|
||||
it('should get the wallet ids', function(done) {
|
||||
var api = new API({Storage: Storage});
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
api.getWallets(function(err, result) {
|
||||
result.length.should.be.greaterThan(-1);
|
||||
done();
|
||||
|
|
@ -130,7 +148,9 @@ describe('API', function() {
|
|||
|
||||
describe('#help', function() {
|
||||
it('should call _cmd_getCommands', function(done) {
|
||||
var api = new API({Storage: Storage});
|
||||
var api = new API({
|
||||
Storage: Storage
|
||||
});
|
||||
api._cmd_getCommands = function(callback) {
|
||||
(typeof arguments[0]).should.equal('function');
|
||||
callback(null, ['item']);
|
||||
|
|
|
|||
|
|
@ -1,47 +1,47 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var Address = bitcore.Address;
|
||||
var buffertools = bitcore.buffertools;
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var Address = bitcore.Address;
|
||||
var buffertools = bitcore.buffertools;
|
||||
try {
|
||||
var copay = require('copay'); //browser
|
||||
} catch (e) {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var PublicKeyRing = copay.PublicKeyRing;
|
||||
var AddressIndex = copay.AddressIndex;
|
||||
var PublicKeyRing = copay.PublicKeyRing;
|
||||
var AddressIndex = copay.AddressIndex;
|
||||
|
||||
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
networkName: 'livenet',
|
||||
};
|
||||
|
||||
var createAI = function () {
|
||||
var createAI = function() {
|
||||
var i = new AddressIndex();
|
||||
should.exist(i);
|
||||
|
||||
i.walletId = '1234567';
|
||||
|
||||
|
||||
return i;
|
||||
};
|
||||
|
||||
describe('AddressIndex model', function() {
|
||||
|
||||
it('should create an instance (livenet)', function () {
|
||||
it('should create an instance (livenet)', function() {
|
||||
var i = new AddressIndex();
|
||||
should.exist(i);
|
||||
});
|
||||
|
||||
it('show be able to tostore and read', function () {
|
||||
it('show be able to tostore and read', function() {
|
||||
var i = createAI();
|
||||
var changeN = 2;
|
||||
var addressN = 2;
|
||||
for(var j=0; j<changeN; j++) {
|
||||
for (var j = 0; j < changeN; j++) {
|
||||
i.increment(true);
|
||||
}
|
||||
for(var j=0; j<addressN; j++) {
|
||||
for (var j = 0; j < addressN; j++) {
|
||||
i.increment(false);
|
||||
}
|
||||
|
||||
|
|
@ -51,38 +51,36 @@ describe('AddressIndex model', function() {
|
|||
var i2 = AddressIndex.fromObj(data);
|
||||
i2.walletId.should.equal(i.walletId);
|
||||
|
||||
i2.getChangeIndex().should.equal(changeN);
|
||||
i2.getReceiveIndex().should.equal(addressN);
|
||||
i2.getChangeIndex().should.equal(changeN);
|
||||
i2.getReceiveIndex().should.equal(addressN);
|
||||
});
|
||||
|
||||
it('should count generation indexes', function () {
|
||||
it('should count generation indexes', function() {
|
||||
var j = createAI();
|
||||
for(var i=0; i<3; i++)
|
||||
for (var i = 0; i < 3; i++)
|
||||
j.increment(true);
|
||||
for(var i=0; i<2; i++)
|
||||
for (var i = 0; i < 2; i++)
|
||||
j.increment(false);
|
||||
|
||||
j.changeIndex.should.equal(3);
|
||||
j.receiveIndex.should.equal(2);
|
||||
j.changeIndex.should.equal(3);
|
||||
j.receiveIndex.should.equal(2);
|
||||
});
|
||||
|
||||
it('#merge tests', function () {
|
||||
it('#merge tests', function() {
|
||||
var j = createAI();
|
||||
|
||||
for(var i=0; i<15; i++)
|
||||
for (var i = 0; i < 15; i++)
|
||||
j.increment(true);
|
||||
for(var i=0; i<7; i++)
|
||||
for (var i = 0; i < 7; i++)
|
||||
j.increment(false);
|
||||
var j2 = new AddressIndex({
|
||||
walletId: j.walletId,
|
||||
});
|
||||
j2.merge(j).should.equal(true);
|
||||
j2.changeIndex.should.equal(15);
|
||||
j2.receiveIndex.should.equal(7);
|
||||
j2.receiveIndex.should.equal(7);
|
||||
|
||||
j2.merge(j).should.equal(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var buffertools = bitcore.buffertools;
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var buffertools = bitcore.buffertools;
|
||||
try {
|
||||
var copay = require('copay'); //browser
|
||||
} catch (e) {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var Passphrase = copay.Passphrase;
|
||||
var Passphrase = copay.Passphrase;
|
||||
|
||||
|
||||
|
||||
describe('Passphrase model', function() {
|
||||
|
||||
it('should create an instance', function () {
|
||||
it('should create an instance', function() {
|
||||
var p = new Passphrase();
|
||||
should.exist(p);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,43 +1,43 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var Transaction = bitcore.Transaction;
|
||||
var buffertools = bitcore.buffertools;
|
||||
var WalletKey = bitcore.WalletKey;
|
||||
var Key = bitcore.Key;
|
||||
var bignum = bitcore.Bignum;
|
||||
var networks = bitcore.networks;
|
||||
var Address = bitcore.Address;
|
||||
var BitcorePrivateKey = bitcore.PrivateKey;
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var Transaction = bitcore.Transaction;
|
||||
var buffertools = bitcore.buffertools;
|
||||
var WalletKey = bitcore.WalletKey;
|
||||
var Key = bitcore.Key;
|
||||
var bignum = bitcore.Bignum;
|
||||
var networks = bitcore.networks;
|
||||
var Address = bitcore.Address;
|
||||
var BitcorePrivateKey = bitcore.PrivateKey;
|
||||
try {
|
||||
var copay = require('copay'); //browser
|
||||
} catch (e) {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var PrivateKey = copay.PrivateKey || require('../js/models/core/PrivateKey');
|
||||
var PrivateKey = copay.PrivateKey || require('../js/models/core/PrivateKey');
|
||||
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
networkName: 'livenet',
|
||||
};
|
||||
|
||||
describe('PrivateKey model', function() {
|
||||
|
||||
it('should create an instance', function () {
|
||||
it('should create an instance', function() {
|
||||
var w = new PrivateKey(config);
|
||||
should.exist(w);
|
||||
should.exist(w.bip);
|
||||
should.exist(w.bip.derive);
|
||||
});
|
||||
|
||||
it('should derive priv keys', function () {
|
||||
it('should derive priv keys', function() {
|
||||
var pk = new PrivateKey(config);
|
||||
for(var j=0; j<2; j++) {
|
||||
for(var i=0; i<3; i++) {
|
||||
var wk = pk.get(i,j);
|
||||
for (var j = 0; j < 2; j++) {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var wk = pk.get(i, j);
|
||||
should.exist(wk);
|
||||
var o=wk.storeObj();
|
||||
var o = wk.storeObj();
|
||||
should.exist(o);
|
||||
should.exist(o.priv);
|
||||
should.exist(o.pub);
|
||||
|
|
@ -50,14 +50,14 @@ describe('PrivateKey model', function() {
|
|||
}
|
||||
}
|
||||
});
|
||||
it('should derive priv keys array', function () {
|
||||
it('should derive priv keys array', function() {
|
||||
var w = new PrivateKey(config);
|
||||
var wks = w.getAll(2,3);
|
||||
var wks = w.getAll(2, 3);
|
||||
wks.length.should.equal(5);
|
||||
for(var j=0; j<wks.length; j++) {
|
||||
for (var j = 0; j < wks.length; j++) {
|
||||
var wk = wks[j];
|
||||
should.exist(wk);
|
||||
var o=wk.storeObj();
|
||||
var o = wk.storeObj();
|
||||
should.exist(o);
|
||||
should.exist(o.priv);
|
||||
should.exist(o.pub);
|
||||
|
|
@ -70,7 +70,7 @@ describe('PrivateKey model', function() {
|
|||
}
|
||||
});
|
||||
|
||||
it('fromObj toObj roundtrip', function () {
|
||||
it('fromObj toObj roundtrip', function() {
|
||||
var w1 = new PrivateKey(config);
|
||||
var o = JSON.parse(JSON.stringify(w1.toObj()))
|
||||
var w2 = PrivateKey.fromObj(o);
|
||||
|
|
@ -78,17 +78,17 @@ describe('PrivateKey model', function() {
|
|||
w2.toObj().extendedPrivateKeyString.should.equal(w1.toObj().extendedPrivateKeyString);
|
||||
w2.getId().should.equal(w1.getId());
|
||||
|
||||
JSON.stringify(w2.get(1,1).storeObj()).should
|
||||
.equal(JSON.stringify(w1.get(1,1).storeObj()));
|
||||
JSON.stringify(w2.get(1,0).storeObj()).should
|
||||
.equal(JSON.stringify(w1.get(1,0).storeObj()));
|
||||
JSON.stringify(w2.get(1, 1).storeObj()).should
|
||||
.equal(JSON.stringify(w1.get(1, 1).storeObj()));
|
||||
JSON.stringify(w2.get(1, 0).storeObj()).should
|
||||
.equal(JSON.stringify(w1.get(1, 0).storeObj()));
|
||||
});
|
||||
|
||||
|
||||
describe('#getId', function() {
|
||||
it('should calculate the copayerId', function() {
|
||||
var w1 = new PrivateKey(config);
|
||||
should.exist(w1.getId());
|
||||
w1.getId().length.should.equal(33*2);
|
||||
w1.getId().length.should.equal(33 * 2);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ describe('PrivateKey model', function() {
|
|||
it('should calculate .id', function() {
|
||||
var w1 = new PrivateKey(config);
|
||||
should.exist(w1.getIdPriv());
|
||||
w1.getIdPriv().length.should.equal(32*2);
|
||||
w1.getIdPriv().length.should.equal(32 * 2);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -106,8 +106,8 @@ describe('PrivateKey model', function() {
|
|||
w1.cacheId();
|
||||
var pub = w1.id;
|
||||
var priv = w1.idpriv;
|
||||
pub.length.should.equal(33*2);
|
||||
priv.length.should.equal(32*2);
|
||||
pub.length.should.equal(33 * 2);
|
||||
priv.length.should.equal(32 * 2);
|
||||
});
|
||||
|
||||
it('should set the id equal to the public key of the idpriv private key', function() {
|
||||
|
|
@ -115,8 +115,8 @@ describe('PrivateKey model', function() {
|
|||
w1.cacheId();
|
||||
var pub = w1.id;
|
||||
var priv = w1.idpriv;
|
||||
pub.length.should.equal(33*2);
|
||||
priv.length.should.equal(32*2);
|
||||
pub.length.should.equal(33 * 2);
|
||||
priv.length.should.equal(32 * 2);
|
||||
|
||||
var key1 = new bitcore.Key();
|
||||
key1.private = new bitcore.Buffer(priv, 'hex');
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var Address = bitcore.Address;
|
||||
var buffertools = bitcore.buffertools;
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var Address = bitcore.Address;
|
||||
var buffertools = bitcore.buffertools;
|
||||
try {
|
||||
var copay = require('copay'); //browser
|
||||
} catch (e) {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var PublicKeyRing = copay.PublicKeyRing;
|
||||
var PublicKeyRing = copay.PublicKeyRing;
|
||||
|
||||
var aMasterPubKey = 'tprv8ZgxMBicQKsPdSVTiWXEqCCzqRaRr9EAQdn5UVMpT9UHX67Dh1FmzEMbavPumpAicsUm2XvC6NTdcWB89yN5DUWx5HQ7z3KByUg7Ht74VRZ';
|
||||
|
||||
|
||||
var createW = function (networkName) {
|
||||
var createW = function(networkName) {
|
||||
var config = {
|
||||
networkName: networkName || 'livenet',
|
||||
};
|
||||
|
|
@ -24,21 +24,24 @@ var createW = function (networkName) {
|
|||
should.exist(w);
|
||||
|
||||
var copayers = [];
|
||||
for(var i=0; i<5; i++) {
|
||||
for (var i = 0; i < 5; i++) {
|
||||
w.isComplete().should.equal(false);
|
||||
var newEpk = w.addCopayer();
|
||||
copayers.push(newEpk);
|
||||
}
|
||||
w.walletId = '1234567';
|
||||
|
||||
return {w:w, copayers: copayers};
|
||||
|
||||
return {
|
||||
w: w,
|
||||
copayers: copayers
|
||||
};
|
||||
};
|
||||
|
||||
describe('PublicKeyRing model', function() {
|
||||
|
||||
it('should create an instance (livenet)', function () {
|
||||
it('should create an instance (livenet)', function() {
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
networkName: 'livenet',
|
||||
};
|
||||
|
||||
var w = new PublicKeyRing({
|
||||
|
|
@ -47,48 +50,52 @@ describe('PublicKeyRing model', function() {
|
|||
should.exist(w);
|
||||
w.network.name.should.equal('livenet');
|
||||
});
|
||||
it('should create an instance (testnet)', function () {
|
||||
it('should create an instance (testnet)', function() {
|
||||
var w2 = new PublicKeyRing();
|
||||
should.exist(w2);
|
||||
w2.network.name.should.equal('testnet');
|
||||
});
|
||||
|
||||
it('should fail to generate shared pub keys wo extended key', function () {
|
||||
it('should fail to generate shared pub keys wo extended key', function() {
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
networkName: 'livenet',
|
||||
};
|
||||
var w2 = new PublicKeyRing(config);
|
||||
should.exist(w2);
|
||||
|
||||
w2.registeredCopayers().should.equal(0);
|
||||
w2.registeredCopayers().should.equal(0);
|
||||
w2.isComplete().should.equal(false);
|
||||
|
||||
(function() {w2.getAddress(0, false);}).should.throw();
|
||||
(function() {
|
||||
w2.getAddress(0, false);
|
||||
}).should.throw();
|
||||
});
|
||||
|
||||
it('should add and check when adding shared pub keys', function () {
|
||||
it('should add and check when adding shared pub keys', function() {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
var copayers = k.copayers;
|
||||
|
||||
w.isComplete().should.equal(true);
|
||||
w.addCopayer.should.throw();
|
||||
for(var i =0; i<5; i++) {
|
||||
(function() {w.addCopayer(copayers[i])}).should.throw();
|
||||
for (var i = 0; i < 5; i++) {
|
||||
(function() {
|
||||
w.addCopayer(copayers[i])
|
||||
}).should.throw();
|
||||
}
|
||||
});
|
||||
|
||||
it('show be able to tostore and read', function () {
|
||||
it('show be able to tostore and read', function() {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
var copayers = k.copayers;
|
||||
var changeN = 2;
|
||||
var addressN = 2;
|
||||
var start = new Date().getTime();
|
||||
for(var i=0; i<changeN; i++) {
|
||||
for (var i = 0; i < changeN; i++) {
|
||||
w.generateAddress(true);
|
||||
}
|
||||
for(var i=0; i<addressN; i++) {
|
||||
for (var i = 0; i < addressN; i++) {
|
||||
w.generateAddress(false);
|
||||
}
|
||||
|
||||
|
|
@ -99,34 +106,36 @@ describe('PublicKeyRing model', function() {
|
|||
w2.walletId.should.equal(w.walletId);
|
||||
w2.isComplete().should.equal(true);
|
||||
w2.addCopayer.should.throw();
|
||||
for(var i =0; i<5; i++) {
|
||||
(function() {w.addCopayer(copayers[i])}).should.throw();
|
||||
for (var i = 0; i < 5; i++) {
|
||||
(function() {
|
||||
w.addCopayer(copayers[i])
|
||||
}).should.throw();
|
||||
}
|
||||
|
||||
w2.indexes.getChangeIndex().should.equal(changeN);
|
||||
w2.indexes.getReceiveIndex().should.equal(addressN);
|
||||
w2.indexes.getChangeIndex().should.equal(changeN);
|
||||
w2.indexes.getReceiveIndex().should.equal(addressN);
|
||||
});
|
||||
|
||||
|
||||
it('should generate some p2sh addresses', function () {
|
||||
it('should generate some p2sh addresses', function() {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
|
||||
for(var isChange=0; isChange<2; isChange++) {
|
||||
for(var i=0; i<2; i++) {
|
||||
for (var isChange = 0; isChange < 2; isChange++) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var a = w.generateAddress(isChange);
|
||||
a.isValid().should.equal(true);
|
||||
a.isScript().should.equal(true);
|
||||
a.network().name.should.equal('livenet');
|
||||
if (i>1) {
|
||||
w.getAddress(i-1,isChange).toString().should
|
||||
.not.equal(w.getAddress(i-2,isChange).toString());
|
||||
if (i > 1) {
|
||||
w.getAddress(i - 1, isChange).toString().should
|
||||
.not.equal(w.getAddress(i - 2, isChange).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('should return PublicKeyRing addresses', function () {
|
||||
it('should return PublicKeyRing addresses', function() {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
|
||||
|
|
@ -134,38 +143,38 @@ describe('PublicKeyRing model', function() {
|
|||
var a = w.getAddresses();
|
||||
a.length.should.equal(0);
|
||||
|
||||
for(var isChange=0; isChange<2; isChange++)
|
||||
for(var i=0; i<2; i++)
|
||||
w.generateAddress(isChange);
|
||||
|
||||
for (var isChange = 0; isChange < 2; isChange++)
|
||||
for (var i = 0; i < 2; i++)
|
||||
w.generateAddress(isChange);
|
||||
|
||||
var as = w.getAddresses();
|
||||
as.length.should.equal(4);
|
||||
for(var j in as) {
|
||||
for (var j in as) {
|
||||
var a = as[j];
|
||||
a.isValid().should.equal(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('should count generation indexes', function () {
|
||||
it('should count generation indexes', function() {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
|
||||
for(var i=0; i<3; i++)
|
||||
for (var i = 0; i < 3; i++)
|
||||
w.generateAddress(true);
|
||||
for(var i=0; i<2; i++)
|
||||
for (var i = 0; i < 2; i++)
|
||||
w.generateAddress(false);
|
||||
|
||||
w.indexes.getChangeIndex().should.equal(3);
|
||||
w.indexes.getReceiveIndex().should.equal(2);
|
||||
w.indexes.getChangeIndex().should.equal(3);
|
||||
w.indexes.getReceiveIndex().should.equal(2);
|
||||
});
|
||||
|
||||
it('#merge index tests', function () {
|
||||
it('#merge index tests', function() {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
|
||||
for(var i=0; i<2; i++)
|
||||
for (var i = 0; i < 2; i++)
|
||||
w.generateAddress(true);
|
||||
for(var i=0; i<3; i++)
|
||||
for (var i = 0; i < 3; i++)
|
||||
w.generateAddress(false);
|
||||
|
||||
var w2 = new PublicKeyRing({
|
||||
|
|
@ -173,17 +182,17 @@ describe('PublicKeyRing model', function() {
|
|||
walletId: w.walletId,
|
||||
});
|
||||
w2.merge(w).should.equal(true);
|
||||
w2.requiredCopayers.should.equal(3);
|
||||
w2.totalCopayers.should.equal(5);
|
||||
w2.indexes.getChangeIndex().should.equal(2);
|
||||
w2.indexes.getReceiveIndex().should.equal(3);
|
||||
w2.requiredCopayers.should.equal(3);
|
||||
w2.totalCopayers.should.equal(5);
|
||||
w2.indexes.getChangeIndex().should.equal(2);
|
||||
w2.indexes.getReceiveIndex().should.equal(3);
|
||||
|
||||
//
|
||||
w2.merge(w).should.equal(false);
|
||||
});
|
||||
|
||||
|
||||
it('#merge check tests', function () {
|
||||
it('#merge check tests', function() {
|
||||
var config = {
|
||||
networkName: 'livenet',
|
||||
};
|
||||
|
|
@ -191,32 +200,42 @@ describe('PublicKeyRing model', function() {
|
|||
var w = new PublicKeyRing(config);
|
||||
w.walletId = 'lwjd5qra8257b9';
|
||||
var w2 = new PublicKeyRing({
|
||||
networkName: 'testnet', //wrong
|
||||
networkName: 'testnet', //wrong
|
||||
walletId: w.walletId,
|
||||
});
|
||||
(function() { w2.merge(w);}).should.throw();
|
||||
(function() {
|
||||
w2.merge(w);
|
||||
}).should.throw();
|
||||
|
||||
var w3 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
walletId: w.walletId,
|
||||
requiredCopayers: 2, // wrong
|
||||
requiredCopayers: 2, // wrong
|
||||
});
|
||||
(function() { w3.merge(w);}).should.throw();
|
||||
(function() {
|
||||
w3.merge(w);
|
||||
}).should.throw();
|
||||
|
||||
var w4 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
walletId: w.walletId,
|
||||
totalCopayers: 3, // wrong
|
||||
totalCopayers: 3, // wrong
|
||||
});
|
||||
(function() { w4.merge(w);}).should.throw();
|
||||
(function() {
|
||||
w4.merge(w);
|
||||
}).should.throw();
|
||||
|
||||
|
||||
var w6 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
});
|
||||
(function() { w6.merge(w);}).should.throw();
|
||||
w.networkName= 'livenet';
|
||||
(function() { w6.merge(w);}).should.throw();
|
||||
(function() {
|
||||
w6.merge(w);
|
||||
}).should.throw();
|
||||
w.networkName = 'livenet';
|
||||
(function() {
|
||||
w6.merge(w);
|
||||
}).should.throw();
|
||||
|
||||
|
||||
var w0 = new PublicKeyRing({
|
||||
|
|
@ -227,28 +246,32 @@ describe('PublicKeyRing model', function() {
|
|||
w0.addCopayer();
|
||||
w0.addCopayer();
|
||||
w0.addCopayer();
|
||||
(function() { w0.merge(w);}).should.throw();
|
||||
w.merge(w0,true).should.equal(true);
|
||||
(function() {
|
||||
w0.merge(w);
|
||||
}).should.throw();
|
||||
w.merge(w0, true).should.equal(true);
|
||||
w.isComplete().should.equal(true);
|
||||
|
||||
var wx = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
});
|
||||
wx.addCopayer();
|
||||
(function() { w.merge(wx);}).should.throw();
|
||||
(function() {
|
||||
w.merge(wx);
|
||||
}).should.throw();
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('#merge pubkey tests', function () {
|
||||
it('#merge pubkey tests', function() {
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
networkName: 'livenet',
|
||||
};
|
||||
var w = new PublicKeyRing(config);
|
||||
should.exist(w);
|
||||
var copayers = [];
|
||||
for(var i=0; i<2; i++) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
w.isComplete().should.equal(false);
|
||||
w.addCopayer();
|
||||
}
|
||||
|
|
@ -259,7 +282,7 @@ describe('PublicKeyRing model', function() {
|
|||
});
|
||||
should.exist(w);
|
||||
var copayers = [];
|
||||
for(var i=0; i<3; i++) {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
w2.isComplete().should.equal(false);
|
||||
w2.addCopayer();
|
||||
}
|
||||
|
|
@ -273,14 +296,14 @@ describe('PublicKeyRing model', function() {
|
|||
w.merge(w2).should.equal(false);
|
||||
});
|
||||
|
||||
it('#merge pubkey tests (case 2)', function () {
|
||||
it('#merge pubkey tests (case 2)', function() {
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
networkName: 'livenet',
|
||||
};
|
||||
var w = new PublicKeyRing(config);
|
||||
should.exist(w);
|
||||
|
||||
for(var i=0; i<5; i++) {
|
||||
for (var i = 0; i < 5; i++) {
|
||||
w.isComplete().should.equal(false);
|
||||
var w2 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
|
|
@ -293,31 +316,31 @@ describe('PublicKeyRing model', function() {
|
|||
});
|
||||
|
||||
|
||||
it('#merge with nickname', function () {
|
||||
it('#merge with nickname', function() {
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
networkName: 'livenet',
|
||||
};
|
||||
var w = new PublicKeyRing(config);
|
||||
should.exist(w);
|
||||
for(var i=0; i<3; i++) {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
w.addCopayer();
|
||||
};
|
||||
w._setNicknameForIndex(0,'pepe0');
|
||||
w._setNicknameForIndex(1,'pepe1');
|
||||
w._setNicknameForIndex(0, 'pepe0');
|
||||
w._setNicknameForIndex(1, 'pepe1');
|
||||
|
||||
w.nicknameForIndex(0).should.equal('pepe0');
|
||||
w.nicknameForIndex(1).should.equal('pepe1');
|
||||
should.not.exist(w.nicknameForIndex(2));
|
||||
|
||||
|
||||
for(var i=0; i<2; i++) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
w.isComplete().should.equal(false);
|
||||
var w2 = new PublicKeyRing({
|
||||
networkName: 'livenet',
|
||||
id: w.id,
|
||||
});
|
||||
w2.addCopayer();
|
||||
w2._setNicknameForIndex(0,'juan' + i);
|
||||
w2._setNicknameForIndex(0, 'juan' + i);
|
||||
w.merge(w2).should.equal(true);
|
||||
}
|
||||
w.isComplete().should.equal(true);
|
||||
|
|
@ -330,14 +353,14 @@ describe('PublicKeyRing model', function() {
|
|||
});
|
||||
|
||||
|
||||
it('#toObj #fromObj with nickname', function () {
|
||||
it('#toObj #fromObj with nickname', function() {
|
||||
var config = {
|
||||
networkName:'livenet',
|
||||
networkName: 'livenet',
|
||||
};
|
||||
var w = new PublicKeyRing(config);
|
||||
should.exist(w);
|
||||
for(var i=0; i<3; i++) {
|
||||
w.addCopayer(null, 'tito'+i);
|
||||
for (var i = 0; i < 3; i++) {
|
||||
w.addCopayer(null, 'tito' + i);
|
||||
};
|
||||
w.nicknameForIndex(0).should.equal('tito0');
|
||||
w.nicknameForIndex(1).should.equal('tito1');
|
||||
|
|
@ -345,7 +368,7 @@ describe('PublicKeyRing model', function() {
|
|||
should.not.exist(w.nicknameForIndex(3));
|
||||
|
||||
var o = JSON.parse(JSON.stringify(w.toObj()));
|
||||
var w2 = PublicKeyRing.fromObj( o );
|
||||
var w2 = PublicKeyRing.fromObj(o);
|
||||
w2.nicknameForIndex(0).should.equal('tito0');
|
||||
w2.nicknameForIndex(1).should.equal('tito1');
|
||||
w2.nicknameForIndex(2).should.equal('tito2');
|
||||
|
|
@ -353,22 +376,20 @@ describe('PublicKeyRing model', function() {
|
|||
});
|
||||
|
||||
|
||||
it('#getRedeemScriptMap check tests', function () {
|
||||
it('#getRedeemScriptMap check tests', function() {
|
||||
var k = createW();
|
||||
var w = k.w;
|
||||
|
||||
for(var i=0; i<2; i++)
|
||||
for (var i = 0; i < 2; i++)
|
||||
w.generateAddress(true);
|
||||
for(var i=0; i<2; i++)
|
||||
for (var i = 0; i < 2; i++)
|
||||
w.generateAddress(false);
|
||||
|
||||
var m = w.getRedeemScriptMap();
|
||||
Object.keys(m).length.should.equal(4);
|
||||
Object.keys(m).forEach(function (k) {
|
||||
Object.keys(m).forEach(function(k) {
|
||||
should.exist(m[k]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +1,41 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
try {
|
||||
var copay = require('copay'); //browser
|
||||
} catch (e) {
|
||||
var copay = require('../copay'); //node
|
||||
}
|
||||
var Structure = require('../js/models/core/Structure');
|
||||
var Structure = require('../js/models/core/Structure');
|
||||
|
||||
describe('Structure model', function() {
|
||||
it('should have the correct constants', function () {
|
||||
Structure.MAX_NON_HARDENED.should.equal(Math.pow(2,31) - 1);
|
||||
it('should have the correct constants', function() {
|
||||
Structure.MAX_NON_HARDENED.should.equal(Math.pow(2, 31) - 1);
|
||||
Structure.SHARED_INDEX.should.equal(Structure.MAX_NON_HARDENED);
|
||||
Structure.ID_INDEX.should.equal(Structure.SHARED_INDEX - 1);
|
||||
Structure.IdFullBranch.should.equal('m/45\'/2147483646/0/0');
|
||||
});
|
||||
|
||||
it('should get the correct branches', function () {
|
||||
it('should get the correct branches', function() {
|
||||
// shared branch (no cosigner index specified)
|
||||
Structure.FullBranch(0,false).should.equal('m/45\'/2147483647/0/0');
|
||||
Structure.FullBranch(0, false).should.equal('m/45\'/2147483647/0/0');
|
||||
|
||||
// copayer 0, address 0, external address (receiving)
|
||||
Structure.FullBranch(0,false,0).should.equal('m/45\'/0/0/0');
|
||||
Structure.FullBranch(0, false, 0).should.equal('m/45\'/0/0/0');
|
||||
|
||||
// copayer 0, address 10, external address (receiving)
|
||||
Structure.FullBranch(0,false,10).should.equal('m/45\'/10/0/0');
|
||||
Structure.FullBranch(0, false, 10).should.equal('m/45\'/10/0/0');
|
||||
|
||||
// copayer 0, address 0, internal address (change)
|
||||
Structure.FullBranch(0,true,0).should.equal('m/45\'/0/1/0');
|
||||
Structure.FullBranch(0, true, 0).should.equal('m/45\'/0/1/0');
|
||||
|
||||
// copayer 0, address 10, internal address (change)
|
||||
Structure.FullBranch(10,true,0).should.equal('m/45\'/0/1/10');
|
||||
Structure.FullBranch(10, true, 0).should.equal('m/45\'/0/1/10');
|
||||
|
||||
// copayer 7, address 10, internal address (change)
|
||||
Structure.FullBranch(10,true,7).should.equal('m/45\'/7/1/10');
|
||||
Structure.FullBranch(10, true, 7).should.equal('m/45\'/7/1/10');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -132,27 +132,48 @@ describe('Insight model', function() {
|
|||
cb([]);
|
||||
};
|
||||
|
||||
w.checkActivity(addresses, function(err, actives){
|
||||
w.checkActivity(addresses, function(err, actives) {
|
||||
console.log(err);
|
||||
actives.length.should.equal(addresses.length);
|
||||
actives.filter(function(i) { return i }).length.should.equal(0);
|
||||
actives.filter(function(i) {
|
||||
return i
|
||||
}).length.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('#checkActivity for active addreses', function(done) {
|
||||
var w = new Insight();
|
||||
w.getTransactions = function(addresses, cb) {
|
||||
cb([
|
||||
{vin: [{ addr: '2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM'}], vout: []},
|
||||
{vin: [{ addr: '2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM'}], vout: []},
|
||||
{vin: [{ addr: '2N9D5bcCQ2bPWUDByQ6Qb5bMgMtgsk1rw3x'}], vout: []},
|
||||
{vin: [], vout: [{scriptPubKey: {addresses: ['2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY']}}]}
|
||||
]);
|
||||
cb([{
|
||||
vin: [{
|
||||
addr: '2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM'
|
||||
}],
|
||||
vout: []
|
||||
}, {
|
||||
vin: [{
|
||||
addr: '2NATQJnaQe2CUKLyhL1zdNkttJM1dUH9HaM'
|
||||
}],
|
||||
vout: []
|
||||
}, {
|
||||
vin: [{
|
||||
addr: '2N9D5bcCQ2bPWUDByQ6Qb5bMgMtgsk1rw3x'
|
||||
}],
|
||||
vout: []
|
||||
}, {
|
||||
vin: [],
|
||||
vout: [{
|
||||
scriptPubKey: {
|
||||
addresses: ['2NFjCBFZSsxiwWAD7CKQ3hzWFtf9DcqTucY']
|
||||
}
|
||||
}]
|
||||
}]);
|
||||
};
|
||||
|
||||
w.checkActivity(addresses, function(err, actives){
|
||||
w.checkActivity(addresses, function(err, actives) {
|
||||
actives.length.should.equal(addresses.length);
|
||||
actives.filter(function(i) { return i }).length.should.equal(3);
|
||||
actives.filter(function(i) {
|
||||
return i
|
||||
}).length.should.equal(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var expect = chai.expect;
|
||||
var sinon = sinon || require('sinon');
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var chai = chai || require('chai');
|
||||
var should = chai.should();
|
||||
var expect = chai.expect;
|
||||
var sinon = sinon || require('sinon');
|
||||
var bitcore = bitcore || require('bitcore');
|
||||
var WebRTC = require('../js/models/network/WebRTC');
|
||||
|
||||
describe('Network / WebRTC', function() {
|
||||
|
||||
it('should create an instance', function () {
|
||||
it('should create an instance', function() {
|
||||
var n = new WebRTC();
|
||||
should.exist(n);
|
||||
});
|
||||
|
|
@ -28,7 +28,7 @@ describe('Network / WebRTC', function() {
|
|||
n.cleanUp.calledOnce.should.equal(true);
|
||||
WebRTC.prototype.cleanUp = save;
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
describe('#cleanUp', function() {
|
||||
|
|
@ -95,7 +95,9 @@ describe('Network / WebRTC', function() {
|
|||
key.regenerateSync();
|
||||
|
||||
var copayerId = key.public.toString('hex');
|
||||
n._sendToOne = function(a1, a2, a3, cb) {cb();};
|
||||
n._sendToOne = function(a1, a2, a3, cb) {
|
||||
cb();
|
||||
};
|
||||
var sig = undefined;
|
||||
n.send(copayerId, data, function() {
|
||||
done();
|
||||
|
|
@ -138,7 +140,9 @@ describe('Network / WebRTC', function() {
|
|||
key.regenerateSync();
|
||||
|
||||
var copayerIds = [key.public.toString('hex')];
|
||||
n._sendToOne = function(a1, a2, a3, cb) {cb();};
|
||||
n._sendToOne = function(a1, a2, a3, cb) {
|
||||
cb();
|
||||
};
|
||||
var sig = undefined;
|
||||
n.send(copayerIds, data, function() {
|
||||
done();
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
var chai = require('chai');
|
||||
var should = chai.should();
|
||||
var Storage = require('../js/models/storage/File.js');
|
||||
var sinon = require('sinon');
|
||||
var crypto = require('crypto');
|
||||
var CryptoJS = require('node-cryptojs-aes').CryptoJS;
|
||||
var chai = require('chai');
|
||||
var should = chai.should();
|
||||
var Storage = require('../js/models/storage/File.js');
|
||||
var sinon = require('sinon');
|
||||
var crypto = require('crypto');
|
||||
var CryptoJS = require('node-cryptojs-aes').CryptoJS;
|
||||
|
||||
describe('Storage/File', function() {
|
||||
it('should exist', function() {
|
||||
|
|
@ -17,12 +17,18 @@ describe('Storage/File', function() {
|
|||
var fs = {}
|
||||
fs.readFile = function(filename, callback) {
|
||||
filename.should.equal('myfilename');
|
||||
var obj = {"test":"test"};
|
||||
var obj = {
|
||||
"test": "test"
|
||||
};
|
||||
var encryptedStr = CryptoJS.AES.encrypt(JSON.stringify(obj), "password").toString();
|
||||
callback(null, encryptedStr);
|
||||
};
|
||||
var Storage = require('soop').load('../js/models/storage/File.js', {fs: fs});
|
||||
var storage = new Storage({password: 'password'});
|
||||
var Storage = require('soop').load('../js/models/storage/File.js', {
|
||||
fs: fs
|
||||
});
|
||||
var storage = new Storage({
|
||||
password: 'password'
|
||||
});
|
||||
storage.load('myfilename', function(err) {
|
||||
done();
|
||||
});
|
||||
|
|
@ -36,8 +42,12 @@ describe('Storage/File', function() {
|
|||
filename.should.equal('myfilename');
|
||||
callback();
|
||||
};
|
||||
var Storage = require('soop').load('../js/models/storage/File.js', {fs: fs});
|
||||
var storage = new Storage({password: 'password'});
|
||||
var Storage = require('soop').load('../js/models/storage/File.js', {
|
||||
fs: fs
|
||||
});
|
||||
var storage = new Storage({
|
||||
password: 'password'
|
||||
});
|
||||
storage.save('myfilename', function(err) {
|
||||
done();
|
||||
});
|
||||
|
|
@ -47,7 +57,11 @@ describe('Storage/File', function() {
|
|||
describe('#_read', function() {
|
||||
it('should return the value of a key', function() {
|
||||
var storage = new Storage();
|
||||
storage.data = {'walletId':{'test':'data'}};
|
||||
storage.data = {
|
||||
'walletId': {
|
||||
'test': 'data'
|
||||
}
|
||||
};
|
||||
storage._read('walletId::test').should.equal('data');
|
||||
});
|
||||
});
|
||||
|
|
@ -68,7 +82,11 @@ describe('Storage/File', function() {
|
|||
describe('#getGlobal', function() {
|
||||
it('should call storage._read', function() {
|
||||
var storage = new Storage();
|
||||
storage.data = {'walletId':{'test':'test'}};
|
||||
storage.data = {
|
||||
'walletId': {
|
||||
'test': 'test'
|
||||
}
|
||||
};
|
||||
storage._read = sinon.spy();
|
||||
storage.getGlobal('walletId::test');
|
||||
storage._read.calledOnce.should.equal(true);
|
||||
|
|
@ -91,7 +109,11 @@ describe('Storage/File', function() {
|
|||
describe('#removeGlobal', function() {
|
||||
it('should remove a global key', function(done) {
|
||||
var storage = new Storage();
|
||||
storage.data = {'walletId':{'key':'value'}};
|
||||
storage.data = {
|
||||
'walletId': {
|
||||
'key': 'value'
|
||||
}
|
||||
};
|
||||
storage.save = function(walletId, callback) {
|
||||
should.not.exist(storage.data[walletId]['key']);
|
||||
callback();
|
||||
|
|
@ -141,7 +163,9 @@ describe('Storage/File', function() {
|
|||
|
||||
describe('#setFromObj', function() {
|
||||
it('should set this object for a wallet', function(done) {
|
||||
var obj = {test:'testval'};
|
||||
var obj = {
|
||||
test: 'testval'
|
||||
};
|
||||
var storage = new Storage();
|
||||
storage.save = function(walletId, callback) {
|
||||
callback();
|
||||
|
|
@ -155,25 +179,29 @@ describe('Storage/File', function() {
|
|||
|
||||
describe('#getEncryptedObj', function() {
|
||||
it('should give an encrypted object', function() {
|
||||
var obj = {test:'testval'};
|
||||
var obj = {
|
||||
test: 'testval'
|
||||
};
|
||||
var data = JSON.stringify(obj);
|
||||
var encrypted = CryptoJS.AES.encrypt(data, 'password');
|
||||
var base64 = encrypted.toString();
|
||||
|
||||
var storage = new Storage({password: 'password'});
|
||||
var storage = new Storage({
|
||||
password: 'password'
|
||||
});
|
||||
storage.data['walletId'] = obj;
|
||||
|
||||
var enc = storage.getEncryptedObj('walletId');
|
||||
//enc.length.should.equal(96);
|
||||
enc.length.should.be.greaterThan(10);
|
||||
enc.slice(0,10).should.equal(base64.slice(0,10));
|
||||
enc.slice(0, 10).should.equal(base64.slice(0, 10));
|
||||
//enc.slice(0,6).should.equal("53616c");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clearAll', function() {
|
||||
it('should set data to {}', function() {
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -20,48 +20,58 @@ if (typeof process === 'undefined' || !process.version) {
|
|||
});
|
||||
it('should fail when encrypting without a password', function() {
|
||||
var s = new LocalEncrypted();
|
||||
(function(){
|
||||
(function() {
|
||||
s.set(fakeWallet, timeStamp, 1);
|
||||
localStorage.removeItem(fakeWallet +'::'+ timeStamp);
|
||||
localStorage.removeItem(fakeWallet + '::' + timeStamp);
|
||||
}).should.throw();
|
||||
});
|
||||
it('should be able to encrypt and decrypt', function() {
|
||||
s._write(fakeWallet+timeStamp, 'value');
|
||||
s._read(fakeWallet+timeStamp).should.equal('value');
|
||||
localStorage.removeItem(fakeWallet+timeStamp);
|
||||
s._write(fakeWallet + timeStamp, 'value');
|
||||
s._read(fakeWallet + timeStamp).should.equal('value');
|
||||
localStorage.removeItem(fakeWallet + timeStamp);
|
||||
});
|
||||
it('should be able to set a value', function() {
|
||||
s.set(fakeWallet, timeStamp, 1);
|
||||
localStorage.removeItem(fakeWallet +'::'+ timeStamp);
|
||||
localStorage.removeItem(fakeWallet + '::' + timeStamp);
|
||||
});
|
||||
var getSetData = [
|
||||
1,1000,-15, -1000,
|
||||
1, 1000, -15, -1000,
|
||||
0.1, -0.5, -0.5e-10, Math.PI,
|
||||
'hi', 'auydoaiusyodaisudyoa', '0b5b8556a0c2ce828c9ccfa58b3dd0a1ae879b9b',
|
||||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC', 'OP_DUP OP_HASH160 80ad90d4035',
|
||||
[1,2,3,4,5,6],
|
||||
{ x: 1, y: 2},
|
||||
{ x: 'hi', y: null},
|
||||
{ a: {}, b: [], c: [1,2,'hi']},
|
||||
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC', 'OP_DUP OP_HASH160 80ad90d4035', [1, 2, 3, 4, 5, 6], {
|
||||
x: 1,
|
||||
y: 2
|
||||
}, {
|
||||
x: 'hi',
|
||||
y: null
|
||||
}, {
|
||||
a: {},
|
||||
b: [],
|
||||
c: [1, 2, 'hi']
|
||||
},
|
||||
null
|
||||
];
|
||||
getSetData.forEach(function(obj) {
|
||||
it('should be able to set a value and get it for '+JSON.stringify(obj), function() {
|
||||
it('should be able to set a value and get it for ' + JSON.stringify(obj), function() {
|
||||
s.set(fakeWallet, timeStamp, obj);
|
||||
var obj2 = s.get(fakeWallet, timeStamp);
|
||||
JSON.stringify(obj2).should.equal(JSON.stringify(obj));
|
||||
localStorage.removeItem(fakeWallet +'::'+ timeStamp);
|
||||
localStorage.removeItem(fakeWallet + '::' + timeStamp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#export', function() {
|
||||
it('should export the encrypted wallet', function() {
|
||||
var storage = new LocalEncrypted({password: 'password'});
|
||||
var storage = new LocalEncrypted({
|
||||
password: 'password'
|
||||
});
|
||||
storage.set(fakeWallet, timeStamp, 'testval');
|
||||
var obj = {test:'testval'};
|
||||
var obj = {
|
||||
test: 'testval'
|
||||
};
|
||||
var encrypted = storage.export(obj);
|
||||
encrypted.length.should.be.greaterThan(10);
|
||||
localStorage.removeItem(fakeWallet +'::'+ timeStamp);
|
||||
localStorage.removeItem(fakeWallet + '::' + timeStamp);
|
||||
//encrypted.slice(0,6).should.equal("53616c");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ if (typeof process === 'undefined' || !process.version) {
|
|||
}
|
||||
};
|
||||
var storage = new LocalPlain();
|
||||
storage.setFromObj(fakeWallet+timeStamp, obj);
|
||||
storage.get(fakeWallet+timeStamp, 'test').should.equal('testval');
|
||||
storage.setFromObj(fakeWallet + timeStamp, obj);
|
||||
storage.get(fakeWallet + timeStamp, 'test').should.equal('testval');
|
||||
|
||||
// Clean data used in localstorage
|
||||
localStorage.removeItem(fakeWallet+timeStamp+'::test');
|
||||
localStorage.removeItem(fakeWallet+timeStamp+'::opts');
|
||||
localStorage.removeItem('nameFor::'+fakeWallet+timeStamp);
|
||||
localStorage.removeItem(fakeWallet + timeStamp + '::test');
|
||||
localStorage.removeItem(fakeWallet + timeStamp + '::opts');
|
||||
localStorage.removeItem('nameFor::' + fakeWallet + timeStamp);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ describe("Unit: Controllers", function() {
|
|||
totalCopayers: 5,
|
||||
spendUnconfirmed: 1,
|
||||
reconnectDelay: 100,
|
||||
networkName: 'testnet'
|
||||
networkName: 'testnet'
|
||||
};
|
||||
|
||||
describe('Backup Controller', function() {
|
||||
|
|
@ -117,7 +117,7 @@ describe("Unit: Controllers", function() {
|
|||
describe('Send Controller', function() {
|
||||
var scope, form;
|
||||
beforeEach(angular.mock.module('copayApp'));
|
||||
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller){
|
||||
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller) {
|
||||
scope = $rootScope.$new();
|
||||
$rootScope.wallet = new FakeWallet(config);
|
||||
var element = angular.element(
|
||||
|
|
@ -131,7 +131,8 @@ describe("Unit: Controllers", function() {
|
|||
newlabel: null,
|
||||
};
|
||||
$compile(element)(scope);
|
||||
$controller('SendController', {$scope: scope,
|
||||
$controller('SendController', {
|
||||
$scope: scope,
|
||||
$modal: {},
|
||||
});
|
||||
scope.$digest();
|
||||
|
|
|
|||
|
|
@ -85,7 +85,11 @@ describe("Unit: Testing Directives", function() {
|
|||
|
||||
beforeEach(inject(function($compile, $rootScope) {
|
||||
$rootScope.wallet = {
|
||||
addressBook: {'2MtBXKLtZuXGDshUcyH6yq7aZ33Snbb49pT': {label: ':)'}}
|
||||
addressBook: {
|
||||
'2MtBXKLtZuXGDshUcyH6yq7aZ33Snbb49pT': {
|
||||
label: ':)'
|
||||
}
|
||||
}
|
||||
}
|
||||
element1 = angular.element(
|
||||
'<contact address="2MtBXKLtZuXGDshUcyH6yq7aZ33Snbb49pT" />'
|
||||
|
|
|
|||
|
|
@ -22,16 +22,31 @@ describe('Unit: Testing Filters', function() {
|
|||
|
||||
it('should filter correctly', inject(function($filter) {
|
||||
var limitAddress = $filter('limitAddress');
|
||||
var addresses = [
|
||||
{isChange: true, balance: 0},
|
||||
{isChange: false, balance: 0},
|
||||
{isChange: true, balance: 0},
|
||||
{isChange: false, balance: 0},
|
||||
{isChange: true, balance: 0},
|
||||
{isChange: false, balance: 0},
|
||||
{isChange: true, balance: 0},
|
||||
{isChange: false, balance: 0}
|
||||
];
|
||||
var addresses = [{
|
||||
isChange: true,
|
||||
balance: 0
|
||||
}, {
|
||||
isChange: false,
|
||||
balance: 0
|
||||
}, {
|
||||
isChange: true,
|
||||
balance: 0
|
||||
}, {
|
||||
isChange: false,
|
||||
balance: 0
|
||||
}, {
|
||||
isChange: true,
|
||||
balance: 0
|
||||
}, {
|
||||
isChange: false,
|
||||
balance: 0
|
||||
}, {
|
||||
isChange: true,
|
||||
balance: 0
|
||||
}, {
|
||||
isChange: false,
|
||||
balance: 0
|
||||
}];
|
||||
expect(limitAddress(addresses, false).length).to.equal(1);
|
||||
|
||||
addresses[0].isChange = false;
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ describe("Unit: isMobile Service", function() {
|
|||
isMobile.any().should.equal(false);
|
||||
}));
|
||||
it('should detect mobile if user agent is Android', inject(function(isMobile) {
|
||||
navigator.__defineGetter__('userAgent', function(){
|
||||
navigator.__defineGetter__('userAgent', function() {
|
||||
return 'Android 2.2.3';
|
||||
});
|
||||
isMobile.any().should.equal(true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue