package peer

import (
	"net/netip"
	"testing"
	"time"
)

func TestPubAddrStore(t *testing.T) {
	s := newPubAddrStore(netip.AddrPort{})

	l := []netip.AddrPort{
		netip.AddrPortFrom(netip.AddrFrom4([4]byte{0, 1, 2, 3}), 20),
		netip.AddrPortFrom(netip.AddrFrom4([4]byte{1, 1, 2, 3}), 21),
		netip.AddrPortFrom(netip.AddrFrom4([4]byte{2, 1, 2, 3}), 22),
	}

	for i := range l {
		s.Store(l[i])
		time.Sleep(time.Millisecond)
	}

	s.clean()

	l2 := s.Get()
	if l2[0] != l[2] || l2[1] != l[1] || l2[2] != l[0] {
		t.Fatal(l, l2)
	}
}
