github.com/prysmaticlabs/prysm@v1.4.4/shared/slashutil/surround_votes_test.go (about) 1 package slashutil 2 3 import ( 4 "testing" 5 6 types "github.com/prysmaticlabs/eth2-types" 7 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 8 ) 9 10 func TestIsSurround(t *testing.T) { 11 type args struct { 12 a *ethpb.IndexedAttestation 13 b *ethpb.IndexedAttestation 14 } 15 tests := []struct { 16 name string 17 args args 18 want bool 19 }{ 20 { 21 name: "0 values returns false", 22 args: args{ 23 a: createAttestation(0, 0), 24 b: createAttestation(0, 0), 25 }, 26 want: false, 27 }, 28 { 29 name: "detects surrounding attestation", 30 args: args{ 31 a: createAttestation(2, 5), 32 b: createAttestation(3, 4), 33 }, 34 want: true, 35 }, 36 { 37 name: "new attestation source == old source, but new target < old target", 38 args: args{ 39 a: createAttestation(3, 5), 40 b: createAttestation(3, 4), 41 }, 42 want: false, 43 }, 44 { 45 name: "new attestation source > old source, but new target == old target", 46 args: args{ 47 a: createAttestation(3, 5), 48 b: createAttestation(4, 5), 49 }, 50 want: false, 51 }, 52 { 53 name: "new attestation source and targets equal to old one", 54 args: args{ 55 a: createAttestation(3, 5), 56 b: createAttestation(3, 5), 57 }, 58 want: false, 59 }, 60 { 61 name: "new attestation source == old source, but new target > old target", 62 args: args{ 63 a: createAttestation(3, 5), 64 b: createAttestation(3, 6), 65 }, 66 want: false, 67 }, 68 { 69 name: "new attestation source < old source, but new target == old target", 70 args: args{ 71 a: createAttestation(3, 5), 72 b: createAttestation(2, 5), 73 }, 74 want: false, 75 }, 76 } 77 for _, tt := range tests { 78 t.Run(tt.name, func(t *testing.T) { 79 if got := IsSurround(tt.args.a, tt.args.b); got != tt.want { 80 t.Errorf("IsSurrounding() = %v, want %v", got, tt.want) 81 } 82 }) 83 } 84 } 85 86 func createAttestation(source, target types.Epoch) *ethpb.IndexedAttestation { 87 return ðpb.IndexedAttestation{ 88 Data: ðpb.AttestationData{ 89 Source: ðpb.Checkpoint{Epoch: source}, 90 Target: ðpb.Checkpoint{Epoch: target}, 91 }, 92 } 93 }