mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
afbe02697d
* Add a service for the monitor * Do not block service start * gaz * move channel subscription outide go routine * add service start test * fix panic on node tests * Radek's first pass * Radek's take 2 * uncap error messages * revert reversal * Terence take 1 * gaz * Missing locks found by Terence * Track via bool not empty interface * Add tests for every function * fix allocation of slice * Minor cleanups Co-authored-by: terence tsao <terence@prysmaticlabs.com>
119 lines
2.4 KiB
Go
119 lines
2.4 KiB
Go
package monitor
|
|
|
|
import (
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestProcessExitsFromBlockTrackedIndices(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
s := &Service{
|
|
TrackedValidators: map[types.ValidatorIndex]bool{
|
|
1: true,
|
|
2: true,
|
|
},
|
|
}
|
|
|
|
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,
|
|
},
|
|
}
|
|
|
|
s.processExitsFromBlock(wrapper.WrappedPhase0BeaconBlock(block))
|
|
require.LogsContain(t, hook, "\"Voluntary exit was included\" Slot=0 ValidatorIndex=2")
|
|
}
|
|
|
|
func TestProcessExitsFromBlockUntrackedIndices(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
s := &Service{
|
|
TrackedValidators: map[types.ValidatorIndex]bool{
|
|
1: true,
|
|
2: true,
|
|
},
|
|
}
|
|
|
|
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,
|
|
},
|
|
}
|
|
|
|
s.processExitsFromBlock(wrapper.WrappedPhase0BeaconBlock(block))
|
|
require.LogsDoNotContain(t, hook, "\"Voluntary exit was included\"")
|
|
}
|
|
|
|
func TestProcessExitP2PTrackedIndices(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
s := &Service{
|
|
TrackedValidators: map[types.ValidatorIndex]bool{
|
|
1: true,
|
|
2: true,
|
|
},
|
|
}
|
|
|
|
exit := ðpb.SignedVoluntaryExit{
|
|
Exit: ðpb.VoluntaryExit{
|
|
ValidatorIndex: 1,
|
|
Epoch: 1,
|
|
},
|
|
Signature: make([]byte, 96),
|
|
}
|
|
s.processExit(exit)
|
|
require.LogsContain(t, hook, "\"Voluntary exit was processed\" ValidatorIndex=1")
|
|
}
|
|
|
|
func TestProcessExitP2PUntrackedIndices(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
s := &Service{
|
|
TrackedValidators: map[types.ValidatorIndex]bool{
|
|
1: true,
|
|
2: true,
|
|
},
|
|
}
|
|
|
|
exit := ðpb.SignedVoluntaryExit{
|
|
Exit: ðpb.VoluntaryExit{
|
|
ValidatorIndex: 3,
|
|
Epoch: 1,
|
|
},
|
|
}
|
|
s.processExit(exit)
|
|
require.LogsDoNotContain(t, hook, "\"Voluntary exit was processed\"")
|
|
}
|