Search in sources :

Example 6 with SwirldTransaction

use of com.swirlds.common.SwirldTransaction in project hedera-services by hashgraph.

the class PlatformTxnAccessorTest method failsOnInvalidSignedTxn.

@Test
void failsOnInvalidSignedTxn() {
    // given:
    SwirldTransaction platformTxn = new SwirldTransaction(NONSENSE);
    // expect:
    assertThrows(InvalidProtocolBufferException.class, () -> new PlatformTxnAccessor(platformTxn));
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Example 7 with SwirldTransaction

use of com.swirlds.common.SwirldTransaction in project hedera-services by hashgraph.

the class PlatformTxnAccessorTest method getsCorrectLoggableFormWithSignedTransactionBytes.

@Test
void getsCorrectLoggableFormWithSignedTransactionBytes() throws Exception {
    SignedTransaction signedTxn = SignedTransaction.newBuilder().setBodyBytes(someTxn.toByteString()).setSigMap(SignatureMap.newBuilder().addSigPair(SignaturePair.newBuilder().setPubKeyPrefix(ByteString.copyFrom("UNREAL".getBytes())).setEd25519(ByteString.copyFrom("FAKE".getBytes())).build())).build();
    Transaction txn = Transaction.newBuilder().setSignedTransactionBytes(signedTxn.toByteString()).build();
    SwirldTransaction platformTxn = new SwirldTransaction(txn.toByteArray());
    // when:
    PlatformTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
    Transaction signedTxn4Log = subject.getSignedTxnWrapper();
    ByteString signedTxnBytes = signedTxn4Log.getSignedTransactionBytes();
    Transaction asBodyBytes = signedTxn4Log.toBuilder().setSignedTransactionBytes(CommonUtils.extractTransactionBodyByteString(signedTxn4Log)).build();
    // then:
    assertEquals(signedTxnBytes, txn.getSignedTransactionBytes());
    assertEquals(signedTxn.getBodyBytes(), asBodyBytes.getSignedTransactionBytes());
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) ByteString(com.google.protobuf.ByteString) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 8 with SwirldTransaction

use of com.swirlds.common.SwirldTransaction in project hedera-services by hashgraph.

the class PlatformTxnAccessorTest method usesBodyBytesCorrectly.

@Test
void usesBodyBytesCorrectly() throws Exception {
    // given:
    Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
    SwirldTransaction platformTxn = new SwirldTransaction(signedTxnWithBody.toByteArray());
    // when:
    PlatformTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
    // then:
    assertEquals(someTxn, subject.getTxn());
    assertThat(List.of(subject.getTxnBytes()), contains(someTxn.toByteArray()));
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

SwirldTransaction (com.swirlds.common.SwirldTransaction)8 Test (org.junit.jupiter.api.Test)8 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)7 Transaction (com.hederahashgraph.api.proto.java.Transaction)7 ByteString (com.google.protobuf.ByteString)1 AccountID (com.hederahashgraph.api.proto.java.AccountID)1 HashMap (java.util.HashMap)1