| 1 | package wallet |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // Cursors come back from clients, so anything at all can arrive. decodeCursor |
| 6 | // must never panic, and must only accept cursors that encodeCursor could have |
| 7 | // written: anything else, a client should hear is invalid. |
| 8 | func FuzzDecodeCursor(f *testing.F) { |
| 9 | f.Add("") |
| 10 | f.Add(encodeCursor(1)) |
| 11 | f.Add(encodeCursor(1_234_567)) |
| 12 | f.Fuzz(func(t *testing.T, cursor string) { |
| 13 | id, err := decodeCursor(cursor) |
| 14 | if err != nil || cursor == "" { |
| 15 | return // refused, or the first page |
| 16 | } |
| 17 | if id <= 0 || encodeCursor(id) != cursor { |
| 18 | t.Errorf("decodeCursor(%q) = %d, but we'd write %d as %q", cursor, id, id, encodeCursor(id)) |
| 19 | } |
| 20 | }) |
| 21 | } |