From f3a152ca30e1fc6c427e2b6f2204f305f6c7fa2a Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 19 Feb 2015 17:47:51 -0300 Subject: [PATCH] send TX tests --- lib/client/Verifier.js | 1 - lib/client/api.js | 1 - lib/walletutils.js | 3 +++ test/integration/clientApi.js | 41 +++++++++++++++++++++++++++++++---- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lib/client/Verifier.js b/lib/client/Verifier.js index a653a72..9cc75e4 100644 --- a/lib/client/Verifier.js +++ b/lib/client/Verifier.js @@ -58,7 +58,6 @@ Verifier.checkTxProposal = function(data, txp) { if (WalletUtils.xPubToCopayerId(xPubKey) === txp.creatorId) return true; }); if (!creatorXPubKey) return false; - var creatorSigningPubKey = (new Bitcore.HDPublicKey(creatorXPubKey)).derive('m/1/0').publicKey.toString(); var hash = WalletUtils.getProposalHash(txp.toAddress, txp.amount, txp.message); diff --git a/lib/client/api.js b/lib/client/api.js index 9cb714a..4f3e452 100644 --- a/lib/client/api.js +++ b/lib/client/api.js @@ -457,7 +457,6 @@ API.prototype.signTxProposal = function(txp, cb) { return cb(new ServerCompromisedError('Server sent fake transaction proposal')); } - //Derive proper key to sign, for each input var privs = [], derived = {}; diff --git a/lib/walletutils.js b/lib/walletutils.js index 9138f83..6707a63 100644 --- a/lib/walletutils.js +++ b/lib/walletutils.js @@ -109,6 +109,9 @@ WalletUtils.UNITS = { }; WalletUtils.parseAmount = function(text) { + if (!_.isString(text)) + text = text.toString(); + var regex = '^(\\d*(\\.\\d{0,8})?)\\s*(' + _.keys(WalletUtils.UNITS).join('|') + ')?$'; var match = new RegExp(regex, 'i').exec(text.trim()); diff --git a/test/integration/clientApi.js b/test/integration/clientApi.js index 1d5b438..8739c69 100644 --- a/test/integration/clientApi.js +++ b/test/integration/clientApi.js @@ -355,7 +355,7 @@ describe('client API ', function() { }); - describe.only('Send TXs', function() { + describe.only('Send Transactions', function() { it('Send and broadcast in 1-1 wallet', function(done) { helpers.createAndJoinWallet(clients, 1, 1, function(err, w) { clients[0].createAddress(function(err, x0) { @@ -363,19 +363,52 @@ describe('client API ', function() { should.exist(x0.address); blockExplorerMock.setUtxo(x0, 10, 1); var opts = { - amount: 1000, + amount: 10000, toAddress: 'n2TBMPzPECGUfcT2EByiTJ12TPZkhN2mN5', message: 'hola 1-1', }; clients[0].sendTxProposal(opts, function(err, x) { should.not.exist(err); -console.log('[clientApi.js.372]',x); //TODO - done(); + x.requiredRejections.should.equal(1); + x.requiredSignatures.should.equal(1); + x.status.should.equal('pending'); + x.changeAddress.path.should.equal('m/2147483647/1/0'); + clients[0].signTxProposal(x.id, function(err, res) { + should.not.exist(err, err.message); + done(); + }); }); }); }); }); + it('Send and broadcast in 2-3 wallet', function(done) { + helpers.createAndJoinWallet(clients, 2, 3, function(err, w) { + clients[0].createAddress(function(err, x0) { + should.not.exist(err); + should.exist(x0.address); + blockExplorerMock.setUtxo(x0, 10, 1); + var opts = { + amount: 10000, + toAddress: 'n2TBMPzPECGUfcT2EByiTJ12TPZkhN2mN5', + message: 'hola 1-1', + }; + clients[0].sendTxProposal(opts, function(err, x) { + should.not.exist(err); + x.status.should.equal('pending'); + x.requiredRejections.should.equal(2); + x.requiredSignatures.should.equal(2); + clients[0].signTxProposal(x.id, function(err, res) { + should.not.exist(err, err.message); + done(); + }); + }); + }); + }); + }); + }); + + /* describe('TODO', function(x) { it('should detect fake addresses ', function(done) {