Files
nandi 4d79d78f06
check / check (macos-latest) (push) Failing after 28s
check / check (ubuntu-latest) (push) Failing after 29s
check / check (windows-latest) (push) Failing after 30s
feat: add working native SAMv3 TCP client and CLI with sane defaults
2026-11-27 19:10:01 +00:00

44 lines
1.5 KiB
MoonBit

///|
test "SamConfig::default has sane modern I2P defaults" {
let cfg = @sam_client.SamConfig::default()
assert_eq(cfg.host, "127.0.0.1")
assert_eq(cfg.port, 7656)
assert_eq(cfg.min_version, "3.1")
assert_eq(cfg.max_version, "3.3")
assert_eq(cfg.signature_type, 7)
assert_eq(cfg.destination, "TRANSIENT")
assert_eq(cfg.i2cp_options.length(), 5)
assert_eq(cfg.i2cp_options[0], ("i2cp.leaseSetEncType", "4,0"))
assert_eq(cfg.i2cp_options[1], ("inbound.quantity", "3"))
assert_eq(cfg.i2cp_options[2], ("outbound.quantity", "3"))
assert_eq(cfg.i2cp_options[3], ("inbound.length", "3"))
assert_eq(cfg.i2cp_options[4], ("outbound.length", "3"))
}
///|
test "SamConfig::with_address parses host:port and host-only" {
let base = @sam_client.SamConfig::default()
let c1 = base.with_address("10.0.0.5:17656")
assert_eq(c1.host, "10.0.0.5")
assert_eq(c1.port, 17656)
let c2 = base.with_address("sam.internal")
assert_eq(c2.host, "sam.internal")
assert_eq(c2.port, 7656)
}
///|
test "destination_from_base64 derives canonical b32.i2p address" {
let crypto_pub = FixedArray::make(32, b'\x11')
let sign_pub = FixedArray::make(32, b'\x22')
let dest = @common.Destination::new_x25519_ed25519(
Bytes::from_array(crypto_pub),
Bytes::from_array(sign_pub),
)
let b64 = dest.to_base64()
let parsed = @sam_client.destination_from_base64(b64)
assert_eq(parsed.pub_b64, b64)
assert_eq(parsed.b32_address, dest.b32_address())
assert_true(parsed.b32_address.has_suffix(".b32.i2p"))
}