mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 09:37:38 +00:00
fix consensus tests
This commit is contained in:
parent
deb1528ca0
commit
b8c21e9aad
@ -101,6 +101,12 @@ func randSlice(min, max uint32) []byte {
|
||||
|
||||
func TestDifficultyCalculators(t *testing.T) {
|
||||
rand.Seed(2)
|
||||
|
||||
wrap := func(f func(time, parentTime uint64, parentDifficulty, parentNumber *big.Int) *big.Int) func(time, parentTime uint64, parentDifficulty, parentNumber *big.Int, unkleHash common.Hash) *big.Int {
|
||||
return func(time, parentTime uint64, parentDifficulty, parentNumber *big.Int, unkleHash common.Hash) *big.Int {
|
||||
return f(time, parentTime, parentDifficulty, parentNumber)
|
||||
}
|
||||
}
|
||||
for i := 0; i < 5000; i++ {
|
||||
// 1 to 300 seconds diff
|
||||
var timeDelta = uint64(1 + rand.Uint32()%3000)
|
||||
@ -119,15 +125,16 @@ func TestDifficultyCalculators(t *testing.T) {
|
||||
}
|
||||
bombDelay := new(big.Int).SetUint64(rand.Uint64() % 50_000_000)
|
||||
for i, pair := range []struct {
|
||||
bigFn func(time uint64, parent *types.Header) *big.Int
|
||||
bigFn func(time, parentTime uint64, parentDifficulty, parentNumber *big.Int, uncleHash common.Hash) *big.Int
|
||||
u256Fn func(time uint64, parent *types.Header) *big.Int
|
||||
}{
|
||||
{FrontierDifficultyCalulator, CalcDifficultyFrontierU256},
|
||||
{HomesteadDifficultyCalulator, CalcDifficultyHomesteadU256},
|
||||
{wrap(FrontierDifficultyCalulator), CalcDifficultyFrontierU256},
|
||||
{wrap(HomesteadDifficultyCalulator), CalcDifficultyHomesteadU256},
|
||||
{DynamicDifficultyCalculator(bombDelay), MakeDifficultyCalculatorU256(bombDelay)},
|
||||
} {
|
||||
time := header.Time + timeDelta
|
||||
want := pair.bigFn(time, header)
|
||||
|
||||
want := pair.bigFn(time, header.Time, header.Difficulty, header.Number, header.UncleHash)
|
||||
have := pair.u256Fn(time, header)
|
||||
if want.BitLen() > 256 {
|
||||
continue
|
||||
@ -153,7 +160,7 @@ func BenchmarkDifficultyCalculator(b *testing.B) {
|
||||
b.Run("big-frontier", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
calcDifficultyFrontier(1000014, h)
|
||||
calcDifficultyFrontier(1000014, h.Time, h.Difficulty, h.Number)
|
||||
}
|
||||
})
|
||||
b.Run("u256-frontier", func(b *testing.B) {
|
||||
@ -165,7 +172,7 @@ func BenchmarkDifficultyCalculator(b *testing.B) {
|
||||
b.Run("big-homestead", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
calcDifficultyHomestead(1000014, h)
|
||||
calcDifficultyHomestead(1000014, h.Time, h.Difficulty, h.Number)
|
||||
}
|
||||
})
|
||||
b.Run("u256-homestead", func(b *testing.B) {
|
||||
@ -177,7 +184,7 @@ func BenchmarkDifficultyCalculator(b *testing.B) {
|
||||
b.Run("big-generic", func(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
x1(1000014, h)
|
||||
x1(1000014, h.Time, h.Difficulty, h.Number, h.UncleHash)
|
||||
}
|
||||
})
|
||||
b.Run("u256-generic", func(b *testing.B) {
|
||||
|
Loading…
Reference in New Issue
Block a user