Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
potuz committed Oct 16, 2024
1 parent 4163eb3 commit 8a10c65
Showing 1 changed file with 4 additions and 75 deletions.
79 changes: 4 additions & 75 deletions beacon-chain/forkchoice/doubly-linked-tree/epbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,77 +10,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/testing/require"
)

func TestStore_Insert_PayloadContent(t *testing.T) {
ctx := context.Background()
f := setup(0, 0)
s := f.store
// The tree root is full
fr := [32]byte{}
tn := s.emptyNodeByRoot[fr]
require.Equal(t, true, tn.block.isParentFull())

// Insert a child with a payload
cr := [32]byte{'a'}
cp := [32]byte{'p'}
n, err := s.insert(ctx, 1, cr, fr, cp, fr, 0, 0)
require.NoError(t, err)
require.Equal(t, true, n.isParentFull())
require.Equal(t, s.treeRootNode, n.parent)
require.Equal(t, s.emptyNodeByRoot[cr], n)

// Insert a grandchild without a payload
gr := [32]byte{'b'}
gn, err := s.insert(ctx, 2, gr, cr, fr, cp, 0, 0)
require.NoError(t, err)
require.Equal(t, true, gn.isParentFull())
require.Equal(t, n, gn.parent)

// Insert the payload of the same grandchild
gp := [32]byte{'q'}
gfn, err := s.insert(ctx, 2, gr, cr, gp, cp, 0, 0)
require.NoError(t, err)
require.Equal(t, true, gfn.isParentFull())
require.Equal(t, n, gfn.parent)

// Insert an empty great grandchild based on empty
ggr := [32]byte{'c'}
ggn, err := s.insert(ctx, 3, ggr, gr, fr, cp, 0, 0)
require.NoError(t, err)
require.Equal(t, false, ggn.isParentFull())
require.Equal(t, gn, ggn.parent)

// Insert an empty great grandchild based on full
ggfr := [32]byte{'d'}
ggfn, err := s.insert(ctx, 3, ggfr, gr, fr, gp, 0, 0)
require.NoError(t, err)
require.Equal(t, gfn, ggfn.parent)
require.Equal(t, true, ggfn.isParentFull())

// Insert the payload for the great grandchild based on empty
ggp := [32]byte{'r'}
n, err = s.insert(ctx, 3, ggr, gr, ggp, cp, 0, 0)
require.NoError(t, err)
require.Equal(t, false, n.isParentFull())
require.Equal(t, gn, n.parent)

// Insert the payload for the great grandchild based on full
ggfp := [32]byte{'s'}
n, err = s.insert(ctx, 3, ggfr, gr, ggfp, gp, 0, 0)
require.NoError(t, err)
require.Equal(t, true, n.isParentFull())
require.Equal(t, gfn, n.parent)

// Reinsert an empty node
ggfn2, err := s.insert(ctx, 3, ggfr, gr, fr, gp, 0, 0)
require.NoError(t, err)
require.Equal(t, ggfn, ggfn2)

// Reinsert a full node
n2, err := s.insert(ctx, 3, ggfr, gr, ggfp, gp, 0, 0)
require.NoError(t, err)
require.Equal(t, n, n2)
}

func TestStore_Insert_PayloadEnvelope(t *testing.T) {
ctx := context.Background()
f := setup(0, 0)
Expand All @@ -97,7 +26,7 @@ func TestStore_Insert_PayloadEnvelope(t *testing.T) {
require.NoError(t, err)
require.Equal(t, true, n.isParentFull())
require.Equal(t, s.treeRootNode, n.parent)
require.Equal(t, s.emptyNodeByRoot[cr], n)
require.Equal(t, s.emptyNodeByRoot[cr].block, n)
// Insert its payload
p := &enginev1.ExecutionPayloadEnvelope{
Payload: &enginev1.ExecutionPayloadElectra{
Expand Down Expand Up @@ -146,7 +75,7 @@ func TestStore_Insert_PayloadEnvelope(t *testing.T) {
ggn, err := s.insert(ctx, 3, ggr, gr, fr, cp, 0, 0)
require.NoError(t, err)
require.Equal(t, false, ggn.isParentFull())
require.Equal(t, gn, ggn.parent)
require.Equal(t, gn, ggn.parent.block)

// Insert an empty great grandchild based on full
ggfr := [32]byte{'d'}
Expand All @@ -171,7 +100,7 @@ func TestStore_Insert_PayloadEnvelope(t *testing.T) {
require.NoError(t, f.InsertPayloadEnvelope(e))
tn = s.fullNodeByPayload[ggp]
require.Equal(t, false, tn.block.isParentFull())
require.Equal(t, gn, tn.block.parent)
require.Equal(t, gn, tn.block.parent.block)

// Insert the payload for the great grandchild based on full
ggfp := [32]byte{'s'}
Expand Down Expand Up @@ -204,7 +133,7 @@ func TestGetPTCVote(t *testing.T) {
cp := [32]byte{'p'}
n, err := s.insert(ctx, 1, cr, fr, cp, fr, 0, 0)
require.NoError(t, err)
require.Equal(t, n, s.highestReceivedNode)
require.Equal(t, n, s.highestReceivedNode.block)
require.Equal(t, primitives.PAYLOAD_ABSENT, f.GetPTCVote())
driftGenesisTime(f, 1, 0)
require.Equal(t, primitives.PAYLOAD_PRESENT, f.GetPTCVote())
Expand Down

0 comments on commit 8a10c65

Please sign in to comment.