Skip to content

Commit

Permalink
Add test to check that old address is removed from peerstore
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Sep 27, 2023
1 parent 1bc90f6 commit 07c2bf5
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions dagsync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dagsync_test

import (
"context"
"path"
"testing"
"time"

Expand All @@ -17,6 +18,7 @@ import (
"github.com/ipni/go-libipni/dagsync/ipnisync"
"github.com/ipni/go-libipni/dagsync/test"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -399,6 +401,49 @@ func TestSyncOnAnnounceDataTransfer(t *testing.T) {
announceTest(t, pub, sub, dstStore, watcher, pubInfo, chainLnks[0])
}

func TestUpdatePeerstoreAddr(t *testing.T) {
dstStore := dssync.MutexWrap(datastore.NewMapDatastore())
dstHost := test.MkTestHost(t)
dstLnkS := test.MkLinkSystem(dstStore)

sub, err := dagsync.NewSubscriber(dstHost, dstStore, dstLnkS, testTopic,
dagsync.RecvAnnounce(), dagsync.StrictAdsSelector(false))
require.NoError(t, err)
defer sub.Close()

watcher, cncl := sub.OnSyncFinished()
defer cncl()

srcHost := test.MkTestHost(t)
srcStore := dssync.MutexWrap(datastore.NewMapDatastore())
srcLnkS := test.MkLinkSystem(srcStore)
pub, err := dtsync.NewPublisher(srcHost, srcStore, srcLnkS, testTopic)
require.NoError(t, err)
defer pub.Close()
require.NoError(t, test.WaitForP2PPublisher(pub, dstHost, testTopic))

srcHost.Peerstore().AddAddrs(dstHost.ID(), dstHost.Addrs(), time.Hour)
dstHost.Peerstore().AddAddrs(srcHost.ID(), srcHost.Addrs(), time.Hour)

// Store the whole chain in source node
chainLnks := test.MkChain(srcLnkS, true)

pubInfo := peer.AddrInfo{
ID: pub.ID(),
Addrs: pub.Addrs(),
}

announceTest(t, pub, sub, dstStore, watcher, pubInfo, chainLnks[2])
require.Equal(t, pubInfo.Addrs, dstHost.Peerstore().Addrs(pub.ID()))

// Update publisher address, sync, and check that peerstore matches.
maddr, err := multiaddr.NewMultiaddr("/dns4/localhost/tcp/" + path.Base(pub.Addrs()[0].String()))
require.NoError(t, err)
pubInfo.Addrs = []multiaddr.Multiaddr{maddr}
announceTest(t, pub, sub, dstStore, watcher, pubInfo, chainLnks[1])
require.Equal(t, pubInfo.Addrs, dstHost.Peerstore().Addrs(pub.ID()))
}

func TestSyncOnAnnounceIPNI(t *testing.T) {
dstStore := dssync.MutexWrap(datastore.NewMapDatastore())
dstHost := test.MkTestHost(t)
Expand Down

0 comments on commit 07c2bf5

Please sign in to comment.