Skip to content

Commit

Permalink
test(direct-peers): ensure correct configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Mar 21, 2024
1 parent 76741d7 commit 7735e87
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@

import static org.assertj.core.api.Assertions.assertThat;

import io.libp2p.core.multiformats.Multiaddr;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.networking.p2p.gossip.config.GossipPeerScoringConfig.DirectPeerManager;
import tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId;
import tech.pegasys.teku.networking.p2p.peer.NodeId;

@SuppressWarnings("AddressSelection")
class NetworkConfigTest {
Expand Down Expand Up @@ -75,4 +80,32 @@ void checkPrivateKeySourceCreatedCorrectly() {
private NetworkConfig createConfig() {
return NetworkConfig.builder().advertisedIp(advertisedIp).networkInterface(listenIp).build();
}

@Test
void checkDirectPeersConfigCreatedCorrectly() {
final String peerAddress1 =
"/ip4/198.51.100.0/tcp/4242/p2p/QmYyQSo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjhx5N";
final String peerAddress2 =
"/ip4/198.51.100.0/tcp/4242/p2p/QmTESTo1c1Ym7orWxLYvCrM2EmxFTANf8wXmmE7DWjTEST";
final LibP2PNodeId peerId1 = new LibP2PNodeId(new Multiaddr(peerAddress1).getPeerId());
final LibP2PNodeId peerId2 = new LibP2PNodeId(new Multiaddr(peerAddress2).getPeerId());

final List<NodeId> directPeers = List.of(peerId1);

final NetworkConfig config =
NetworkConfig.builder()
.advertisedIp(advertisedIp)
.networkInterface(listenIp)
.directPeers(directPeers)
.build();

final Optional<DirectPeerManager> optionalDirectPeerManager =
config.getGossipConfig().getScoringConfig().getPeerScoringConfig().getDirectPeerManager();
assertThat(optionalDirectPeerManager).isPresent();

final DirectPeerManager manager = optionalDirectPeerManager.get();

assert manager.isDirectPeer(peerId1);
assert !manager.isDirectPeer(peerId2);
}
}

0 comments on commit 7735e87

Please sign in to comment.