Skip to content

Commit

Permalink
Adjust the key gathering context methods to translate exceptions from…
Browse files Browse the repository at this point in the history
… preHandle (#9841)

Signed-off-by: Joseph Sinclair <joseph.sinclair@swirldslabs.com>
  • Loading branch information
jsync-swirlds committed Nov 16, 2023
1 parent 172c669 commit 8946316
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
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 @@ -459,7 +459,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.HandleContext.TransactionCategory.CHILD;
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));
}
}
}

0 comments on commit 8946316

Please sign in to comment.