Skip to content

Commit

Permalink
Fixup itest net tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Jul 7, 2022
1 parent edd06e8 commit dde1ddc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
1 change: 0 additions & 1 deletion itests/kit/ensemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ func (n *Ensemble) Start() *Ensemble {
node.FullAPI(&full.FullNode, node.Lite(full.options.lite)),
node.Base(),
node.Repo(r),
node.MockHost(n.mn),
node.Test(),

// so that we subscribe to pubsub topics immediately
Expand Down
75 changes: 49 additions & 26 deletions itests/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ func TestNetConn(t *testing.T) {
t.Errorf("agents not matching. %s", err.Error())
}

//stm: @NETWORK_COMMON_BANDWIDTH_STATS_001
bandwidth, err := secondNode.NetBandwidthStats(ctx)
require.NoError(t, err)

//stm: @NETWORK_COMMON_BANDWIDTH_STATS_BY_PEER_001
peerBandwidths, err := firstNode.NetBandwidthStatsByPeer(ctx)
require.NoError(t, err)

if peerBandwidths[secondNodeID.String()] != bandwidth {
t.Errorf("bandwidths differ")
}

//stm: @NETWORK_COMMON_FIND_PEER_001
secondNodePeer, err := firstNode.NetFindPeer(ctx, secondNodeID)
require.NoError(t, err)
Expand All @@ -81,10 +69,7 @@ func TestNetConn(t *testing.T) {
//stm: @NETWORK_COMMON_PEERS_001
addrs, err := firstNode.NetPeers(ctx)
require.NoError(t, err)

if len(addrs) > 0 {
t.Errorf("connected peer does not exist in network")
}
require.NotEqual(t, 0, len(addrs))

//stm: @NETWORK_COMMON_DISCONNECT_001
err = firstNode.NetDisconnect(ctx, secondNodeID)
Expand Down Expand Up @@ -170,13 +155,19 @@ func TestNetLimit(t *testing.T) {
func TestNetBlockPeer(t *testing.T) {
ctx := context.Background()

firstNode, secondNode, _, ens := kit.EnsembleTwoOne(t)
ens.InterconnectAll()
firstNode, secondNode, _, _ := kit.EnsembleTwoOne(t)

//stm: @NETWORK_COMMON_ID_001
firstAddrInfo, _ := firstNode.NetAddrsListen(ctx)
firstNodeID, err := firstNode.ID(ctx)
secondNodeID, err := secondNode.ID(ctx)
require.NoError(t, err)

// Sanity check that we're not already connected somehow
connectedness, err := secondNode.NetConnectedness(ctx, firstNodeID)
require.NoError(t, err, "failed to determine connectedness")
require.NotEqual(t, connectedness, network.Connected, "shouldn't already be connected")

//stm: @NETWORK_COMMON_BLOCK_ADD_001
err = firstNode.NetBlockAdd(ctx, api.NetBlockList{Peers: []peer.ID{secondNodeID}})
require.NoError(t, err)
Expand All @@ -189,6 +180,11 @@ func TestNetBlockPeer(t *testing.T) {
t.Errorf("blocked peer not in blocked peer list")
}

require.Error(t, secondNode.NetConnect(ctx, firstAddrInfo), "failed to connect to second node")
connectedness, err = secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.NotEqual(t, connectedness, network.Connected)

//stm: @NETWORK_COMMON_BLOCK_REMOVE_001
err = firstNode.NetBlockRemove(ctx, api.NetBlockList{Peers: []peer.ID{secondNodeID}})
require.NoError(t, err)
Expand All @@ -201,39 +197,62 @@ func TestNetBlockPeer(t *testing.T) {
t.Errorf("failed to remove blocked peer from blocked peer list")
}

require.NoError(t, secondNode.NetConnect(ctx, firstAddrInfo), "failed to connect to second node")
connectedness, err = secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.Equal(t, connectedness, network.Connected)
}

func TestNetBlockIPAddr(t *testing.T) {
ctx := context.Background()

firstNode, secondNode, _, ens := kit.EnsembleTwoOne(t)
ens.InterconnectAll()
firstNode, secondNode, _, _ := kit.EnsembleTwoOne(t)

//stm: @NETWORK_COMMON_ADDRS_LISTEN_001
addrInfo, _ := secondNode.NetAddrsListen(ctx)
firstAddrInfo, _ := firstNode.NetAddrsListen(ctx)
secondAddrInfo, _ := secondNode.NetAddrsListen(ctx)

var secondNodeIPs []string

for _, addr := range addrInfo.Addrs {
for _, addr := range secondAddrInfo.Addrs {
ip, err := manet.ToIP(addr)
if err != nil {
continue
}
secondNodeIPs = append(secondNodeIPs, ip.String())
}

// Sanity check that we're not already connected somehow
connectedness, err := secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.NotEqual(t, connectedness, network.Connected, "shouldn't already be connected")

//stm: @NETWORK_COMMON_BLOCK_ADD_001
err := firstNode.NetBlockAdd(ctx, api.NetBlockList{IPAddrs: secondNodeIPs})
require.NoError(t, err)
require.NoError(t, firstNode.NetBlockAdd(ctx, api.NetBlockList{
IPAddrs: secondNodeIPs}), "failed to add blocked IPs")

//stm: @NETWORK_COMMON_BLOCK_LIST_001
list, err := firstNode.NetBlockList(ctx)
require.NoError(t, err)

if len(list.IPAddrs) == 0 || list.IPAddrs[0] != secondNodeIPs[0] {
t.Errorf("blocked ip not in blocked ip list")
require.Equal(t, len(list.IPAddrs), len(secondNodeIPs), "expected %d blocked IPs", len(secondNodeIPs))
for _, blockedIP := range list.IPAddrs {
found := false
for _, secondNodeIP := range secondNodeIPs {
if blockedIP == secondNodeIP {
found = true
break
}
}

require.True(t, found, "blocked IP %s is not one of secondNodeIPs", blockedIP)
}

require.Error(t, secondNode.NetConnect(ctx, firstAddrInfo), "failed to connect to second node")
connectedness, err = secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.NotEqual(t, connectedness, network.Connected)

//stm: @NETWORK_COMMON_BLOCK_REMOVE_001
err = firstNode.NetBlockRemove(ctx, api.NetBlockList{IPAddrs: secondNodeIPs})
require.NoError(t, err)
Expand All @@ -246,6 +265,10 @@ func TestNetBlockIPAddr(t *testing.T) {
t.Errorf("failed to remove blocked ip from blocked ip list")
}

require.NoError(t, secondNode.NetConnect(ctx, firstAddrInfo), "failed to connect to second node")
connectedness, err = secondNode.NetConnectedness(ctx, firstAddrInfo.ID)
require.NoError(t, err, "failed to determine connectedness")
require.Equal(t, connectedness, network.Connected)
}

func getConnState(ctx context.Context, t *testing.T, node *kit.TestFullNode, peer peer.ID) network.Connectedness {
Expand Down

0 comments on commit dde1ddc

Please sign in to comment.