Browse Source

fix addrbook tests (#4526)

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
Co-authored-by: Erik Grinaker <erik@grinaker.org>
pull/4533/head
mergify[bot] 5 years ago
committed by GitHub
parent
commit
632b53d653
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 15 deletions
  1. +11
    -15
      p2p/pex/addrbook_test.go

+ 11
- 15
p2p/pex/addrbook_test.go View File

@ -60,15 +60,15 @@ func TestAddrBookSaveLoad(t *testing.T) {
defer deleteTempFile(fname) defer deleteTempFile(fname)
// 0 addresses // 0 addresses
book := NewAddrBook(fname, true).(*addrBook)
book := NewAddrBook(fname, true)
book.SetLogger(log.TestingLogger()) book.SetLogger(log.TestingLogger())
book.saveToFile(fname)
book.Save()
book = NewAddrBook(fname, true).(*addrBook)
book = NewAddrBook(fname, true)
book.SetLogger(log.TestingLogger()) book.SetLogger(log.TestingLogger())
book.loadFromFile(fname)
book.Start()
assert.Zero(t, book.Size())
assert.True(t, book.Empty())
// 100 addresses // 100 addresses
randAddrs := randNetAddressPairs(t, 100) randAddrs := randNetAddressPairs(t, 100)
@ -78,11 +78,11 @@ func TestAddrBookSaveLoad(t *testing.T) {
} }
assert.Equal(t, 100, book.Size()) assert.Equal(t, 100, book.Size())
book.saveToFile(fname)
book.Save()
book = NewAddrBook(fname, true).(*addrBook)
book = NewAddrBook(fname, true)
book.SetLogger(log.TestingLogger()) book.SetLogger(log.TestingLogger())
book.loadFromFile(fname)
book.Start()
assert.Equal(t, 100, book.Size()) assert.Equal(t, 100, book.Size())
} }
@ -93,19 +93,15 @@ func TestAddrBookLookup(t *testing.T) {
randAddrs := randNetAddressPairs(t, 100) randAddrs := randNetAddressPairs(t, 100)
book := NewAddrBook(fname, true).(*addrBook)
book := NewAddrBook(fname, true)
book.SetLogger(log.TestingLogger()) book.SetLogger(log.TestingLogger())
for _, addrSrc := range randAddrs { for _, addrSrc := range randAddrs {
addr := addrSrc.addr addr := addrSrc.addr
src := addrSrc.src src := addrSrc.src
book.AddAddress(addr, src) book.AddAddress(addr, src)
ka := book.addrLookup[addr.ID]
assert.NotNil(t, ka, "Expected to find KnownAddress %v but wasn't there.", addr)
if !(ka.Addr.Equals(addr) && ka.Src.Equals(src)) {
t.Fatalf("KnownAddress doesn't match addr & src")
}
ka := book.HasAddress(addr)
assert.True(t, ka, "Expected to find KnownAddress %v but wasn't there.", addr)
} }
} }


Loading…
Cancel
Save