Search in sources :

Example 11 with InvalidTransactionException

use of com.hedera.services.exceptions.InvalidTransactionException in project hedera-services by hashgraph.

the class TopicCreateTransitionLogicTest method badSubmitKey.

@Test
void badSubmitKey() {
    givenTransactionWithInvalidSubmitKey();
    given(transactionContext.accessor()).willReturn(accessor);
    given(accessor.getTxn()).willReturn(transactionBody);
    given(validator.attemptDecodeOrThrow(any())).willThrow(new InvalidTransactionException(BAD_ENCODING));
    assertFailsWith(() -> subject.doStateTransition(), BAD_ENCODING);
    assertTrue(topics.isEmpty());
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) Test(org.junit.jupiter.api.Test)

Example 12 with InvalidTransactionException

use of com.hedera.services.exceptions.InvalidTransactionException in project hedera-services by hashgraph.

the class ContractCreateTransitionLogicTest method rejectSerializationFailed.

@Test
void rejectSerializationFailed() {
    Key key = Key.getDefaultInstance();
    var op = ContractCreateTransactionBody.newBuilder().setFileID(bytecodeSrc).setInitialBalance(balance).setGas(gas).setAdminKey(key).setProxyAccountID(proxy);
    var txn = TransactionBody.newBuilder().setTransactionID(ourTxnId()).setContractCreateInstance(op);
    contractCreateTxn = txn.build();
    given(accessor.getTxn()).willReturn(contractCreateTxn);
    given(txnCtx.accessor()).willReturn(accessor);
    given(validator.attemptToDecodeOrThrow(key, SERIALIZATION_FAILED)).willThrow(new InvalidTransactionException(SERIALIZATION_FAILED));
    // when:
    Exception exception = assertThrows(InvalidTransactionException.class, () -> subject.doStateTransition());
    // then:
    assertEquals("SERIALIZATION_FAILED", exception.getMessage());
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) JContractIDKey(com.hedera.services.legacy.core.jproto.JContractIDKey) JEd25519Key(com.hedera.services.legacy.core.jproto.JEd25519Key) Key(com.hederahashgraph.api.proto.java.Key) InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) Test(org.junit.jupiter.api.Test)

Example 13 with InvalidTransactionException

use of com.hedera.services.exceptions.InvalidTransactionException in project hedera-services by hashgraph.

the class TokenDeleteTransitionLogicTest method capturesInvalidDelete.

@Test
void capturesInvalidDelete() {
    givenValidTxnCtx();
    given(typedTokenStore.loadToken(tokenId)).willThrow(new InvalidTransactionException(INVALID_TOKEN_ID));
    assertFailsWith(() -> subject.doStateTransition(), INVALID_TOKEN_ID);
    verify(token, never()).delete();
    verify(typedTokenStore, never()).commitToken(token);
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) Test(org.junit.jupiter.api.Test)

Example 14 with InvalidTransactionException

use of com.hedera.services.exceptions.InvalidTransactionException in project hedera-services by hashgraph.

the class MintPrecompilesTest method mintFailurePathWorks.

