Skip to content

Commit

Permalink
Fix waiting time in issueCandidacyPayloadInBackground
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed May 9, 2024
1 parent 8055580 commit bf4393c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tools/docker-network/tests/api_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func Test_ValidatorsAPI(t *testing.T) {

// issue candidacy payload in the next epoch (currentEpoch + 1), in order to issue it before epochNearingThreshold
d.AwaitCommitment(clt.CommittedAPI().TimeProvider().EpochEnd(currentEpoch))
blkID := d.IssueCandidacyPayloadFromAccount(wallet)
blkID := d.IssueCandidacyPayloadFromAccount(ctx, wallet)
fmt.Println("Candidacy payload:", blkID.ToHex(), blkID.Slot())
d.AwaitCommitment(blkID.Slot())
}()
Expand Down
4 changes: 2 additions & 2 deletions tools/docker-network/tests/dockertestframework/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (d *DockerTestFramework) StopIssueCandidacyPayload(nodes ...*Node) {
require.NoError(d.Testing, err)
}

func (d *DockerTestFramework) IssueCandidacyPayloadFromAccount(wallet *mock.Wallet) iotago.BlockID {
block, err := wallet.CreateAndSubmitBasicBlock(context.TODO(), "candidacy_payload", mock.WithPayload(&iotago.CandidacyAnnouncement{}))
func (d *DockerTestFramework) IssueCandidacyPayloadFromAccount(ctx context.Context, wallet *mock.Wallet) iotago.BlockID {
block, err := wallet.CreateAndSubmitBasicBlock(ctx, "candidacy_payload", mock.WithPayload(&iotago.CandidacyAnnouncement{}))
require.NoError(d.Testing, err)

return block.ID()
Expand Down
27 changes: 16 additions & 11 deletions tools/docker-network/tests/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func Test_ValidatorRewards(t *testing.T) {
d,
goodWallet,
clt.CommittedAPI().TimeProvider().CurrentSlot(),
goodClaimingSlot,
slotsDuration)
goodClaimingSlot)

// create lazy account
lazyWallet, lazyAccountOutputData := d.CreateImplicitAccount(ctx)
Expand All @@ -98,8 +97,7 @@ func Test_ValidatorRewards(t *testing.T) {
d,
lazyWallet,
clt.CommittedAPI().TimeProvider().CurrentSlot(),
lazyClaimingSlot,
slotsDuration)
lazyClaimingSlot)

// make sure the account is in the committee, so it can issue validation blocks
goodAccountAddrBech32 := goodAccountData.Address.Bech32(clt.CommittedAPI().ProtocolParameters().Bech32HRP())
Expand Down Expand Up @@ -273,19 +271,26 @@ func Test_DelayedClaimingRewards(t *testing.T) {
}
}

func issueCandidacyPayloadInBackground(ctx context.Context, d *dockertestframework.DockerTestFramework, wallet *mock.Wallet, startSlot, endSlot iotago.SlotIndex, slotDuration uint8) {
func issueCandidacyPayloadInBackground(ctx context.Context, d *dockertestframework.DockerTestFramework, wallet *mock.Wallet, startSlot, endSlot iotago.SlotIndex) {
go func() {
fmt.Println("Issuing candidacy payloads for account", wallet.BlockIssuer.AccountData.ID, "in the background...")
defer fmt.Println("Issuing candidacy payloads for account", wallet.BlockIssuer.AccountData.ID, "in the background......done")

for i := startSlot; i < endSlot; i++ {
if ctx.Err() != nil {
// context is canceled
return
// wait until the slot is reached
for {
if ctx.Err() != nil {
// context is canceled
return
}

if wallet.CurrentSlot() == i {
break
}
time.Sleep(2 * time.Second)
}

d.IssueCandidacyPayloadFromAccount(wallet)
time.Sleep(time.Duration(slotDuration) * time.Second)
d.IssueCandidacyPayloadFromAccount(ctx, wallet)
}
}()
}
Expand Down Expand Up @@ -318,7 +323,7 @@ func issueValidationBlockInBackground(ctx context.Context, wg *sync.WaitGroup, w
return
}

wallet.CreateAndSubmitValidationBlock(context.Background(), "", nil)
wallet.CreateAndSubmitValidationBlock(ctx, "", nil)
time.Sleep(1 * time.Second)
}
}
Expand Down

0 comments on commit bf4393c

Please sign in to comment.