2021-09-28 18:13:16 +00:00
|
|
|
package slasher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-16 12:20:13 +00:00
|
|
|
slashertypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/slasher/types"
|
2023-01-26 14:40:12 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
2021-09-28 18:13:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_attestationsQueue(t *testing.T) {
|
|
|
|
t.Run("push_and_dequeue", func(tt *testing.T) {
|
|
|
|
attQueue := newAttestationsQueue()
|
|
|
|
wantedAtts := []*slashertypes.IndexedAttestationWrapper{
|
|
|
|
createAttestationWrapper(t, 0, 1, []uint64{1}, make([]byte, 32)),
|
|
|
|
createAttestationWrapper(t, 1, 2, []uint64{1}, make([]byte, 32)),
|
|
|
|
}
|
|
|
|
attQueue.push(wantedAtts[0])
|
|
|
|
attQueue.push(wantedAtts[1])
|
|
|
|
require.DeepEqual(t, 2, attQueue.size())
|
|
|
|
|
|
|
|
received := attQueue.dequeue()
|
|
|
|
require.DeepEqual(t, 0, attQueue.size())
|
|
|
|
require.DeepEqual(t, wantedAtts, received)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("extend_and_dequeue", func(tt *testing.T) {
|
|
|
|
attQueue := newAttestationsQueue()
|
|
|
|
wantedAtts := []*slashertypes.IndexedAttestationWrapper{
|
|
|
|
createAttestationWrapper(t, 0, 1, []uint64{1}, make([]byte, 32)),
|
|
|
|
createAttestationWrapper(t, 1, 2, []uint64{1}, make([]byte, 32)),
|
|
|
|
}
|
|
|
|
attQueue.extend(wantedAtts)
|
|
|
|
require.DeepEqual(t, 2, attQueue.size())
|
|
|
|
|
|
|
|
received := attQueue.dequeue()
|
|
|
|
require.DeepEqual(t, 0, attQueue.size())
|
|
|
|
require.DeepEqual(t, wantedAtts, received)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_blocksQueue(t *testing.T) {
|
|
|
|
t.Run("push_and_dequeue", func(tt *testing.T) {
|
|
|
|
blkQueue := newBlocksQueue()
|
|
|
|
wantedBlks := []*slashertypes.SignedBlockHeaderWrapper{
|
2023-01-26 14:40:12 +00:00
|
|
|
createProposalWrapper(t, 0, primitives.ValidatorIndex(1), make([]byte, 32)),
|
|
|
|
createProposalWrapper(t, 1, primitives.ValidatorIndex(1), make([]byte, 32)),
|
2021-09-28 18:13:16 +00:00
|
|
|
}
|
|
|
|
blkQueue.push(wantedBlks[0])
|
|
|
|
blkQueue.push(wantedBlks[1])
|
|
|
|
require.DeepEqual(t, 2, blkQueue.size())
|
|
|
|
|
|
|
|
received := blkQueue.dequeue()
|
|
|
|
require.DeepEqual(t, 0, blkQueue.size())
|
|
|
|
require.DeepEqual(t, wantedBlks, received)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("extend_and_dequeue", func(tt *testing.T) {
|
|
|
|
blkQueue := newBlocksQueue()
|
|
|
|
wantedBlks := []*slashertypes.SignedBlockHeaderWrapper{
|
2023-01-26 14:40:12 +00:00
|
|
|
createProposalWrapper(t, 0, primitives.ValidatorIndex(1), make([]byte, 32)),
|
|
|
|
createProposalWrapper(t, 1, primitives.ValidatorIndex(1), make([]byte, 32)),
|
2021-09-28 18:13:16 +00:00
|
|
|
}
|
|
|
|
blkQueue.extend(wantedBlks)
|
|
|
|
require.DeepEqual(t, 2, blkQueue.size())
|
|
|
|
|
|
|
|
received := blkQueue.dequeue()
|
|
|
|
require.DeepEqual(t, 0, blkQueue.size())
|
|
|
|
require.DeepEqual(t, wantedBlks, received)
|
|
|
|
})
|
|
|
|
}
|