2018-12-22 20:30:59 +00:00
|
|
|
package attestations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-12-28 07:29:02 +00:00
|
|
|
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
2018-12-22 20:30:59 +00:00
|
|
|
)
|
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestIsDoubleVote_SameAndDifferentEpochs(t *testing.T) {
|
2018-12-28 07:29:02 +00:00
|
|
|
att1 := &pb.AttestationData{
|
2018-12-31 21:52:12 +00:00
|
|
|
Slot: 0,
|
2018-12-28 07:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
att2 := &pb.AttestationData{
|
2018-12-31 21:52:12 +00:00
|
|
|
Slot: 64,
|
2018-12-28 07:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if IsDoubleVote(att1, att2) {
|
2018-12-31 21:52:12 +00:00
|
|
|
t.Error("It is a double vote despite the attestations being on different epochs")
|
2018-12-28 07:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
att2.Slot = 1
|
|
|
|
|
|
|
|
if !IsDoubleVote(att1, att2) {
|
2018-12-31 21:52:12 +00:00
|
|
|
t.Error("It is not a double vote despite the attestations being on the same epoch")
|
2018-12-28 07:29:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 15:11:26 +00:00
|
|
|
func TestIsSurroundVote_SameAndDifferentEpochs(t *testing.T) {
|
2018-12-28 07:29:02 +00:00
|
|
|
att1 := &pb.AttestationData{
|
2019-02-13 16:42:33 +00:00
|
|
|
Slot: 0,
|
|
|
|
JustifiedEpoch: 0,
|
2018-12-28 07:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
att2 := &pb.AttestationData{
|
2019-02-13 16:42:33 +00:00
|
|
|
Slot: 0,
|
|
|
|
JustifiedEpoch: 0,
|
2018-12-28 07:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if IsSurroundVote(att1, att2) {
|
2018-12-31 21:52:12 +00:00
|
|
|
t.Error("It is a surround vote despite both attestations having the same epoch")
|
2018-12-28 07:29:02 +00:00
|
|
|
}
|
|
|
|
|
2018-12-31 21:52:12 +00:00
|
|
|
att1.Slot = 192
|
2019-02-13 16:42:33 +00:00
|
|
|
att2.JustifiedEpoch = 1
|
2018-12-31 21:52:12 +00:00
|
|
|
att2.Slot = 128
|
2018-12-28 07:29:02 +00:00
|
|
|
|
|
|
|
if !IsSurroundVote(att1, att2) {
|
|
|
|
t.Error("It is not a surround vote despite all the surround conditions being fulfilled")
|
|
|
|
}
|
|
|
|
}
|