Don't allow negative outcome for unsigned digit decomp events (#2446)

This commit is contained in:
benthecarman 2020-12-30 07:30:27 -06:00 committed by GitHub
parent 4e862b7297
commit 7ad477fdaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -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 =

View file

@ -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) {