Search in sources :

Example 1 with BlockRequest

use of com.google.showcase.v1beta1.BlockRequest in project web3signer by ConsenSys.

the class BlockRequestDeserializer method deserialize.

@Override
public BlockRequest deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
    final ObjectCodec codec = p.getCodec();
    final JsonNode node = codec.readTree(p);
    final SpecMilestone specMilestone = SpecMilestone.valueOf(node.findValue("version").asText());
    final BeaconBlock beaconBlock;
    final BeaconBlockHeader beaconBlockHeader;
    final BlockRequest blockRequest;
    switch(specMilestone) {
        case PHASE0:
            beaconBlock = codec.treeToValue(node.findValue("block"), BeaconBlock.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlock);
            break;
        case ALTAIR:
            beaconBlock = codec.treeToValue(node.findValue("block"), BeaconBlockAltair.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlock);
            break;
        case BELLATRIX:
            // for BELLATRIX we only need block_header instead of complete block
            beaconBlockHeader = codec.treeToValue(node.findValue("block_header"), BeaconBlockHeader.class);
            blockRequest = new BlockRequest(specMilestone, beaconBlockHeader);
            break;
        default:
            throw new IllegalStateException("Fork version not yet supported: " + specMilestone);
    }
    return blockRequest;
}
Also used : BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) BeaconBlockHeader(tech.pegasys.teku.api.schema.BeaconBlockHeader) BlockRequest(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) BeaconBlockAltair(tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)

Example 2 with BlockRequest

use of com.google.showcase.v1beta1.BlockRequest in project web3signer by ConsenSys.

the class Eth2BlockSigningAcceptanceTest method emptyBlockRequestReturnsBadRequestStatus.

@Test
void emptyBlockRequestReturnsBadRequestStatus() throws JsonProcessingException {
    final Eth2BlockSigningRequestUtil util = new Eth2BlockSigningRequestUtil(SpecMilestone.BELLATRIX);
    setupEth2Signer(Eth2Network.MINIMAL, SpecMilestone.BELLATRIX);
    final Eth2SigningRequestBody request = util.createBlockV2Request(new BlockRequest(SpecMilestone.BELLATRIX));
    final Response response = signer.eth2Sign(keyPair.getPublicKey().toString(), request, ContentType.JSON);
    response.then().statusCode(400);
}
Also used : Response(io.restassured.response.Response) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Eth2BlockSigningRequestUtil(tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil) BlockRequest(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BlockRequest (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest)2 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Response (io.restassured.response.Response)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)1 BeaconBlockHeader (tech.pegasys.teku.api.schema.BeaconBlockHeader)1 BeaconBlockAltair (tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)1 SpecMilestone (tech.pegasys.teku.spec.SpecMilestone)1 Eth2SigningRequestBody (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody)1 Eth2BlockSigningRequestUtil (tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil)1