Merge pull request #1268 from pacu/dbz-mitigation
This commit is contained in:
commit
0abe7f8cdf
|
@ -12,8 +12,11 @@ struct ScanProgress: Equatable {
|
|||
let denominator: UInt64
|
||||
|
||||
func progress() throws -> Float {
|
||||
// division by 0 is not a concern here because `ZcashRustBackend.getScanProgress() -> ScanProgress?`
|
||||
// handles the 0 and returns nil rather than returning nil progress or 0 value here
|
||||
guard denominator != 0 else {
|
||||
// this shouldn't happen but if it does, we need to get notified by clients and work on a fix
|
||||
throw ZcashError.rustScanProgressOutOfRange("\(numerator)/\(denominator)")
|
||||
}
|
||||
|
||||
let value = Float(numerator) / Float(denominator)
|
||||
|
||||
// this shouldn't happen but if it does, we need to get notified by clients and work on a fix
|
||||
|
|
|
@ -157,4 +157,14 @@ class ZcashRustBackendTests: XCTestCase {
|
|||
XCTAssertEqual(metadata?.networkType, .mainnet)
|
||||
XCTAssertEqual(metadata?.addressType, .sapling)
|
||||
}
|
||||
|
||||
func testScanProgressThrowsOnWrongValues() {
|
||||
// Assert that throws on Zero denominator
|
||||
XCTAssertThrowsError(try ScanProgress(numerator: 0, denominator: 0).progress())
|
||||
|
||||
// Assert that throws on numerator > denominator
|
||||
XCTAssertThrowsError(try ScanProgress(numerator: 23, denominator: 2).progress())
|
||||
|
||||
XCTAssertNoThrow(try ScanProgress(numerator: 3, denominator: 4).progress())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue