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 TestSyncCommitteeContributionCache_Nil(t *testing.T) {
|
|
|
|
store := NewStore()
|
|
|
|
require.Equal(t, errNilContribution, store.SaveSyncCommitteeContribution(nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyncCommitteeContributionCache_RoundTrip(t *testing.T) {
|
|
|
|
store := NewStore()
|
|
|
|
|
2021-07-30 18:05:38 +00:00
|
|
|
conts := []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 1, SubcommitteeIndex: 0, Signature: []byte{'a'}},
|
|
|
|
{Slot: 1, SubcommitteeIndex: 1, Signature: []byte{'b'}},
|
|
|
|
{Slot: 2, SubcommitteeIndex: 0, Signature: []byte{'c'}},
|
|
|
|
{Slot: 2, SubcommitteeIndex: 1, Signature: []byte{'d'}},
|
|
|
|
{Slot: 3, SubcommitteeIndex: 0, Signature: []byte{'e'}},
|
|
|
|
{Slot: 3, SubcommitteeIndex: 1, Signature: []byte{'f'}},
|
|
|
|
{Slot: 4, SubcommitteeIndex: 0, Signature: []byte{'g'}},
|
|
|
|
{Slot: 4, SubcommitteeIndex: 1, Signature: []byte{'h'}},
|
|
|
|
{Slot: 5, SubcommitteeIndex: 0, Signature: []byte{'i'}},
|
|
|
|
{Slot: 5, SubcommitteeIndex: 1, Signature: []byte{'j'}},
|
|
|
|
{Slot: 6, SubcommitteeIndex: 0, Signature: []byte{'k'}},
|
|
|
|
{Slot: 6, SubcommitteeIndex: 1, Signature: []byte{'l'}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, sig := range conts {
|
|
|
|
require.NoError(t, store.SaveSyncCommitteeContribution(sig))
|
|
|
|
}
|
|
|
|
|
|
|
|
conts, err := store.SyncCommitteeContributions(1)
|
|
|
|
require.NoError(t, err)
|
2021-10-20 21:45:57 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{}, conts)
|
2021-07-19 19:06:49 +00:00
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(2)
|
|
|
|
require.NoError(t, err)
|
2021-10-20 21:45:57 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{}, conts)
|
2021-07-19 19:06:49 +00:00
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(3)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 3, SubcommitteeIndex: 0, Signature: []byte{'e'}},
|
|
|
|
{Slot: 3, SubcommitteeIndex: 1, Signature: []byte{'f'}},
|
|
|
|
}, conts)
|
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(4)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 4, SubcommitteeIndex: 0, Signature: []byte{'g'}},
|
|
|
|
{Slot: 4, SubcommitteeIndex: 1, Signature: []byte{'h'}},
|
|
|
|
}, conts)
|
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(5)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 5, SubcommitteeIndex: 0, Signature: []byte{'i'}},
|
|
|
|
{Slot: 5, SubcommitteeIndex: 1, Signature: []byte{'j'}},
|
|
|
|
}, conts)
|
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(6)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 6, SubcommitteeIndex: 0, Signature: []byte{'k'}},
|
|
|
|
{Slot: 6, SubcommitteeIndex: 1, Signature: []byte{'l'}},
|
|
|
|
}, conts)
|
|
|
|
|
|
|
|
// All the contributions should persist after get.
|
|
|
|
conts, err = store.SyncCommitteeContributions(1)
|
|
|
|
require.NoError(t, err)
|
2021-10-20 21:45:57 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{}, conts)
|
2021-07-19 19:06:49 +00:00
|
|
|
conts, err = store.SyncCommitteeContributions(2)
|
|
|
|
require.NoError(t, err)
|
2021-10-20 21:45:57 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{}, conts)
|
2021-07-19 19:06:49 +00:00
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(3)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 3, SubcommitteeIndex: 0, Signature: []byte{'e'}},
|
|
|
|
{Slot: 3, SubcommitteeIndex: 1, Signature: []byte{'f'}},
|
|
|
|
}, conts)
|
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(4)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 4, SubcommitteeIndex: 0, Signature: []byte{'g'}},
|
|
|
|
{Slot: 4, SubcommitteeIndex: 1, Signature: []byte{'h'}},
|
|
|
|
}, conts)
|
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(5)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 5, SubcommitteeIndex: 0, Signature: []byte{'i'}},
|
|
|
|
{Slot: 5, SubcommitteeIndex: 1, Signature: []byte{'j'}},
|
|
|
|
}, conts)
|
|
|
|
|
|
|
|
conts, err = store.SyncCommitteeContributions(6)
|
|
|
|
require.NoError(t, err)
|
2021-07-30 18:05:38 +00:00
|
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeContribution{
|
2021-07-19 19:06:49 +00:00
|
|
|
{Slot: 6, SubcommitteeIndex: 0, Signature: []byte{'k'}},
|
|
|
|
{Slot: 6, SubcommitteeIndex: 1, Signature: []byte{'l'}},
|
|
|
|
}, conts)
|
|
|
|
}
|