remove low-level tests and add api tests for string encoding

This commit is contained in:
glyph 2022-09-20 19:35:52 +01:00
parent 3732f34ded
commit 22c820ca73
3 changed files with 46 additions and 70 deletions

View File

@ -1,53 +0,0 @@
defmodule SsbBfeEncoderTest do
use ExUnit.Case
@blob_id "&S7+CwHM6dZ9si5Vn4ftpk/l/ldbRMqzzJos+spZbWf4=.sha256"
@box1_msg "siZEm1zFx1icq0SrEynGDpNRmJCXMxTB3iEteXFn+IhJH8WhMbT8tp9qOIaFkIYcdOyerSon6RK0l4RE1ZdDh/3lcGZSdP0Ljq59qsdqlf2ngwbIbV9AWdPRrPsoVZBV6RhI+YcVTloWWP5aauu1hZKjcm62ezLBTQ3EmFPYtDuwsOFkx9/7FP97ljhj67CwvlGzuiWp6FNICHbt5kOCxs9H0k6Tr8JJVdaJtJ2pqkX4p0ECMuEuYxCYbh3FpncCqlNZJXb0dj3iSsfsMNWTJLDqfkqJKH1jBVfxDL6+xAXBDS+E4F2hD4y9gRDZEej99uVBQWlbxr5eCRV+VbfBGYxwoAYtqux6rg3jBabImKKinBwHShEP5F/+wlb9IxQn4swyOgyv+UKx/jbx+91Ayso5bnNPZMpwRRX5p5DbpK1BnryeVJhktMgFqgni1g0lHyU8sQ2QzwZgXGw7dfYoamkqK4D24NOLnUoHuVuhd7Q5SxZWSAO6wpDa4nrODePoJdl328pbMwCoQlUNeHINmKxh/o/oCNbgXitn4oN3kSVEg/umdgwwI94gmZUjiYwP1v7HA7dI.box"
@box2_msg "WQyfhDDHQ1gH34uppHbj8SldRu8hD2764gQ6TAhaVp6R01EMBnJQj5ewD5F+UT5NwvV91uU8q5XCjuvcP4ihCJ0RtX8HjKyN+tDKP5gKB3UZo/eO/rP5CcPGoIG7pcLBsd3DQbZLfTnb/iqECEji9gclNcGENTS2u6aATwbQ4uQ7RzIAKKT2NfC2qk86p/gXC2owDFAazuPlQTT8DMNvO8G52gb48a75CGKsDAevrC//Bz38VFxwUiTKzRWaxCbTK9knj39u3qoCP9VLyyRqITg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dAtRbVHNX1g==.box2"
@classic_feed "@d/zDvFswFbQaYJc03i47C9CgDev+/A8QQSfG5l/SEfw=.ed25519"
@classic_msg "%R8heq/tQoxEIPkWf0Kxn1nCm/CsxG2CDpUYnAvdbXY8=.sha256"
@sig "nkY4Wsn9feosxvX7bpLK7OxjdSrw6gSL8sun1n2TMLXKySYK9L5itVQnV2nQUctFsrUOa2istD2vDk1B0uAMBQ==.sig.ed25519"
@str "golden ripples in the meshwork"
test "encode_blob_works" do
encoded_blob = SsbBfe.Encoder.encode_blob(@blob_id)
assert encoded_blob == <<2, 0, 75, 191, 130, 192, 115, 58, 117, 159, 108, 139, 149, 103, 225, 251, 105, 147, 249, 127, 149, 214, 209, 50, 172, 243, 38, 139, 62, 178, 150, 91, 89, 254>>
end
test "encode_bool_works" do
assert SsbBfe.Encoder.encode_bool(true) == <<6, 1, 1>>
assert SsbBfe.Encoder.encode_bool(false) == <<6, 1, 0>>
end
test "encode_box1_works" do
encoded_box1 = SsbBfe.Encoder.encode_box(@box1_msg)
assert String.starts_with?(encoded_box1, <<5, 0>>)
end
test "encode_box2_works" do
encoded_box2 = SsbBfe.Encoder.encode_box(@box2_msg)
assert String.starts_with?(encoded_box2, <<5, 1>>)
end
test "encode_classic_feed_works" do
encoded_classic_feed = SsbBfe.Encoder.encode_feed(@classic_feed)
assert String.starts_with?(encoded_classic_feed, <<0, 0>>)
end
test "encode_classic_msg_works" do
encoded_classic_msg = SsbBfe.Encoder.encode_msg(@classic_msg)
assert encoded_classic_msg == <<1, 0, 71, 200, 94, 171, 251, 80, 163, 17, 8, 62, 69, 159, 208, 172, 103, 214, 112, 166, 252, 43, 49, 27, 96, 131, 165, 70, 39, 2, 247, 91, 93, 143>>
end
test "encode_sig_works" do
encoded_sig = SsbBfe.Encoder.encode_sig(@sig)
assert encoded_sig == <<4, 0, 158, 70, 56, 90, 201, 253, 125, 234, 44, 198, 245, 251, 110, 146, 202, 236, 236, 99, 117, 42, 240, 234, 4, 139, 242, 203, 167, 214, 125, 147, 48, 181, 202, 201, 38, 10, 244, 190, 98, 181, 84, 39, 87, 105, 208, 81, 203, 69, 178, 181, 14, 107, 104, 172, 180, 61, 175, 14, 77, 65, 210, 224, 12, 5>>
end
test "encode_str_works" do
encoded_str = SsbBfe.Encoder.encode_str(@str)
assert encoded_str == <<6, 0, 103, 111, 108, 100, 101, 110, 32, 114, 105, 112, 112, 108, 101, 115, 32, 105, 110, 32, 116, 104, 101, 32, 109, 101, 115, 104, 119, 111, 114, 107>>
end
end

