erigon-pulse/txpool/pool_fuzz_test.go

75 lines
2.2 KiB
Go
Raw Normal View History

2021-07-30 07:10:58 +00:00
//go:build gofuzzbeta
2021-07-29 08:23:17 +00:00
// +build gofuzzbeta
package txpool
import (
"testing"
2021-07-30 07:10:58 +00:00
"github.com/stretchr/testify/require"
2021-07-29 08:23:17 +00:00
)
// https://blog.golang.org/fuzz-beta
// golang.org/s/draft-fuzzing-design
//gotip doc testing
//gotip doc testing.F
//gotip doc testing.F.Add
//gotip doc testing.F.Fuzz
2021-07-29 08:33:22 +00:00
// gotip test -trimpath -v -fuzz=Fuzz -fuzztime=10s ./txpool
2021-07-30 07:10:58 +00:00
func FuzzTwoQueue(f *testing.F) {
f.Add([]uint8{0b11000, 0b00101, 0b000111})
f.Fuzz(func(t *testing.T, in []uint8) {
t.Parallel()
sub := NewSubPool()
for _, i := range in {
sub.Add(&MetaTx{SubPool: SubPoolMarker(i & 0b11111)})
}
for sub.Len() > 0 {
require.Equal(t, (*sub.worst)[0].SubPool, sub.Best().SubPool)
require.Equal(t, (*sub.best)[0].SubPool, sub.Worst().SubPool)
sub.PopBest()
}
})
}
2021-07-29 08:23:17 +00:00
func FuzzPromoteStep(f *testing.F) {
f.Add([]uint8{0b11111, 0b10001, 0b10101, 0b00001, 0b00000}, []uint8{0b11111, 0b10001, 0b10101, 0b00001, 0b00000}, []uint8{0b11111, 0b10001, 0b10101, 0b00001, 0b00000})
2021-07-30 03:28:03 +00:00
f.Add([]uint8{0b11111}, []uint8{0b11111}, []uint8{0b11110, 0b0, 0b1010})
2021-07-30 07:10:58 +00:00
f.Add([]uint8{0b11000, 0b00101, 0b000111}, []uint8{0b11000, 0b00101, 0b000111}, []uint8{0b11000, 0b00101, 0b000111})
2021-07-29 08:23:17 +00:00
f.Fuzz(func(t *testing.T, s1, s2, s3 []uint8) {
t.Parallel()
2021-07-30 07:10:58 +00:00
pending, baseFee, queued := NewSubPool(), NewSubPool(), NewSubPool()
for _, i := range s1 {
pending.Add(&MetaTx{SubPool: SubPoolMarker(i & 0b11111)})
2021-07-29 08:23:17 +00:00
}
2021-07-30 07:10:58 +00:00
for _, i := range s2 {
baseFee.Add(&MetaTx{SubPool: SubPoolMarker(i & 0b11111)})
2021-07-29 08:23:17 +00:00
}
2021-07-30 07:10:58 +00:00
for _, i := range s3 {
queued.Add(&MetaTx{SubPool: SubPoolMarker(i & 0b11111)})
2021-07-29 08:23:17 +00:00
}
2021-07-30 07:10:58 +00:00
PromoteStep(pending, baseFee, queued)
2021-07-29 08:23:17 +00:00
2021-07-29 08:33:22 +00:00
best, worst := pending.Best(), pending.Worst()
2021-07-29 08:48:23 +00:00
_ = best
2021-07-30 03:28:03 +00:00
if worst != nil && worst.SubPool < 0b01111 {
2021-07-30 07:10:58 +00:00
t.Fatalf("pending worst too small %b, input: \n%x\n%x\n%x", worst.SubPool, s1, s2, s3)
2021-07-29 08:23:17 +00:00
}
2021-07-30 03:28:03 +00:00
best, worst = baseFee.Best(), baseFee.Worst()
_ = best
if worst != nil && worst.SubPool < 0b01111 {
2021-07-30 07:10:58 +00:00
t.Fatalf("baseFee worst too small %b, input: \n%x\n%x\n%x", worst.SubPool, s1, s2, s3)
2021-07-30 03:28:03 +00:00
}
2021-07-30 07:10:58 +00:00
best, worst = queued.Best(), queued.Worst()
2021-07-30 03:28:03 +00:00
_ = best
if worst != nil && worst.SubPool < 0b01111 {
2021-07-30 07:10:58 +00:00
t.Fatalf("queued worst too small %b, input: \n%x\n%x\n%x", worst.SubPool, s1, s2, s3)
2021-07-30 03:28:03 +00:00
}
2021-07-29 08:23:17 +00:00
})
}