mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
addrmgr: Test timestamp update during AddAddress()
Test for codepath that adds the same address twice and is supposed to update the timestamp.
This commit is contained in:
parent
5c2768047d
commit
dfee810f04
@ -175,7 +175,46 @@ func TestAddAddressByIP(t *testing.T) {
|
||||
amgr = New(dir, nil)
|
||||
amgr.Start()
|
||||
if ka := amgr.GetAddress(); ka == nil {
|
||||
t.Fatalf("Address Manager should contain known address")
|
||||
t.Errorf("Address Manager should contain known address")
|
||||
}
|
||||
if err := amgr.Stop(); err != nil {
|
||||
t.Fatalf("Address Manager failed to stop: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddAddressUpdate(t *testing.T) {
|
||||
amgr := New("testaddaddressupdate", nil)
|
||||
amgr.Start()
|
||||
if ka := amgr.GetAddress(); ka != nil {
|
||||
t.Fatalf("Address Manager should contain no address")
|
||||
}
|
||||
ip := net.ParseIP(someIP)
|
||||
if ip == nil {
|
||||
t.Fatalf("Invalid IP address %s", someIP)
|
||||
}
|
||||
na := wire.NewNetAddressIPPort(ip, 8333, 0)
|
||||
amgr.AddAddress(na, na)
|
||||
ka := amgr.GetAddress()
|
||||
if ka == nil {
|
||||
t.Errorf("Address Manager should contain known address")
|
||||
}
|
||||
if !reflect.DeepEqual(ka.NetAddress(), na) {
|
||||
t.Errorf("Address Manager should contain address that was added")
|
||||
}
|
||||
// add address again, but with different time stamp (to trigger update)
|
||||
ts := na.Timestamp.Add(time.Second)
|
||||
na.Timestamp = ts
|
||||
amgr.AddAddress(na, na)
|
||||
// address should be in there
|
||||
ka = amgr.GetAddress()
|
||||
if ka == nil {
|
||||
t.Errorf("Address Manager should contain known address")
|
||||
}
|
||||
if !reflect.DeepEqual(ka.NetAddress(), na) {
|
||||
t.Errorf("Address Manager should contain address that was added")
|
||||
}
|
||||
if !ka.NetAddress().Timestamp.Equal(ts) {
|
||||
t.Errorf("Address Manager did not update timestamp")
|
||||
}
|
||||
if err := amgr.Stop(); err != nil {
|
||||
t.Fatalf("Address Manager failed to stop: %v", err)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user