Files
crypto/utils/constants/network_ids_test.go
T
Hanzo Dev 0be2fe8f6c crypto: implement post-quantum primitives with circl
- Implement ML-DSA-65 (FIPS 204) using cloudflare/circl
  * Single implementation with automatic CGO optimization
  * Sign ~440μs, Verify ~130μs, KeyGen ~165μs on M1 Max
  * All 11 tests passing

- Simplify ML-KEM implementation
  * Remove redundant optimized versions
  * Use circl ML-KEM-768 directly

- Simplify SLH-DSA implementation
  * Remove premature optimizations
  * Clean stub for future circl support (FIPS 205)

- Add comprehensive cache package
  * LRU cache from luxfi/node
  * Metercacher for metrics integration
  * Test utilities

- Add crypto utils
  * Atomic operations
  * Bytes utilities
  * Complete utils package from luxfi/node

- Update secp256k1 and BLS
  * All BLS tests passing (23 tests)
  * secp256k1 fuzz test added

All post-quantum implementations now use cloudflare/circl as single source
of truth, following DRY principle and ensuring FIPS compliance.
2025-11-22 16:37:21 -08:00

135 lines
2.0 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,
},
{
id: 4294967295,
hrp: FallbackHRP,
},
}
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)
})
}
}