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)));
}
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)));
}
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");
}
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;
}
}
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);
}
Aggregations