Skip to content

Commit

Permalink
Issue validation blocks within registered staking epochs
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed May 14, 2024
1 parent 6b5d767 commit f06d398
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions tools/docker-network/tests/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,20 @@ func Test_ValidatorRewards(t *testing.T) {
latestCommitmentSlot := blockIssuance.LatestCommitment.Slot
stakingStartEpoch := d.DefaultWallet().StakingStartEpochFromSlot(latestCommitmentSlot)
// Set end epoch so the staking feature can be removed as soon as possible.
endEpoch := stakingStartEpoch + clt.CommittedAPI().ProtocolParameters().StakingUnbondingPeriod()
// The earliest epoch in which we can remove the staking feature and claim rewards.
goodClaimingSlot := clt.CommittedAPI().TimeProvider().EpochStart(endEpoch + 1)
goodEndEpoch := stakingStartEpoch + clt.CommittedAPI().ProtocolParameters().StakingUnbondingPeriod()

goodAccountData := d.CreateAccountFromImplicitAccount(goodWallet,
goodAccountOutputData,
blockIssuance,
dockertestframework.WithStakingFeature(100, 1, stakingStartEpoch, endEpoch),
dockertestframework.WithStakingFeature(100, 1, stakingStartEpoch, goodEndEpoch),
)

initialMana := goodAccountData.Output.StoredMana()
issueCandidacyPayloadInBackground(ctx,
d,
goodWallet,
clt.CommittedAPI().TimeProvider().CurrentSlot(),
goodClaimingSlot)
clt.CommittedAPI().TimeProvider().EpochStart(goodEndEpoch))

// create lazy account
lazyWallet, lazyAccountOutputData := d.CreateImplicitAccount(ctx)
Expand All @@ -86,21 +84,21 @@ func Test_ValidatorRewards(t *testing.T) {

latestCommitmentSlot = blockIssuance.LatestCommitment.Slot
stakingStartEpoch = d.DefaultWallet().StakingStartEpochFromSlot(latestCommitmentSlot)
endEpoch = stakingStartEpoch + clt.CommittedAPI().ProtocolParameters().StakingUnbondingPeriod()
lazyClaimingSlot := clt.CommittedAPI().TimeProvider().EpochStart(endEpoch + 1)
lazyEndEpoch := stakingStartEpoch + clt.CommittedAPI().ProtocolParameters().StakingUnbondingPeriod()
lazyClaimingSlot := clt.CommittedAPI().TimeProvider().EpochStart(lazyEndEpoch + 1)

lazyAccountData := d.CreateAccountFromImplicitAccount(lazyWallet,
lazyAccountOutputData,
blockIssuance,
dockertestframework.WithStakingFeature(100, 1, stakingStartEpoch, endEpoch),
dockertestframework.WithStakingFeature(100, 1, stakingStartEpoch, lazyEndEpoch),
)

lazyInitialMana := lazyAccountData.Output.StoredMana()
issueCandidacyPayloadInBackground(ctx,
d,
lazyWallet,
clt.CommittedAPI().TimeProvider().CurrentSlot(),
lazyClaimingSlot)
clt.CommittedAPI().TimeProvider().EpochStart(lazyEndEpoch))

// make sure the account is in the committee, so it can issue validation blocks
goodAccountAddrBech32 := goodAccountData.Address.Bech32(clt.CommittedAPI().ProtocolParameters().Bech32HRP())
Expand All @@ -114,8 +112,8 @@ func Test_ValidatorRewards(t *testing.T) {
fmt.Println("Issue validation blocks, wait for ", secToWait, "until expected slot: ", lazyClaimingSlot)

var wg sync.WaitGroup
issueValidationBlockInBackground(ctx, &wg, goodWallet, currentSlot, goodClaimingSlot, 5)
issueValidationBlockInBackground(ctx, &wg, lazyWallet, currentSlot, lazyClaimingSlot, 1)
issueValidationBlockInBackground(ctx, &wg, goodWallet, currentSlot, clt.CommittedAPI().TimeProvider().EpochEnd(goodEndEpoch), 5)
issueValidationBlockInBackground(ctx, &wg, lazyWallet, currentSlot, clt.CommittedAPI().TimeProvider().EpochEnd(lazyEndEpoch), 1)

wg.Wait()

Expand Down

0 comments on commit f06d398

Please sign in to comment.