an atproto pds written in F# (.NET 9) 馃
pds fsharp giraffe dotnet atproto
at main 2.1 kB view raw
1module CarTests 2 3open Xunit 4open PDSharp.Core 5open PDSharp.Core.Car 6open PDSharp.Core.Crypto 7 8[<Fact>] 9let ``Varint encodes zero correctly`` () = 10 let result = encodeVarint 0 11 Assert.Equal<byte[]>([| 0uy |], result) 12 13[<Fact>] 14let ``Varint encodes single byte values correctly`` () = 15 let result1 = encodeVarint 1 16 Assert.Equal<byte[]>([| 1uy |], result1) 17 18 let result127 = encodeVarint 127 19 Assert.Equal<byte[]>([| 127uy |], result127) 20 21[<Fact>] 22let ``Varint encodes multi-byte values correctly`` () = 23 let result128 = encodeVarint 128 24 Assert.Equal<byte[]>([| 0x80uy; 0x01uy |], result128) 25 26 let result300 = encodeVarint 300 27 Assert.Equal<byte[]>([| 0xACuy; 0x02uy |], result300) 28 29 let result16384 = encodeVarint 16384 30 Assert.Equal<byte[]>([| 0x80uy; 0x80uy; 0x01uy |], result16384) 31 32[<Fact>] 33let ``CAR header starts with version and roots`` () = 34 let hash = sha256Str "test-root" 35 let root = Cid.FromHash hash 36 let header = createHeader [ root ] 37 38 Assert.True(header.Length > 0, "Header should not be empty") 39 Assert.True(header.[0] >= 0xa0uy && header.[0] <= 0xbfuy, "Header should be a CBOR map") 40 41[<Fact>] 42let ``CAR block section is varint + CID + data`` () = 43 let hash = sha256Str "test-block" 44 let cid = Cid.FromHash hash 45 let data = [| 1uy; 2uy; 3uy; 4uy |] 46 47 let block = encodeBlock cid data 48 49 Assert.Equal(40uy, block.[0]) 50 Assert.Equal(41, block.Length) 51 52[<Fact>] 53let ``Full CAR creation produces valid structure`` () = 54 let hash = sha256Str "root-data" 55 let rootCid = Cid.FromHash hash 56 let blocks = [ (rootCid, [| 1uy; 2uy; 3uy |]) ] 57 let car = createCar [ rootCid ] blocks 58 59 Assert.True(car.Length > 0, "CAR should not be empty") 60 Assert.True(car.[0] < 128uy, "Header length should fit in one varint byte for small headers") 61 62[<Fact>] 63let ``CAR with multiple blocks`` () = 64 let hash1 = sha256Str "block1" 65 let hash2 = sha256Str "block2" 66 let cid1 = Cid.FromHash hash1 67 let cid2 = Cid.FromHash hash2 68 69 let blocks = [ cid1, [| 1uy; 2uy; 3uy |]; cid2, [| 4uy; 5uy; 6uy; 7uy |] ] 70 let car = createCar [ cid1 ] blocks 71 Assert.True(car.Length > 80, "CAR with two blocks should be substantial")