Skip to content

Commit

Permalink
cmd/devp2p: refactor eth test suite (ethereum#22843)
Browse files Browse the repository at this point in the history
This PR refactors the eth test suite to make it more readable and
easier to use. Some notable differences:

- A new file helpers.go stores all of the methods used between
  both eth66 and eth65 and below tests, as well as methods shared
  among many test functions.
- suite.go now contains all of the test functions for both eth65
  tests and eth66 tests.
- The utesting.T object doesn't get passed through to other helper methods,
  but is instead only used within the scope of the test function,
  whereas helper methods return errors, so only the test function
  itself can fatal out in the case of an error.
- The full test suite now only takes 13.5 seconds to run.
  • Loading branch information
renaynay authored and i-norden committed Sep 10, 2021
1 parent 291289e commit b3dd32c
Show file tree
Hide file tree
Showing 7 changed files with 1,467 additions and 1,422 deletions.
20 changes: 17 additions & 3 deletions cmd/devp2p/internal/ethtest/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,24 @@ func (c *Chain) Len() int {
return len(c.blocks)
}

// TD calculates the total difficulty of the chain.
func (c *Chain) TD(height int) *big.Int { // TODO later on channge scheme so that the height is included in range
// TD calculates the total difficulty of the chain at the
// chain head.
func (c *Chain) TD() *big.Int {
sum := big.NewInt(0)
for _, block := range c.blocks[:height] {
for _, block := range c.blocks[:c.Len()] {
sum.Add(sum, block.Difficulty())
}
return sum
}

// TotalDifficultyAt calculates the total difficulty of the chain
// at the given block height.
func (c *Chain) TotalDifficultyAt(height int) *big.Int {
sum := big.NewInt(0)
if height >= c.Len() {
return sum
}
for _, block := range c.blocks[:height+1] {
sum.Add(sum, block.Difficulty())
}
return sum
Expand Down

0 comments on commit b3dd32c

Please sign in to comment.