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