test #getWalletFromIdentifier

This commit is contained in:
Ivan Socolsky 2017-06-29 10:56:42 -03:00
parent 565bc01339
commit 279d2ecc68
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
2 changed files with 105 additions and 3 deletions

View File

@ -405,6 +405,8 @@ WalletService.prototype.getWallet = function(opts, cb) {
WalletService.prototype.getWalletFromIdentifier = function(opts, cb) {
var self = this;
if (!opts.identifier) return cb();
var walletId;
async.parallel([
@ -437,7 +439,6 @@ WalletService.prototype.getWalletFromIdentifier = function(opts, cb) {
var bc = self._getBlockchainExplorer(network);
bc.getTransaction(opts.identifier, function(err, tx) {
if (err || !tx) return nextNetwork(err, false);
var outputs = _.first(self._normalizeTxHistory(tx)).outputs;
var toAddresses = _.pluck(outputs, 'address');
async.detect(toAddresses, function(addressStr, nextAddress) {

View File

@ -4395,7 +4395,6 @@ describe('Wallet service', function() {
});
});
describe('#getSendMaxInfo', function() {
var server, wallet;
beforeEach(function(done) {
@ -5240,7 +5239,6 @@ describe('Wallet service', function() {
});
});
});
});
describe('Tx proposal workflow', function() {
@ -7477,4 +7475,107 @@ describe('Wallet service', function() {
});
});
});
describe('#getWalletFromIdentifier', function() {
var server, wallet;
beforeEach(function(done) {
helpers.createAndJoinWallet(1, 1, {}, function(s, w) {
server = s;
wallet = w;
done();
});
});
it('should get wallet from id', function(done) {
server.getWalletFromIdentifier({
identifier: wallet.id
}, function(err, w) {
should.not.exist(err);
should.exist(w);
w.id.should.equal(wallet.id);
done();
});
});
it('should get wallet from address', function(done) {
server.createAddress({}, function(err, address) {
should.not.exist(err);
should.exist(address);
server.getWalletFromIdentifier({
identifier: address.address
}, function(err, w) {
should.not.exist(err);
should.exist(w);
w.id.should.equal(wallet.id);
done();
});
});
});
it('should get wallet from tx proposal', function(done) {
helpers.stubUtxos(server, wallet, '1 btc', function() {
helpers.stubBroadcast();
var txOpts = {
outputs: [{
toAddress: '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7',
amount: 1000e2
}],
feePerKb: 100e2,
message: 'some message',
};
helpers.createAndPublishTx(server, txOpts, TestData.copayers[0].privKey_1H_0, function(txp) {
should.exist(txp);
var signatures = helpers.clientSign(txp, TestData.copayers[0].xPrivKey_44H_0H_0H);
server.signTx({
txProposalId: txp.id,
signatures: signatures,
}, function(err) {
should.not.exist(err);
server.getPendingTxs({}, function(err, txps) {
should.not.exist(err);
txp = txps[0];
server.getWalletFromIdentifier({
identifier: txp.txid
}, function(err, w) {
should.not.exist(err);
should.exist(w);
w.id.should.equal(wallet.id);
done();
});
});
});
});
});
});
it('should get wallet from incoming txid', function(done) {
server.createAddress({}, function(err, address) {
should.not.exist(err);
should.exist(address);
blockchainExplorer.getTransaction = sinon.stub().callsArgWith(1, null, {
txid: '999',
vout: [{
scriptPubKey: {
addresses: [address.address]
}
}],
});
server.getWalletFromIdentifier({
identifier: '999'
}, function(err, w) {
should.not.exist(err);
should.exist(w);
w.id.should.equal(wallet.id);
done();
});
});
});
it('should return nothing if identifier not associated with a wallet', function(done) {
blockchainExplorer.getTransaction = sinon.stub().callsArgWith(1, null, null);
server.getWalletFromIdentifier({
identifier: 'dummy'
}, function(err, w) {
should.not.exist(err);
should.not.exist(w);
done();
});
});
});
});