2020-08-21 23:27:51 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAttCaches_hasSeenBit(t *testing.T) {
|
|
|
|
c := NewAttCaches()
|
2020-08-27 18:13:32 +00:00
|
|
|
d := ðpb.AttestationData{
|
|
|
|
Source: ðpb.Checkpoint{Root: make([]byte, 32)},
|
|
|
|
Target: ðpb.Checkpoint{Root: make([]byte, 32)},
|
|
|
|
BeaconBlockRoot: make([]byte, 32),
|
|
|
|
}
|
|
|
|
seenA1 := ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}, Signature: make([]byte, 96)}
|
|
|
|
seenA2 := ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}, Signature: make([]byte, 96)}
|
2020-08-21 23:27:51 +00:00
|
|
|
require.NoError(t, c.insertSeenBit(seenA1))
|
|
|
|
require.NoError(t, c.insertSeenBit(seenA2))
|
|
|
|
tests := []struct {
|
|
|
|
att *ethpb.Attestation
|
|
|
|
want bool
|
|
|
|
}{
|
2020-08-27 18:13:32 +00:00
|
|
|
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000000}, Signature: make([]byte, 96)}, want: true},
|
|
|
|
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000001}, Signature: make([]byte, 96)}, want: true},
|
|
|
|
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11100000}, Signature: make([]byte, 96)}, want: true},
|
|
|
|
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b10000011}, Signature: make([]byte, 96)}, want: true},
|
|
|
|
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b00001000}, Signature: make([]byte, 96)}, want: false},
|
|
|
|
{att: ðpb.Attestation{Data: d, AggregationBits: bitfield.Bitlist{0b11110111}, Signature: make([]byte, 96)}, want: false},
|
2020-08-21 23:27:51 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
got, err := c.hasSeenBit(tt.att)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if got != tt.want {
|
|
|
|
t.Errorf("hasSeenBit() got = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|