Search in sources :

Example 1 with SignatureMap

use of com.hederahashgraph.api.proto.java.SignatureMap in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerScheduleTest method scheduleSignDuplicateEd25519Signatures.

@Test
void scheduleSignDuplicateEd25519Signatures() {
    SignatureMap signatureMap = getSigMap(3, true);
    SignaturePair first = signatureMap.getSigPair(0);
    SignaturePair third = signatureMap.getSigPair(2);
    SignatureMap signatureMapWithDuplicate = signatureMap.toBuilder().addSigPair(first).addSigPair(third).build();
    insertScheduleSign(SIGN_TIMESTAMP, signatureMapWithDuplicate, SCHEDULE_ID);
    // verify lack of schedule data and transaction
    assertTransactionSignatureInRepository(toTransactionSignatureList(SIGN_TIMESTAMP, SCHEDULE_ID, signatureMap));
    assertThat(transactionRepository.count()).isEqualTo(1);
}
Also used : SignaturePair(com.hederahashgraph.api.proto.java.SignaturePair) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with SignatureMap

use of com.hederahashgraph.api.proto.java.SignatureMap in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerScheduleTest method unsupportedSignature.

@Test
void unsupportedSignature() {
    SignatureMap signatureMap = SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().build()).build();
    assertThatThrownBy(() -> insertScheduleSign(SIGN_TIMESTAMP, signatureMap, SCHEDULE_ID)).isInstanceOf(InvalidDatasetException.class).hasMessageContaining("Unsupported signature");
    // verify
    assertThat(transactionRepository.count()).isZero();
    assertThat(transactionSignatureRepository.count()).isZero();
}
Also used : InvalidDatasetException(com.hedera.mirror.importer.exception.InvalidDatasetException) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with SignatureMap

use of com.hederahashgraph.api.proto.java.SignatureMap in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerScheduleTest method scheduleSignTwoBatches.

@Test
void scheduleSignTwoBatches() {
    insertScheduleCreateTransaction(CREATE_TIMESTAMP, null, SCHEDULE_ID);
    // first sign
    SignatureMap firstSignatureMap = getSigMap(2, true);
    insertScheduleSign(SIGN_TIMESTAMP, firstSignatureMap, SCHEDULE_ID);
    // verify schedule signatures
    List<TransactionSignature> expectedTransactionSignatureList = new ArrayList<>(defaultSignatureList);
    expectedTransactionSignatureList.addAll(toTransactionSignatureList(SIGN_TIMESTAMP, SCHEDULE_ID, firstSignatureMap));
    assertTransactionSignatureInRepository(expectedTransactionSignatureList);
    // second sign
    long timestamp = SIGN_TIMESTAMP + 10;
    SignatureMap secondSignatureMap = getSigMap(3, true);
    insertScheduleSign(timestamp, secondSignatureMap, SCHEDULE_ID);
    expectedTransactionSignatureList.addAll(toTransactionSignatureList(timestamp, SCHEDULE_ID, secondSignatureMap));
    assertTransactionSignatureInRepository(expectedTransactionSignatureList);
    // verify entity count
    Entity expected = createEntity(EntityId.of(SCHEDULE_ID), SCHEDULE_REF_KEY, null, null, false, null, SCHEDULE_CREATE_MEMO, null, CREATE_TIMESTAMP, CREATE_TIMESTAMP);
    assertEquals(1, entityRepository.count());
    assertEntity(expected);
    // verify schedule
    assertThat(scheduleRepository.count()).isOne();
    assertScheduleInRepository(SCHEDULE_ID, CREATE_TIMESTAMP, PAYER, null);
    // verify transaction
    assertTransactionInRepository(SIGN_TIMESTAMP, false, SUCCESS);
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) ArrayList(java.util.ArrayList) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with SignatureMap

use of com.hederahashgraph.api.proto.java.SignatureMap in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerScheduleTest method scheduleExecute.

