mirror of
https://github.com/luxfi/const.git
synced 2026-10-30 16:59:18 +00:00
LocalHRP = "local" → network ID 1337 (--local 5-node, --dev single node) CustomHRP = "custom" → any unknown network ID (fallback for GetHRP) These are NOT aliases. Local is the known dev network. Custom is anything else. Also fixed: - GetHRP fallback returns CustomHRP for unknown IDs - server.go: "custom" is deprecated alias for "local" (was backwards) - Tests updated to reflect correct mapping
135 lines
2.1 KiB
Go
135 lines
2.1 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package constants
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetHRP(t *testing.T) {
|
|
tests := []struct {
|
|
id uint32
|
|
hrp string
|
|
}{
|
|
{
|
|
id: MainnetID,
|
|
hrp: MainnetHRP,
|
|
},
|
|
{
|
|
id: TestnetID,
|
|
hrp: TestnetHRP,
|
|
},
|
|
{
|
|
id: TestnetID,
|
|
hrp: TestnetHRP,
|
|
},
|
|
{
|
|
id: LocalID,
|
|
hrp: LocalHRP, // 1337 → "local"
|
|
},
|
|
{
|
|
id: 4294967295,
|
|
hrp: CustomHRP, // unknown → "custom"
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.hrp, func(t *testing.T) {
|
|
require.Equal(t, test.hrp, GetHRP(test.id))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNetworkName(t *testing.T) {
|
|
tests := []struct {
|
|
id uint32
|
|
name string
|
|
}{
|
|
{
|
|
id: MainnetID,
|
|
name: MainnetName,
|
|
},
|
|
{
|
|
id: TestnetID,
|
|
name: TestnetName,
|
|
},
|
|
{
|
|
id: TestnetID,
|
|
name: TestnetName,
|
|
},
|
|
{
|
|
id: LocalID,
|
|
name: LocalName,
|
|
},
|
|
{
|
|
id: 4294967295,
|
|
name: "network-4294967295",
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
require.Equal(t, test.name, NetworkName(test.id))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNetworkID(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
id uint32
|
|
expectedErr error
|
|
}{
|
|
{
|
|
name: MainnetName,
|
|
id: MainnetID,
|
|
},
|
|
{
|
|
name: "MaInNeT",
|
|
id: MainnetID,
|
|
},
|
|
{
|
|
name: TestnetName,
|
|
id: TestnetID,
|
|
},
|
|
{
|
|
name: TestnetName,
|
|
id: TestnetID,
|
|
},
|
|
{
|
|
name: LocalName,
|
|
id: LocalID,
|
|
},
|
|
{
|
|
name: "network-4294967295",
|
|
id: 4294967295,
|
|
},
|
|
{
|
|
name: "4294967295",
|
|
id: 4294967295,
|
|
},
|
|
{
|
|
name: "networ-4294967295",
|
|
expectedErr: ErrParseNetworkName,
|
|
},
|
|
{
|
|
name: "network-4294967295123123",
|
|
expectedErr: ErrParseNetworkName,
|
|
},
|
|
{
|
|
name: "4294967295123123",
|
|
expectedErr: ErrParseNetworkName,
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
id, err := NetworkID(test.name)
|
|
require.ErrorIs(err, test.expectedErr)
|
|
require.Equal(test.id, id)
|
|
})
|
|
}
|
|
}
|