diff --git a/test/network.Async.js b/test/network.Async.js index e086a1330..4b1180410 100644 --- a/test/network.Async.js +++ b/test/network.Async.js @@ -369,5 +369,53 @@ describe('Network / Async', function() { }); }); + describe('#getCopayerIds', function() { + it('should return the copayer ids', function() { + var n = createN(); + n.getCopayerIds().length.should.be.equal(1); + }); + }); + + describe('#isOnline', function() { + it('should return if is online', function() { + var n = createN(); + n.isOnline().should.be.true; + n.cleanUp(); + n.isOnline().should.be.false; + }); + }); + + describe('#greet', function() { + it('should greet ', function() { + var n = createN(); + n.greet('03b51d01d798522cf61211b4dfcdd6db219ee33cf166e1cb7f43d836ab00ccddee', 'mySecret'); + }); + }); + + describe('#setCopayers', function() { + it('should setCopayers ', function() { + var n = createN(); + n.connectedPeers.length.should.be.equal(0); + var cids = ['abc001', 'abc002']; + n.setCopayers(cids); + n.connectedPeers.length.should.be.equal(2); + }); + }); + + + describe('#lockIncommingConnections', function() { + it('should lock Incomming Connections ', function() { + var n = createN(); + var cids = ['abc001', 'abc002', 'abc003']; + n.setCopayers(cids); + + var lockIds = ['abc001', 'abc002']; + n.lockIncommingConnections(lockIds); + console.log(n.allowedCopayerIds); + Object.keys(n.allowedCopayerIds).length.should.be.equal(2); + + + }); + }); }); diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index edf7f472f..abf95dada 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -52,7 +52,7 @@ describe("Unit: Controllers", function() { // // TODO Use the REAL wallet, and stub only networking and DB components! // - + var w = {}; w.id = 1234; w.isComplete = sinon.stub().returns(true); @@ -148,8 +148,80 @@ describe("Unit: Controllers", function() { c = $controller('ReceiveController', { $scope: scope, }); + + + var createW = function(N, conf) { + + var c = JSON.parse(JSON.stringify(conf || walletConfig)); + if (!N) N = c.totalCopayers; + + var mainPrivateKey = new copay.PrivateKey({ + networkName: walletConfig.networkName + }); + var mainCopayerEPK = mainPrivateKey.deriveBIP45Branch().extendedPublicKeyString(); + c.privateKey = mainPrivateKey; + + c.publicKeyRing = new copay.PublicKeyRing({ + networkName: c.networkName, + requiredCopayers: Math.min(N, c.requiredCopayers), + totalCopayers: N, + }); + c.publicKeyRing.addCopayer(mainCopayerEPK); + + c.publicKeyRing.getAddressesOrdered = sinon.stub().returns(null); + + c.txProposals = new copay.TxProposals({ + networkName: c.networkName, + }); + + c.blockchain = new Blockchain(walletConfig.blockchain); + + c.network = sinon.stub(); + c.network.setHexNonce = sinon.stub(); + c.network.setHexNonces = sinon.stub(); + c.network.getHexNonce = sinon.stub(); + c.network.getHexNonces = sinon.stub(); + c.network.peerFromCopayer = sinon.stub().returns('xxxx'); + c.network.send = sinon.stub(); + + c.addressBook = { + '2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ': { + label: 'John', + copayerId: '026a55261b7c898fff760ebe14fd22a71892295f3b49e0ca66727bc0a0d7f94d03', + createdTs: 1403102115, + hidden: false + }, + '2MtP8WyiwG7ZdVWM96CVsk2M1N8zyfiVQsY': { + label: 'Jennifer', + copayerId: '032991f836543a492bd6d0bb112552bfc7c5f3b7d5388fcbcbf2fbb893b44770d7', + createdTs: 1403103115, + hidden: false + } + }; + + c.networkName = walletConfig.networkName; + c.version = '0.0.1'; + + c.balanceInfo = {}; + + return new Wallet(c); + }; + + $rootScope.wallet = createW(); + $rootScope.wallet.balanceInfo = {}; })); + it('should exist', function() { + should.exist(c); + }); + + it('should call setAddressList', function() { + scope.setAddressList(); + expect(scope.addresses).to.be.empty; + scope.toggleShowAll(); + scope.setAddressList(); + expect(scope.addresses).to.be.empty; + }); }); describe('History Controller', function() {