go-blockchain/hsd/client_test.go
Claude 46ed9a1204
Some checks are pending
Security Scan / security (push) Waiting to run
Test / Test (push) Waiting to run
test: close audit gaps — HSD client, config, genesis, daemon tests
hsd/client_test.go: 5 integration tests (blockchain info, name resource,
  not found, height, wrong URL)
config/file_test.go: 4 unit tests (defaults, IsTestnet, ToChainConfig, env)
chain/genesis_test.go: DetectNetwork for mainnet/testnet/unknown
daemon/server_test.go: 8 unit tests with nil-meta fix

Closing gaps found in honest audit. 15/15 packages pass.

Co-Authored-By: Charon <charon@lethean.io>
2026-04-02 03:18:36 +01:00

80 lines
1.9 KiB
Go

// Copyright (c) 2017-2026 Lethean (https://lt.hn)
//
// Licensed under the European Union Public Licence (EUPL) version 1.2.
// SPDX-License-Identifier: EUPL-1.2
//go:build integration
package hsd
import (
"testing"
)
func TestClient_GetBlockchainInfo_Good(t *testing.T) {
client := NewClient("http://127.0.0.1:14037", "testkey")
info, err := client.GetBlockchainInfo()
if err != nil {
t.Fatalf("GetBlockchainInfo: %v", err)
}
if info.Blocks == 0 {
t.Error("expected non-zero block count")
}
if info.TreeRoot == "" {
t.Error("expected non-empty tree root")
}
}
func TestClient_GetNameResource_Good(t *testing.T) {
client := NewClient("http://127.0.0.1:14037", "testkey")
resource, err := client.GetNameResource("charon")
if err != nil {
t.Fatalf("GetNameResource: %v", err)
}
if len(resource.Records) == 0 {
t.Error("expected records for charon")
}
hasGLUE4 := false
for _, r := range resource.Records {
if r.Type == "GLUE4" {
hasGLUE4 = true
if r.Address == "" {
t.Error("GLUE4 record has no address")
}
}
}
if !hasGLUE4 {
t.Error("expected GLUE4 record for charon")
}
}
func TestClient_GetNameResource_Bad_NotFound(t *testing.T) {
client := NewClient("http://127.0.0.1:14037", "testkey")
resource, err := client.GetNameResource("nonexistent_name_12345")
if err != nil {
// Error is acceptable for non-existent names
return
}
if resource != nil && len(resource.Records) > 0 {
t.Error("expected no records for nonexistent name")
}
}
func TestClient_GetHeight_Good(t *testing.T) {
client := NewClient("http://127.0.0.1:14037", "testkey")
height, err := client.GetHeight()
if err != nil {
t.Fatalf("GetHeight: %v", err)
}
if height == 0 {
t.Error("expected non-zero height")
}
}
func TestClient_Bad_WrongURL(t *testing.T) {
client := NewClient("http://127.0.0.1:19999", "badkey")
_, err := client.GetBlockchainInfo()
if err == nil {
t.Error("expected error for wrong URL")
}
}