Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust the key gathering context methods to translate exceptions from preHandle #9841

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,12 @@ public TransactionKeys allKeysForTransaction(
dispatcher.dispatchPureChecks(nestedTxn);
final var nestedContext = new PreHandleContextImpl(
readableStoreFactory(), nestedTxn, payerForNested, configuration(), dispatcher);
dispatcher.dispatchPreHandle(nestedContext);
try {
dispatcher.dispatchPreHandle(nestedContext);
} catch (final PreCheckException ignored) {
// We must ignore/translate the exception here, as this is key gathering, not transaction validation.
throw new PreCheckException(ResponseCodeEnum.UNRESOLVABLE_REQUIRED_SIGNERS);
}
return nestedContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,12 @@ public TransactionKeys allKeysForTransaction(
dispatcher.dispatchPureChecks(nestedTxn);
final var nestedContext =
new PreHandleContextImpl(storeFactory, nestedTxn, payerForNested, configuration, dispatcher);
dispatcher.dispatchPreHandle(nestedContext);
try {
dispatcher.dispatchPreHandle(nestedContext);
} catch (final PreCheckException ignored) {
// We must ignore/translate the exception here, as this is key gathering, not transaction validation.
throw new PreCheckException(ResponseCodeEnum.UNRESOLVABLE_REQUIRED_SIGNERS);
}
return nestedContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.hedera.hapi.node.base.ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE;
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TRANSACTION_BODY;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS;
import static com.hedera.hapi.node.base.ResponseCodeEnum.UNRESOLVABLE_REQUIRED_SIGNERS;
import static com.hedera.node.app.spi.HapiUtils.functionOf;
import static com.hedera.node.app.spi.fixtures.workflows.ExceptionConditions.responseCode;
import static com.hedera.node.app.spi.workflows.record.ExternalizedRecordCustomizer.NOOP_EXTERNALIZED_RECORD_CUSTOMIZER;
Expand Down Expand Up @@ -573,15 +574,14 @@ void testAllKeysForTransactionWithFailingPureCheck() throws PreCheckException {

@Test
void testAllKeysForTransactionWithFailingPreHandle() throws PreCheckException {
// given
doThrow(new PreCheckException(INSUFFICIENT_ACCOUNT_BALANCE))
.when(dispatcher)
.dispatchPreHandle(any());

// when
// gathering keys should not throw exceptions except for inability to read a key.
assertThatThrownBy(() -> context.allKeysForTransaction(defaultTransactionBody(), ERIN.accountID()))
.isInstanceOf(PreCheckException.class)
.has(responseCode(INSUFFICIENT_ACCOUNT_BALANCE));
.has(responseCode(UNRESOLVABLE_REQUIRED_SIGNERS));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.hedera.hapi.node.base.ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE;
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TRANSACTION_BODY;
import static com.hedera.hapi.node.base.ResponseCodeEnum.UNRESOLVABLE_REQUIRED_SIGNERS;
import static com.hedera.node.app.spi.fixtures.workflows.ExceptionConditions.responseCode;
import static com.hedera.node.app.workflows.prehandle.PreHandleContextListUpdatesTest.A_COMPLEX_KEY;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -189,10 +190,10 @@ void testAllKeysForTransactionWithFailingPreHandle() throws PreCheckException {
.when(dispatcher)
.dispatchPreHandle(any());

// then
// gathering keys should not throw exceptions except for inability to read a key.
assertThatThrownBy(() -> subject.allKeysForTransaction(TransactionBody.DEFAULT, ERIN.accountID()))
.isInstanceOf(PreCheckException.class)
.has(responseCode(INSUFFICIENT_ACCOUNT_BALANCE));
.has(responseCode(UNRESOLVABLE_REQUIRED_SIGNERS));
}
}
}
Loading