Merge branch 'master' into develop

This commit is contained in:
Raul Jordan 2020-12-01 08:06:16 -06:00
commit 3bd5e58a5c
2 changed files with 8 additions and 7 deletions

View File

@ -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 {

View File

@ -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) {