Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test of IsGood() #487

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions p2p/pex/addrbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,30 @@ func TestAddrBookRemoveAddress(t *testing.T) {
assert.Equal(t, 0, book.Size())
}

func TestAddrBookIsGood(t *testing.T) {
fname := createTempFileName("addrbook_test")
defer deleteTempFile(fname)

book := NewAddrBook(fname, true).(*addrBook)
book.SetLogger(log.TestingLogger())
assert.Zero(t, book.Size())

randAddrGood := netAddressPair{addr: randIPv4Address(t), src: randIPv4Address(t)}
err := book.AddAddress(randAddrGood.addr, randAddrGood.src)
require.NoError(t, err)
book.MarkGood(randAddrGood.addr.ID)

randAddrNew := netAddressPair{addr: randIPv4Address(t), src: randIPv4Address(t)}
err = book.AddAddress(randAddrNew.addr, randAddrNew.src)
require.NoError(t, err)

randAddrUnknown := netAddressPair{addr: randIPv4Address(t), src: randIPv4Address(t)}

assert.Equal(t, true, book.IsGood(randAddrGood.addr))
assert.Equal(t, false, book.IsGood(randAddrNew.addr))
assert.Equal(t, false, book.IsGood(randAddrUnknown.addr))
}

func TestAddrBookGetSelectionWithOneMarkedGood(t *testing.T) {
// create a book with 10 addresses, 1 good/old and 9 new
book, fname := createAddrBookWithMOldAndNNewAddrs(t, 1, 9)
Expand Down