@@ -37,6 +37,7 @@ import (
37
37
"github.com/ava-labs/avalanchego/upgrade"
38
38
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
39
39
"github.com/ava-labs/avalanchego/utils"
40
+ "github.com/ava-labs/avalanchego/utils/constants"
40
41
"github.com/ava-labs/avalanchego/utils/logging"
41
42
"github.com/ava-labs/avalanchego/utils/timer/mockable"
42
43
"github.com/ava-labs/avalanchego/vms/proposervm/proposer"
@@ -2571,3 +2572,91 @@ func TestTimestampMetrics(t *testing.T) {
2571
2572
})
2572
2573
}
2573
2574
}
2575
+
2576
+ func TestSelectChildPChainHeight (t * testing.T ) {
2577
+ var (
2578
+ activationTime = time .Unix (0 , 0 )
2579
+ durangoTime = activationTime
2580
+
2581
+ beforeOverrideEnds = fujiOverridePChainHeightUntilTimestamp .Add (- time .Minute )
2582
+ )
2583
+ for _ , test := range []struct {
2584
+ name string
2585
+ time time.Time
2586
+ networkID uint32
2587
+ subnetID ids.ID
2588
+ currentPChainHeight uint64
2589
+ minPChainHeight uint64
2590
+ expectedPChainHeight uint64
2591
+ }{
2592
+ {
2593
+ name : "no override - mainnet" ,
2594
+ time : beforeOverrideEnds ,
2595
+ networkID : constants .MainnetID ,
2596
+ subnetID : ids .GenerateTestID (),
2597
+ currentPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2598
+ minPChainHeight : fujiOverridePChainHeightUntilHeight - 5 ,
2599
+ expectedPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2600
+ },
2601
+ {
2602
+ name : "no override - primary network" ,
2603
+ time : beforeOverrideEnds ,
2604
+ networkID : constants .FujiID ,
2605
+ subnetID : constants .PrimaryNetworkID ,
2606
+ currentPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2607
+ minPChainHeight : fujiOverridePChainHeightUntilHeight - 5 ,
2608
+ expectedPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2609
+ },
2610
+ {
2611
+ name : "no override - expired network" ,
2612
+ time : fujiOverridePChainHeightUntilTimestamp ,
2613
+ networkID : constants .FujiID ,
2614
+ subnetID : ids .GenerateTestID (),
2615
+ currentPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2616
+ minPChainHeight : fujiOverridePChainHeightUntilHeight - 5 ,
2617
+ expectedPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2618
+ },
2619
+ {
2620
+ name : "no override - chain previously advanced" ,
2621
+ time : beforeOverrideEnds ,
2622
+ networkID : constants .FujiID ,
2623
+ subnetID : ids .GenerateTestID (),
2624
+ currentPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2625
+ minPChainHeight : fujiOverridePChainHeightUntilHeight + 1 ,
2626
+ expectedPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2627
+ },
2628
+ {
2629
+ name : "override" ,
2630
+ time : beforeOverrideEnds ,
2631
+ networkID : constants .FujiID ,
2632
+ subnetID : ids .GenerateTestID (),
2633
+ currentPChainHeight : fujiOverridePChainHeightUntilHeight + 2 ,
2634
+ minPChainHeight : fujiOverridePChainHeightUntilHeight - 5 ,
2635
+ expectedPChainHeight : fujiOverridePChainHeightUntilHeight - 5 ,
2636
+ },
2637
+ } {
2638
+ t .Run (test .name , func (t * testing.T ) {
2639
+ require := require .New (t )
2640
+
2641
+ _ , vdrState , proVM , _ := initTestProposerVM (t , activationTime , durangoTime , 0 )
2642
+ defer func () {
2643
+ require .NoError (proVM .Shutdown (context .Background ()))
2644
+ }()
2645
+
2646
+ proVM .Clock .Set (test .time )
2647
+ proVM .ctx .NetworkID = test .networkID
2648
+ proVM .ctx .SubnetID = test .subnetID
2649
+
2650
+ vdrState .GetMinimumHeightF = func (context.Context ) (uint64 , error ) {
2651
+ return test .currentPChainHeight , nil
2652
+ }
2653
+
2654
+ actualPChainHeight , err := proVM .selectChildPChainHeight (
2655
+ context .Background (),
2656
+ test .minPChainHeight ,
2657
+ )
2658
+ require .NoError (err )
2659
+ require .Equal (test .expectedPChainHeight , actualPChainHeight )
2660
+ })
2661
+ }
2662
+ }
0 commit comments