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);
}
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);
}
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);
}
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());
}
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);
}
}
Aggregations