void scheduleExecute(ResponseCodeEnum responseCodeEnum) {
    insertScheduleCreateTransaction(CREATE_TIMESTAMP, null, SCHEDULE_ID);
    // sign
    SignatureMap signatureMap = getSigMap(3, true);
    insertScheduleSign(SIGN_TIMESTAMP, signatureMap, SCHEDULE_ID);
    // scheduled transaction
    insertScheduledTransaction(EXECUTE_TIMESTAMP, SCHEDULE_ID, responseCodeEnum);
    // verify entity count
    Entity expected = createEntity(EntityId.of(SCHEDULE_ID), SCHEDULE_REF_KEY, null, null, false, null, SCHEDULE_CREATE_MEMO, null, CREATE_TIMESTAMP, CREATE_TIMESTAMP);
    assertEquals(1, entityRepository.count());
    assertEntity(expected);
    // verify schedule
    assertScheduleInRepository(SCHEDULE_ID, CREATE_TIMESTAMP, PAYER, EXECUTE_TIMESTAMP);
    // verify schedule signatures
    List<TransactionSignature> expectedTransactionList = new ArrayList<>(defaultSignatureList);
    expectedTransactionList.addAll(toTransactionSignatureList(SIGN_TIMESTAMP, SCHEDULE_ID, signatureMap));
    assertTransactionSignatureInRepository(expectedTransactionList);
    // verify transaction
    assertTransactionInRepository(EXECUTE_TIMESTAMP, true, responseCodeEnum);
}
Also used : Entity(com.hedera.mirror.common.domain.entity.Entity) ArrayList(java.util.ArrayList) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap)

Example 5 with SignatureMap

use of com.hederahashgraph.api.proto.java.SignatureMap in project hedera-mirror-node by hashgraph.

the class EntityRecordItemListenerScheduleTest method unknownSignatureType.

@Test
void unknownSignatureType() {
    int unknownType = 999;
    ByteString sig = ByteString.copyFromUtf8("123");
    UnknownFieldSet.Field unknownField = UnknownFieldSet.Field.newBuilder().addLengthDelimited(sig).build();
    SignatureMap.Builder signatureMap = SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(byteString(8)).setContract(sig).build()).addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(byteString(8)).setECDSA384(sig).build()).addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(byteString(8)).setECDSASecp256K1(sig).build()).addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(byteString(8)).setEd25519(sig).build()).addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(byteString(8)).setRSA3072(sig).build()).addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(byteString(8)).setUnknownFields(UnknownFieldSet.newBuilder().addField(unknownType, unknownField).build()).build());
    insertScheduleSign(SIGN_TIMESTAMP, signatureMap.build(), SCHEDULE_ID);
    // verify
    assertThat(transactionRepository.count()).isEqualTo(1);
    assertThat(transactionSignatureRepository.findAll()).isNotNull().hasSize(signatureMap.getSigPairCount()).allSatisfy(t -> assertThat(t).returns(sig.toByteArray(), TransactionSignature::getSignature).extracting(TransactionSignature::getPublicKeyPrefix).isNotNull()).extracting(TransactionSignature::getType).containsExactlyInAnyOrder(SignaturePair.SignatureCase.CONTRACT.getNumber(), SignaturePair.SignatureCase.ECDSA_384.getNumber(), SignaturePair.SignatureCase.ECDSA_SECP256K1.getNumber(), SignaturePair.SignatureCase.ED25519.getNumber(), SignaturePair.SignatureCase.RSA_3072.getNumber(), unknownType);
}
Also used : ByteString(com.google.protobuf.ByteString) TransactionSignature(com.hedera.mirror.common.domain.transaction.TransactionSignature) UnknownFieldSet(com.google.protobuf.UnknownFieldSet) SignatureMap(com.hederahashgraph.api.proto.java.SignatureMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SignatureMap (com.hederahashgraph.api.proto.java.SignatureMap)12 Test (org.junit.jupiter.api.Test)8 ByteString (com.google.protobuf.ByteString)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 TransactionSignature (com.hedera.mirror.common.domain.transaction.TransactionSignature)4 SignaturePair (com.hederahashgraph.api.proto.java.SignaturePair)4 ArrayList (java.util.ArrayList)3 Entity (com.hedera.mirror.common.domain.entity.Entity)2 BaseTransactionMeta (com.hedera.services.usage.BaseTransactionMeta)2 SigUsage (com.hedera.services.usage.SigUsage)2 UsageAccumulator (com.hedera.services.usage.state.UsageAccumulator)2 UnknownFieldSet (com.google.protobuf.UnknownFieldSet)1 InvalidDatasetException (com.hedera.mirror.importer.exception.InvalidDatasetException)1 KeyPrefixMismatchException (com.hedera.services.legacy.exception.KeyPrefixMismatchException)1 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)1 Transaction (com.hederahashgraph.api.proto.java.Transaction)1