go-blockchain/chain/alias_test.go
Claude a328c9f859
Some checks are pending
Security Scan / security (push) Waiting to run
Test / Test (push) Waiting to run
test: add tests for service, dns, forge, alias, blockdata (6 files)
service_test.go: NewBlockchainService, seedToRPC routing
dns_test.go: DNSRecord struct
forge_test.go: publish_release, dispatch_build, no-version error
chain/alias_test.go: PutGet round-trip, GetAll, NotFound error
chain/blockdata_test.go: WriteAtomic (no temp left), EnsureDir

21 untested files → 15 remaining. Closing gaps systematically.

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

54 lines
1.1 KiB
Go

package chain
import (
"testing"
store "dappco.re/go/core/store"
)
func TestAlias_PutGet_Good(t *testing.T) {
s, _ := store.New(t.TempDir() + "/test.db")
defer s.Close()
c := New(s)
err := c.PutAlias(Alias{Name: "charon", Address: "abc123", Comment: "v=lthn1"})
if err != nil {
t.Fatalf("PutAlias: %v", err)
}
alias, err := c.GetAlias("charon")
if err != nil {
t.Fatalf("GetAlias: %v", err)
}
if alias.Name != "charon" {
t.Errorf("name: got %s", alias.Name)
}
if alias.Comment != "v=lthn1" {
t.Errorf("comment: got %s", alias.Comment)
}
}
func TestAlias_GetAll_Good(t *testing.T) {
s, _ := store.New(t.TempDir() + "/test.db")
defer s.Close()
c := New(s)
c.PutAlias(Alias{Name: "a", Address: "1", Comment: "x"})
c.PutAlias(Alias{Name: "b", Address: "2", Comment: "y"})
all := c.GetAllAliases()
if len(all) != 2 {
t.Errorf("expected 2 aliases, got %d", len(all))
}
}
func TestAlias_Get_Bad_NotFound(t *testing.T) {
s, _ := store.New(t.TempDir() + "/test.db")
defer s.Close()
c := New(s)
_, err := c.GetAlias("nonexistent")
if err == nil {
t.Error("expected error for missing alias")
}
}