test: fix handling of start height in generated E2E testnets (#5563)

In #5488 the E2E testnet generator changed to setting explicit `StartAt` heights for initial nodes. This broke the runner, which expected all initial nodes to have `StartAt: 0`, as well as validator set scheduling in the generator. Testnet loading now normalizes initial nodes to have `StartAt: 0`.

This also tweaks waiting for misbehavior heights to only use an additional wait if there actually is any misbehavior in the testnet, and to output information when waiting.
This commit is contained in:
Erik Grinaker
2020-10-26 10:09:46 +00:00
committed by GitHub
parent d1ef5028a0
commit 10dda219a1
5 changed files with 43 additions and 30 deletions
+22 -1
View File
@@ -151,6 +151,9 @@ func LoadTestnet(file string) (*Testnet, error) {
Perturbations: []Perturbation{},
Misbehaviors: make(map[int64]string),
}
if node.StartAt == testnet.InitialHeight {
node.StartAt = 0 // normalize to 0 for initial nodes, since code expects this
}
if nodeManifest.Mode != "" {
node.Mode = Mode(nodeManifest.Mode)
}
@@ -341,7 +344,12 @@ func (n Node) Validate(testnet Testnet) error {
for height, misbehavior := range n.Misbehaviors {
if height < n.StartAt {
return fmt.Errorf("misbehavior height %d is before start height %d", height, n.StartAt)
return fmt.Errorf("misbehavior height %d is below node start height %d",
height, n.StartAt)
}
if height < testnet.InitialHeight {
return fmt.Errorf("misbehavior height %d is below network initial height %d",
height, testnet.InitialHeight)
}
exists := false
for possibleBehaviors := range mcs.MisbehaviorList {
@@ -395,6 +403,19 @@ func (t Testnet) IPv6() bool {
return t.IP.IP.To4() == nil
}
// LastMisbehaviorHeight returns the height of the last misbehavior.
func (t Testnet) LastMisbehaviorHeight() int64 {
lastHeight := int64(0)
for _, node := range t.Nodes {
for height := range node.Misbehaviors {
if height > lastHeight {
lastHeight = height
}
}
}
return lastHeight
}
// Address returns a P2P endpoint address for the node.
func (n Node) AddressP2P(withID bool) string {
ip := n.IP.String()