2021-02-18 19:08:27 +00:00
|
|
|
package blockchain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-07-21 21:34:07 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-07-28 21:23:44 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/block"
|
2021-07-21 21:34:07 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
|
2021-02-18 19:08:27 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_logStateTransitionData(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2021-07-23 20:10:15 +00:00
|
|
|
b block.BeaconBlock
|
2021-02-18 19:08:27 +00:00
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{name: "empty block body",
|
2021-07-06 15:34:05 +00:00
|
|
|
b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}),
|
2021-02-18 19:08:27 +00:00
|
|
|
want: "\"Finished applying state transition\" prefix=blockchain slot=0",
|
|
|
|
},
|
|
|
|
{name: "has attestation",
|
2021-07-06 15:34:05 +00:00
|
|
|
b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{Attestations: []*ethpb.Attestation{{}}}}),
|
2021-02-18 19:08:27 +00:00
|
|
|
want: "\"Finished applying state transition\" attestations=1 prefix=blockchain slot=0",
|
|
|
|
},
|
|
|
|
{name: "has deposit",
|
2021-07-06 15:34:05 +00:00
|
|
|
b: wrapper.WrappedPhase0BeaconBlock(
|
2021-07-02 19:01:37 +00:00
|
|
|
ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
|
|
|
Attestations: []*ethpb.Attestation{{}},
|
|
|
|
Deposits: []*ethpb.Deposit{{}}}}),
|
2021-02-18 19:08:27 +00:00
|
|
|
want: "\"Finished applying state transition\" attestations=1 deposits=1 prefix=blockchain slot=0",
|
|
|
|
},
|
|
|
|
{name: "has attester slashing",
|
2021-07-06 15:34:05 +00:00
|
|
|
b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
2021-07-02 19:01:37 +00:00
|
|
|
AttesterSlashings: []*ethpb.AttesterSlashing{{}}}}),
|
2021-02-18 19:08:27 +00:00
|
|
|
want: "\"Finished applying state transition\" attesterSlashings=1 prefix=blockchain slot=0",
|
|
|
|
},
|
|
|
|
{name: "has proposer slashing",
|
2021-07-06 15:34:05 +00:00
|
|
|
b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
2021-07-02 19:01:37 +00:00
|
|
|
ProposerSlashings: []*ethpb.ProposerSlashing{{}}}}),
|
2021-02-18 19:08:27 +00:00
|
|
|
want: "\"Finished applying state transition\" prefix=blockchain proposerSlashings=1 slot=0",
|
|
|
|
},
|
|
|
|
{name: "has exit",
|
2021-07-06 15:34:05 +00:00
|
|
|
b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
2021-07-02 19:01:37 +00:00
|
|
|
VoluntaryExits: []*ethpb.SignedVoluntaryExit{{}}}}),
|
2021-02-18 19:08:27 +00:00
|
|
|
want: "\"Finished applying state transition\" prefix=blockchain slot=0 voluntaryExits=1",
|
|
|
|
},
|
|
|
|
{name: "has everything",
|
2021-07-06 15:34:05 +00:00
|
|
|
b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
2021-02-18 19:08:27 +00:00
|
|
|
Attestations: []*ethpb.Attestation{{}},
|
|
|
|
Deposits: []*ethpb.Deposit{{}},
|
|
|
|
AttesterSlashings: []*ethpb.AttesterSlashing{{}},
|
|
|
|
ProposerSlashings: []*ethpb.ProposerSlashing{{}},
|
2021-07-02 19:01:37 +00:00
|
|
|
VoluntaryExits: []*ethpb.SignedVoluntaryExit{{}}}}),
|
2021-02-18 19:08:27 +00:00
|
|
|
want: "\"Finished applying state transition\" attestations=1 attesterSlashings=1 deposits=1 prefix=blockchain proposerSlashings=1 slot=0 voluntaryExits=1",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
hook := logTest.NewGlobal()
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-07-02 19:01:37 +00:00
|
|
|
logStateTransitionData(tt.b)
|
2021-02-18 19:08:27 +00:00
|
|
|
require.LogsContain(t, hook, tt.want)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|