Files
next.orly.dev/pkg/encoders/envelopes/okenvelope/okenvelope_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

72 lines
1.5 KiB
Go

package okenvelope
import (
"testing"
"lol.mleku.dev/chk"
"lukechampine.com/frand"
"github.com/minio/sha256-simd"
"next.orly.dev/pkg/encoders/envelopes"
"next.orly.dev/pkg/encoders/envelopes/messages"
"next.orly.dev/pkg/utils"
)
func TestMarshalUnmarshal(t *testing.T) {
var err error
rb, rb1, rb2 := make([]byte, 0, 65535), make([]byte, 0, 65535), make(
[]byte, 0, 65535,
)
for i := range 1000 {
var randMsg []byte
ok := i%2 == 1
if !ok {
randMsg = messages.RandomMessage()
}
req := NewFrom(frand.Bytes(sha256.Size), ok, randMsg)
rb = req.Marshal(rb)
rb1 = rb1[:len(rb)]
copy(rb1, rb)
var rem []byte
var l string
if l, rb, err = envelopes.Identify(rb); chk.E(err) {
t.Fatal(err)
}
if l != L {
t.Fatalf("invalid sentinel %s, expect %s", l, L)
}
req2 := New()
if rem, err = req2.Unmarshal(rb); chk.E(err) {
t.Fatal(err)
}
if len(rem) > 0 {
t.Fatalf(
"unmarshal failed, remainder\n%d %s",
len(rem), rem,
)
}
rb2 = req2.Marshal(rb2)
if !utils.FastEqual(rb1, rb2) {
if len(rb1) != len(rb2) {
t.Fatalf(
"unmarshal failed, different lengths\n%d %s\n%d %s\n",
len(rb1), rb1, len(rb2), rb2,
)
}
for i := range rb1 {
if rb1[i] != rb2[i] {
t.Fatalf(
"unmarshal failed, difference at position %d\n%d %s\n%s\n%d %s\n%s\n",
i, len(rb1), rb1[:i], rb1[i:], len(rb2), rb2[:i],
rb2[i:],
)
}
}
t.Fatalf(
"unmarshal failed\n%d %s\n%d %s\n",
len(rb1), rb1, len(rb2), rb2,
)
}
rb, rb1, rb2 = rb[:0], rb1[:0], rb2[:0]
}
}