Search in sources :

Example 1 with Eth2BlockSigningRequestUtil

use of tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil in project web3signer by ConsenSys.

the class Eth2AltairBlockSigningAcceptanceTest method signAndVerifyLegacyBlockSignature.

@Test
void signAndVerifyLegacyBlockSignature() throws Exception {
    final Eth2BlockSigningRequestUtil util = new Eth2BlockSigningRequestUtil(SpecMilestone.PHASE0);
    setupEth2SignerMinimalWithoutAltairFork();
    final Eth2SigningRequestBody request = util.createLegacyBlockRequest();
    final Response response = signer.eth2Sign(keyPair.getPublicKey().toString(), request, ContentType.JSON);
    final Bytes signature = verifyAndGetSignatureResponse(response, ContentType.JSON);
    final BLSSignature expectedSignature = BLS.sign(keyPair.getSecretKey(), request.getSigningRoot());
    assertThat(signature).isEqualTo(expectedSignature.toBytesCompressed());
}
Also used : Response(io.restassured.response.Response) Bytes(org.apache.tuweni.bytes.Bytes) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Eth2BlockSigningRequestUtil(tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Eth2BlockSigningRequestUtil

use of tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil in project web3signer by ConsenSys.

the class Eth2CustomNetworkFileAcceptanceTest method createBlockV2SigningRequest.

private Eth2SigningRequestBody createBlockV2SigningRequest(final Spec spec, final ForkAndSpecMilestone forkAndMilestone) {
    final UInt64 forkEpoch = forkAndMilestone.getFork().getEpoch();
    final UInt64 startSlot = spec.computeStartSlotAtEpoch(forkEpoch);
    final Eth2BlockSigningRequestUtil util = new Eth2BlockSigningRequestUtil(spec, forkEpoch, startSlot);
    return util.createBlockV2Request();
}
Also used : Eth2BlockSigningRequestUtil(tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 3 with Eth2BlockSigningRequestUtil

use of tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil in project web3signer by ConsenSys.

the class Eth2BlockSigningAcceptanceTest method signAndVerifyLegacyBlockSignature.

@Test
void signAndVerifyLegacyBlockSignature() throws Exception {
    final Eth2BlockSigningRequestUtil util = new Eth2BlockSigningRequestUtil(SpecMilestone.PHASE0);
    setupEth2Signer(Eth2Network.MINIMAL, SpecMilestone.PHASE0);
    final Eth2SigningRequestBody request = util.createLegacyBlockRequest();
    final Response response = signer.eth2Sign(keyPair.getPublicKey().toString(), request, ContentType.JSON);
    final Bytes signature = verifyAndGetSignatureResponse(response, ContentType.JSON);
    final BLSSignature expectedSignature = BLS.sign(keyPair.getSecretKey(), request.getSigningRoot());
    assertThat(signature).isEqualTo(expectedSignature.toBytesCompressed());
}
Also used : Response(io.restassured.response.Response) Bytes(org.apache.tuweni.bytes.Bytes) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Eth2BlockSigningRequestUtil(tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Eth2BlockSigningRequestUtil

use of tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil 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)

Example 5 with Eth2BlockSigningRequestUtil

use of tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil in project web3signer by ConsenSys.

the class Eth2BlockSigningAcceptanceTest method signAndVerifyBlockV2Signature.

@ParameterizedTest
@EnumSource(value = SpecMilestone.class, names = { "PHASE0", "ALTAIR", "BELLATRIX" })
void signAndVerifyBlockV2Signature(final SpecMilestone specMilestone) throws Exception {
    final Eth2BlockSigningRequestUtil util = new Eth2BlockSigningRequestUtil(specMilestone);
    setupEth2Signer(Eth2Network.MINIMAL, specMilestone);
    final Eth2SigningRequestBody request = util.createBlockV2Request();
    final Response response = signer.eth2Sign(keyPair.getPublicKey().toString(), request, ContentType.JSON);
    final Bytes signature = verifyAndGetSignatureResponse(response, ContentType.JSON);
    final BLSSignature expectedSignature = BLS.sign(keyPair.getSecretKey(), request.getSigningRoot());
    assertThat(signature).isEqualTo(expectedSignature.toBytesCompressed());
}
Also used : Response(io.restassured.response.Response) Bytes(org.apache.tuweni.bytes.Bytes) Eth2SigningRequestBody(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody) Eth2BlockSigningRequestUtil(tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil) BLSSignature(tech.pegasys.teku.bls.BLSSignature) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Eth2BlockSigningRequestUtil (tech.pegasys.web3signer.dsl.utils.Eth2BlockSigningRequestUtil)6 Response (io.restassured.response.Response)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Eth2SigningRequestBody (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.Eth2SigningRequestBody)5 Bytes (org.apache.tuweni.bytes.Bytes)4 BLSSignature (tech.pegasys.teku.bls.BLSSignature)4 Test (org.junit.jupiter.api.Test)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 BlockRequest (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest)1