mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
parent
9ad00ffafb
commit
5828278807
@ -2,6 +2,7 @@ package kv
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
@ -56,6 +57,70 @@ func TestStore_AttestationCRUD(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStore_BoltDontPanic(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer teardownDB(t, db)
|
||||
var wg sync.WaitGroup
|
||||
|
||||
for i := 0; i <= 100; i++ {
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Crosslink: ðpb.Crosslink{
|
||||
Shard: 5,
|
||||
ParentRoot: []byte("parent"),
|
||||
StartEpoch: uint64(i + 1),
|
||||
EndEpoch: 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := context.Background()
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
retrievedAtt, err := db.Attestation(ctx, attDataRoot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if retrievedAtt != nil {
|
||||
t.Errorf("Expected nil attestation, received %v", retrievedAtt)
|
||||
}
|
||||
if err := db.SaveAttestation(ctx, att); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// if indices are improperly deleted this test will then panic.
|
||||
for i := 0; i <= 100; i++ {
|
||||
startEpoch := i + 1
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
Crosslink: ðpb.Crosslink{
|
||||
Shard: 5,
|
||||
ParentRoot: []byte("parent"),
|
||||
StartEpoch: uint64(startEpoch),
|
||||
EndEpoch: 2,
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := context.Background()
|
||||
attDataRoot, err := ssz.HashTreeRoot(att.Data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.DeleteAttestation(ctx, attDataRoot); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if db.HasAttestation(ctx, attDataRoot) {
|
||||
t.Error("Expected attestation to have been deleted from the db")
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestStore_Attestations_FiltersCorrectly(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer teardownDB(t, db)
|
||||
|
@ -61,7 +61,14 @@ func deleteValueForIndices(indicesByBucket map[string][]byte, root []byte, tx *b
|
||||
// We clear out the root from the values at index slice. For example,
|
||||
// If we had [0x32, 0x33, 0x45] and we wanted to clear out 0x33, the code below
|
||||
// updates the slice to [0x32, 0x45].
|
||||
valuesAtIndex = append(valuesAtIndex[:start], valuesAtIndex[start+len(root):]...)
|
||||
|
||||
valuesStart := make([]byte, len(valuesAtIndex[:start]))
|
||||
copy(valuesStart, valuesAtIndex[:start])
|
||||
|
||||
valuesEnd := make([]byte, len(valuesAtIndex[start+len(root):]))
|
||||
copy(valuesEnd, valuesAtIndex[start+len(root):])
|
||||
|
||||
valuesAtIndex = append(valuesStart, valuesEnd...)
|
||||
if err := bkt.Put(idx, valuesAtIndex); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user