Skip to content

Commit 16667fa

Browse files
fix: Fix flakiness in HIP-1064 tests (#18822)
Signed-off-by: Neeharika-Sompalli <[email protected]>
1 parent 91cf5b4 commit 16667fa

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/integration/RepeatableHip1064Tests.java

+45-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package com.hedera.services.bdd.suites.integration;
33

4+
import static com.hedera.hapi.util.HapiUtils.asInstant;
5+
import static com.hedera.node.app.hapi.utils.CommonPbjConverters.toPbj;
46
import static com.hedera.services.bdd.junit.RepeatableReason.NEEDS_VIRTUAL_TIME_FOR_FAST_EXECUTION;
57
import static com.hedera.services.bdd.junit.TestTags.INTEGRATION;
68
import static com.hedera.services.bdd.junit.hedera.embedded.EmbeddedMode.REPEATABLE;
@@ -48,9 +50,11 @@
4850
import com.hederahashgraph.api.proto.java.AccountAmount;
4951
import edu.umd.cs.findbugs.annotations.NonNull;
5052
import java.time.Duration;
53+
import java.time.Instant;
5154
import java.util.List;
5255
import java.util.Map;
5356
import java.util.concurrent.atomic.AtomicLong;
57+
import java.util.concurrent.atomic.AtomicReference;
5458
import java.util.function.LongSupplier;
5559
import java.util.stream.Stream;
5660
import org.junit.jupiter.api.BeforeAll;
@@ -98,18 +102,20 @@ static void beforeAll(@NonNull final TestLifecycle testLifecycle) {
98102
final Stream<DynamicTest> paysAdjustedFeesToAllEligibleActiveAccountsAtStartOfNewPeriod() {
99103
final AtomicLong expectedNodeFees = new AtomicLong(0);
100104
final AtomicLong expectedNodeRewards = new AtomicLong(0);
105+
final AtomicReference<Instant> startConsensusTime = new AtomicReference<>();
101106
return hapiTest(
102-
recordStreamMustIncludePassFrom(
103-
selectedItems(
104-
nodeRewardsValidator(expectedNodeRewards::get),
105-
// We expect two node rewards payments in this test.
106-
// But first staking period all nodes are inactive and minReward is 0.
107-
// So no synthetic node rewards payment is expected.
108-
1,
109-
(spec, item) -> item.getRecord().getTransferList().getAccountAmountsList().stream()
110-
.anyMatch(aa ->
111-
aa.getAccountID().getAccountNum() == 801L && aa.getAmount() < 0L)),
112-
Duration.ofSeconds(1)),
107+
doingContextual(spec -> startConsensusTime.set(spec.consensusTime())),
108+
recordStreamMustIncludePassFrom(selectedItems(
109+
nodeRewardsValidator(expectedNodeRewards::get),
110+
// We expect two node rewards payments in this test.
111+
// But first staking period all nodes are inactive and minReward is 0.
112+
// So no synthetic node rewards payment is expected.
113+
1,
114+
(spec, item) -> item.getRecord().getTransferList().getAccountAmountsList().stream()
115+
.anyMatch(
116+
aa -> aa.getAccountID().getAccountNum() == 801L && aa.getAmount() < 0L)
117+
&& asInstant(toPbj(item.getRecord().getConsensusTimestamp()))
118+
.isAfter(startConsensusTime.get()))),
113119
cryptoTransfer(TokenMovement.movingHbar(100000 * ONE_HBAR).between(GENESIS, NODE_REWARD)),
114120
nodeUpdate("0").declineReward(true),
115121
// Start a new period
@@ -121,12 +127,13 @@ final Stream<DynamicTest> paysAdjustedFeesToAllEligibleActiveAccountsAtStartOfNe
121127
.payingWith(CIVILIAN_PAYER)
122128
.via("notFree"),
123129
// Collects ~1.8M tinybar in node fees; so ~450k tinybar per node
124-
getTxnRecord("notFree")
125-
.exposingTo(r -> expectedNodeFees.set(r.getTransferList().getAccountAmountsList().stream()
126-
.filter(a -> a.getAccountID().getAccountNum() == 3L)
127-
.findFirst()
128-
.orElseThrow()
129-
.getAmount())),
130+
getTxnRecord("notFree").exposingTo(r -> {
131+
expectedNodeFees.set(r.getTransferList().getAccountAmountsList().stream()
132+
.filter(a -> a.getAccountID().getAccountNum() == 3L)
133+
.findFirst()
134+
.orElseThrow()
135+
.getAmount());
136+
}),
130137
// validate all network fees go to 0.0.801
131138
validateRecordFees("notFree", List.of(3L, 801L)),
132139
doWithStartupConfig(
@@ -185,8 +192,10 @@ final Stream<DynamicTest> paysAdjustedFeesToAllEligibleActiveAccountsAtStartOfNe
185192
final Stream<DynamicTest> paysNonAdjustedFeesToAllEligibleActiveAccountsAtStartOfNewPeriod() {
186193
final AtomicLong expectedNodeFees = new AtomicLong(0);
187194
final AtomicLong expectedNodeRewards = new AtomicLong(0);
195+
final AtomicReference<Instant> startConsensusTime = new AtomicReference<>();
188196
return hapiTest(
189197
overriding("nodes.adjustNodeFees", "false"),
198+
doingContextual(spec -> startConsensusTime.set(spec.consensusTime())),
190199
recordStreamMustIncludePassFrom(
191200
selectedItems(
192201
nodeRewardsValidator(expectedNodeRewards::get),
@@ -195,8 +204,11 @@ final Stream<DynamicTest> paysNonAdjustedFeesToAllEligibleActiveAccountsAtStartO
195204
// So no synthetic node rewards payment is expected.
196205
1,
197206
(spec, item) -> item.getRecord().getTransferList().getAccountAmountsList().stream()
198-
.anyMatch(aa ->
199-
aa.getAccountID().getAccountNum() == 801L && aa.getAmount() < 0L)),
207+
.anyMatch(
208+
aa -> aa.getAccountID().getAccountNum() == 801L
209+
&& aa.getAmount() < 0L)
210+
&& asInstant(toPbj(item.getRecord().getConsensusTimestamp()))
211+
.isAfter(startConsensusTime.get())),
200212
Duration.ofSeconds(1)),
201213
cryptoTransfer(TokenMovement.movingHbar(100000 * ONE_HBAR).between(GENESIS, NODE_REWARD)),
202214
nodeUpdate("0").declineReward(true),
@@ -271,11 +283,13 @@ final Stream<DynamicTest> paysNonAdjustedFeesToAllEligibleActiveAccountsAtStartO
271283
overrides = {"nodes.minPerPeriodNodeRewardUsd"})
272284
@Order(2)
273285
final Stream<DynamicTest> inactiveNodesPaidWhenMinRewardsGreaterThanZero() {
286+
final AtomicReference<Instant> startConsensusTime = new AtomicReference<>();
274287
final AtomicLong expectedNodeFees = new AtomicLong(0);
275288
final AtomicLong expectedNodeRewards = new AtomicLong(0);
276289
final AtomicLong expectedMinNodeReward = new AtomicLong(0);
277290
return hapiTest(
278291
overriding("nodes.minPerPeriodNodeRewardUsd", "10"),
292+
doingContextual(spec -> startConsensusTime.set(spec.consensusTime())),
279293
recordStreamMustIncludePassFrom(
280294
selectedItems(
281295
nodeRewardsValidatorWithInactiveNodes(
@@ -285,8 +299,11 @@ final Stream<DynamicTest> inactiveNodesPaidWhenMinRewardsGreaterThanZero() {
285299
// Second staking period, two nodes are active and one node is inactive
286300
2,
287301
(spec, item) -> item.getRecord().getTransferList().getAccountAmountsList().stream()
288-
.anyMatch(aa ->
289-
aa.getAccountID().getAccountNum() == 801L && aa.getAmount() < 0L)),
302+
.anyMatch(
303+
aa -> aa.getAccountID().getAccountNum() == 801L
304+
&& aa.getAmount() < 0L)
305+
&& asInstant(toPbj(item.getRecord().getConsensusTimestamp()))
306+
.isAfter(startConsensusTime.get())),
290307
Duration.ofSeconds(1)),
291308
nodeUpdate("0").declineReward(true),
292309
cryptoTransfer(TokenMovement.movingHbar(10000000 * ONE_HBAR).between(GENESIS, NODE_REWARD)),
@@ -349,10 +366,12 @@ final Stream<DynamicTest> inactiveNodesPaidWhenMinRewardsGreaterThanZero() {
349366
overrides = {"nodes.preserveMinNodeRewardBalance"})
350367
@Order(3)
351368
final Stream<DynamicTest> preserveNodeRewardBalanceHasEffectWhenFeatureEnabled() {
369+
final AtomicReference<Instant> startConsensusTime = new AtomicReference<>();
352370
final AtomicLong expectedNodeFees = new AtomicLong(0);
353371
final AtomicLong expectedNodeRewards = new AtomicLong(0);
354372
return hapiTest(
355373
overriding("nodes.preserveMinNodeRewardBalance", "false"),
374+
doingContextual(spec -> startConsensusTime.set(spec.consensusTime())),
356375
recordStreamMustIncludePassFrom(
357376
selectedItems(
358377
nodeRewardsValidator(expectedNodeRewards::get),
@@ -361,8 +380,11 @@ final Stream<DynamicTest> preserveNodeRewardBalanceHasEffectWhenFeatureEnabled()
361380
// So no synthetic node rewards payment is expected.
362381
1,
363382
(spec, item) -> item.getRecord().getTransferList().getAccountAmountsList().stream()
364-
.anyMatch(aa ->
365-
aa.getAccountID().getAccountNum() == 801L && aa.getAmount() < 0L)),
383+
.anyMatch(
384+
aa -> aa.getAccountID().getAccountNum() == 801L
385+
&& aa.getAmount() < 0L)
386+
&& asInstant(toPbj(item.getRecord().getConsensusTimestamp()))
387+
.isAfter(startConsensusTime.get())),
366388
Duration.ofSeconds(1)),
367389
cryptoTransfer(TokenMovement.movingHbar(100000 * ONE_HBAR).between(GENESIS, NODE_REWARD)),
368390
nodeUpdate("0").declineReward(true),

0 commit comments

Comments
 (0)