mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-30 23:02:15 +00:00
Test the ability to choose your own change address. This clears a FindBugs warning about the field never being written.
This commit is contained in:
parent
8540f879bd
commit
440619f1c5
@ -1512,7 +1512,7 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
* don't really control as it depends on who sent you money), and the value being sent somewhere else. The
|
||||
* change address should be selected from this wallet, normally. <b>If null this will be chosen for you.</b>
|
||||
*/
|
||||
public Address changeAddress;
|
||||
public Address changeAddress = null;
|
||||
|
||||
/**
|
||||
* A transaction can have a fee attached, which is defined as the difference between the input values
|
||||
|
@ -108,6 +108,7 @@ public class WalletTest {
|
||||
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.UNSPENT));
|
||||
assertEquals(1, wallet.getPoolSize(WalletTransaction.Pool.ALL));
|
||||
assertEquals(TransactionConfidence.Source.SELF, t2.getConfidence().getSource());
|
||||
assertEquals(wallet.getChangeAddress(), t2.getOutput(1).getScriptPubKey().getToAddress());
|
||||
|
||||
// Do some basic sanity checks.
|
||||
assertEquals(1, t2.getInputs().size());
|
||||
@ -138,9 +139,13 @@ public class WalletTest {
|
||||
assertEquals(t2, txns.getFirst());
|
||||
assertEquals(1, txns.size());
|
||||
|
||||
// Now check that we can spend the unconfirmed change.
|
||||
// Now check that we can spend the unconfirmed change, with a new change address of our own selection.
|
||||
assertEquals(v3, wallet.getBalance());
|
||||
Transaction t3 = wallet.createSend(new ECKey().toAddress(params), v3);
|
||||
req = Wallet.SendRequest.to(new ECKey().toAddress(params), toNanoCoins(0, 48));
|
||||
Address a = req.changeAddress = new ECKey().toAddress(params);
|
||||
wallet.completeTx(req);
|
||||
Transaction t3 = req.tx;
|
||||
assertEquals(a, t3.getOutput(1).getScriptPubKey().getToAddress());
|
||||
assertNotNull(t3);
|
||||
wallet.commitTx(t3);
|
||||
assertTrue(wallet.isConsistent());
|
||||
|
Loading…
Reference in New Issue
Block a user