Files
status-go/params/cluster_test.go
Igor SirotinandClaude Opus 4.8 075510ce3b feat(messaging): extract Waku fleet registry into pkg/messaging/waku/fleets (#7590)
Move the fleet definitions (waku nodes, discv5 bootstrap nodes, cluster
IDs, store nodes) out of params/cluster.go into a new leaf package
pkg/messaging/waku/fleets, behind the Waku layer. It exposes a registry
API (Supported / IsSupported / WakuNodes / DiscV5Nodes / ClusterID /
StoreNodes / LoadFromFile) plus Register() so local/interop harnesses
can register an ephemeral network as a named fleet.

params/cluster.go keeps back-compat re-exports (type aliases, fleet-name
constants, delegating helpers) so existing callers are unchanged. The
registry is a lightweight leaf package (deps: enr, multiaddr,
messaging/types only) so params does not pull in the go-waku runtime.

Part of pm#380 / status-go#7589 (Phase 2a).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-02 11:33:05 +01:00

72 lines
1.9 KiB
Go

package params
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestLoadPushFleetsFromFile tests the loadPushFleetsFromFile function.
func TestLoadPushFleetsFromFile(t *testing.T) {
t.Run("valid file", func(t *testing.T) {
// Arrange: Create a temporary valid JSON file.
tempFile, err := os.CreateTemp("", "fleets*.json")
require.NoError(t, err)
defer os.Remove(tempFile.Name())
// Write valid JSON data into the temp file.
validFleets := []string{
// There's no public key validation at this stage, so we can use any string.
gofakeit.LetterN(5),
gofakeit.LetterN(5),
gofakeit.LetterN(5),
}
err = json.NewEncoder(tempFile).Encode(validFleets)
require.NoError(t, err)
err = tempFile.Close()
require.NoError(t, err)
// Act: Call the function.
result, err := loadPushFleetsFromFile(tempFile.Name())
// Assert: Check the error.
require.NoError(t, err)
assert.Equal(t, validFleets, result)
})
t.Run("missing file", func(t *testing.T) {
// Arrange: Use a non-existent file path.
nonExistentFile := filepath.Join(os.TempDir(), "non_existent_file.json")
// Act: Call the function.
_, err := loadPushFleetsFromFile(nonExistentFile)
// Assert: Check the error.
require.Error(t, err)
require.ErrorIs(t, err, os.ErrNotExist)
})
t.Run("malformed JSON", func(t *testing.T) {
// Arrange: Create a temporary file with invalid JSON.
tempFile, err := os.CreateTemp("", "malformed*.json")
require.NoError(t, err)
defer os.Remove(tempFile.Name())
_, err = tempFile.WriteString("{ invalid json }")
require.NoError(t, err)
tempFile.Close()
// Act: Call the function.
_, err = loadPushFleetsFromFile(tempFile.Name())
// Assert: Check the error.
require.Error(t, err)
require.ErrorContains(t, err, "invalid character") // Match JSON parsing error.
})
}