Files
consensus/TESTING.md
T
zeekayandHanzo Dev fe378a9557 cmd: delete six unshipped tools, make the shipped one honest and tested
Seven main packages sat at 0% coverage. Only cmd/consensus reaches a user:
.hanzo/workflows/release.yml builds it into the release artifact. The other
six were built by a Makefile CI never invokes, or by nothing at all, and
nothing in or outside the module imports them.

They did not merely go unused, they misreported. bench printed a 30k TPS
figure that was the throughput of a failed map lookup, its chain half unable
to start at all. checker exited 0 announcing "all health checks passed" while
asserting nothing. sim drew from rand and formatted it like a quorum. server
asserted its engine to an interface the engine does not implement, so health
was a hardcoded true, and it was in no build recipe. conformance printed a
1-of-3 accept as normal. params duplicated cmd/consensus.

cmd/consensus keeps only what it can prove. The engine "test" and "health"
actions started an engine, printed a check mark and asserted nothing, so they
would pass against a Start that does nothing; they are gone along with the
stale "not yet implemented" arms for constructors that do exist. What remains
is the parameter report, absorbing the -json flag from params.

An unknown -network no longer falls back to mainnet. A typo used to print
mainnet's K=21 while the operator read it as the network they asked for.

Its old test never called a single symbol from main.go: it reimplemented a
CLI in the test file, parsed flags main.go does not have, and passed with
main.go deleted. Replaced with tests pinned to config, each verified to fail
under a deliberate mutation of the code it covers.

The .gitignore build-artifact patterns were unanchored, so `consensus` and
`bench` matched the cmd/consensus and bench source directories and silently
untracked new files in both. Anchored to the root artifacts they meant.

Also drops the Makefile and scripts that drove the deleted binaries, the
zmq-bench target chain building a cmd/ package absent for many commits, and
the E2E server test that can now only ever skip.

cmd/consensus: 0.0% -> 100.0% of statements, 1302 lines deleted.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-15 22:38:07 -07:00

2.3 KiB

Testing

Always GOWORK=off in this repo.

The suite

GOWORK=off go test ./...                    # everything
GOWORK=off go test -race ./...              # what CI runs
GOWORK=off go test -run TestName ./config   # one test

protocol/quasar is the long pole: ~11600 SLH-DSA tests, which the race detector multiplies by roughly 22. Give it -timeout=40m under -race, or it gets killed mid-run and reports FAIL at exactly the timeout.

Coverage

GOWORK=off go test -coverprofile=coverage.out ./...
GOWORK=off go tool cover -func=coverage.out    # per function
GOWORK=off go tool cover -html=coverage.out    # annotated source

make coverage-95 fails the build under 95%.

A coverage number only means something if the tests can fail. Before trusting one, break the code on purpose and confirm the test that covers it goes red — a test that passes against a mutilated implementation is measuring nothing.

Integration

test/integration drives the engines through the public API. Nothing there needs a server or a fixture process; go test ./test/integration is the whole story.

Benchmarks

GOWORK=off go test -bench=. -benchmem ./...
make benchmark                              # config, protocol, engine, core
make benchmark-zmq                          # ZAP transport, needs ginkgo

Increase -benchtime=30s when results scatter. Numbers in BENCHMARKS.md were taken on an M1 Max; treat anything measured elsewhere as a different data set, not a regression.

Profiling

GOWORK=off go test -cpuprofile=cpu.prof -bench=.
GOWORK=off go tool pprof cpu.prof

GOWORK=off go test -memprofile=mem.prof -bench=.
GOWORK=off go tool pprof mem.prof

The CLI

make build produces bin/consensus, which reports the parameters this build ships for a network:

./bin/consensus                       # mainnet, as a table
./bin/consensus -network local -json  # local, as JSON

It refuses a network it does not know rather than defaulting, so a typo exits non-zero instead of printing mainnet's numbers under the name you asked for.

CI

Native runners via .hanzo/workflows — ci.yml for the suite, lint and the C and Rust wrappers, release.yml for the cross-compiled consensus binaries.

gh run list --repo luxfi/consensus --limit 5
gh run view <run-id> --repo luxfi/consensus