Skip to content

Commit

Permalink
refactor: address PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Mustafa Uzun <[email protected]>
  • Loading branch information
mustafauzunn committed Jan 7, 2025
1 parent 9da0556 commit c1f7e96
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
public class ConsistencyTestingToolStateTest {

private static ConsistencyTestingToolState state;
private ConsistencyTestingToolMain main;
private Random random;
private PlatformStateModifier platformStateModifier;
private Platform platform;
Expand Down Expand Up @@ -101,7 +100,6 @@ void setUp() {

state.init(platform, initTrigger, softwareVersion);

main = mock(ConsistencyTestingToolMain.class);
random = new Random();
platformStateModifier = mock(PlatformStateModifier.class);
round = mock(Round.class);
Expand All @@ -123,7 +121,7 @@ void setUp() {
}

@Test
void handleConsensusRoundWithApplicationTransactionEmptySystemTransactionList() {
void handleConsensusRoundWithApplicationTransaction() {
final var bytes = Bytes.wrap(new byte[] {1, 1, 1, 1, 1, 1, 1, 1});
when(consensusTransaction.getApplicationTransaction()).thenReturn(bytes);

Expand All @@ -144,7 +142,6 @@ void handleConsensusRoundWithApplicationTransactionEmptySystemTransactionList()
void handleConsensusRoundWithSystemTransaction() {
final var stateSignatureTransactionBytes =
StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction);
when(main.encodeSystemTransaction(stateSignatureTransaction)).thenReturn(stateSignatureTransactionBytes);
when(consensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes);

doAnswer(invocation -> {
Expand Down Expand Up @@ -176,7 +173,6 @@ void handleConsensusRoundWithMultipleSystemTransactions() {

final var stateSignatureTransactionBytes =
StateSignatureTransaction.PROTOBUF.toBytes(stateSignatureTransaction);
when(main.encodeSystemTransaction(stateSignatureTransaction)).thenReturn(stateSignatureTransactionBytes);
when(consensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes);
when(secondConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes);
when(thirdConsensusTransaction.getApplicationTransaction()).thenReturn(stateSignatureTransactionBytes);
Expand Down Expand Up @@ -265,6 +261,24 @@ void preHandleEventWithSystemTransaction() {
assertThat(consumedTransactions).hasSize(1);
}

@Test
void preHandleEventWithApplicationTransaction() {
final var bytes = Bytes.wrap(new byte[] {1, 1, 1, 1, 1, 1, 1, 1});
when(consensusTransaction.getApplicationTransaction()).thenReturn(bytes);

doAnswer(invocation -> {
Consumer<Transaction> consumer = invocation.getArgument(0);
consumer.accept(consensusTransaction);
return null;
})
.when(event)
.forEachTransaction(any());

state.preHandle(event, consumer);

assertThat(consumedTransactions).isEmpty();
}

@Test
void preHandleEventWithDeprecatedSystemTransaction() {
when(round.iterator()).thenReturn(Collections.singletonList(event).iterator());
Expand Down

0 comments on commit c1f7e96

Please sign in to comment.