test attestations are equal (#2274)

This commit is contained in:
terence tsao 2019-04-16 17:09:31 -07:00 committed by GitHub
parent a9da23f444
commit 8a6b55e93c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package rpc
import (
"context"
"reflect"
"strconv"
"testing"
"time"
@ -253,6 +254,15 @@ func TestPendingAttestations_FiltersExpiredAttestations(t *testing.T) {
len(res.PendingAttestations),
)
}
expectedAtts := []*pbp2p.Attestation{
{Data: &pbp2p.AttestationData{Slot: currentSlot - 5, JustifiedEpoch: expectedEpoch}},
{Data: &pbp2p.AttestationData{Slot: currentSlot - 2, JustifiedEpoch: expectedEpoch}},
{Data: &pbp2p.AttestationData{Slot: currentSlot, JustifiedEpoch: expectedEpoch}},
}
if !reflect.DeepEqual(res.PendingAttestations, expectedAtts) {
t.Error("Did not receive expected attestations")
}
}
func TestPendingAttestations_OK(t *testing.T) {
@ -345,6 +355,8 @@ func TestPendingAttestations_FiltersCanonicalAttestations(t *testing.T) {
t.Fatalf("couldnt update chainhead: %v", err)
}
for _, atts := range opService.pendingAttestations {
// Insert all of the attestations, since last 3 attestations are same slot number
// the last 2 get overridden, and only the last 1 is canonical.
proposerServer.chainService.InsertsCanonical(atts.Data.Slot, atts.Data.BeaconBlockRootHash32)
}
@ -364,4 +376,13 @@ func TestPendingAttestations_FiltersCanonicalAttestations(t *testing.T) {
len(res.PendingAttestations),
)
}
expectedAtts := []*pbp2p.Attestation{
{Data: &pbp2p.AttestationData{Slot: currentSlot - 5, JustifiedEpoch: expectedEpoch, BeaconBlockRootHash32: []byte{'A'}}},
{Data: &pbp2p.AttestationData{Slot: currentSlot - 2, JustifiedEpoch: expectedEpoch, BeaconBlockRootHash32: []byte{'B'}}},
{Data: &pbp2p.AttestationData{Slot: currentSlot, JustifiedEpoch: expectedEpoch, BeaconBlockRootHash32: []byte{'E'}}},
}
if !reflect.DeepEqual(res.PendingAttestations, expectedAtts) {
t.Error("Did not receive expected attestations")
}
}