prysm-pulse/beacon-chain/operations/attestations/kv/forkchoice_test.go
terence tsao c309ba6a10
Applies assertion funcs to operation tests (#6608)
* Update kv aggregated_test.go
* Update block_test.go
* Update forkchoice_test.go
* Update unaggregated_test.go
* Update prepare_forkchoice_test.go
* Update prune_expired_test.go
* Update atts service_test.go
* Update service_attester_test.go
* Update service_proposer_test.go
* Upate exit service_test.go
* Gaz
2020-07-15 18:37:51 +00:00

60 lines
1.8 KiB
Go

package kv
import (
"sort"
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
)
func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) {
cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts {
if err := cache.SaveForkchoiceAttestation(att); err != nil {
t.Fatal(err)
}
}
returned := cache.ForkchoiceAttestations()
sort.Slice(returned, func(i, j int) bool {
return returned[i].Data.Slot < returned[j].Data.Slot
})
assert.DeepEqual(t, atts, returned)
}
func TestKV_Forkchoice_CanDelete(t *testing.T) {
cache := NewAttCaches()
att1 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
att2 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
att3 := &ethpb.Attestation{Data: &ethpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
atts := []*ethpb.Attestation{att1, att2, att3}
for _, att := range atts {
if err := cache.SaveForkchoiceAttestation(att); err != nil {
t.Fatal(err)
}
}
if err := cache.DeleteForkchoiceAttestation(att1); err != nil {
t.Fatal(err)
}
if err := cache.DeleteForkchoiceAttestation(att3); err != nil {
t.Fatal(err)
}
returned := cache.ForkchoiceAttestations()
wanted := []*ethpb.Attestation{att2}
assert.DeepEqual(t, wanted, returned)
}