feat: bootstrap moon-i2p core protocol foundation
check / check (ubuntu-latest) (push) Failing after 30s
check / check (macos-latest) (push) Failing after 33s
check / check (windows-latest) (push) Failing after 32s

This commit is contained in:
Antigravity committed 2026-11-27 15:37:42 +00:00
commit e527b84bc3
47 files changed
+5350

No files matched your search

+109
View File
@@ -0,0 +1,109 @@
///|
test "Mapping canonical sorted encoding and round-trip" {
let m = @common.Mapping::new()
m.set("v", "2")
m.set("host", "127.0.0.1")
m.set("port", "12345")
m.set("caps", "LR")
let w = @encoding.Writer::new()
m.encode(w)
let raw = w.to_bytes()
let decoded = @common.Mapping::decode(@encoding.Reader::new(raw))
assert_eq(decoded.length(), 4)
assert_eq(decoded.get("caps"), Some("LR"))
assert_eq(decoded.get("host"), Some("127.0.0.1"))
assert_eq(decoded.get("port"), Some("12345"))
assert_eq(decoded.get("v"), Some("2"))
// Verify canonical sorted order: caps, host, port, v
assert_eq(decoded.entries[0].0, "caps")
assert_eq(decoded.entries[1].0, "host")
assert_eq(decoded.entries[2].0, "port")
assert_eq(decoded.entries[3].0, "v")
}
///|
test "Destination X25519+Ed25519 key extraction, Base64, and .b32.i2p address" {
let crypto_pub = Bytes::make(32, b'\x11')
let sig_pub = Bytes::make(32, b'\x22')
let dest = @common.Destination::new_x25519_ed25519(crypto_pub, sig_pub)
let raw = dest.to_bytes()
// 384 bytes keys + 1 byte type + 2 bytes len + 4 bytes KeyCert = 391 bytes
assert_eq(raw.length(), 391)
assert_eq(dest.inner.crypto_public_key(), crypto_pub)
assert_eq(dest.inner.signing_public_key(), sig_pub)
assert_eq(dest.inner.crypto_type(), X25519)
assert_eq(dest.inner.signing_type(), EdDsaSha512Ed25519)
// Base64 round-trip
let b64 = dest.to_base64()
let restored = @common.Destination::from_base64(b64)
assert_eq(restored, dest)
// .b32.i2p address is 52 base32 chars + ".b32.i2p" (60 chars total)
let b32 = dest.b32_address()
assert_eq(b32.length(), 60)
assert_true(b32.has_suffix(".b32.i2p"))
}
///|
test "RouterInfo encode and decode round-trip" {
let ri_id = @common.RouterIdentity::new_x25519_ed25519(
Bytes::make(32, b'\x33'),
Bytes::make(32, b'\x44'),
)
let addr_opts = @common.Mapping::from_entries([
("host", "192.0.2.10"),
("port", "9001"),
("v", "2"),
])
let addr = @common.RouterAddress::new(b'\x03', "NTCP2", addr_opts)
let ri_opts = @common.Mapping::from_entries([
("caps", "OR"),
("netId", "2"),
("router.version", "0.9.64"),
])
let ri : @common.RouterInfo = {
identity: ri_id,
published: 1700000000000UL,
addresses: [addr],
options: ri_opts,
signature: Bytes::make(64, b'\x55'),
}
let w = @encoding.Writer::new()
ri.encode(w)
let decoded = @common.RouterInfo::decode(@encoding.Reader::new(w.to_bytes()))
assert_eq(decoded.identity, ri.identity)
assert_eq(decoded.published, ri.published)
assert_eq(decoded.addresses.length(), 1)
assert_eq(decoded.addresses[0].transport_style, "NTCP2")
assert_eq(decoded.options.get("netId"), Some("2"))
assert_eq(decoded.signature, ri.signature)
}
///|
test "LeaseSet2 encode and decode round-trip" {
let dest = @common.Destination::new_x25519_ed25519(
Bytes::make(32, b'\xaa'),
Bytes::make(32, b'\xbb'),
)
let gw = @common.Hash::from_bytes(Bytes::make(32, b'\xcc'))
let lease : @common.Lease2 = {
tunnel_gw: gw,
tunnel_id: 424242U,
end_date_sec: 1700000600U,
}
let ls2 : @common.LeaseSet2 = {
destination: dest,
published_sec: 1700000000U,
expires_offset: 600U,
flags: 0U,
options: @common.Mapping::new(),
encryption_keys: [{ key_type: X25519, key_data: Bytes::make(32, b'\xdd'), }],
leases: [lease],
signature: Bytes::make(64, b'\xee'),
}
let w = @encoding.Writer::new()
ls2.encode(w)
let decoded = @common.LeaseSet2::decode(@encoding.Reader::new(w.to_bytes()))
assert_eq(decoded, ls2)
}