mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
879e310332
* panic in SizeSSZ * moving slowly * adapt old code to new interfaces * return interfaces from factory functions * replace the rest of WrappedSignedBeaconBlock * WrappedBeaconBlock * WrappedBeaconBlockBody * miscellaneous * Test_BeaconBlockIsNil * replace usages of BeaconBlockIsNil * replace usages of mutator * fix all build errors * fix some more issues * mutator changes * relax assertions when initializing * revert changes in object_mapping.go * allow calling Proto on nil * Revert "allow calling Proto on nil" This reverts commit ecc84e455381b03d24aec2fa0fa17bddbec71705. * modify Copy and Proto methods * remove unused var * fix block batch tests * correct BUILD file * Error when initializing nil objects * one more error fix * add missing comma * rename alias to blocktest * add logging * error when SignedBeaconBlock is nil * fix last test * import fix * broken * working * test fixes * reduce complexity of processPendingBlocks * simplified
111 lines
3.9 KiB
Go
111 lines
3.9 KiB
Go
package blockchain
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/consensus-types/blocks"
|
|
"github.com/prysmaticlabs/prysm/consensus-types/interfaces"
|
|
enginev1 "github.com/prysmaticlabs/prysm/proto/engine/v1"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func Test_logStateTransitionData(t *testing.T) {
|
|
payloadBlk := ðpb.BeaconBlockBellatrix{
|
|
Body: ðpb.BeaconBlockBodyBellatrix{
|
|
SyncAggregate: ðpb.SyncAggregate{},
|
|
ExecutionPayload: &enginev1.ExecutionPayload{
|
|
BlockHash: []byte{1, 2, 3},
|
|
Transactions: [][]byte{{}, {}},
|
|
},
|
|
},
|
|
}
|
|
wrappedPayloadBlk, err := blocks.NewBeaconBlock(payloadBlk)
|
|
require.NoError(t, err)
|
|
tests := []struct {
|
|
name string
|
|
b func() interfaces.BeaconBlock
|
|
want string
|
|
}{
|
|
{name: "empty block body",
|
|
b: func() interfaces.BeaconBlock {
|
|
wb, err := blocks.NewBeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{}})
|
|
require.NoError(t, err)
|
|
return wb
|
|
},
|
|
want: "\"Finished applying state transition\" prefix=blockchain slot=0",
|
|
},
|
|
{name: "has attestation",
|
|
b: func() interfaces.BeaconBlock {
|
|
wb, err := blocks.NewBeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{Attestations: []*ethpb.Attestation{{}}}})
|
|
require.NoError(t, err)
|
|
return wb
|
|
},
|
|
want: "\"Finished applying state transition\" attestations=1 prefix=blockchain slot=0",
|
|
},
|
|
{name: "has deposit",
|
|
b: func() interfaces.BeaconBlock {
|
|
wb, err := blocks.NewBeaconBlock(
|
|
ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
|
Attestations: []*ethpb.Attestation{{}},
|
|
Deposits: []*ethpb.Deposit{{}}}})
|
|
require.NoError(t, err)
|
|
return wb
|
|
},
|
|
want: "\"Finished applying state transition\" attestations=1 deposits=1 prefix=blockchain slot=0",
|
|
},
|
|
{name: "has attester slashing",
|
|
b: func() interfaces.BeaconBlock {
|
|
wb, err := blocks.NewBeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
|
AttesterSlashings: []*ethpb.AttesterSlashing{{}}}})
|
|
require.NoError(t, err)
|
|
return wb
|
|
},
|
|
want: "\"Finished applying state transition\" attesterSlashings=1 prefix=blockchain slot=0",
|
|
},
|
|
{name: "has proposer slashing",
|
|
b: func() interfaces.BeaconBlock {
|
|
wb, err := blocks.NewBeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
|
ProposerSlashings: []*ethpb.ProposerSlashing{{}}}})
|
|
require.NoError(t, err)
|
|
return wb
|
|
},
|
|
want: "\"Finished applying state transition\" prefix=blockchain proposerSlashings=1 slot=0",
|
|
},
|
|
{name: "has exit",
|
|
b: func() interfaces.BeaconBlock {
|
|
wb, err := blocks.NewBeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
|
VoluntaryExits: []*ethpb.SignedVoluntaryExit{{}}}})
|
|
require.NoError(t, err)
|
|
return wb
|
|
},
|
|
want: "\"Finished applying state transition\" prefix=blockchain slot=0 voluntaryExits=1",
|
|
},
|
|
{name: "has everything",
|
|
b: func() interfaces.BeaconBlock {
|
|
wb, err := blocks.NewBeaconBlock(ðpb.BeaconBlock{Body: ðpb.BeaconBlockBody{
|
|
Attestations: []*ethpb.Attestation{{}},
|
|
Deposits: []*ethpb.Deposit{{}},
|
|
AttesterSlashings: []*ethpb.AttesterSlashing{{}},
|
|
ProposerSlashings: []*ethpb.ProposerSlashing{{}},
|
|
VoluntaryExits: []*ethpb.SignedVoluntaryExit{{}}}})
|
|
require.NoError(t, err)
|
|
return wb
|
|
},
|
|
want: "\"Finished applying state transition\" attestations=1 attesterSlashings=1 deposits=1 prefix=blockchain proposerSlashings=1 slot=0 voluntaryExits=1",
|
|
},
|
|
{name: "has payload",
|
|
b: func() interfaces.BeaconBlock { return wrappedPayloadBlk },
|
|
want: "\"Finished applying state transition\" payloadHash=0x010203 prefix=blockchain slot=0 syncBitsCount=0 txCount=2",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
hook := logTest.NewGlobal()
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
require.NoError(t, logStateTransitionData(tt.b()))
|
|
require.LogsContain(t, hook, tt.want)
|
|
})
|
|
}
|
|
}
|