mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
110 lines
3.7 KiB
Go
110 lines
3.7 KiB
Go
package synccommittee
|
|
|
|
import (
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
)
|
|
|
|
func TestSyncCommitteeSignatureCache_Nil(t *testing.T) {
|
|
store := NewStore()
|
|
require.Equal(t, errNilMessage, store.SaveSyncCommitteeMessage(nil))
|
|
}
|
|
|
|
func TestSyncCommitteeSignatureCache_RoundTrip(t *testing.T) {
|
|
store := NewStore()
|
|
|
|
msgs := []*ethpb.SyncCommitteeMessage{
|
|
{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)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage(nil), msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(2)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage(nil), msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(3)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
|
{Slot: 3, ValidatorIndex: 0, Signature: []byte{'e'}},
|
|
{Slot: 3, ValidatorIndex: 1, Signature: []byte{'f'}},
|
|
}, msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(4)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
|
{Slot: 4, ValidatorIndex: 0, Signature: []byte{'g'}},
|
|
{Slot: 4, ValidatorIndex: 1, Signature: []byte{'h'}},
|
|
}, msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(5)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
|
{Slot: 5, ValidatorIndex: 0, Signature: []byte{'i'}},
|
|
{Slot: 5, ValidatorIndex: 1, Signature: []byte{'j'}},
|
|
}, msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(6)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
|
{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)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage(nil), msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(2)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage(nil), msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(3)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
|
{Slot: 3, ValidatorIndex: 0, Signature: []byte{'e'}},
|
|
{Slot: 3, ValidatorIndex: 1, Signature: []byte{'f'}},
|
|
}, msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(4)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
|
{Slot: 4, ValidatorIndex: 0, Signature: []byte{'g'}},
|
|
{Slot: 4, ValidatorIndex: 1, Signature: []byte{'h'}},
|
|
}, msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(5)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
|
{Slot: 5, ValidatorIndex: 0, Signature: []byte{'i'}},
|
|
{Slot: 5, ValidatorIndex: 1, Signature: []byte{'j'}},
|
|
}, msgs)
|
|
|
|
msgs, err = store.SyncCommitteeMessages(6)
|
|
require.NoError(t, err)
|
|
require.DeepSSZEqual(t, []*ethpb.SyncCommitteeMessage{
|
|
{Slot: 6, ValidatorIndex: 0, Signature: []byte{'k'}},
|
|
{Slot: 6, ValidatorIndex: 1, Signature: []byte{'l'}},
|
|
}, msgs)
|
|
}
|