@Test
void mintFailurePathWorks() {
    givenNonFungibleFrameContext();
    given(sigsVerifier.hasActiveSupplyKey(nonFungibleTokenAddr, recipientAddr, contractAddr, recipientAddr, aliases)).willThrow(new InvalidTransactionException(INVALID_SIGNATURE));
    given(feeCalculator.estimatedGasPriceInTinybars(HederaFunctionality.ContractCall, timestamp)).willReturn(1L);
    given(mockSynthBodyBuilder.build()).willReturn(TransactionBody.newBuilder().build());
    given(mockSynthBodyBuilder.setTransactionID(any(TransactionID.class))).willReturn(mockSynthBodyBuilder);
    given(feeCalculator.computeFee(any(), any(), any(), any())).willReturn(mockFeeObject);
    given(mockFeeObject.getServiceFee()).willReturn(1L);
    given(creator.createUnsuccessfulSyntheticRecord(INVALID_SIGNATURE)).willReturn(mockRecordBuilder);
    given(encoder.encodeMintFailure(INVALID_SIGNATURE)).willReturn(invalidSigResult);
    given(worldUpdater.aliases()).willReturn(aliases);
    given(aliases.resolveForEvm(any())).willAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
    // when:
    subject.prepareFields(frame);
    subject.prepareComputation(pretendArguments, а -> а);
    subject.computeGasRequirement(TEST_CONSENSUS_TIME);
    final var result = subject.computeInternal(frame);
    // then:
    assertEquals(invalidSigResult, result);
    verify(worldUpdater).manageInProgressRecord(recordsHistorian, mockRecordBuilder, mockSynthBodyBuilder);
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Example 15 with InvalidTransactionException

use of com.hedera.services.exceptions.InvalidTransactionException in project hedera-services by hashgraph.

the class TransferPrecompilesTest method transferFailsAndCatchesProperly.

@Test
void transferFailsAndCatchesProperly() {
    givenMinimalFrameContext();
    givenLedgers();
    given(sigsVerifier.hasActiveKeyOrNoReceiverSigReq(any(), any(), any(), any(), any())).willReturn(true);
    given(sigsVerifier.hasActiveKey(any(), any(), any(), any(), any())).willReturn(true);
    given(impliedTransfersMarshal.validityWithCurrentProps(cryptoTransferTransactionBody)).willReturn(OK);
    given(hederaTokenStoreFactory.newHederaTokenStore(ids, validator, sideEffects, dynamicProperties, tokenRels, nfts, tokens)).willReturn(hederaTokenStore);
    given(transferLogicFactory.newLogic(accounts, nfts, tokenRels, hederaTokenStore, sideEffects, dynamicProperties, validator, null, recordsHistorian)).willReturn(transferLogic);
    given(decoder.decodeTransferToken(eq(pretendArguments), any())).willReturn(Collections.singletonList(TOKEN_TRANSFER_WRAPPER));
    given(impliedTransfersMarshal.assessCustomFeesAndValidate(anyInt(), anyInt(), any(), any(), any())).willReturn(impliedTransfers);
    given(impliedTransfers.getAllBalanceChanges()).willReturn(tokenTransferChanges);
    given(impliedTransfers.getMeta()).willReturn(impliedTransfersMeta);
    given(impliedTransfersMeta.code()).willReturn(OK);
    given(pretendArguments.getInt(0)).willReturn(ABI_ID_TRANSFER_TOKEN);
    given(syntheticTxnFactory.createCryptoTransfer(any())).willReturn(mockSynthBodyBuilder);
    given(mockSynthBodyBuilder.getCryptoTransfer()).willReturn(cryptoTransferTransactionBody);
    given(feeCalculator.estimatedGasPriceInTinybars(HederaFunctionality.ContractCall, timestamp)).willReturn(1L);
    given(mockSynthBodyBuilder.build()).willReturn(TransactionBody.newBuilder().setCryptoTransfer(cryptoTransferTransactionBody).build());
    given(mockSynthBodyBuilder.setTransactionID(any(TransactionID.class))).willReturn(mockSynthBodyBuilder);
    given(feeCalculator.computeFee(any(), any(), any(), any())).willReturn(mockFeeObject);
    given(mockFeeObject.getServiceFee()).willReturn(1L);
    given(creator.createUnsuccessfulSyntheticRecord(ResponseCodeEnum.FAIL_INVALID)).willReturn(mockRecordBuilder);
    doThrow(new InvalidTransactionException(ResponseCodeEnum.FAIL_INVALID)).when(transferLogic).doZeroSum(tokenTransferChanges);
    given(aliases.resolveForEvm(any())).willAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
    given(worldUpdater.aliases()).willReturn(aliases);
    // when:
    subject.prepareFields(frame);
    subject.prepareComputation(pretendArguments, а -> а);
    subject.computeGasRequirement(TEST_CONSENSUS_TIME);
    final var result = subject.computeInternal(frame);
    // then:
    assertNotEquals(successResult, result);
    // and:
    verify(transferLogic).doZeroSum(tokenTransferChanges);
    verify(wrappedLedgers, never()).commit();
    verify(worldUpdater).manageInProgressRecord(recordsHistorian, mockRecordBuilder, mockSynthBodyBuilder);
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidTransactionException (com.hedera.services.exceptions.InvalidTransactionException)26 Test (org.junit.jupiter.api.Test)24 TransactionID (com.hederahashgraph.api.proto.java.TransactionID)4 JContractIDKey (com.hedera.services.legacy.core.jproto.JContractIDKey)1 JEd25519Key (com.hedera.services.legacy.core.jproto.JEd25519Key)1 HederaWorldState (com.hedera.services.store.contracts.HederaWorldState)1 HederaWorldUpdater (com.hedera.services.store.contracts.HederaWorldUpdater)1 Key (com.hederahashgraph.api.proto.java.Key)1 ArrayDeque (java.util.ArrayDeque)1 Map (java.util.Map)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Address (org.hyperledger.besu.datatypes.Address)1 Wei (org.hyperledger.besu.datatypes.Wei)1 Gas (org.hyperledger.besu.evm.Gas)1 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)1 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)1