Skip to content

Commit 094d23d

Browse files
committed
update to use networkHub ticker
1 parent f5eda11 commit 094d23d

File tree

10 files changed

+42
-141
lines changed

10 files changed

+42
-141
lines changed

cmd/txsimulation/lifecycle/engine.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
utils2 "github.com/vechain/hayabusa-e2e/cmd/txsimulation/utils"
1313
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/validators"
1414
"github.com/vechain/hayabusa-e2e/hayabusa"
15-
"github.com/vechain/hayabusa-e2e/utils"
15+
netUtils "github.com/vechain/networkhub/utils/common"
1616
"github.com/vechain/thor/v2/api"
1717
"github.com/vechain/thor/v2/test/datagen"
1818
"github.com/vechain/thor/v2/thor"
@@ -82,7 +82,7 @@ func (e *Engine) AddLifecycle(lifecycle Lifecycle) {
8282
}
8383

8484
func (e *Engine) Run() {
85-
ticker := utils.NewTicker(e.stack.Client())
85+
ticker := netUtils.NewTicker(e.stack.Client())
8686
for {
8787
select {
8888
case <-e.stack.Context().Done():
@@ -95,8 +95,8 @@ func (e *Engine) Run() {
9595
}
9696
_, id, _ := e.stack.Staker().FirstActive()
9797
if !id.IsZero() {
98-
e.generateValidatorCycles(best)
99-
e.generateDelegatorCycles(best)
98+
e.generateValidatorCycles(best.(*api.JSONExpandedBlock))
99+
e.generateDelegatorCycles(best.(*api.JSONExpandedBlock))
100100
}
101101

102102
delegationStatus := make(map[Status]int)
@@ -112,7 +112,7 @@ func (e *Engine) Run() {
112112
}
113113
if lifecycle.Status() != StatusWithdrawn {
114114
e.workerPool.Run(func() {
115-
if err := lifecycle.Process(best.Number); err != nil {
115+
if err := lifecycle.Process(best.(*api.JSONExpandedBlock).Number); err != nil {
116116
slog.Error("failed to process lifecycle", "type", lifecycle.Type(), "id", lifecycle.ID(), "error", err)
117117
}
118118
})
@@ -156,7 +156,7 @@ func (e *Engine) Flush(status Status) error {
156156
e.mu.Lock()
157157
defer e.mu.Unlock()
158158

159-
ticker := utils.NewTicker(e.stack.Client())
159+
ticker := netUtils.NewTicker(e.stack.Client())
160160

161161
processed := false
162162
for !processed {
@@ -168,11 +168,11 @@ func (e *Engine) Flush(status Status) error {
168168
for _, lifecycle := range e.lifecycles {
169169
e.workerPool.Run(func(l Lifecycle, current *api.JSONExpandedBlock) Worker {
170170
return func() {
171-
if err := lifecycle.Process(best.Number); err != nil {
171+
if err := lifecycle.Process(best.(*api.JSONExpandedBlock).Number); err != nil {
172172
slog.Error("failed to process lifecycle", "type", lifecycle.Type(), "id", lifecycle.ID(), "error", err)
173173
}
174174
}
175-
}(lifecycle, best))
175+
}(lifecycle, best.(*api.JSONExpandedBlock)))
176176
}
177177

178178
processed = true

cmd/txsimulation/validators/validations.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/ethereum/go-ethereum/common/math"
1818
lru "github.com/hashicorp/golang-lru"
1919
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/stack"
20-
"github.com/vechain/hayabusa-e2e/utils"
20+
netUtils "github.com/vechain/networkhub/utils/common"
2121
"github.com/vechain/thor/v2/api"
2222
"github.com/vechain/thor/v2/builtin/staker/validation"
2323
"github.com/vechain/thor/v2/thor"
@@ -65,7 +65,7 @@ func (s *Service) LookupAddress(id thor.Address) (*validation.Validation, bool)
6565
}
6666

6767
func (s *Service) poll() {
68-
ticker := utils.NewTicker(s.stack.Client())
68+
ticker := netUtils.NewTicker(s.stack.Client())
6969
for {
7070
select {
7171
case <-s.stack.Context().Done():
@@ -77,9 +77,9 @@ func (s *Service) poll() {
7777
time.Sleep(5 * time.Second) // Retry after a short delay
7878
continue
7979
}
80-
validators, err := s.FetchAll(block.ID)
80+
validators, err := s.FetchAll(block.(*api.JSONExpandedBlock).ID)
8181
if err != nil {
82-
slog.Error("Failed to fetch validatorInfo", "error", err, "block", block.ID)
82+
slog.Error("Failed to fetch validatorInfo", "error", err, "block", block.(*api.JSONExpandedBlock).ID)
8383
continue
8484
}
8585

tests/delegations/delegations_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/vechain/hayabusa-e2e/hayabusa"
1313
"github.com/vechain/hayabusa-e2e/testutil"
1414
"github.com/vechain/hayabusa-e2e/utils"
15+
"github.com/vechain/networkhub/utils/common"
1516
"github.com/vechain/thor/v2/thor"
1617
"github.com/vechain/thor/v2/thorclient"
1718
"github.com/vechain/thor/v2/thorclient/builtin"
@@ -42,7 +43,7 @@ func Test_StargateRewards(t *testing.T) {
4243
require.NoError(t, err)
4344
}
4445

45-
ticker := utils.NewTicker(staker.Raw().Client())
46+
ticker := common.NewTicker(staker.Raw().Client())
4647
best, err := staker.Raw().Client().Block("best")
4748
require.NoError(t, err)
4849
require.NoError(t, ticker.WaitForBlock(best.Number+config.MinStakingPeriod))
@@ -83,7 +84,7 @@ func Test_StargateRewards(t *testing.T) {
8384
func Test_Delegations_Delegate1PeriodOnly(t *testing.T) {
8485
t.Parallel()
8586
staker, config, validationIDs := newDelegationSetup(t)
86-
ticker := utils.NewTicker(staker.Raw().Client())
87+
ticker := common.NewTicker(staker.Raw().Client())
8788

8889
multiplier := uint8(100)
8990
receipt := testutil.Send(t, hayabusa.Stargate,
@@ -128,7 +129,7 @@ func Test_Delegations_Delegate1PeriodOnly(t *testing.T) {
128129

129130
func Test_Delegations(t *testing.T) {
130131
staker, config, validationIDs := newDelegationSetup(t)
131-
ticker := utils.NewTicker(staker.Raw().Client())
132+
ticker := common.NewTicker(staker.Raw().Client())
132133

133134
t.Run("Delegate update auto renew after first period", func(t *testing.T) {
134135
t.Parallel()

tests/energy/energy_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/vechain/hayabusa-e2e/hayabusa"
1212
"github.com/vechain/hayabusa-e2e/testutil"
1313
"github.com/vechain/hayabusa-e2e/utils"
14+
"github.com/vechain/networkhub/utils/common"
1415
native "github.com/vechain/thor/v2/builtin"
1516
"github.com/vechain/thor/v2/thor"
1617
"github.com/vechain/thor/v2/thorclient/builtin"
@@ -141,7 +142,7 @@ func runEnergyTest(t *testing.T) error {
141142

142143
firstPoSBlock := poaBlock + config.TransitionPeriod
143144
block = config.ForkBlock + config.TransitionPeriod + config.MinStakingPeriod + 10 // wait for 1 staking period + 10 blocks (to handle forks)
144-
require.NoError(t, utils.NewTicker(staker.Raw().Client()).WaitForBlock(block))
145+
require.NoError(t, common.NewTicker(staker.Raw().Client()).WaitForBlock(block))
145146

146147
acc1Blocks := 0
147148
for i := firstPoSBlock; i < block-10; i++ {

tests/eviction/eviction_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/vechain/hayabusa-e2e/hayabusa"
1010
"github.com/vechain/hayabusa-e2e/testutil"
1111
"github.com/vechain/hayabusa-e2e/utils"
12+
"github.com/vechain/networkhub/utils/common"
1213
"github.com/vechain/thor/v2/thor"
1314
"github.com/vechain/thor/v2/thorclient/builtin"
1415
)
@@ -91,7 +92,7 @@ func TestHayabusaEviction(t *testing.T) {
9192

9293
offlineBlock := config.ForkBlock + config.TransitionPeriod
9394
exitBlock := offlineBlock + config.EpochLength + config.ValidatorEvictionThreshold + 1
94-
ticker := utils.NewTicker(staker.Raw().Client())
95+
ticker := common.NewTicker(staker.Raw().Client())
9596
t.Log("✅ waiting for block", exitBlock)
9697
require.NoError(t, ticker.WaitForBlock(exitBlock))
9798
t.Log("✅ waiting done")
@@ -105,7 +106,7 @@ func TestHayabusaEviction(t *testing.T) {
105106
}
106107

107108
func assertValidatorStatus(t *testing.T, staker *builtin.Staker, validatorID thor.Address, expectedStatus builtin.StakerStatus, waitForBlock uint32) {
108-
assert.NoError(t, utils.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
109+
assert.NoError(t, common.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
109110
validator, err := staker.GetValidation(validatorID)
110111
assert.NoError(t, err)
111112
assert.Equal(t, expectedStatus, validator.Status)

tests/pause/pause_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/vechain/hayabusa-e2e/hayabusa"
1414
"github.com/vechain/hayabusa-e2e/testutil"
1515
"github.com/vechain/hayabusa-e2e/utils"
16+
"github.com/vechain/networkhub/utils/common"
1617
"github.com/vechain/thor/v2/api"
1718
"github.com/vechain/thor/v2/thor"
1819
"github.com/vechain/thor/v2/thorclient"
@@ -150,7 +151,7 @@ func TestStakerPauseForValidation(t *testing.T) {
150151
func TestPauseForDelegator(t *testing.T) {
151152
t.Parallel()
152153
config, client := setupTestNetwork(t, 2)
153-
ticker := utils.NewTicker(client)
154+
ticker := common.NewTicker(client)
154155

155156
validator1 := hayabusa.ValidatorAccounts[0]
156157
validator2 := hayabusa.ValidatorAccounts[1]
@@ -372,7 +373,7 @@ func waitForPoSAndAssertFirstActive(t *testing.T, staker *builtin.Staker, config
372373
}
373374

374375
func assertValidatorStatus(t *testing.T, staker *builtin.Staker, validatorID thor.Address, expectedStatus builtin.StakerStatus, waitForBlock uint32) {
375-
assert.NoError(t, utils.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
376+
assert.NoError(t, common.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
376377
validator, err := staker.GetValidation(validatorID)
377378
assert.NoError(t, err)
378379
assert.Equal(t, expectedStatus, validator.Status)

tests/slots/slots_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"testing"
77
"time"
88

9+
"github.com/vechain/networkhub/utils/common"
10+
"github.com/vechain/thor/v2/api"
911
"github.com/vechain/thor/v2/thorclient"
1012

1113
"github.com/stretchr/testify/require"
@@ -68,7 +70,7 @@ func runTestMissedSlot(t *testing.T) error {
6870

6971
// wait for PoS
7072
block := config.ForkBlock + config.TransitionPeriod
71-
ticker := utils.NewTicker(staker.Raw().Client())
73+
ticker := common.NewTicker(staker.Raw().Client())
7274
require.NoError(t, utils.WaitForPOS(staker, block))
7375

7476
// wait for a missed slot
@@ -82,7 +84,7 @@ func runTestMissedSlot(t *testing.T) error {
8284
for range 60 {
8385
best, err := ticker.Wait(5 * time.Minute)
8486
require.NoError(t, err)
85-
if best.Timestamp-prev.Timestamp > 15 {
87+
if best.(*api.JSONExpandedBlock).Timestamp-prev.(*api.JSONExpandedBlock).Timestamp > 15 {
8688
missedSlot = true
8789
break
8890
}

tests/stargate/stargate_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12+
"github.com/vechain/networkhub/utils/common"
1213
native "github.com/vechain/thor/v2/builtin"
1314
"github.com/vechain/thor/v2/thorclient"
1415

@@ -34,7 +35,7 @@ func Test_Stargate_SingleDelegator(t *testing.T) {
3435
})
3536
}
3637

37-
func waitForCompletedPeriods(ticker *utils.Ticker, staker *builtin.Staker, validationID thor.Address, expectedPeriods uint32) error {
38+
func waitForCompletedPeriods(ticker *common.Ticker, staker *builtin.Staker, validationID thor.Address, expectedPeriods uint32) error {
3839
err := ticker.WaitForCondition(time.Minute*1, func() (bool, error) {
3940
periodDetails, err := staker.GetValidationPeriodDetails(validationID)
4041
slog.Info("⚠️ - completed periods, waiting for greater or equal than expected", "completed", int(periodDetails.CompletedPeriods), "expected", expectedPeriods)
@@ -54,7 +55,7 @@ func runTestStargateSingleDelegator(t *testing.T) error {
5455
staker, stargate, config, validationIDs, client := newDelegationSetup(t)
5556

5657
validationID := validationIDs[0]
57-
ticker := utils.NewTicker(staker.Raw().Client())
58+
ticker := common.NewTicker(staker.Raw().Client())
5859
validation, err := staker.GetValidation(validationID)
5960
require.NoError(t, err)
6061

@@ -224,7 +225,7 @@ func runTestStargateDelegatorFlowStakeAndClaimAutoRenewOff(t *testing.T) error {
224225
staker, stargate, config, validationIDs, _ := newDelegationSetup(t)
225226

226227
validationID := validationIDs[0]
227-
ticker := utils.NewTicker(staker.Raw().Client())
228+
ticker := common.NewTicker(staker.Raw().Client())
228229
_, err := staker.GetValidation(validationID)
229230
require.NoError(t, err)
230231

@@ -330,7 +331,7 @@ func runTestStargateDelegatorFlowStakeAndClaimAutoRenewOnAndOff(t *testing.T) er
330331
staker, stargate, config, validationIDs, _ := newDelegationSetup(t)
331332

332333
validationID := validationIDs[0]
333-
ticker := utils.NewTicker(staker.Raw().Client())
334+
ticker := common.NewTicker(staker.Raw().Client())
334335
_, err := staker.GetValidation(validationID)
335336
require.NoError(t, err)
336337

tests/validations/validations_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/vechain/hayabusa-e2e/hayabusa"
1212
"github.com/vechain/hayabusa-e2e/testutil"
1313
"github.com/vechain/hayabusa-e2e/utils"
14+
"github.com/vechain/networkhub/utils/common"
1415
"github.com/vechain/thor/v2/api"
1516
"github.com/vechain/thor/v2/test/datagen"
1617
"github.com/vechain/thor/v2/thor"
@@ -99,7 +100,7 @@ func TestHayabusaNoForkThenJoinLater(t *testing.T) {
99100
t.Log("✅ - Queued validator OK")
100101

101102
block := config.ForkBlock + config.TransitionPeriod
102-
ticker := utils.NewTicker(client)
103+
ticker := common.NewTicker(client)
103104
require.NoError(t, ticker.WaitForBlock(block))
104105

105106
_, validatorID, err := staker.FirstActive()
@@ -136,7 +137,7 @@ func TestHayabusaFullFlowJoinQueuedCooldownExit(t *testing.T) {
136137
sequence := testutil.NewTxSequence(t)
137138

138139
staker := testutil.SetupStakerAndWaitForFork(t, client, config)
139-
ticker := utils.NewTicker(client)
140+
ticker := common.NewTicker(client)
140141

141142
id1 := testutil.AddValidator(sequence, staker, validator1, config.MinStakingPeriod)
142143
id2 := testutil.AddValidator(sequence, staker, validator2, config.MinStakingPeriod)
@@ -725,15 +726,15 @@ func TestBeneficiary(t *testing.T) {
725726
assert.NoError(t, utils.WaitForPOS(staker, config.ForkBlock+config.TransitionPeriod))
726727

727728
blockRewards := hayabusa.GetExpectedReward(big.NewInt(0).Mul(builtin.MinStake(), big.NewInt(2)))
728-
ticker := utils.NewTicker(client)
729+
ticker := common.NewTicker(client)
729730
block, err := ticker.Wait(time.Second * 20)
730731
require.NoError(t, err)
731732

732-
assert.Equal(t, block.Beneficiary, beneficiary, "Block beneficiary should match the set beneficiary")
733+
assert.Equal(t, block.(*api.JSONExpandedBlock).Beneficiary, beneficiary, "Block beneficiary should match the set beneficiary")
733734

734-
beneficiaryBeforeBlock, err := staker.Raw().Client().Account(&beneficiary, thorclient.Revision(block.ParentID.String()))
735+
beneficiaryBeforeBlock, err := staker.Raw().Client().Account(&beneficiary, thorclient.Revision(block.(*api.JSONExpandedBlock).ParentID.String()))
735736
require.NoError(t, err)
736-
beneficiaryAfterBlock, err := staker.Raw().Client().Account(&beneficiary, thorclient.Revision(block.ID.String()))
737+
beneficiaryAfterBlock, err := staker.Raw().Client().Account(&beneficiary, thorclient.Revision(block.(*api.JSONExpandedBlock).ID.String()))
737738
require.NoError(t, err)
738739

739740
difference := new(big.Int).Sub((*big.Int)(beneficiaryAfterBlock.Energy), (*big.Int)(beneficiaryBeforeBlock.Energy))
@@ -770,14 +771,14 @@ func assertMatchingValidators(t *testing.T, staker *builtin.Staker, id1 thor.Add
770771
}
771772

772773
func assertValidatorStatus(t *testing.T, staker *builtin.Staker, validatorID thor.Address, expectedStatus builtin.StakerStatus, waitForBlock uint32) {
773-
assert.NoError(t, utils.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
774+
assert.NoError(t, common.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
774775
validator, err := staker.GetValidation(validatorID)
775776
assert.NoError(t, err)
776777
assert.Equal(t, expectedStatus, validator.Status)
777778
}
778779

779780
func assertValidatorStatusUnknown(t *testing.T, staker *builtin.Staker, validatorID thor.Address, expectedStatus builtin.StakerStatus, waitForBlock uint32) error {
780-
assert.NoError(t, utils.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
781+
assert.NoError(t, common.NewTicker(staker.Raw().Client()).WaitForBlock(waitForBlock))
781782
validator, err := staker.GetValidation(validatorID)
782783
assert.NoError(t, err)
783784
if validator.Status == builtin.StakerStatusUnknown {

0 commit comments

Comments
 (0)