erigon-pulse/txpool/pool_fuzz_test.go

60 lines
1.6 KiB
Go
Raw Normal View History

2021-07-29 08:23:17 +00:00
// +build gofuzzbeta
package txpool
import (
"testing"
)
// 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-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-29 08:23:17 +00:00
f.Fuzz(func(t *testing.T, s1, s2, s3 []uint8) {
t.Parallel()
pending := NewSubPool()
for i := range s1 {
s1[i] &= 0b11111
pending.Add(&MetaTx{SubPool: SubPoolMarker(s1[i])})
}
baseFee := NewSubPool()
for i := range s2 {
s2[i] &= 0b11111
baseFee.Add(&MetaTx{SubPool: SubPoolMarker(s2[i])})
}
queue := NewSubPool()
for i := range s3 {
s3[i] &= 0b11111
queue.Add(&MetaTx{SubPool: SubPoolMarker(s3[i])})
}
PromoteStep(pending, baseFee, queue)
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 {
t.Fatalf("Pending worst too small %b, input: %b,%b,%b", 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 {
t.Fatalf("Pending worst too small %b, input: %b,%b,%b", worst.SubPool, s1, s2, s3)
}
best, worst = queue.Best(), queue.Worst()
_ = best
if worst != nil && worst.SubPool < 0b01111 {
t.Fatalf("Pending worst too small %b, input: %b,%b,%b", worst.SubPool, s1, s2, s3)
}
2021-07-29 08:23:17 +00:00
})
}