Search in sources :

Example 1 with KeyPrefixMismatchException

use of com.hedera.services.legacy.exception.KeyPrefixMismatchException in project hedera-services by hashgraph.

the class PojoSigMapPubKeyToSigBytesTest method rejectsNonUniqueSigBytes.

@Test
void rejectsNonUniqueSigBytes() {
    // given:
    String str = "TEST_STRING";
    byte[] pubKey = str.getBytes(StandardCharsets.UTF_8);
    SignaturePair sigPair = SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFromUtf8(str)).build();
    SignatureMap sigMap = SignatureMap.newBuilder().addSigPair(sigPair).addSigPair(sigPair).build();
    PojoSigMapPubKeyToSigBytes sigMapPubKeyToSigBytes = new PojoSigMapPubKeyToSigBytes(sigMap);
    // expect:
    KeyPrefixMismatchException exception = assertThrows(KeyPrefixMismatchException.class, () -> {
        sigMapPubKeyToSigBytes.sigBytesFor(pubKey);
    });
    assertEquals("Source signature map with prefix 544553545f535452494e47 is ambiguous for given public key! " + "(544553545f535452494e47)", exception.getMessage());
}
Also used : KeyPrefixMismatchException(com.hedera.services.legacy.exception.KeyPrefixMismatchException) SignaturePair(com.hederahashgraph.api.proto.java.SignaturePair) ByteString(com.google.protobuf.ByteString) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test)

Example 2 with KeyPrefixMismatchException

use of com.hedera.services.legacy.exception.KeyPrefixMismatchException in project hedera-services by hashgraph.

the class PlatformSigOpsTest method reportsInvalidSigMap.

@Test
void reportsInvalidSigMap() {
    final var subject = new PlatformSigsCreationResult();
    subject.setTerminatingEx(new KeyPrefixMismatchException("No!"));
    final var status = subject.asCode();
    assertEquals(KEY_PREFIX_MISMATCH, status);
}
Also used : KeyPrefixMismatchException(com.hedera.services.legacy.exception.KeyPrefixMismatchException) Test(org.junit.jupiter.api.Test)

Aggregations

KeyPrefixMismatchException (com.hedera.services.legacy.exception.KeyPrefixMismatchException)2 Test (org.junit.jupiter.api.Test)2 ByteString (com.google.protobuf.ByteString)1 SignatureMap (com.hederahashgraph.api.proto.java.SignatureMap)1 SignaturePair (com.hederahashgraph.api.proto.java.SignaturePair)1