prysm-pulse/proto/prysm/v1alpha1/slashings/surround_votes_test.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* 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>
2022-08-16 12:20:13 +00:00

94 lines
2.0 KiB
Go

package slashings
import (
"testing"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
)
func TestIsSurround(t *testing.T) {
type args struct {
a *ethpb.IndexedAttestation
b *ethpb.IndexedAttestation
}
tests := []struct {
name string
args args
want bool
}{
{
name: "0 values returns false",
args: args{
a: createAttestation(0, 0),
b: createAttestation(0, 0),
},
want: false,
},
{
name: "detects surrounding attestation",
args: args{
a: createAttestation(2, 5),
b: createAttestation(3, 4),
},
want: true,
},
{
name: "new attestation source == old source, but new target < old target",
args: args{
a: createAttestation(3, 5),
b: createAttestation(3, 4),
},
want: false,
},
{
name: "new attestation source > old source, but new target == old target",
args: args{
a: createAttestation(3, 5),
b: createAttestation(4, 5),
},
want: false,
},
{
name: "new attestation source and targets equal to old one",
args: args{
a: createAttestation(3, 5),
b: createAttestation(3, 5),
},
want: false,
},
{
name: "new attestation source == old source, but new target > old target",
args: args{
a: createAttestation(3, 5),
b: createAttestation(3, 6),
},
want: false,
},
{
name: "new attestation source < old source, but new target == old target",
args: args{
a: createAttestation(3, 5),
b: createAttestation(2, 5),
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IsSurround(tt.args.a, tt.args.b); got != tt.want {
t.Errorf("IsSurrounding() = %v, want %v", got, tt.want)
}
})
}
}
func createAttestation(source, target types.Epoch) *ethpb.IndexedAttestation {
return &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{
Source: &ethpb.Checkpoint{Epoch: source},
Target: &ethpb.Checkpoint{Epoch: target},
},
}
}