Chain integration for P2P mining nodes: - GetChainInfo — query daemon for height, aliases, sync status - DiscoverPools — find pool aliases from chain (cap=pool) - DiscoverGateways — find gateway nodes from chain - parseComment — v=lthn1 comment parser Constants: testnet/mainnet daemon URLs and pool endpoints. 4/4 tests passing. Co-Authored-By: Charon <charon@lethean.io>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Copyright (c) 2017-2026 Lethean (https://lt.hn)
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package node
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseComment_Good(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
key string
|
|
want string
|
|
}{
|
|
{"v=lthn1;type=gateway;cap=vpn,dns", "type", "gateway"},
|
|
{"v=lthn1;cap=pool", "cap", "pool"},
|
|
{"v=lthn1", "v", "lthn1"},
|
|
}
|
|
for _, tt := range tests {
|
|
result := parseComment(tt.input)
|
|
if result[tt.key] != tt.want {
|
|
t.Errorf("parseComment(%q)[%q] = %q, want %q", tt.input, tt.key, result[tt.key], tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetChainInfo_Bad_WrongURL(t *testing.T) {
|
|
_, err := GetChainInfo("http://127.0.0.1:19999")
|
|
if err == nil {
|
|
t.Error("expected error for unreachable daemon")
|
|
}
|
|
}
|
|
|
|
func TestDiscoverPools_Bad_WrongURL(t *testing.T) {
|
|
pools := DiscoverPools("http://127.0.0.1:19999")
|
|
if len(pools) != 0 {
|
|
t.Errorf("expected 0 pools for unreachable daemon, got %d", len(pools))
|
|
}
|
|
}
|
|
|
|
func TestDiscoverGateways_Bad_WrongURL(t *testing.T) {
|
|
gateways := DiscoverGateways("http://127.0.0.1:19999")
|
|
if len(gateways) != 0 {
|
|
t.Errorf("expected 0 gateways for unreachable daemon, got %d", len(gateways))
|
|
}
|
|
}
|