mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-15 06:28:20 +00:00
d97596348e
* Revert "Revert New Attester Protection DB Logic (#8237)"
This reverts commit 6738fa3493
.
* Batch Attestation Records and Flush All at Once in Validator DB (#8243)
* begin flushing logic
* finalize logic before starting tests
* make code DRY
* better log fields
* gaz
* tweak parameter
* rename
* clarifying comment on error handling in event feed
* comprehensive tests
* more comments
* explain parameters in comments
* renamed consts
* Apply suggestions from code review
* gaz
* simplify
* typo
* comments
93 lines
1.9 KiB
Go
93 lines
1.9 KiB
Go
package slashutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/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 uint64) *ethpb.IndexedAttestation {
|
|
return ðpb.IndexedAttestation{
|
|
Data: ðpb.AttestationData{
|
|
Source: ðpb.Checkpoint{Epoch: source},
|
|
Target: ðpb.Checkpoint{Epoch: target},
|
|
},
|
|
}
|
|
}
|