mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-19 05:25:11 +01:00
Don't allow negative outcome for unsigned digit decomp events (#2446)
This commit is contained in:
parent
4e862b7297
commit
7ad477fdaa
2 changed files with 24 additions and 1 deletions
|
@ -540,6 +540,24 @@ class DLCOracleTest extends DLCOracleFixture {
|
|||
}
|
||||
}
|
||||
|
||||
it must "fail to sign a negative number for a unsigned digit decomp event" in {
|
||||
dlcOracle: DLCOracle =>
|
||||
for {
|
||||
announcement <-
|
||||
dlcOracle.createNewLargeRangedEvent(eventName = "test",
|
||||
maturationTime = futureTime,
|
||||
base = UInt16(2),
|
||||
isSigned = false,
|
||||
numDigits = 3,
|
||||
unit = "units",
|
||||
precision = Int32.zero)
|
||||
|
||||
res <- recoverToSucceededIf[IllegalArgumentException] {
|
||||
dlcOracle.signDigits(announcement.eventTLV, -2)
|
||||
}
|
||||
} yield res
|
||||
}
|
||||
|
||||
it must "fail to sign a range outcome that doesn't exist" in {
|
||||
dlcOracle: DLCOracle =>
|
||||
val descriptor =
|
||||
|
|
|
@ -316,7 +316,12 @@ case class DLCOracle(private val extPrivateKey: ExtPrivateKeyHardened)(implicit
|
|||
signEvent(oracleEventTLV.nonces.head, signOutcome).map(db =>
|
||||
Vector(db))
|
||||
case _: UnsignedDigitDecompositionEventDescriptor =>
|
||||
FutureUtil.emptyVec[EventDb]
|
||||
if (num >= 0) {
|
||||
FutureUtil.emptyVec[EventDb]
|
||||
} else {
|
||||
Future.failed(new IllegalArgumentException(
|
||||
s"Cannot sign a negative number for an unsigned event, got $num"))
|
||||
}
|
||||
}
|
||||
|
||||
val boundedNum = if (num < eventDescriptorTLV.minNum) {
|
||||
|
|
Loading…
Add table
Reference in a new issue