mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
The node moved every chain route from /v1/bc/<alias> to /v1/chain/<alias> and deleted the old prefix, so every chain call answered 404. The address was spelled out at 112 sites across 34 files and constants.ChainAliasPrefix was used at none of them, which is why nothing failed to compile when the segment moved. route.Chain(uri, alias) composes it now, and route.Alias reads one back, replacing three hand-rolled parsers — one of which took the alias by position in the split path and only worked because the new segment happens to leave the component count unchanged. TestChainAddressBuiltOnlyHere walks every .go file in the module and fails on a chain address in a string literal, so the segment cannot drift back; prose is free to name a route. TestGuardCatchesEachShape plants each forbidden shape and requires the guard to find it. The endpoint box and the eleven-chain table were the same list written twice; there is one list, rendered once, measured rather than hand-padded. The generated CLI reference and the faucet manifest compose through the same function. Co-authored-by: Hanzo Dev <[email protected]>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package ux
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestCompactChainEndpointsAreSquareAndComposed renders the endpoint box and
|
|
// measures it: every address is the one the composer builds, and every framed
|
|
// line is the same width.
|
|
//
|
|
// The box used to be padded by hand against a segment two characters long, and
|
|
// the addresses inside it were written out. A rename moved the addresses and
|
|
// would have left the frame ragged; both are now derived.
|
|
func TestCompactChainEndpointsAreSquareAndComposed(t *testing.T) {
|
|
saved := Logger
|
|
t.Cleanup(func() { Logger = saved })
|
|
|
|
var buf bytes.Buffer
|
|
Logger = &UserLog{writer: &buf}
|
|
PrintCompactChainEndpoints(9650)
|
|
out := buf.String()
|
|
|
|
for _, c := range GetNativeChains() {
|
|
scheme := "http"
|
|
if c.Type == "WS" {
|
|
scheme = "ws"
|
|
}
|
|
want := c.Address(scheme + "://localhost:9650")
|
|
if !strings.Contains(out, want) {
|
|
t.Errorf("compact endpoints missing %s", want)
|
|
}
|
|
}
|
|
|
|
width := -1
|
|
framed := 0
|
|
for _, line := range strings.Split(out, "\n") {
|
|
edge := strings.TrimSpace(line)
|
|
if edge == "" || !strings.ContainsAny(edge[:3], "┌│└") {
|
|
continue
|
|
}
|
|
framed++
|
|
switch n := len([]rune(edge)); {
|
|
case width < 0:
|
|
width = n
|
|
case n != width:
|
|
t.Errorf("box line is %d runes, want %d: %q", n, width, edge)
|
|
}
|
|
}
|
|
if framed != len(GetNativeChains())+2 {
|
|
t.Fatalf("framed %d lines, want %d rows plus two edges", framed, len(GetNativeChains()))
|
|
}
|
|
}
|