Search in sources :

Example 6 with Attestation

use of tech.pegasys.teku.api.schema.Attestation in project teku by ConsenSys.

the class OkHttpValidatorRestApiClientTest method sendSignedAttestation_WhenServerError_ThrowsRuntimeException.

@Test
public void sendSignedAttestation_WhenServerError_ThrowsRuntimeException() {
    final Attestation attestation = schemaObjects.attestation();
    mockWebServer.enqueue(new MockResponse().setResponseCode(SC_INTERNAL_SERVER_ERROR));
    assertThatThrownBy(() -> apiClient.sendSignedAttestations(List.of(attestation))).isInstanceOf(RuntimeException.class).hasMessageContaining("Unexpected response from Beacon Node API");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Attestation(tech.pegasys.teku.api.schema.Attestation) Test(org.junit.jupiter.api.Test)

Example 7 with Attestation

use of tech.pegasys.teku.api.schema.Attestation in project web3signer by ConsenSys.

the class Eth2RequestUtils method createAggregateAndProof.

private static Eth2SigningRequestBody createAggregateAndProof() {
    final ForkInfo forkInfo = forkInfo();
    final Bytes sszBytes = Bytes.of(0, 0, 1, 1);
    final Attestation attestation = new Attestation(sszBytes, new AttestationData(UInt64.ZERO, UInt64.ZERO, Bytes32.fromHexString("0x100814c335d0ced5014cfa9d2e375e6d9b4e197381f8ce8af0473200fdc917fd"), new Checkpoint(UInt64.ZERO, Bytes32.ZERO), new Checkpoint(UInt64.ZERO, Bytes32.fromHexString("0x100814c335d0ced5014cfa9d2e375e6d9b4e197381f8ce8af0473200fdc917fd"))), BLSSignature.fromHexString("0xa627242e4a5853708f4ebf923960fb8192f93f2233cd347e05239d86dd9fb66b721ceec1baeae6647f498c9126074f1101a87854d674b6eebc220fd8c3d8405bdfd8e286b707975d9e00a56ec6cbbf762f23607d490f0bbb16c3e0e483d51875"));
    final BLSSignature selectionProof = BLSSignature.fromHexString("0xa63f73a03f1f42b1fd0a988b614d511eb346d0a91c809694ef76df5ae021f0f144d64e612d735bc8820950cf6f7f84cd0ae194bfe3d4242fe79688f83462e3f69d9d33de71aab0721b7dab9d6960875e5fdfd26b171a75fb51af822043820c47");
    final AggregateAndProof aggregateAndProof = new AggregateAndProof(UInt64.ONE, attestation, selectionProof);
    final Bytes signingRoot = signingRootUtil.signingRootForSignAggregateAndProof(aggregateAndProof.asInternalAggregateAndProof(spec), forkInfo.asInternalForkInfo());
    return new Eth2SigningRequestBody(ArtifactType.AGGREGATE_AND_PROOF, signingRoot, forkInfo, null, null, null, null, aggregateAndProof, null, null, null, null, null, null);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) AttestationData(tech.pegasys.teku.api.schema.AttestationData) Checkpoint(tech.pegasys.teku.api.schema.Checkpoint) ForkInfo(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.ForkInfo) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Attestation(tech.pegasys.teku.api.schema.Attestation) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) AggregateAndProof(tech.pegasys.teku.api.schema.AggregateAndProof)

Example 8 with Attestation

use of tech.pegasys.teku.api.schema.Attestation in project teku by ConsenSys.

the class GetBlockAttestationsIntegrationTest method shouldGetBlockAttestations.

@Test
public void shouldGetBlockAttestations() throws IOException {
    final List<SignedBlockAndState> created = createBlocksAtSlots(10);
    final Response response = get("head");
    final GetBlockAttestationsResponse body = jsonProvider.jsonToObject(response.body().string(), GetBlockAttestationsResponse.class);
    final List<Attestation> data = body.data;
    final List<Attestation> attestations = created.get(0).getBlock().getMessage().getBody().getAttestations().stream().map(Attestation::new).collect(toList());
    assertThat(data).isEqualTo(attestations);
}
Also used : Response(okhttp3.Response) GetBlockAttestationsResponse(tech.pegasys.teku.api.response.v1.beacon.GetBlockAttestationsResponse) GetBlockAttestationsResponse(tech.pegasys.teku.api.response.v1.beacon.GetBlockAttestationsResponse) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Attestation(tech.pegasys.teku.api.schema.Attestation) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 9 with Attestation

