Search in sources :

Example 1 with EnrForkId

use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId in project teku by ConsenSys.

the class NodeRecordConverterTest method shouldConvertEnrForkId.

@Test
public void shouldConvertEnrForkId() {
    EnrForkId enrForkId = new DataStructureUtil().randomEnrForkId();
    Bytes encodedForkId = enrForkId.sszSerialize();
    final Optional<DiscoveryPeer> result = convertNodeRecordWithFields(new EnrField(EnrField.IP_V6, IPV6_LOCALHOST), new EnrField(EnrField.TCP_V6, 1234), new EnrField(ETH2_ENR_FIELD, encodedForkId));
    assertThat(result).contains(new DiscoveryPeer(PUB_KEY, new InetSocketAddress("::1", 1234), Optional.of(enrForkId), ATTNETS, SYNCNETS));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) DiscoveryPeer(tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer) EnrField(org.ethereum.beacon.discovery.schema.EnrField) InetSocketAddress(java.net.InetSocketAddress) EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 2 with EnrForkId

use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId in project teku by ConsenSys.

the class DiscoveryNetworkTest method setForkInfo_noFutureForkScheduled.

@Test
public void setForkInfo_noFutureForkScheduled() {
    discoveryNetwork.setForkInfo(currentForkInfo, Optional.empty());
    final EnrForkId expectedEnrForkId = new EnrForkId(currentForkInfo.getForkDigest(spec), currentForkInfo.getFork().getCurrent_version(), SpecConfig.FAR_FUTURE_EPOCH);
    verify(discoveryService).updateCustomENRField("eth2", expectedEnrForkId.sszSerialize());
}
Also used : EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) Test(org.junit.jupiter.api.Test)

Example 3 with EnrForkId

use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId in project teku by ConsenSys.

the class DiscoveryNetworkTest method setForkInfo_futureForkScheduled.

@Test
public void setForkInfo_futureForkScheduled() {
    discoveryNetwork.setForkInfo(currentForkInfo, Optional.of(nextFork));
    final EnrForkId expectedEnrForkId = new EnrForkId(currentForkInfo.getForkDigest(spec), nextFork.getCurrent_version(), nextFork.getEpoch());
    verify(discoveryService).updateCustomENRField("eth2", expectedEnrForkId.sszSerialize());
}
Also used : EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) Test(org.junit.jupiter.api.Test)

Example 4 with EnrForkId

use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId in project teku by ConsenSys.

the class DiscoveryNetworkTest method setForkInfoAtInitialization.

@Test
public void setForkInfoAtInitialization() {
    final SpecVersion genesisSpec = spec.getGenesisSpec();
    final Bytes4 genesisForkVersion = genesisSpec.getConfig().getGenesisForkVersion();
    final EnrForkId enrForkId = new EnrForkId(genesisSpec.miscHelpers().computeForkDigest(genesisForkVersion, Bytes32.ZERO), genesisForkVersion, SpecConfig.FAR_FUTURE_EPOCH);
    verify(discoveryService).updateCustomENRField("eth2", enrForkId.sszSerialize());
}
Also used : SpecVersion(tech.pegasys.teku.spec.SpecVersion) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) Test(org.junit.jupiter.api.Test)

Example 5 with EnrForkId

use of tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId in project teku by ConsenSys.

the class DiscoveryNetworkTest method shouldNotConnectToPeersWhenNodeHasNoEnrForkId.

@Test
@SuppressWarnings("unchecked")
public void shouldNotConnectToPeersWhenNodeHasNoEnrForkId() {
    final EnrForkId enrForkId = new EnrForkId(currentForkInfo.getForkDigest(spec), currentForkInfo.getFork().getCurrent_version(), SpecConfig.FAR_FUTURE_EPOCH);
    ArgumentCaptor<Predicate<DiscoveryPeer>> peerPredicateArgumentCaptor = ArgumentCaptor.forClass(Predicate.class);
    verify(connectionManager).addPeerPredicate(peerPredicateArgumentCaptor.capture());
    DiscoveryPeer peer1 = createDiscoveryPeer(Optional.of(enrForkId));
    assertThat(peerPredicateArgumentCaptor.getValue().test(peer1)).isFalse();
}
Also used : EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) Predicate(java.util.function.Predicate) Test(org.junit.jupiter.api.Test)

Aggregations

EnrForkId (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId)10 Test (org.junit.jupiter.api.Test)7 Bytes (org.apache.tuweni.bytes.Bytes)5 Predicate (java.util.function.Predicate)3 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)3 DiscoveryPeer (tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer)2 SpecVersion (tech.pegasys.teku.spec.SpecVersion)2 InetSocketAddress (java.net.InetSocketAddress)1 EnrField (org.ethereum.beacon.discovery.schema.EnrField)1 SszBitvector (tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)1