From 62b69505fad19f7015795e245c68eb28dfe4d8bd Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Fri, 30 Jul 2021 16:26:56 +0700 Subject: [PATCH] fix queues --- txpool/pool_fuzz_test.go | 6 +++++ txpool/pool_test.go | 51 ---------------------------------------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/txpool/pool_fuzz_test.go b/txpool/pool_fuzz_test.go index 5082f8e99..4d28d489d 100644 --- a/txpool/pool_fuzz_test.go +++ b/txpool/pool_fuzz_test.go @@ -45,6 +45,9 @@ func FuzzTwoQueue(f *testing.F) { i-- } assert.Zero(i) + assert.Zero(sub.Len()) + assert.Zero(sub.best.Len()) + assert.Zero(sub.worst.Len()) } { @@ -64,6 +67,9 @@ func FuzzTwoQueue(f *testing.F) { i-- } assert.Zero(i) + assert.Zero(sub.Len()) + assert.Zero(sub.best.Len()) + assert.Zero(sub.worst.Len()) } }) } diff --git a/txpool/pool_test.go b/txpool/pool_test.go index 60896885a..a50c1a5b1 100644 --- a/txpool/pool_test.go +++ b/txpool/pool_test.go @@ -20,7 +20,6 @@ import ( "encoding/hex" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -76,56 +75,6 @@ func TestSubPoolOrder(t *testing.T) { require.Equal(t, uint8(sub.Best().SubPool), uint8(sub.PopBest().SubPool)) } -func TestSubPoolOrderInv(t *testing.T) { - //sub := NewSubPool() - //require.Equal(t, uint8(0b11110), uint8(sub.Best().SubPool)) - //require.Equal(t, uint8(0b10001), uint8(sub.Worst().SubPool)) - // - //require.Equal(t, uint8(sub.Best().SubPool), uint8(sub.PopBest().SubPool)) - //require.Equal(t, uint8(sub.Worst().SubPool), uint8(sub.PopWorst().SubPool)) - - //s := fromHex("b8940c10a547") - s := []uint8{0b11000, 0b101, 0b111} - - { - sub := NewSubPool() - for _, i := range s { - sub.Add(&MetaTx{SubPool: SubPoolMarker(i & 0b11111)}) - } - var prevBest *uint8 - i := sub.Len() - for sub.Len() > 0 { - best := uint8(sub.Best().SubPool) - assert.Equal(t, best, uint8(sub.PopBest().SubPool)) - if prevBest != nil { - assert.Less(t, best, *prevBest) - } - prevBest = &best - i-- - } - assert.Zero(t, i) - } - - { - sub := NewSubPool() - for _, i := range s { - sub.Add(&MetaTx{SubPool: SubPoolMarker(i & 0b11111)}) - } - var prev *uint8 - i := sub.Len() - for sub.Len() > 0 { - worst := uint8(sub.Worst().SubPool) - assert.Equal(t, worst, uint8(sub.PopWorst().SubPool)) - if prev != nil { - assert.Greater(t, worst, *prev) - } - prev = &worst - i-- - } - assert.Zero(t, i) - } -} - func TestSubPoolsPromote(t *testing.T) { s1 := []uint8{0b11000, 0b101, 0b111} s2 := []uint8{0b11000, 0b101, 0b111}