Search in sources :

Example 16 with InvalidTransactionException

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

the class FileDeleteTransitionLogicTest method resultIsRespected.

@Test
void resultIsRespected() {
    givenTxnCtxDeleting(TargetType.VALID);
    doThrow(new InvalidTransactionException(ENTITY_NOT_ALLOWED_TO_DELETE)).when(hfs).delete(any());
    assertFailsWith(() -> subject.doStateTransition(), ENTITY_NOT_ALLOWED_TO_DELETE);
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) Test(org.junit.jupiter.api.Test)

Example 17 with InvalidTransactionException

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

the class CryptoTransferTransitionLogicTest method happyPathUsesLedgerNetZero.

@Test
void happyPathUsesLedgerNetZero() {
    final var a = asAccount("1.2.3");
    final var b = asAccount("2.3.4");
    final var impliedTransfers = ImpliedTransfers.valid(validationProps, List.of(hbarChange(a, +100), hbarChange(b, -100)), new ArrayList<>(), new ArrayList<>());
    givenValidTxnCtx();
    // and:
    given(spanMapAccessor.getImpliedTransfers(accessor)).willReturn(impliedTransfers);
    doThrow(new InvalidTransactionException(INSUFFICIENT_ACCOUNT_BALANCE)).when(ledger).doZeroSum(anyList());
    // when:
    assertFailsWith(() -> subject.doStateTransition(), INSUFFICIENT_ACCOUNT_BALANCE);
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) Test(org.junit.jupiter.api.Test)

Example 18 with InvalidTransactionException

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

the class TransitionRunnerTest method logsWarningIfInvalidTxnExceptionWasFailInvalid.

@Test
void logsWarningIfInvalidTxnExceptionWasFailInvalid() {
    given(accessor.getFunction()).willReturn(TokenMint);
    given(accessor.getTxn()).willReturn(mockBody);
    given(accessor.getSignedTxnWrapper()).willReturn(mockTxn);
    given(lookup.lookupFor(TokenMint, mockBody)).willReturn(Optional.of(logic));
    given(logic.validateSemantics(accessor)).willReturn(OK);
    willThrow(new InvalidTransactionException("Yikes!", FAIL_INVALID)).given(logic).doStateTransition();
    var result = subject.tryTransition(accessor);
    verify(txnCtx).setStatus(FAIL_INVALID);
    assertThat(logCaptor.warnLogs(), contains(startsWith("Avoidable failure while handling " + "com.hedera.services.exceptions.InvalidTransactionException: Yikes!")));
    assertTrue(result);
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) Test(org.junit.jupiter.api.Test)

Example 19 with InvalidTransactionException

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

the class TopicCreateTransitionLogicTest method invalidAutoRenewAccountId.

@Test
void invalidAutoRenewAccountId() {
    givenTransactionWithInvalidAutoRenewAccountId();
    given(validator.memoCheck(anyString())).willReturn(OK);
    given(transactionContext.accessor()).willReturn(accessor);
    given(accessor.getTxn()).willReturn(transactionBody);
    given(accountStore.loadAccountOrFailWith(any(), any())).willThrow(new InvalidTransactionException(INVALID_AUTORENEW_ACCOUNT));
    given(validator.isValidAutoRenewPeriod(Duration.newBuilder().setSeconds(VALID_AUTORENEW_PERIOD_SECONDS).build())).willReturn(true);
    assertFailsWith(() -> subject.doStateTransition(), INVALID_AUTORENEW_ACCOUNT);
    assertTrue(topics.isEmpty());
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException) Test(org.junit.jupiter.api.Test)

Example 20 with InvalidTransactionException

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

the class ContractCreateTransitionLogic method prepareCodeWithConstructorArguments.

Bytes prepareCodeWithConstructorArguments(ContractCreateTransactionBody op) {
    var bytecodeSrc = op.getFileID();
    validateTrue(hfs.exists(bytecodeSrc), INVALID_FILE_ID);
    byte[] bytecode = hfs.cat(bytecodeSrc);
    validateFalse(bytecode.length == 0, CONTRACT_FILE_EMPTY);
    var contractByteCodeString = new String(bytecode);
    if (!op.getConstructorParameters().isEmpty()) {
        final var constructorParamsHexString = CommonUtils.hex(op.getConstructorParameters().toByteArray());
        contractByteCodeString += constructorParamsHexString;
    }
    try {
        return Bytes.fromHexString(contractByteCodeString);
    } catch (IllegalArgumentException e) {
        throw new InvalidTransactionException(ResponseCodeEnum.ERROR_DECODING_BYTESTRING);
    }
}
Also used : InvalidTransactionException(com.hedera.services.exceptions.InvalidTransactionException)

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