Files
next.orly.dev/pkg/encoders/text/helpers_test.go
mleku e56bf76257
Some checks failed
Go / build (push) Has been cancelled
Go / release (push) Has been cancelled
Add NIP-11 relay synchronization and group management features
- Introduced a new `sync` package for managing NIP-11 relay information and relay group configurations.
- Implemented a cache for NIP-11 documents, allowing retrieval of relay public keys and authoritative configurations.
- Enhanced the sync manager to update peer lists based on authoritative configurations from relay group events.
- Updated event handling to incorporate policy checks during event imports, ensuring compliance with relay rules.
- Refactored various components to utilize the new `sha256-simd` package for improved performance.
- Added comprehensive tests to validate the new synchronization and group management functionalities.
- Bumped version to v0.24.1 to reflect these changes.
2025-11-03 18:17:15 +00:00

55 lines
1.0 KiB
Go

package text
import (
"testing"
"lol.mleku.dev/chk"
"lukechampine.com/frand"
"github.com/minio/sha256-simd"
"next.orly.dev/pkg/encoders/hex"
"next.orly.dev/pkg/utils"
)
func TestUnmarshalHexArray(t *testing.T) {
var ha [][]byte
h := make([]byte, sha256.Size)
frand.Read(h)
var dst []byte
for _ = range 20 {
hh := sha256.Sum256(h)
h = hh[:]
ha = append(ha, h)
}
dst = append(dst, '[')
for i := range ha {
dst = AppendQuote(dst, ha[i], hex.EncAppend)
if i != len(ha)-1 {
dst = append(dst, ',')
}
}
dst = append(dst, ']')
var ha2 [][]byte
var rem []byte
var err error
if ha2, rem, err = UnmarshalHexArray(dst, sha256.Size); chk.E(err) {
t.Fatal(err)
}
if len(ha2) != len(ha) {
t.Fatalf(
"failed to unmarshal, got %d fields, expected %d", len(ha2),
len(ha),
)
}
if len(rem) > 0 {
t.Fatalf("failed to unmarshal, remnant afterwards '%s'", rem)
}
for i := range ha2 {
if !utils.FastEqual(ha[i], ha2[i]) {
t.Fatalf(
"failed to unmarshal at element %d; got %x, expected %x",
i, ha[i], ha2[i],
)
}
}
}