mirror of
https://github.com/luxfi/p2p.git
synced 2026-10-30 15:22:55 +00:00
github.com/luxfi/utils is now github.com/luxfi/util. Import paths and the module requirement follow the rename. Co-authored-by: Hanzo Dev <[email protected]>
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package peer
|
|
|
|
import (
|
|
"crypto"
|
|
"net/netip"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/crypto/bls/signer/localsigner"
|
|
luxtls "github.com/luxfi/tls"
|
|
"github.com/luxfi/util"
|
|
)
|
|
|
|
func TestIPSigner(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
dynIP := utils.NewAtomic(netip.AddrPortFrom(
|
|
netip.IPv6Loopback(),
|
|
0,
|
|
))
|
|
|
|
tlsCert, err := luxtls.NewTLSCert()
|
|
require.NoError(err)
|
|
|
|
tlsKey := tlsCert.PrivateKey.(crypto.Signer)
|
|
blsSigner, err := localsigner.New()
|
|
require.NoError(err)
|
|
|
|
s := NewIPSigner(dynIP, tlsKey, blsSigner)
|
|
|
|
s.clock.Set(time.Unix(10, 0))
|
|
|
|
signedIP1, err := s.GetSignedIP()
|
|
require.NoError(err)
|
|
require.Equal(dynIP.Get(), signedIP1.AddrPort)
|
|
require.Equal(uint64(10), signedIP1.Timestamp)
|
|
|
|
s.clock.Set(time.Unix(11, 0))
|
|
|
|
signedIP2, err := s.GetSignedIP()
|
|
require.NoError(err)
|
|
require.Equal(dynIP.Get(), signedIP2.AddrPort)
|
|
require.Equal(uint64(10), signedIP2.Timestamp)
|
|
require.Equal(signedIP1.TLSSignature, signedIP2.TLSSignature)
|
|
|
|
dynIP.Set(netip.AddrPortFrom(
|
|
netip.AddrFrom4([4]byte{1, 2, 3, 4}),
|
|
dynIP.Get().Port(),
|
|
))
|
|
|
|
signedIP3, err := s.GetSignedIP()
|
|
require.NoError(err)
|
|
require.Equal(dynIP.Get(), signedIP3.AddrPort)
|
|
require.Equal(uint64(11), signedIP3.Timestamp)
|
|
require.NotEqual(signedIP2.TLSSignature, signedIP3.TLSSignature)
|
|
}
|