mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 04:00:05 +00:00
Create Bucket If Not Exists When Fetching Proposal History (#8011)
* create bucket if not exist when fetching proposal history * adding unit test
This commit is contained in:
parent
b150acffca
commit
fc7c6776f6
@ -51,11 +51,11 @@ func (store *Store) ProposalHistoryForSlot(ctx context.Context, publicKey [48]by
|
||||
var err error
|
||||
var proposalExists bool
|
||||
signingRoot := [32]byte{}
|
||||
err = store.view(func(tx *bolt.Tx) error {
|
||||
err = store.update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(newHistoricProposalsBucket)
|
||||
valBucket := bucket.Bucket(publicKey[:])
|
||||
if valBucket == nil {
|
||||
return fmt.Errorf("validator history empty for public key: %#x", publicKey)
|
||||
valBucket, err := bucket.CreateBucketIfNotExists(publicKey[:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create bucket for public key %#x", publicKey[:])
|
||||
}
|
||||
signingRootBytes := valBucket.Get(bytesutil.Uint64ToBytesBigEndian(slot))
|
||||
if signingRootBytes == nil {
|
||||
|
@ -22,12 +22,13 @@ func TestProposalHistoryForSlot_InitializesNewPubKeys(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewProposalHistoryForSlot_NilDB(t *testing.T) {
|
||||
func TestNewProposalHistoryForSlot_ReturnsNilIfNoHistory(t *testing.T) {
|
||||
valPubkey := [48]byte{1, 2, 3}
|
||||
db := setupDB(t, [][48]byte{})
|
||||
|
||||
_, _, err := db.ProposalHistoryForSlot(context.Background(), valPubkey, 0)
|
||||
require.ErrorContains(t, "validator history empty for public key", err, "Unexpected error for nil DB")
|
||||
_, proposalExists, err := db.ProposalHistoryForSlot(context.Background(), valPubkey, 0)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, false, proposalExists)
|
||||
}
|
||||
|
||||
func TestSaveProposalHistoryForSlot_OK(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user