go-blockchain/p2p/ping_test.go
Snider 34128d8e98
Some checks failed
Security Scan / security (pull_request) Successful in 11s
Test / Test (pull_request) Failing after 19s
refactor: migrate module path to dappco.re/go/core/blockchain
Update go.mod module line, all require/replace directives, and every
.go import path from forge.lthn.ai/core/go-blockchain to
dappco.re/go/core/blockchain. Add replace directives to bridge
dappco.re paths to existing forge.lthn.ai registry during migration.
Update CLAUDE.md, README, and docs to reflect the new module path.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 01:49:26 +00:00

44 lines
1,000 B
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
package p2p
import (
"testing"
"dappco.re/go/core/p2p/node/levin"
)
func TestEncodePingRequest_Good_EmptySection(t *testing.T) {
data, err := EncodePingRequest()
if err != nil {
t.Fatalf("encode: %v", err)
}
s, err := levin.DecodeStorage(data)
if err != nil {
t.Fatalf("decode: %v", err)
}
if len(s) != 0 {
t.Errorf("ping request should be empty, got %d fields", len(s))
}
}
func TestDecodePingResponse_Good(t *testing.T) {
s := levin.Section{
"status": levin.StringVal([]byte("OK")),
"peer_id": levin.Uint64Val(12345),
}
data, _ := levin.EncodeStorage(s)
status, peerID, err := DecodePingResponse(data)
if err != nil {
t.Fatalf("decode: %v", err)
}
if status != "OK" {
t.Errorf("status: got %q, want %q", status, "OK")
}
if peerID != 12345 {
t.Errorf("peer_id: got %d, want 12345", peerID)
}
}