diff --git a/lib/server.js b/lib/server.js index 2362fd0..b39ed4a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -2156,7 +2156,7 @@ WalletService.prototype.createTx = function(opts, cb) { self._selectTxInputs(txp, opts.utxosToExclude, next); }, function(next) { - if (!changeAddress || opts.dryRun) return next(); + if (!changeAddress || wallet.singleAddress || opts.dryRun) return next(); self.storage.storeAddressAndWallet(wallet, txp.changeAddress, next); }, function(next) { diff --git a/test/integration/server.js b/test/integration/server.js index 954890f..4058608 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -4369,6 +4369,32 @@ describe('Wallet service', function() { }); }); }); + + it('should not duplicate address on storage after TX creation', function(done) { + helpers.stubUtxos(server, wallet, 2, function() { + var toAddress = '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7'; + var opts = { + outputs: [{ + amount: 1e8, + toAddress: toAddress, + }], + feePerKb: 100e2, + }; + server.createTx(opts, function(err, txp) { + should.not.exist(err); + server.storage.fetchAddresses(wallet.id, function(err, addresses) { + should.not.exist(err); + addresses.length.should.equal(1); + done(); + }); + }); + }); + }); + + + + + it('should not be able to specify custom changeAddress', function(done) { helpers.stubUtxos(server, wallet, 2, function() { var toAddress = '18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7';