Search in sources :

Example 1 with MetadataMessage

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

the class GetIdentityIntegrationTest method shouldReturnNetworkIdentityAltair.

@Test
public void shouldReturnNetworkIdentityAltair() throws Exception {
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final MetadataMessage metadataMessage = spec.getGenesisSchemaDefinitions().getMetadataMessageSchema().create(seqnr, List.of(1, 11, 15), List.of(0, 1, 2, 3));
    when(eth2P2PNetwork.getMetadata()).thenReturn(metadataMessage);
    final Response response = get();
    assertThat(response.code()).isEqualTo(SC_OK);
    final IdentityResponse identityResponse = jsonProvider.jsonToObject(response.body().string(), IdentityResponse.class);
    assertThat(identityResponse.data).isEqualTo(new Identity(node1.toBase58(), enr, List.of(address), List.of(discoveryAddress), new Metadata(metadataMessage)));
}
Also used : IdentityResponse(tech.pegasys.teku.api.response.v1.node.IdentityResponse) Response(okhttp3.Response) MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) IdentityResponse(tech.pegasys.teku.api.response.v1.node.IdentityResponse) Metadata(tech.pegasys.teku.api.schema.Metadata) Identity(tech.pegasys.teku.api.response.v1.node.Identity) GetIdentity(tech.pegasys.teku.beaconrestapi.handlers.v1.node.GetIdentity) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with MetadataMessage

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

the class GetIdentityIntegrationTest method shouldReturnNetworkIdentity.

@Test
public void shouldReturnNetworkIdentity() throws Exception {
    startRestAPIAtGenesis();
    final MetadataMessage metadataMessage = spec.getGenesisSchemaDefinitions().getMetadataMessageSchema().create(seqnr, List.of(1, 11, 15), Collections.emptyList());
    when(eth2P2PNetwork.getMetadata()).thenReturn(metadataMessage);
    final Response response = get();
    assertThat(response.code()).isEqualTo(SC_OK);
    final IdentityResponse identityResponse = jsonProvider.jsonToObject(response.body().string(), IdentityResponse.class);
    assertThat(identityResponse.data).isEqualTo(new Identity(node1.toBase58(), enr, List.of(address), List.of(discoveryAddress), new Metadata(metadataMessage)));
}
Also used : IdentityResponse(tech.pegasys.teku.api.response.v1.node.IdentityResponse) Response(okhttp3.Response) MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) IdentityResponse(tech.pegasys.teku.api.response.v1.node.IdentityResponse) Metadata(tech.pegasys.teku.api.schema.Metadata) Identity(tech.pegasys.teku.api.response.v1.node.Identity) GetIdentity(tech.pegasys.teku.beaconrestapi.handlers.v1.node.GetIdentity) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 3 with MetadataMessage

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

the class GetIdentityTest method shouldReturnExpectedObjectType.

@Test
public void shouldReturnExpectedObjectType() throws Exception {
    final MetadataMessage defaultMetadata = spec.getGenesisSchemaDefinitions().getMetadataMessageSchema().createDefault();
    GetIdentity handler = new GetIdentity(network, jsonProvider);
    NodeId nodeid = mock(NodeId.class);
    when(eth2P2PNetwork.getMetadata()).thenReturn(defaultMetadata);
    when(eth2P2PNetwork.getNodeId()).thenReturn(nodeid);
    when(nodeid.toBase58()).thenReturn("aeiou");
    when(eth2P2PNetwork.getNodeAddress()).thenReturn("address");
    handler.handle(context);
    verifyCacheStatus(CACHE_NONE);
    IdentityResponse response = getResponseObject(IdentityResponse.class);
    assertThat(response.data.peerId).isEqualTo("aeiou");
    assertThat(response.data.p2pAddresses.get(0)).isEqualTo("address");
}
Also used : MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) IdentityResponse(tech.pegasys.teku.api.response.v1.node.IdentityResponse) NodeId(tech.pegasys.teku.networking.p2p.peer.NodeId) Test(org.junit.jupiter.api.Test) AbstractBeaconHandlerTest(tech.pegasys.teku.beaconrestapi.AbstractBeaconHandlerTest)