View File

@ -2,7 +2,51 @@ defmodule SsbBfeTest do
use ExUnit.Case
doctest SsbBfe
test "greets the world" do
assert SsbBfe.hello() == :world
setup do
[
blob: "&S7+CwHM6dZ9si5Vn4ftpk/l/ldbRMqzzJos+spZbWf4=.sha256",
box1: "bG92ZSBjb2xsYXBzZXMgc3BhY2V0aW1l.box",
box2: "bG92ZSBjb2xsYXBzZXMgc3BhY2V0aW1l.box2",
feed_classic: "@d/zDvFswFbQaYJc03i47C9CgDev+/A8QQSfG5l/SEfw=.ed25519",
msg_classic: "%R8heq/tQoxEIPkWf0Kxn1nCm/CsxG2CDpUYnAvdbXY8=.sha256",
sig: "nkY4Wsn9feosxvX7bpLK7OxjdSrw6gSL8sun1n2TMLXKySYK9L5itVQnV2nQUctFsrUOa2istD2vDk1B0uAMBQ==.sig.ed25519",
str: "golden ripples in the meshwork",
]
end
test "classic feed is encoded correctly", context do
encoded_feed = SsbBfe.encode(context.feed_classic)
assert encoded_feed == <<0, 0, 119, 252, 195, 188, 91, 48, 21, 180, 26, 96, 151, 52, 222, 46, 59, 11, 208, 160, 13, 235, 254, 252, 15, 16, 65, 39, 198, 230, 95, 210, 17, 252>>
end
test "classic msg is encoded correctly", context do
encoded_msg = SsbBfe.encode(context.msg_classic)
assert encoded_msg == <<1, 0, 71, 200, 94, 171, 251, 80, 163, 17, 8, 62, 69, 159, 208, 172, 103, 214, 112, 166, 252, 43, 49, 27, 96, 131, 165, 70, 39, 2, 247, 91, 93, 143>>
end
test "blob is encoded correctly", context do
encoded_blob = SsbBfe.encode(context.blob)
assert encoded_blob == <<2, 0, 75, 191, 130, 192, 115, 58, 117, 159, 108, 139, 149, 103, 225, 251, 105, 147, 249, 127, 149, 214, 209, 50, 172, 243, 38, 139, 62, 178, 150, 91, 89, 254>>
end
test "signature is encoded correctly", context do
encoded_sig = SsbBfe.encode(context.sig)
assert encoded_sig == <<4, 0, 158, 70, 56, 90, 201, 253, 125, 234, 44, 198, 245, 251, 110, 146, 202, 236, 236, 99, 117, 42, 240, 234, 4, 139, 242, 203, 167, 214, 125, 147, 48, 181, 202, 201, 38, 10, 244, 190, 98, 181, 84, 39, 87, 105, 208, 81, 203, 69, 178, 181, 14, 107, 104, 172, 180, 61, 175, 14, 77, 65, 210, 224, 12, 5>>
end
test "box is encoded correctly", context do
encoded_box = SsbBfe.encode(context.box1)
assert encoded_box == <<5, 0, 108, 111, 118, 101, 32, 99, 111, 108, 108, 97, 112, 115, 101, 115, 32, 115, 112, 97, 99, 101, 116, 105, 109, 101>>
end
test "box2 is encoded correctly", context do
encoded_box2 = SsbBfe.encode(context.box2)
assert encoded_box2 == <<5, 1, 108, 111, 118, 101, 32, 99, 111, 108, 108, 97, 112, 115, 101, 115, 32, 115, 112, 97, 99, 101, 116, 105, 109, 101>>
end
end

View File

@ -1,15 +0,0 @@
defmodule SsbBfeTypesTest do
use ExUnit.Case
test "get_blob_type_matches_classic" do
blob_id = "&S7+CwHM6dZ9si5Vn4ftpk/l/ldbRMqzzJos+spZbWf4=.sha256"
blob_type = SsbBfe.Types.get_blob_type(blob_id)
assert blob_type == <<2, 0>>
end
test "get_blob_type_matches_unknown" do
blob_id = "&what.is_this"
blob_type = SsbBfe.Types.get_blob_type(blob_id)
assert blob_type == nil
end
end