|
1 | 1 | import { expect } from "chai"; |
2 | 2 | import { OrderV2 } from "src/orders/types"; |
| 3 | +import { decodeTokenIds } from "../../src/utils/utils"; |
3 | 4 |
|
4 | 5 | export const expectValidOrder = (order: OrderV2) => { |
5 | 6 | const requiredFields = [ |
@@ -28,3 +29,64 @@ export const expectValidOrder = (order: OrderV2) => { |
28 | 29 | expect(field in order).to.be.true; |
29 | 30 | } |
30 | 31 | }; |
| 32 | + |
| 33 | +describe("decodeTokenIds", () => { |
| 34 | + it('should return ["*"] when given "*" as input', () => { |
| 35 | + expect(decodeTokenIds("*")).deep.equal(["*"]); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should correctly decode a single number", () => { |
| 39 | + expect(decodeTokenIds("123")).deep.equal(["123"]); |
| 40 | + }); |
| 41 | + |
| 42 | + it("should correctly decode multiple comma-separated numbers", () => { |
| 43 | + expect(decodeTokenIds("1,2,3,4")).deep.equal(["1", "2", "3", "4"]); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should correctly decode a single number", () => { |
| 47 | + expect(decodeTokenIds("10:10")).deep.equal(["10"]); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should correctly decode a range of numbers", () => { |
| 51 | + expect(decodeTokenIds("5:8")).deep.equal(["5", "6", "7", "8"]); |
| 52 | + }); |
| 53 | + |
| 54 | + it("should correctly decode multiple ranges of numbers", () => { |
| 55 | + expect(decodeTokenIds("1:3,7:9")).deep.equal([ |
| 56 | + "1", |
| 57 | + "2", |
| 58 | + "3", |
| 59 | + "7", |
| 60 | + "8", |
| 61 | + "9", |
| 62 | + ]); |
| 63 | + }); |
| 64 | + |
| 65 | + it("should correctly decode a mix of single numbers and ranges", () => { |
| 66 | + expect(decodeTokenIds("1,3:5,8")).deep.equal(["1", "3", "4", "5", "8"]); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should throw an error for invalid input format", () => { |
| 70 | + expect(() => decodeTokenIds("1:3:5,8")).throw( |
| 71 | + "Invalid input format. Expected a valid comma-separated list of numbers and ranges.", |
| 72 | + ); |
| 73 | + expect(() => decodeTokenIds("1;3:5,8")).throw( |
| 74 | + "Invalid input format. Expected a valid comma-separated list of numbers and ranges.", |
| 75 | + ); |
| 76 | + }); |
| 77 | + |
| 78 | + it("should throw an error for invalid range format", () => { |
| 79 | + expect(() => decodeTokenIds("5:2")).throws( |
| 80 | + "Invalid range. End value: 2 must be greater than or equal to the start value: 5.", |
| 81 | + ); |
| 82 | + }); |
| 83 | + |
| 84 | + it("should handle very large input numbers", () => { |
| 85 | + const encoded = "10000000000000000000000000:10000000000000000000000002"; |
| 86 | + expect(decodeTokenIds(encoded)).deep.equal([ |
| 87 | + "10000000000000000000000000", |
| 88 | + "10000000000000000000000001", |
| 89 | + "10000000000000000000000002", |
| 90 | + ]); |
| 91 | + }); |
| 92 | +}); |
0 commit comments