TransactionInput: check range of value

The value can't be negative. This also adds a test.
This commit is contained in:
Andreas Schildbach 2023-04-04 10:59:36 +02:00
parent d880570d54
commit 7da2820fa0
2 changed files with 7 additions and 1 deletions

View File

@ -130,6 +130,7 @@ public class TransactionInput {
private TransactionInput(@Nullable Transaction parentTransaction, byte[] scriptBytes,
TransactionOutPoint outpoint, long sequence, @Nullable Coin value) {
checkArgument(value == null || value.signum() >= 0, () -> "value out of range: " + value);
this.scriptBytes = scriptBytes;
this.outpoint = outpoint;
this.sequence = sequence;

View File

@ -142,7 +142,12 @@ public class TransactionInputTest {
byte[] randomBytes = new byte[100];
random.nextBytes(randomBytes);
return new TransactionInput(parent, randomBytes, TransactionOutPoint.UNCONNECTED,
Coin.ofSat(random.nextLong()));
Coin.ofSat(Math.abs(random.nextLong())));
}).limit(10).iterator();
}
@Test(expected = IllegalArgumentException.class)
public void negativeValue() {
new TransactionInput(new Transaction(), new byte[0], TransactionOutPoint.UNCONNECTED, Coin.ofSat(-1));
}
}