Skip to content

Commit

Permalink
Fix Test_ValidatorRewards with correct await and validation blocks is…
Browse files Browse the repository at this point in the history
…suance
  • Loading branch information
jkrvivian committed May 3, 2024
1 parent e902267 commit f1efb3e
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tools/docker-network/tests/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ func Test_ValidatorRewards(t *testing.T) {
latestCommitmentSlot := blockIssuance.LatestCommitment.Slot

stakingStartEpoch := d.defaultWallet.StakingStartEpochFromSlot(latestCommitmentSlot)

currentEpoch := clt.CommittedAPI().TimeProvider().EpochFromSlot(latestCommitmentSlot)
slotsDuration := clt.CommittedAPI().ProtocolParameters().SlotDurationInSeconds()

// Set end epoch so the staking feature can be removed as soon as possible.
endEpoch := stakingStartEpoch + clt.CommittedAPI().ProtocolParameters().StakingUnbondingPeriod() + 1
// The earliest epoch in which we can remove the staking feature and claim rewards.
claimingSlot := clt.CommittedAPI().TimeProvider().EpochStart(endEpoch + 1)
goodClaimingSlot := clt.CommittedAPI().TimeProvider().EpochStart(endEpoch + 1)

// create accounts and continue issuing candidacy payload for account in the background
goodWallet, goodAccountData := d.CreateAccount(WithStakingFeature(100, 1, stakingStartEpoch, endEpoch))
Expand All @@ -69,16 +68,19 @@ func Test_ValidatorRewards(t *testing.T) {
d,
goodWallet,
clt.CommittedAPI().TimeProvider().CurrentSlot(),
claimingSlot,
goodClaimingSlot,
slotsDuration)

lazyWallet, lazyAccountData := d.CreateAccount(WithStakingFeature(100, 1, stakingStartEpoch, endEpoch))
// The StartEpoch and EndEpoch may alter, so we need to recalculate the claiming slot.
// Note that we can only change the StartEpoch and EndEpoch in the wallet during account transition, because we wait for implicit account to be usable in CreateAccount, changing those in advance may still be outdated.
lazyClaimingSlot := clt.CommittedAPI().TimeProvider().EpochStart(lazyAccountData.Output.FeatureSet().Staking().EndEpoch + 1)
lazyInitialMana := lazyAccountData.Output.StoredMana()
issueCandidacyPayloadInBackground(ctx,
d,
lazyWallet,
clt.CommittedAPI().TimeProvider().CurrentSlot(),
claimingSlot,
lazyClaimingSlot,
slotsDuration)

// make sure the account is in the committee, so it can issue validation blocks
Expand All @@ -87,20 +89,15 @@ func Test_ValidatorRewards(t *testing.T) {
d.AssertCommittee(currentEpoch+2, append(d.AccountsFromNodes(d.Nodes("V1", "V3", "V2", "V4")...), goodAccountAddrBech32, lazyAccountAddrBech32))

// issue validation blocks to have performance
if currentSlot := clt.CommittedAPI().TimeProvider().CurrentSlot(); currentSlot < claimingSlot {
slotToWait := claimingSlot - currentSlot
secToWait := time.Duration(slotToWait) * time.Duration(slotsDuration) * time.Second
fmt.Println("Wait for ", secToWait, "until expected slot: ", claimingSlot)

var wg sync.WaitGroup
issueValidationBlockInBackground(ctx, &wg, goodWallet, currentSlot, claimingSlot, 5)
issueValidationBlockInBackground(ctx, &wg, lazyWallet, currentSlot, claimingSlot, 1)
currentSlot := clt.CommittedAPI().TimeProvider().CurrentSlot()
var wg sync.WaitGroup
issueValidationBlockInBackground(ctx, &wg, goodWallet, currentSlot, goodClaimingSlot, 5)
issueValidationBlockInBackground(ctx, &wg, lazyWallet, currentSlot, lazyClaimingSlot, 1)

wg.Wait()
}
wg.Wait()

// claim rewards that put to the account output
d.AwaitCommitment(claimingSlot)
d.AwaitCommitment(lazyClaimingSlot)
d.ClaimRewardsForValidator(ctx, goodWallet)
d.ClaimRewardsForValidator(ctx, lazyWallet)

Expand Down

0 comments on commit f1efb3e

Please sign in to comment.