github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/blockchain/log_test.go (about) 1 package blockchain 2 3 import ( 4 "testing" 5 6 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 7 "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1/wrapper" 8 "github.com/prysmaticlabs/prysm/proto/interfaces" 9 "github.com/prysmaticlabs/prysm/shared/testutil/require" 10 logTest "github.com/sirupsen/logrus/hooks/test" 11 ) 12 13 func Test_logStateTransitionData(t *testing.T) { 14 tests := []struct { 15 name string 16 b interfaces.BeaconBlock 17 want string 18 }{ 19 {name: "empty block body", 20 b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}), 21 want: "\"Finished applying state transition\" prefix=blockchain slot=0", 22 }, 23 {name: "has attestation", 24 b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{Attestations: []*ethpb.Attestation{{}}}}), 25 want: "\"Finished applying state transition\" attestations=1 prefix=blockchain slot=0", 26 }, 27 {name: "has deposit", 28 b: wrapper.WrappedPhase0BeaconBlock( 29 ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ 30 Attestations: []*ethpb.Attestation{{}}, 31 Deposits: []*ethpb.Deposit{{}}}}), 32 want: "\"Finished applying state transition\" attestations=1 deposits=1 prefix=blockchain slot=0", 33 }, 34 {name: "has attester slashing", 35 b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ 36 AttesterSlashings: []*ethpb.AttesterSlashing{{}}}}), 37 want: "\"Finished applying state transition\" attesterSlashings=1 prefix=blockchain slot=0", 38 }, 39 {name: "has proposer slashing", 40 b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ 41 ProposerSlashings: []*ethpb.ProposerSlashing{{}}}}), 42 want: "\"Finished applying state transition\" prefix=blockchain proposerSlashings=1 slot=0", 43 }, 44 {name: "has exit", 45 b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ 46 VoluntaryExits: []*ethpb.SignedVoluntaryExit{{}}}}), 47 want: "\"Finished applying state transition\" prefix=blockchain slot=0 voluntaryExits=1", 48 }, 49 {name: "has everything", 50 b: wrapper.WrappedPhase0BeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ 51 Attestations: []*ethpb.Attestation{{}}, 52 Deposits: []*ethpb.Deposit{{}}, 53 AttesterSlashings: []*ethpb.AttesterSlashing{{}}, 54 ProposerSlashings: []*ethpb.ProposerSlashing{{}}, 55 VoluntaryExits: []*ethpb.SignedVoluntaryExit{{}}}}), 56 want: "\"Finished applying state transition\" attestations=1 attesterSlashings=1 deposits=1 prefix=blockchain proposerSlashings=1 slot=0 voluntaryExits=1", 57 }, 58 } 59 for _, tt := range tests { 60 hook := logTest.NewGlobal() 61 t.Run(tt.name, func(t *testing.T) { 62 logStateTransitionData(tt.b) 63 require.LogsContain(t, hook, tt.want) 64 }) 65 } 66 }