use of tech.pegasys.teku.api.schema.Attestation in project teku by ConsenSys.

the class EventSubscriptionManagerTest method shouldPropagateAttestation.

@Test
void shouldPropagateAttestation() throws IOException {
    when(req.getQueryString()).thenReturn("&topics=attestation");
    manager.registerClient(client1);
    triggerAttestationEvent();
    final String eventString = outputStream.getString();
    assertThat(eventString).contains("event: attestation\n");
    final Attestation event = jsonProvider.jsonToObject(eventString.substring(eventString.indexOf("{")), Attestation.class);
    assertThat(event).isEqualTo(sampleAttestation);
}
Also used : Attestation(tech.pegasys.teku.api.schema.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Test(org.junit.jupiter.api.Test)

Example 10 with Attestation

use of tech.pegasys.teku.api.schema.Attestation in project teku by ConsenSys.

the class ChainDataProviderTest method getBlockAttestations_shouldReturnAttestationsOfBlock.

@Test
public void getBlockAttestations_shouldReturnAttestationsOfBlock() throws Exception {
    final ChainDataProvider provider = new ChainDataProvider(spec, recentChainData, combinedChainDataClient);
    ChainBuilder chainBuilder = storageSystem.chainBuilder();
    ChainBuilder.BlockOptions blockOptions = ChainBuilder.BlockOptions.create();
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, chainBuilder.getValidatorKeys());
    tech.pegasys.teku.spec.datastructures.operations.Attestation attestation1 = attestationGenerator.validAttestation(bestBlock.toUnsigned(), bestBlock.getSlot());
    tech.pegasys.teku.spec.datastructures.operations.Attestation attestation2 = attestationGenerator.validAttestation(bestBlock.toUnsigned(), bestBlock.getSlot().increment());
    blockOptions.addAttestation(attestation1);
    blockOptions.addAttestation(attestation2);
    SignedBlockAndState newHead = storageSystem.chainBuilder().generateBlockAtSlot(bestBlock.getSlot().plus(10), blockOptions);
    storageSystem.chainUpdater().saveBlock(newHead);
    storageSystem.chainUpdater().updateBestBlock(newHead);
    final Optional<ObjectAndMetaData<List<Attestation>>> response = provider.getBlockAttestations("head").get();
    assertThat(response).isPresent();
    assertThat(response.get().getData()).containsExactly(new Attestation(attestation1), new Attestation(attestation2));
}
Also used : ChainBuilder(tech.pegasys.teku.core.ChainBuilder) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Attestation(tech.pegasys.teku.api.schema.Attestation) Test(org.junit.jupiter.api.Test)

Aggregations

Attestation (tech.pegasys.teku.api.schema.Attestation)11 Test (org.junit.jupiter.api.Test)7 MockResponse (okhttp3.mockwebserver.MockResponse)4 List (java.util.List)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 PostDataFailure (tech.pegasys.teku.api.response.v1.beacon.PostDataFailure)2 PostDataFailureResponse (tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse)2 GetAggregatedAttestationResponse (tech.pegasys.teku.api.response.v1.validator.GetAggregatedAttestationResponse)2 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)2 Throwables (com.google.common.base.Throwables)1 Context (io.javalin.http.Context)1 Handler (io.javalin.http.Handler)1 HttpMethod (io.javalin.plugin.openapi.annotations.HttpMethod)1 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)1 OpenApiContent (io.javalin.plugin.openapi.annotations.OpenApiContent)1 OpenApiParam (io.javalin.plugin.openapi.annotations.OpenApiParam)1 OpenApiResponse (io.javalin.plugin.openapi.annotations.OpenApiResponse)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 Collections.emptyList (java.util.Collections.emptyList)1 Map (java.util.Map)1