Skip to content

Commit

Permalink
Add StakingStartEpochFromSlot to wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed May 3, 2024
1 parent 3da9728 commit 77dbc80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions pkg/testsuite/mock/wallet_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ func (w *Wallet) CreateDelegationFromInput(transactionName string, input *Output
return signedTransaction
}

func (w *Wallet) StakingStartEpochFromSlot(latestCommitmentSlot iotago.SlotIndex) iotago.EpochIndex {
apiForSlot := w.Client.APIForSlot(latestCommitmentSlot)

pastBoundedSlot := latestCommitmentSlot + apiForSlot.ProtocolParameters().MaxCommittableAge()
pastBoundedEpoch := apiForSlot.TimeProvider().EpochFromSlot(pastBoundedSlot)

return pastBoundedEpoch
}

func (w *Wallet) DelegationStartFromSlot(slot, latestCommitmentSlot iotago.SlotIndex) iotago.EpochIndex {
apiForSlot := w.Client.APIForSlot(slot)

Expand Down
9 changes: 4 additions & 5 deletions tools/docker-network/tests/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,18 @@ func Test_ValidatorRewards(t *testing.T) {

latestCommitmentSlot := blockIssuance.LatestCommitment.Slot

pastBoundedSlot := latestCommitmentSlot + clt.CommittedAPI().ProtocolParameters().MaxCommittableAge()
pastBoundedEpoch := clt.CommittedAPI().TimeProvider().EpochFromSlot(pastBoundedSlot)
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 := pastBoundedEpoch + clt.CommittedAPI().ProtocolParameters().StakingUnbondingPeriod() + 1
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)

// create accounts and continue issuing candidacy payload for account in the background
goodWallet, goodAccountData := d.CreateAccount(WithStakingFeature(100, 1, pastBoundedEpoch, endEpoch))
goodWallet, goodAccountData := d.CreateAccount(WithStakingFeature(100, 1, stakingStartEpoch, endEpoch))
initialMana := goodAccountData.Output.StoredMana()
issueCandidacyPayloadInBackground(ctx,
d,
Expand All @@ -73,7 +72,7 @@ func Test_ValidatorRewards(t *testing.T) {
claimingSlot,
slotsDuration)

lazyWallet, lazyAccountData := d.CreateAccount(WithStakingFeature(100, 1, pastBoundedEpoch, endEpoch))
lazyWallet, lazyAccountData := d.CreateAccount(WithStakingFeature(100, 1, stakingStartEpoch, endEpoch))
lazyInitialMana := lazyAccountData.Output.StoredMana()
issueCandidacyPayloadInBackground(ctx,
d,
Expand Down

0 comments on commit 77dbc80

Please sign in to comment.