[#1037] Empty string memo throws `ZcashError.memoTextInputEndsWithNullBytes` (#1038)

Fixes the case where the SDK would read an empty string from the Db and would
throw this error incorrectly
closes #1037
This commit is contained in:
Francisco Gindre 2023-05-10 12:39:34 -03:00 committed by GitHub
parent 355a3fc4f5
commit cf53edb3b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -211,7 +211,7 @@ extension Array where Element == UInt8 {
.reversed()
.first(where: { $0.1 != 0 })
.map({ $0.0 + 1 }) else {
return [UInt8](self[0 ..< 1])
return []
}
return [UInt8](self[0 ..< lastNullByte])

View File

@ -77,6 +77,12 @@ class MemoTests: XCTestCase {
let memo: Memo = .arbitrary(Self.validMemoDataExpectedString.data(using: .utf8)!.bytes)
XCTAssertNil(memo.toString())
}
func testEmptyTextMemo() throws {
let emptyMemoBytes = try MemoBytes(bytes: [])
XCTAssertNoThrow(try emptyMemoBytes.intoMemo())
}
/**
*******