2021-11-15 19:45:18 +00:00
|
|
|
package monitor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
2021-11-15 19:45:18 +00:00
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProcessExitsFromBlockTrackedIndices(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
s := &Service{
|
2023-01-26 14:40:12 +00:00
|
|
|
TrackedValidators: map[primitives.ValidatorIndex]bool{
|
2021-11-30 22:27:03 +00:00
|
|
|
1: true,
|
|
|
|
2: true,
|
2021-11-15 19:45:18 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exits := []*ethpb.SignedVoluntaryExit{
|
|
|
|
{
|
|
|
|
Exit: ðpb.VoluntaryExit{
|
|
|
|
ValidatorIndex: 3,
|
|
|
|
Epoch: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Exit: ðpb.VoluntaryExit{
|
|
|
|
ValidatorIndex: 2,
|
|
|
|
Epoch: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
block := ðpb.BeaconBlock{
|
|
|
|
Body: ðpb.BeaconBlockBody{
|
|
|
|
VoluntaryExits: exits,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-02 15:30:46 +00:00
|
|
|
wb, err := blocks.NewBeaconBlock(block)
|
2022-05-04 03:55:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
s.processExitsFromBlock(wb)
|
2024-02-22 22:40:36 +00:00
|
|
|
require.LogsContain(t, hook, "\"Voluntary exit was included\" prefix=monitor slot=0 validatorIndex=2")
|
2021-11-15 19:45:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessExitsFromBlockUntrackedIndices(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
s := &Service{
|
2023-01-26 14:40:12 +00:00
|
|
|
TrackedValidators: map[primitives.ValidatorIndex]bool{
|
2021-11-30 22:27:03 +00:00
|
|
|
1: true,
|
|
|
|
2: true,
|
2021-11-15 19:45:18 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exits := []*ethpb.SignedVoluntaryExit{
|
|
|
|
{
|
|
|
|
Exit: ðpb.VoluntaryExit{
|
|
|
|
ValidatorIndex: 3,
|
|
|
|
Epoch: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Exit: ðpb.VoluntaryExit{
|
|
|
|
ValidatorIndex: 4,
|
|
|
|
Epoch: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
block := ðpb.BeaconBlock{
|
|
|
|
Body: ðpb.BeaconBlockBody{
|
|
|
|
VoluntaryExits: exits,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-02 15:30:46 +00:00
|
|
|
wb, err := blocks.NewBeaconBlock(block)
|
2022-05-04 03:55:35 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
s.processExitsFromBlock(wb)
|
2021-11-15 19:45:18 +00:00
|
|
|
require.LogsDoNotContain(t, hook, "\"Voluntary exit was included\"")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessExitP2PTrackedIndices(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
s := &Service{
|
2023-01-26 14:40:12 +00:00
|
|
|
TrackedValidators: map[primitives.ValidatorIndex]bool{
|
2021-11-30 22:27:03 +00:00
|
|
|
1: true,
|
|
|
|
2: true,
|
2021-11-15 19:45:18 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exit := ðpb.SignedVoluntaryExit{
|
|
|
|
Exit: ðpb.VoluntaryExit{
|
|
|
|
ValidatorIndex: 1,
|
|
|
|
Epoch: 1,
|
|
|
|
},
|
|
|
|
Signature: make([]byte, 96),
|
|
|
|
}
|
|
|
|
s.processExit(exit)
|
2024-02-22 22:40:36 +00:00
|
|
|
require.LogsContain(t, hook, "\"Voluntary exit was processed\" prefix=monitor validatorIndex=1")
|
2021-11-15 19:45:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessExitP2PUntrackedIndices(t *testing.T) {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
s := &Service{
|
2023-01-26 14:40:12 +00:00
|
|
|
TrackedValidators: map[primitives.ValidatorIndex]bool{
|
2021-11-30 22:27:03 +00:00
|
|
|
1: true,
|
|
|
|
2: true,
|
2021-11-15 19:45:18 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exit := ðpb.SignedVoluntaryExit{
|
|
|
|
Exit: ðpb.VoluntaryExit{
|
|
|
|
ValidatorIndex: 3,
|
|
|
|
Epoch: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
s.processExit(exit)
|
|
|
|
require.LogsDoNotContain(t, hook, "\"Voluntary exit was processed\"")
|
|
|
|
}
|