implement BITS + tests
This commit is contained in:
parent
ec859355c6
commit
727bf8524a
14 changed files with 213 additions and 79 deletions
|
|
@ -18,7 +18,6 @@
|
|||
var copay = require('copay');
|
||||
</script>
|
||||
<script src="test.blockchain.Insight.js"></script>
|
||||
<script src="test.performance.js"></script>
|
||||
<script src="test.PrivateKey.js"></script>
|
||||
<script src="test.PublicKeyRing.js"></script>
|
||||
<script src="test.storage.LocalEncrypted.js"></script>
|
||||
|
|
@ -26,6 +25,7 @@
|
|||
<script src="test.TxProposals.js"></script>
|
||||
<script src="test.Wallet.js"></script>
|
||||
<script src="test.Walletfactory.js"></script>
|
||||
<script src="test.performance.js"></script>
|
||||
<!--
|
||||
-->
|
||||
<script>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ FakeBlockchain.prototype.getTransactions = function(addresses, cb) {
|
|||
|
||||
FakeBlockchain.prototype.fixUnspent = function(u) {
|
||||
this.u = u;
|
||||
}
|
||||
};
|
||||
|
||||
FakeBlockchain.prototype.getUnspent = function(addresses, cb) {
|
||||
if (!addresses || !addresses.length) return cb(null, []);
|
||||
|
|
|
|||
34
test/mocks/FakeWallet.js
Normal file
34
test/mocks/FakeWallet.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
var FakeWallet = function(){
|
||||
this.balance=10000;
|
||||
this.safeBalance=1000;
|
||||
this.balanceByAddr={'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC': 1000};
|
||||
};
|
||||
|
||||
FakeWallet.prototype.set = function(balance, safeBalance, balanceByAddr){
|
||||
this.balance=balance;
|
||||
this.safeBalance = safeBalance;
|
||||
this.balanceByAddr = balanceByAddr;
|
||||
};
|
||||
|
||||
FakeWallet.prototype.getAddressesInfo=function(){
|
||||
var ret = [];
|
||||
|
||||
for(var ii in this.balanceByAddr){
|
||||
ret.push({
|
||||
address: ii,
|
||||
isChange: false,
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
FakeWallet.prototype.getBalance=function(cb){
|
||||
return cb(null, this.balance, this.balanceByAddr, this.safeBalance);
|
||||
};
|
||||
|
||||
// This mock is meant for karma, module.exports is not necesary.
|
||||
try {
|
||||
module.exports = require('soop')(FakeWallet);
|
||||
} catch (e) {}
|
||||
|
|
@ -440,9 +440,65 @@ describe('Wallet model', function() {
|
|||
r.length.should.equal(2);
|
||||
r[0].should.not.equal(r[1]);
|
||||
});
|
||||
|
||||
it('#getBalance should call #getUnspent', function(done) {
|
||||
var w = createW2();
|
||||
var spy = sinon.spy(w.blockchain, 'getUnspent');
|
||||
w.generateAddress();
|
||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||
sinon.assert.callCount(spy, 1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('#getBalance should return values in bits', function(done) {
|
||||
var w = createW2();
|
||||
w.generateAddress();
|
||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||
balance.should.equal(25000100.00);
|
||||
safeBalance.should.equal(25000100.00);
|
||||
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(25000100.00);
|
||||
Object.keys(balanceByAddr).length.should.equal(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
var roundErrorChecks=[
|
||||
{ unspent: [ 1.0001 ],
|
||||
balance: 1000100
|
||||
},
|
||||
{ unspent: [ 1.0002 , 1.0003 , 1.0004 ],
|
||||
balance: 3000900
|
||||
},
|
||||
{ unspent: [ 0.000002 , 1.000003 , 2.000004 ],
|
||||
balance: 3000009
|
||||
},
|
||||
{ unspent: [ 0.0001 , 0.0003 ],
|
||||
balance: 400
|
||||
},
|
||||
{ unspent: [ 0.0001 , 0.0003, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0002 ],
|
||||
balance: 1100
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
roundErrorChecks.forEach(function(c){
|
||||
it('check rounding errors '+ c.unspent[0], function(done) {
|
||||
var w = createW2();
|
||||
w.generateAddress();
|
||||
w.blockchain.fixUnspent(c.unspent.map(function(u){return {amount:u}}));
|
||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||
balance.should.equal(c.balance);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should get balance', function(done) {
|
||||
var w = createW();
|
||||
var spy = sinon.spy(w.blockchain, 'getUnspent');
|
||||
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||
sinon.assert.callCount(spy, 1);
|
||||
balance.should.equal(0);
|
||||
done();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ describe("Unit: Controllers", function() {
|
|||
expect(rootScope.insightError).equal(1);
|
||||
scope.$apply();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
//
|
||||
// test/unit/services/servicesSpec.js
|
||||
//
|
||||
describe("Unit: Testing Services", function() {
|
||||
|
||||
describe("Unit: Socket Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
|
||||
it('should contain a Socket service', inject(function(Socket) {
|
||||
|
|
@ -17,7 +16,7 @@ describe("Unit: Testing Services", function() {
|
|||
|
||||
it('Socket should support #sysOn', inject(function(Socket) {
|
||||
expect(Socket.sysOn).to.be.a('function');
|
||||
}))
|
||||
}));
|
||||
|
||||
|
||||
it('Socket should add handlers with #on', inject(function(Socket) {
|
||||
|
|
@ -40,19 +39,39 @@ describe("Unit: Testing Services", function() {
|
|||
ret = Socket.getListeners();
|
||||
expect(Object.keys(ret)).to.have.length(0);
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe("Unit: Walletfactory Service", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
it('should contain a walletFactory service', inject(function(walletFactory) {
|
||||
expect(walletFactory).not.to.equal(null);
|
||||
}));
|
||||
|
||||
|
||||
// TODO
|
||||
/*beforeEach(angular.mock.module('copayApp.controllerUtils'));
|
||||
|
||||
it('should contain a controllerUtils service', inject(function(controllerUtils) {
|
||||
expect(controllerUtils).not.to.equal(null);
|
||||
}));
|
||||
*/
|
||||
});
|
||||
|
||||
describe("Unit: controllerUtils", function() {
|
||||
beforeEach(angular.mock.module('copayApp.services'));
|
||||
beforeEach(angular.mock.module('notifications'));
|
||||
|
||||
it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) {
|
||||
expect(controllerUtils.updateBalance).not.to.equal(null);
|
||||
scope = $rootScope.$new();
|
||||
|
||||
$rootScope.wallet=new FakeWallet();
|
||||
var addr = '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC';
|
||||
var a = {}; a[addr]=100;
|
||||
$rootScope.wallet.set(1000000,900000,a);
|
||||
|
||||
controllerUtils.updateBalance(function() {
|
||||
expect($rootScope.totalBalance).to.be.equal(1000000);
|
||||
expect($rootScope.totalBalanceBTC).to.be.equal('1.000');
|
||||
expect($rootScope.availableBalance).to.be.equal(900000);
|
||||
expect($rootScope.availableBalanceBTC).to.be.equal('0.900');
|
||||
expect($rootScope.addrInfos).not.to.equal(null);
|
||||
expect($rootScope.addrInfos[0].address).to.equal(addr);
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue