Search in sources :

Example 1 with SignedBeaconBlockAltair

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

the class GetBlockV2IntegrationTest method shouldGetAltairBlock.

@Test
public void shouldGetAltairBlock() throws IOException {
    startRestAPIAtGenesis(SpecMilestone.ALTAIR);
    final List<SignedBlockAndState> created = createBlocksAtSlots(10);
    final Response response = get("head");
    final GetBlockResponseV2 body = jsonProvider.jsonToObject(response.body().string(), GetBlockResponseV2.class);
    assertThat(body.getVersion()).isEqualTo(Version.altair);
    assertThat(body.getData()).isInstanceOf(SignedBeaconBlockAltair.class);
    final SignedBeaconBlockAltair data = (SignedBeaconBlockAltair) body.getData();
    assertThat(data.signature.toHexString()).isEqualTo(created.get(0).getBlock().getSignature().toString());
    assertThat(data.getMessage().asInternalBeaconBlock(spec).getRoot().toHexString()).isEqualTo(created.get(0).getBlock().getMessage().getRoot().toHexString());
    assertThat(data.getMessage().getBody().syncAggregate.syncCommitteeBits).isEqualTo(Bytes.fromHexString("0x00000000"));
    assertThat(response.header(HEADER_CONSENSUS_VERSION)).isEqualTo(Version.altair.name());
}
Also used : Response(okhttp3.Response) SignedBeaconBlockAltair(tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair) GetBlockResponseV2(tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) Test(org.junit.jupiter.api.Test) AbstractDataBackedRestAPIIntegrationTest(tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)

Example 2 with SignedBeaconBlockAltair

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

the class TekuNode method waitForFullSyncCommitteeAggregate.

public void waitForFullSyncCommitteeAggregate() {
    LOG.debug("Wait for full sync committee aggregates");
    waitFor(() -> {
        final Optional<SignedBlock> block = fetchHeadBlock();
        assertThat(block).isPresent();
        assertThat(block.get()).isInstanceOf(SignedBeaconBlockAltair.class);
        final SignedBeaconBlockAltair altairBlock = (SignedBeaconBlockAltair) block.get();
        final int syncCommitteeSize = spec.getSyncCommitteeSize(altairBlock.getMessage().slot);
        final SszBitvectorSchema<SszBitvector> syncCommitteeSchema = SszBitvectorSchema.create(syncCommitteeSize);
        final Bytes syncCommitteeBits = altairBlock.getMessage().getBody().syncAggregate.syncCommitteeBits;
        final int actualSyncBitCount = syncCommitteeSchema.sszDeserialize(syncCommitteeBits).getBitCount();
        final double percentageOfBitsSet = actualSyncBitCount == syncCommitteeSize ? 1.0 : actualSyncBitCount / (double) syncCommitteeSize;
        if (percentageOfBitsSet < 1.0) {
            LOG.debug(String.format("Sync committee bits are only %s%% full, expecting %s%%: %s", percentageOfBitsSet * 100, 100, syncCommitteeBits));
        }
        assertThat(percentageOfBitsSet >= 1.0).isTrue();
    }, 5, MINUTES);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SignedBeaconBlockAltair(tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) SignedBlock(tech.pegasys.teku.api.schema.interfaces.SignedBlock)

Aggregations

SignedBeaconBlockAltair (tech.pegasys.teku.api.schema.altair.SignedBeaconBlockAltair)2 Response (okhttp3.Response)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Test (org.junit.jupiter.api.Test)1 GetBlockResponseV2 (tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2)1 SignedBlock (tech.pegasys.teku.api.schema.interfaces.SignedBlock)1 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)1 SszBitvector (tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)1 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)1