Skip to content

Commit

Permalink
Fix inital set of ScheduleExecutionSpecs HapiTest methods.
Browse files Browse the repository at this point in the history
* Modifie the workflow to skip the correct configured number of nanoseconds before the first child transaction consensus time.
* Marked all tests in ScheduleExecutionSpecs with `@HapiTest` or `@todo('issue#')` and file issues for groups with similar failures
* Small code cleanups to move shared methods to ScheduleUtils instead of scattered across various test suites.

Signed-off-by: Joseph Sinclair <joseph.sinclair@swirldslabs.com>
  • Loading branch information
jsync-swirlds committed Nov 21, 2023
1 parent 7417fee commit 050d79b
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,21 @@ private SingleTransactionRecordBuilderImpl doAddChild(
}

// Make sure we have not created so many that we have run out of slots.
final var childCount = childRecordBuilders.size();
final var consensusConfig = configuration.getConfigData(ConsensusConfig.class);
final int childCount = childRecordBuilders.size();
final ConsensusConfig consensusConfig = configuration.getConfigData(ConsensusConfig.class);
if (childCount >= consensusConfig.handleMaxFollowingRecords()) {
throw new HandleException(ResponseCodeEnum.MAX_CHILD_RECORDS_EXCEEDED);
}

// The consensus timestamp of the first item in the child list is T+1, where T is the time of the user tx
final var parentConsensusTimestamp = userTxnRecordBuilder.consensusNow();
final var prevConsensusNow = childRecordBuilders.isEmpty()
? userTxnRecordBuilder.consensusNow()
// The consensus timestamp of the first item in the child list is T+K (in nanoseconds),
// where T is the time of the user tx and K is the maximum number of "preceding" records
// defined for the current configuration.
final long maxPrecedingRecords = consensusConfig.handleMaxPrecedingRecords();
final Instant parentConsensusTimestamp = userTxnRecordBuilder.consensusNow();
final Instant prevConsensusNow = childRecordBuilders.isEmpty()
? userTxnRecordBuilder.consensusNow().plusNanos(maxPrecedingRecords)
: childRecordBuilders.get(childRecordBuilders.size() - 1).consensusNow();
final var consensusNow = prevConsensusNow.plusNanos(1L);
// Note we do not repeat exchange rates for child transactions
final Instant consensusNow = prevConsensusNow.plusNanos(1L);
final var recordBuilder = new SingleTransactionRecordBuilderImpl(consensusNow, reversingBehavior, customizer)
.parentConsensus(parentConsensusTimestamp);
if (!customizer.shouldSuppressRecord()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.hedera.hapi.node.base.ResponseCodeEnum;
import com.hedera.hapi.node.base.Timestamp;
import com.hedera.hapi.node.base.Transaction;
import com.hedera.hapi.node.base.TransactionID;
import com.hedera.node.app.AppTestBase;
import com.hedera.node.app.spi.workflows.HandleException;
import com.hedera.node.app.state.SingleTransactionRecord;
import com.hedera.node.config.data.ConsensusConfig;
import com.hedera.node.config.testfixtures.HederaTestConfigBuilder;
import com.swirlds.config.api.Configuration;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand All @@ -48,6 +50,8 @@ class RecordListBuilderTest extends AppTestBase {
.withValue("consensus.message.maxPrecedingRecords", MAX_PRECEDING)
.withValue("consensus.message.maxFollowingRecords", MAX_CHILDREN)
.getOrCreateConfig();
private static final int EXPECTED_CHILD_NANO_INCREMENT =
Math.toIntExact(CONFIGURATION.getConfigData(ConsensusConfig.class).handleMaxPrecedingRecords());

@SuppressWarnings("ConstantConditions")
@Test
Expand Down Expand Up @@ -885,10 +889,11 @@ TransactionRecordAssertions nanosBefore(final int nanos, @NonNull final SingleTr
}

TransactionRecordAssertions nanosAfter(final int nanos, @NonNull final SingleTransactionRecord otherRecord) {
final var otherTimestamp = otherRecord.transactionRecord().consensusTimestampOrThrow();
final var expectedTimestamp = otherTimestamp
final Timestamp otherTimestamp = otherRecord.transactionRecord().consensusTimestampOrThrow();
final int actualOffset = EXPECTED_CHILD_NANO_INCREMENT + nanos;
final Timestamp expectedTimestamp = otherTimestamp
.copyBuilder()
.nanos(otherTimestamp.nanos() + nanos)
.nanos(otherTimestamp.nanos() + actualOffset)
.build();
assertThat(record.transactionRecord().consensusTimestampOrThrow()).isEqualTo(expectedTimestamp);
return this;
Expand Down

0 comments on commit 050d79b

Please sign in to comment.