mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #748 from ryanxcharles/feature/speed-up-wallet-tests
speed up wallet tests by three times
This commit is contained in:
commit
88e6ea9f40
|
@ -38,7 +38,7 @@ describe('Wallet model', function() {
|
||||||
throw();
|
throw();
|
||||||
});
|
});
|
||||||
it('should getNetworkName', function() {
|
it('should getNetworkName', function() {
|
||||||
var w = createW();
|
var w = cachedCreateW();
|
||||||
w.getNetworkName().should.equal('testnet');
|
w.getNetworkName().should.equal('testnet');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -93,8 +93,20 @@ describe('Wallet model', function() {
|
||||||
return new Wallet(c);
|
return new Wallet(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cachedW = null;
|
||||||
|
var cachedWobj = null;
|
||||||
|
var cachedCreateW = function() {
|
||||||
|
if (!cachedW) {
|
||||||
|
cachedW = createW();
|
||||||
|
cachedWobj = cachedW.toObj();
|
||||||
|
cachedWobj.opts.reconnectDelay = 100;
|
||||||
|
}
|
||||||
|
var w = Wallet.fromObj(cachedWobj, cachedW.storage, cachedW.network, cachedW.blockchain);
|
||||||
|
return w;
|
||||||
|
};
|
||||||
|
|
||||||
it('should create an instance', function() {
|
it('should create an instance', function() {
|
||||||
var w = createW();
|
var w = cachedCreateW();
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
w.publicKeyRing.walletId.should.equal(w.id);
|
w.publicKeyRing.walletId.should.equal(w.id);
|
||||||
w.txProposals.walletId.should.equal(w.id);
|
w.txProposals.walletId.should.equal(w.id);
|
||||||
|
@ -108,7 +120,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('should provide some basic features', function(done) {
|
it('should provide some basic features', function(done) {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
var w = createW();
|
var w = cachedCreateW();
|
||||||
addCopayers(w);
|
addCopayers(w);
|
||||||
w.publicKeyRing.generateAddress(false);
|
w.publicKeyRing.generateAddress(false);
|
||||||
w.publicKeyRing.isComplete().should.equal(true);
|
w.publicKeyRing.isComplete().should.equal(true);
|
||||||
|
@ -148,9 +160,21 @@ describe('Wallet model', function() {
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var cachedW2 = null;
|
||||||
|
var cachedW2obj = null;
|
||||||
|
var cachedCreateW2 = function() {
|
||||||
|
if (!cachedW2) {
|
||||||
|
cachedW2 = createW2();
|
||||||
|
cachedW2obj = cachedW2.toObj();
|
||||||
|
cachedW2obj.opts.reconnectDelay = 100;
|
||||||
|
}
|
||||||
|
var w = Wallet.fromObj(cachedW2obj, cachedW2.storage, cachedW2.network, cachedW2.blockchain);
|
||||||
|
return w;
|
||||||
|
};
|
||||||
|
|
||||||
it('#create, 1 sign', function() {
|
it('#create, 1 sign', function() {
|
||||||
|
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
|
|
||||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
||||||
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true);
|
unspentTest[0].scriptPubKey = w.publicKeyRing.getScriptPubKeyHex(1, true);
|
||||||
|
@ -174,7 +198,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('#create with comment', function() {
|
it('#create with comment', function() {
|
||||||
|
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var comment = 'This is a comment';
|
var comment = 'This is a comment';
|
||||||
|
|
||||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
||||||
|
@ -196,7 +220,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('#create throw exception on long comment', function() {
|
it('#create throw exception on long comment', function() {
|
||||||
|
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var comment = 'Lorem ipsum dolor sit amet, suas euismod vis te, velit deleniti vix an. Pri ex suscipit similique, inermis per';
|
var comment = 'Lorem ipsum dolor sit amet, suas euismod vis te, velit deleniti vix an. Pri ex suscipit similique, inermis per';
|
||||||
|
|
||||||
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
unspentTest[0].address = w.publicKeyRing.getAddress(1, true).toString();
|
||||||
|
@ -215,7 +239,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#addressIsOwn', function() {
|
it('#addressIsOwn', function() {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var l = w.getAddressesStr();
|
var l = w.getAddressesStr();
|
||||||
for (var i = 0; i < l.length; i++)
|
for (var i = 0; i < l.length; i++)
|
||||||
w.addressIsOwn(l[i]).should.equal(true);
|
w.addressIsOwn(l[i]).should.equal(true);
|
||||||
|
@ -230,7 +254,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('#create. Signing with derivate keys', function() {
|
it('#create. Signing with derivate keys', function() {
|
||||||
|
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
|
|
||||||
var ts = Date.now();
|
var ts = Date.now();
|
||||||
for (var isChange = false; !isChange; isChange = true) {
|
for (var isChange = false; !isChange; isChange = true) {
|
||||||
|
@ -258,7 +282,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('#fromObj #toObj round trip', function() {
|
it('#fromObj #toObj round trip', function() {
|
||||||
|
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
|
|
||||||
var o = w.toObj();
|
var o = w.toObj();
|
||||||
o = JSON.parse(JSON.stringify(o));
|
o = JSON.parse(JSON.stringify(o));
|
||||||
|
@ -278,7 +302,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#getSecret decodeSecret', function() {
|
it('#getSecret decodeSecret', function() {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var id = w.getMyCopayerId();
|
var id = w.getMyCopayerId();
|
||||||
|
|
||||||
var sb = w.getSecret();
|
var sb = w.getSecret();
|
||||||
|
@ -304,7 +328,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('call reconnect after interval', function(done) {
|
it('call reconnect after interval', function(done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var spy = sinon.spy(w, 'scheduleConnect');
|
var spy = sinon.spy(w, 'scheduleConnect');
|
||||||
var callCount = 3;
|
var callCount = 3;
|
||||||
w.netStart();
|
w.netStart();
|
||||||
|
@ -446,7 +470,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#getBalance should call #getUnspent', function(done) {
|
it('#getBalance should call #getUnspent', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var spy = sinon.spy(w.blockchain, 'getUnspent');
|
var spy = sinon.spy(w.blockchain, 'getUnspent');
|
||||||
w.generateAddress();
|
w.generateAddress();
|
||||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
|
@ -455,7 +479,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('#getBalance should return values in satoshis', function(done) {
|
it('#getBalance should return values in satoshis', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
w.generateAddress();
|
w.generateAddress();
|
||||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
balance.should.equal(2500010000);
|
balance.should.equal(2500010000);
|
||||||
|
@ -481,7 +505,7 @@ describe('Wallet model', function() {
|
||||||
it('#getUnspent and spendUnconfirmed should count transactions with 1 confirmations', function(done) {
|
it('#getUnspent and spendUnconfirmed should count transactions with 1 confirmations', function(done) {
|
||||||
var conf = JSON.parse(JSON.stringify(config));
|
var conf = JSON.parse(JSON.stringify(config));
|
||||||
conf.spendUnconfirmed = false;
|
conf.spendUnconfirmed = false;
|
||||||
var w = createW2(null, null, conf);
|
var w = cachedCreateW2(null, null, conf);
|
||||||
w.blockchain.getUnspent = w.blockchain.getUnspent2;
|
w.blockchain.getUnspent = w.blockchain.getUnspent2;
|
||||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
balance.should.equal(2500010000);
|
balance.should.equal(2500010000);
|
||||||
|
@ -512,7 +536,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
roundErrorChecks.forEach(function(c) {
|
roundErrorChecks.forEach(function(c) {
|
||||||
it('check rounding errors ' + c.unspent[0], function(done) {
|
it('check rounding errors ' + c.unspent[0], function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
w.generateAddress();
|
w.generateAddress();
|
||||||
w.blockchain.fixUnspent(c.unspent.map(function(u) {
|
w.blockchain.fixUnspent(c.unspent.map(function(u) {
|
||||||
return {
|
return {
|
||||||
|
@ -559,7 +583,7 @@ describe('Wallet model', function() {
|
||||||
var amountSatStr = '1000';
|
var amountSatStr = '1000';
|
||||||
|
|
||||||
it('should create transaction', function(done) {
|
it('should create transaction', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
||||||
|
@ -569,7 +593,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
it('should create & sign transaction from received funds', function(done) {
|
it('should create & sign transaction from received funds', function(done) {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var pk = w.privateKey;
|
var pk = w.privateKey;
|
||||||
w.privateKey = null;
|
w.privateKey = null;
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
|
@ -587,7 +611,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should create & reject transaction', function(done) {
|
it('should create & reject transaction', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
w.privateKey = null;
|
w.privateKey = null;
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
|
@ -612,7 +636,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should send TxProposal', function(done) {
|
it('should send TxProposal', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
||||||
|
@ -624,7 +648,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should send all TxProposal', function(done) {
|
it('should send all TxProposal', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var utxo = createUTXO(w);
|
var utxo = createUTXO(w);
|
||||||
w.blockchain.fixUnspent(utxo);
|
w.blockchain.fixUnspent(utxo);
|
||||||
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
w.createTx(toAddress, amountSatStr, null, function(ntxid) {
|
||||||
|
@ -651,7 +675,7 @@ describe('Wallet model', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
it('#indexDiscovery should work without found activities', function(done) {
|
it('#indexDiscovery should work without found activities', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
mockFakeActivity(w, function(index) {
|
mockFakeActivity(w, function(index) {
|
||||||
return false
|
return false
|
||||||
});
|
});
|
||||||
|
@ -662,7 +686,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#indexDiscovery should continue scanning', function(done) {
|
it('#indexDiscovery should continue scanning', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
mockFakeActivity(w, function(index) {
|
mockFakeActivity(w, function(index) {
|
||||||
return index <= 7
|
return index <= 7
|
||||||
});
|
});
|
||||||
|
@ -673,7 +697,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#indexDiscovery should not found beyond the scannWindow', function(done) {
|
it('#indexDiscovery should not found beyond the scannWindow', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
mockFakeActivity(w, function(index) {
|
mockFakeActivity(w, function(index) {
|
||||||
return index <= 10 || index == 17
|
return index <= 10 || index == 17
|
||||||
});
|
});
|
||||||
|
@ -684,7 +708,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#indexDiscovery should look for activity along the scannWindow', function(done) {
|
it('#indexDiscovery should look for activity along the scannWindow', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
mockFakeActivity(w, function(index) {
|
mockFakeActivity(w, function(index) {
|
||||||
return index <= 14 && index % 2 == 0
|
return index <= 14 && index % 2 == 0
|
||||||
});
|
});
|
||||||
|
@ -695,7 +719,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#updateIndexes should update correctly', function(done) {
|
it('#updateIndexes should update correctly', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
mockFakeActivity(w, function(index) {
|
mockFakeActivity(w, function(index) {
|
||||||
return index <= 14 && index % 2 == 0
|
return index <= 14 && index % 2 == 0
|
||||||
});
|
});
|
||||||
|
@ -707,7 +731,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#updateIndexes should store and emit event', function(done) {
|
it('#updateIndexes should store and emit event', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
mockFakeActivity(w, function(index) {
|
mockFakeActivity(w, function(index) {
|
||||||
return index <= 14 && index % 2 == 0
|
return index <= 14 && index % 2 == 0
|
||||||
});
|
});
|
||||||
|
@ -721,7 +745,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#deriveAddresses', function(done) {
|
it('#deriveAddresses', function(done) {
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
var addresses1 = w.deriveAddresses(0, 5, false);
|
var addresses1 = w.deriveAddresses(0, 5, false);
|
||||||
var addresses2 = w.deriveAddresses(4, 5, false);
|
var addresses2 = w.deriveAddresses(4, 5, false);
|
||||||
|
|
||||||
|
@ -797,7 +821,7 @@ describe('Wallet model', function() {
|
||||||
describe('#getMyCopayerId', function() {
|
describe('#getMyCopayerId', function() {
|
||||||
it('should call getCopayerId', function() {
|
it('should call getCopayerId', function() {
|
||||||
//this.timeout(10000);
|
//this.timeout(10000);
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
w.getCopayerId = sinon.spy();
|
w.getCopayerId = sinon.spy();
|
||||||
w.getMyCopayerId();
|
w.getMyCopayerId();
|
||||||
w.getCopayerId.calledOnce.should.equal(true);
|
w.getCopayerId.calledOnce.should.equal(true);
|
||||||
|
@ -807,7 +831,7 @@ describe('Wallet model', function() {
|
||||||
describe('#getMyCopayerIdPriv', function() {
|
describe('#getMyCopayerIdPriv', function() {
|
||||||
it('should call privateKey.getIdPriv', function() {
|
it('should call privateKey.getIdPriv', function() {
|
||||||
//this.timeout(10000);
|
//this.timeout(10000);
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
w.privateKey.getIdPriv = sinon.spy();
|
w.privateKey.getIdPriv = sinon.spy();
|
||||||
w.getMyCopayerIdPriv();
|
w.getMyCopayerIdPriv();
|
||||||
w.privateKey.getIdPriv.calledOnce.should.equal(true);
|
w.privateKey.getIdPriv.calledOnce.should.equal(true);
|
||||||
|
@ -818,7 +842,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('should call Network.start', function() {
|
it('should call Network.start', function() {
|
||||||
//this.timeout(10000);
|
//this.timeout(10000);
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
w.network.start = sinon.spy();
|
w.network.start = sinon.spy();
|
||||||
w.netStart();
|
w.netStart();
|
||||||
w.network.start.calledOnce.should.equal(true);
|
w.network.start.calledOnce.should.equal(true);
|
||||||
|
@ -826,7 +850,7 @@ describe('Wallet model', function() {
|
||||||
|
|
||||||
it('should call Network.start with a private key', function() {
|
it('should call Network.start with a private key', function() {
|
||||||
//this.timeout(10000);
|
//this.timeout(10000);
|
||||||
var w = createW2();
|
var w = cachedCreateW2();
|
||||||
w.network.start = sinon.spy();
|
w.network.start = sinon.spy();
|
||||||
w.netStart();
|
w.netStart();
|
||||||
w.network.start.getCall(0).args[0].privkey.length.should.equal(64);
|
w.network.start.getCall(0).args[0].privkey.length.should.equal(64);
|
||||||
|
|
Loading…
Reference in New Issue