Example 4 with MetadataMessage

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

the class BeaconChainMethods method createMetadata.

private static Eth2RpcMethod<EmptyMessage, MetadataMessage> createMetadata(final Spec spec, final AsyncRunner asyncRunner, final MetadataMessagesFactory metadataMessagesFactory, final PeerLookup peerLookup, final RpcEncoding rpcEncoding) {
    final MetadataMessageHandler messageHandler = new MetadataMessageHandler(spec, metadataMessagesFactory);
    final EmptyMessageSchema requestType = EmptyMessage.SSZ_SCHEMA;
    final boolean expectResponse = true;
    final SszSchema<MetadataMessage> phase0MetadataSchema = SszSchema.as(MetadataMessage.class, spec.forMilestone(SpecMilestone.PHASE0).getSchemaDefinitions().getMetadataMessageSchema());
    final RpcContextCodec<?, MetadataMessage> phase0ContextCodec = RpcContextCodec.noop(phase0MetadataSchema);
    final SingleProtocolEth2RpcMethod<EmptyMessage, MetadataMessage> v1Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.GET_METADATA, 1, rpcEncoding, requestType, expectResponse, phase0ContextCodec, messageHandler, peerLookup);
    if (spec.isMilestoneSupported(SpecMilestone.ALTAIR)) {
        final SszSchema<MetadataMessage> altairMetadataSchema = SszSchema.as(MetadataMessage.class, spec.forMilestone(SpecMilestone.ALTAIR).getSchemaDefinitions().getMetadataMessageSchema());
        final RpcContextCodec<?, MetadataMessage> altairContextCodec = RpcContextCodec.noop(altairMetadataSchema);
        final SingleProtocolEth2RpcMethod<EmptyMessage, MetadataMessage> v2Method = new SingleProtocolEth2RpcMethod<>(asyncRunner, BeaconChainMethodIds.GET_METADATA, 2, rpcEncoding, requestType, expectResponse, altairContextCodec, messageHandler, peerLookup);
        return VersionedEth2RpcMethod.create(rpcEncoding, requestType, expectResponse, List.of(v2Method, v1Method));
    } else {
        return v1Method;
    }
}
Also used : MetadataMessageHandler(tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessageHandler) SingleProtocolEth2RpcMethod(tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod) MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) EmptyMessageSchema(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage.EmptyMessageSchema) EmptyMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage)

Example 5 with MetadataMessage

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

the class MetadataMessageTest method shouldDeserializeFromSsz.

@Test
public void shouldDeserializeFromSsz() {
    MetadataMessage result = PHASE0_SCHEMA.sszDeserialize(EXPECTED_SSZ);
    assertThatSszData(result).isEqualByAllMeansTo(MESSAGE);
}
Also used : MetadataMessage(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage) Test(org.junit.jupiter.api.Test)

Aggregations

MetadataMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.MetadataMessage)10 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Eth2Peer (tech.pegasys.teku.networking.eth2.peers.Eth2Peer)4 IdentityResponse (tech.pegasys.teku.api.response.v1.node.IdentityResponse)3 Response (okhttp3.Response)2 Identity (tech.pegasys.teku.api.response.v1.node.Identity)2 Metadata (tech.pegasys.teku.api.schema.Metadata)2 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)2 GetIdentity (tech.pegasys.teku.beaconrestapi.handlers.v1.node.GetIdentity)2 MetadataMessageAltair (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.metadata.versions.altair.MetadataMessageAltair)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 AbstractBeaconHandlerTest (tech.pegasys.teku.beaconrestapi.AbstractBeaconHandlerTest)1 SszBitvector (tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 MetadataMessageHandler (tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.MetadataMessageHandler)1 SingleProtocolEth2RpcMethod (tech.pegasys.teku.networking.eth2.rpc.core.methods.SingleProtocolEth2RpcMethod)1 NodeId (tech.pegasys.teku.networking.p2p.peer.NodeId)1 EmptyMessage (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage)1 EmptyMessageSchema (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EmptyMessage.EmptyMessageSchema)1