Skip to content

Commit

Permalink
Merge pull request #916 from iotaledger/test/rewards-dockertest
Browse files Browse the repository at this point in the history
Fix Validator Rewards Test
  • Loading branch information
muXxer authored Apr 17, 2024
2 parents bf28901 + f9253c6 commit 0ed3103
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 4 additions & 1 deletion tools/docker-network/tests/dockerframework.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ func (d *DockerTestFramework) CreateTaggedDataBlock(issuerID iotago.AccountID, t
}, issuerID, congestionResp, issuerResp)
}

func (d *DockerTestFramework) SubmitValidationBlock(issuerID iotago.AccountID) *iotago.Block {
func (d *DockerTestFramework) SubmitValidationBlock(issuerID iotago.AccountID, issueNode ...string) *iotago.Block {
issuer := d.wallet.Account(issuerID)
ctx := context.TODO()
issuingTime := time.Now()
clt := d.wallet.DefaultClient()
if issueNode != nil {
clt = d.wallet.Clients[issueNode[0]]
}
currentSlot := d.wallet.DefaultClient().LatestAPI().TimeProvider().SlotFromTime(issuingTime)
apiForSlot := d.wallet.DefaultClient().APIForSlot(currentSlot)

Expand Down
17 changes: 13 additions & 4 deletions tools/docker-network/tests/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func Test_ValidatorRewards(t *testing.T) {
fmt.Println("Wait for ", secToWait, "until expected slot: ", claimingSlot)

var wg sync.WaitGroup
issueValidationBlockInBackground(&wg, d, account.ID, currentSlot, claimingSlot, 3, slotsDuration)
issueValidationBlockInBackground(&wg, d, lazyAccount.ID, currentSlot, claimingSlot, 1, slotsDuration)
issueValidationBlockInBackground(&wg, d, account.ID, currentSlot, claimingSlot, 5)
issueValidationBlockInBackground(&wg, d, lazyAccount.ID, currentSlot, claimingSlot, 1)

wg.Wait()

Expand Down Expand Up @@ -241,19 +241,28 @@ func issueCandidacyPayloadInBackground(d *DockerTestFramework, accountID iotago.
}()
}

func issueValidationBlockInBackground(wg *sync.WaitGroup, d *DockerTestFramework, accountID iotago.AccountID, startSlot, endSlot iotago.SlotIndex, blocksPerSlot int, slotDuration uint8) {
func issueValidationBlockInBackground(wg *sync.WaitGroup, d *DockerTestFramework, accountID iotago.AccountID, startSlot, endSlot iotago.SlotIndex, blocksPerSlot int) {
wg.Add(1)

go func() {
defer wg.Done()
fmt.Println("Issuing validation block for account", accountID, "in the background...")
defer fmt.Println("Issuing validation block for account", accountID, "in the background......done")
clt := d.wallet.DefaultClient()

for i := startSlot; i < endSlot; i++ {
// wait until the slot is reached
for {
if clt.CommittedAPI().TimeProvider().CurrentSlot() == i {
break
}
time.Sleep(2 * time.Second)
}

for range blocksPerSlot {
d.SubmitValidationBlock(accountID)
time.Sleep(1 * time.Second)
}
time.Sleep(time.Duration(slotDuration) * time.Second)
}
}()
}
2 changes: 1 addition & 1 deletion tools/docker-network/tests/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func (w *DockerWallet) ClaimValidatorRewards(issuerAccountID iotago.AccountID, i
}).
AddRewardInput(&iotago.RewardInput{Index: 0}, rewardResp.Rewards).
AddBlockIssuanceCreditInput(&iotago.BlockIssuanceCreditInput{
AccountID: accountOutput.AccountID,
AccountID: issuerAccountID,
}).
AddCommitmentInput(&iotago.CommitmentInput{CommitmentID: lo.Return1(issuerResp.LatestCommitment.ID())}).
AddOutput(accountOutput).
Expand Down

0 comments on commit 0ed3103

Please sign in to comment.