mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
TransactionInput: check range of value
The value can't be negative. This also adds a test.
This commit is contained in:
parent
d880570d54
commit
7da2820fa0
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user