Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
test #getWalletFromIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
isocolsky committed Jun 29, 2017
1 parent 565bc01 commit 279d2ec
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([

Expand Down Expand Up @@ -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) {
Expand Down
105 changes: 103 additions & 2 deletions test/integration/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4395,7 +4395,6 @@ describe('Wallet service', function() {
});
});


describe('#getSendMaxInfo', function() {
var server, wallet;
beforeEach(function(done) {
Expand Down Expand Up @@ -5240,7 +5239,6 @@ describe('Wallet service', function() {
});
});
});

});

describe('Tx proposal workflow', function() {
Expand Down Expand Up @@ -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();
});
});
});
});

0 comments on commit 279d2ec

Please sign in to comment.