2021-07-19 19:06:49 +00:00
|
|
|
package synccommittee
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-07-30 18:05:38 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
2021-07-19 19:06:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSyncCommitteeSignatureCache_Nil(t *testing.T) {
|
|
|
|
store := NewStore()
|
|
|
|
require.Equal(t, errNilMessage, store.SaveSyncCommitteeMessage(nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyncCommitteeSignatureCache_RoundTrip(t *testing.T) {
|
|
|
|
store := NewStore()
|
|
|
|
|
2021-07-30 18:05:38 +00:00
|
|
|
msgs := []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 1, ValidatorIndex: 0, Signature: []byte{'a'}},
|
|
|
|
{Slot: 1, ValidatorIndex: 1, Signature: []byte{'b'}},
|
|
|
|
{Slot: 2, ValidatorIndex: 0, Signature: []byte{'c'}},
|
|
|
|
{Slot: 2, ValidatorIndex: 1, Signature: []byte{'d'}},
|
|
|
|
{Slot: 3, ValidatorIndex: 0, Signature: []byte{'e'}},
|
|
|
|
{Slot: 3, ValidatorIndex: 1, Signature: []byte{'f'}},
|
|
|
|
{Slot: 4, ValidatorIndex: 0, Signature: []byte{'g'}},
|
|
|
|
{Slot: 4, ValidatorIndex: 1, Signature: []byte{'h'}},
|
|
|
|
{Slot: 5, ValidatorIndex: 0, Signature: []byte{'i'}},
|
|
|
|
{Slot: 5, ValidatorIndex: 1, Signature: []byte{'j'}},
|
|
|
|
{Slot: 6, ValidatorIndex: 0, Signature: []byte{'k'}},
|
|
|
|
{Slot: 6, ValidatorIndex: 1, Signature: []byte{'l'}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, msg := range msgs {
|
|
|
|
require.NoError(t, store.SaveSyncCommitteeMessage(msg))
|
|
|
|
}
|
|
|
|
|
|
|
|
msgs, err := store.SyncCommitteeMessages(1)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage(nil), msgs)
|
2021-07-19 19:06:49 +00:00
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(2)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage(nil), msgs)
|
2021-07-19 19:06:49 +00:00
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(3)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 3, ValidatorIndex: 0, Signature: []byte{'e'}},
|
|
|
|
{Slot: 3, ValidatorIndex: 1, Signature: []byte{'f'}},
|
|
|
|
}, msgs)
|
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(4)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 4, ValidatorIndex: 0, Signature: []byte{'g'}},
|
|
|
|
{Slot: 4, ValidatorIndex: 1, Signature: []byte{'h'}},
|
|
|
|
}, msgs)
|
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(5)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 5, ValidatorIndex: 0, Signature: []byte{'i'}},
|
|
|
|
{Slot: 5, ValidatorIndex: 1, Signature: []byte{'j'}},
|
|
|
|
}, msgs)
|
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(6)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 6, ValidatorIndex: 0, Signature: []byte{'k'}},
|
|
|
|
{Slot: 6, ValidatorIndex: 1, Signature: []byte{'l'}},
|
|
|
|
}, msgs)
|
|
|
|
|
|
|
|
// Messages should persist after retrieval.
|
|
|
|
msgs, err = store.SyncCommitteeMessages(1)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage(nil), msgs)
|
2021-07-19 19:06:49 +00:00
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(2)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage(nil), msgs)
|
2021-07-19 19:06:49 +00:00
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(3)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 3, ValidatorIndex: 0, Signature: []byte{'e'}},
|
|
|
|
{Slot: 3, ValidatorIndex: 1, Signature: []byte{'f'}},
|
|
|
|
}, msgs)
|
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(4)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 4, ValidatorIndex: 0, Signature: []byte{'g'}},
|
|
|
|
{Slot: 4, ValidatorIndex: 1, Signature: []byte{'h'}},
|
|
|
|
}, msgs)
|
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(5)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 5, ValidatorIndex: 0, Signature: []byte{'i'}},
|
|
|
|
{Slot: 5, ValidatorIndex: 1, Signature: []byte{'j'}},
|
|
|
|
}, msgs)
|
|
|
|
|
|
|
|
msgs, err = store.SyncCommitteeMessages(6)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 6, ValidatorIndex: 0, Signature: []byte{'k'}},
|
|
|
|
{Slot: 6, ValidatorIndex: 1, Signature: []byte{'l'}},
|
|
|
|
}, msgs)
|
|
|
|
}
|