-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide beacon operation field in log if it's 0 (#8330)
* Hide beacon operation field if it's 0 * Update test Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
- Loading branch information
1 parent
eea0160
commit d472380
Showing
2 changed files
with
80 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package blockchain | ||
|
||
import ( | ||
"testing" | ||
|
||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/shared/testutil/require" | ||
logTest "github.com/sirupsen/logrus/hooks/test" | ||
) | ||
|
||
func Test_logStateTransitionData(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
b *ethpb.BeaconBlock | ||
want string | ||
}{ | ||
{name: "empty block body", | ||
b: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}}, | ||
want: "\"Finished applying state transition\" prefix=blockchain slot=0", | ||
}, | ||
{name: "has attestation", | ||
b: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{Attestations: []*ethpb.Attestation{{}}}}, | ||
want: "\"Finished applying state transition\" attestations=1 prefix=blockchain slot=0", | ||
}, | ||
{name: "has deposit", | ||
b: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ | ||
Attestations: []*ethpb.Attestation{{}}, | ||
Deposits: []*ethpb.Deposit{{}}}}, | ||
want: "\"Finished applying state transition\" attestations=1 deposits=1 prefix=blockchain slot=0", | ||
}, | ||
{name: "has attester slashing", | ||
b: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ | ||
AttesterSlashings: []*ethpb.AttesterSlashing{{}}}}, | ||
want: "\"Finished applying state transition\" attesterSlashings=1 prefix=blockchain slot=0", | ||
}, | ||
{name: "has proposer slashing", | ||
b: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ | ||
ProposerSlashings: []*ethpb.ProposerSlashing{{}}}}, | ||
want: "\"Finished applying state transition\" prefix=blockchain proposerSlashings=1 slot=0", | ||
}, | ||
{name: "has exit", | ||
b: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ | ||
VoluntaryExits: []*ethpb.SignedVoluntaryExit{{}}}}, | ||
want: "\"Finished applying state transition\" prefix=blockchain slot=0 voluntaryExits=1", | ||
}, | ||
{name: "has everything", | ||
b: ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{ | ||
Attestations: []*ethpb.Attestation{{}}, | ||
Deposits: []*ethpb.Deposit{{}}, | ||
AttesterSlashings: []*ethpb.AttesterSlashing{{}}, | ||
ProposerSlashings: []*ethpb.ProposerSlashing{{}}, | ||
VoluntaryExits: []*ethpb.SignedVoluntaryExit{{}}}}, | ||
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) { | ||
logStateTransitionData(tt.b) | ||
require.LogsContain(t, hook, tt.want) | ||
}) | ||
} | ||
} |