From d7357c53ead8b23d1967930a2bb6e065371cc80e Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 11 Feb 2015 13:44:04 -0300 Subject: [PATCH] add tests --- test/integration.js | 79 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 19 deletions(-) diff --git a/test/integration.js b/test/integration.js index 1f632a3..a616493 100644 --- a/test/integration.js +++ b/test/integration.js @@ -177,27 +177,68 @@ var db, storage; describe('Copay server', function() { - beforeEach(function() { - db = levelup(memdown, { - valueEncoding: 'json' + beforeEach(function() { + db = levelup(memdown, { + valueEncoding: 'json' + }); + storage = new Storage({ + db: db + }); + CopayServer.initialize({ + storage: storage + }); }); - storage = new Storage({ - db: db + + describe('#getInstanceWithAuth', function() { + beforeEach(function() {}); + + it('should get server instance for existing copayer', function(done) { + helpers.createAndJoinWallet(1, 2, function(s, wallet, copayers, copayerIds) { + var xpriv = copayers[0].xPrivKey; + var priv = Bitcore.HDPrivateKey + .fromString(xpriv) + .derive('m/1/0') + .privateKey + .toString(); + + var message = 'hola'; + var sig = SignUtils.sign(message, priv); + + CopayServer.getInstanceWithAuth({ + copayerId: copayerIds[0], + message: message, + signature: sig, + }, function(err, server) { + should.not.exist(err); + done(); + }); + }); + }); + + it('should fail when requesting for non-existent copayer', function(done) { + CopayServer.getInstanceWithAuth({ + copayerId: 'ads', + message: 'dummy', + signature: 'dummy', + }, function(err, server) { + err.should.contain('Copayer not found'); + done(); + }); + }); + + it('should fail when message signature cannot be verified', function(done) { + helpers.createAndJoinWallet(1, 2, function(s, wallet, copayers, copayerIds) { + CopayServer.getInstanceWithAuth({ + copayerId: copayerIds[0], + message: 'dummy', + signature: 'dummy', + }, function(err, server) { + err.should.contain('Invalid signature'); + done(); + }); + }); + }); }); - CopayServer.initialize({ - storage: storage - }); - }); - - describe.skip('#getInstanceWithAuth', function() { - beforeEach(function() {}); - - it('should get server instance for existing copayer', function(done) {}); - - it('should fail when requesting for non-existent copayer', function(done) {}); - - it('should fail when message signature cannot be verified', function(done) {}); - }); describe('#createWallet', function() { var server;