mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-31 20:11:23 +00:00
Fix wrong balance calculation if identical (apart from the index) outputs are involved.
This regression was triggered by a53b508049
, though before that change it only worked by luck.
This commit is contained in:
@@ -419,8 +419,8 @@ public class TransactionOutput extends ChildMessage {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
TransactionOutput other = (TransactionOutput) o;
|
||||
return value == other.value && (parent == null || parent == other.parent)
|
||||
&& Arrays.equals(scriptBytes, other.scriptBytes);
|
||||
return value == other.value && (parent == null || (parent == other.parent && getIndex() == other.getIndex()))
|
||||
&& Arrays.equals(scriptBytes, other.scriptBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -545,6 +545,16 @@ public class WalletTest extends TestWithWallet {
|
||||
assertEquals(v4, wallet.getBalance(Wallet.BalanceType.AVAILABLE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void balanceWithIdenticalOutputs() {
|
||||
assertEquals(Coin.ZERO, wallet.getBalance(BalanceType.ESTIMATED));
|
||||
Transaction tx = new Transaction(PARAMS);
|
||||
tx.addOutput(Coin.COIN, myAddress);
|
||||
tx.addOutput(Coin.COIN, myAddress); // identical to the above
|
||||
wallet.addWalletTransaction(new WalletTransaction(Pool.UNSPENT, tx));
|
||||
assertEquals(Coin.COIN.plus(Coin.COIN), wallet.getBalance(BalanceType.ESTIMATED));
|
||||
}
|
||||
|
||||
// Intuitively you'd expect to be able to create a transaction with identical inputs and outputs and get an
|
||||
// identical result to Bitcoin Core. However the signatures are not deterministic - signing the same data
|
||||
// with the same key twice gives two different outputs. So we cannot prove bit-for-bit compatibility in this test
|
||||
|
Reference in New Issue
Block a user