mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 20:50:05 +00:00
add a few fuzz tests (#4291)
This commit is contained in:
parent
fd93751bf7
commit
3f344aee55
@ -37,6 +37,7 @@ go_test(
|
|||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
size = "medium",
|
size = "medium",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
"block_operations_fuzz_test.go",
|
||||||
"block_operations_test.go",
|
"block_operations_test.go",
|
||||||
"block_test.go",
|
"block_test.go",
|
||||||
"eth1_data_test.go",
|
"eth1_data_test.go",
|
||||||
@ -51,6 +52,7 @@ go_test(
|
|||||||
"//shared/testutil:go_default_library",
|
"//shared/testutil:go_default_library",
|
||||||
"//shared/trieutil:go_default_library",
|
"//shared/trieutil:go_default_library",
|
||||||
"@com_github_gogo_protobuf//proto:go_default_library",
|
"@com_github_gogo_protobuf//proto:go_default_library",
|
||||||
|
"@com_github_google_gofuzz//:go_default_library",
|
||||||
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
|
||||||
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||||
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
|
||||||
|
@ -548,6 +548,10 @@ func ProcessAttestationNoVerify(ctx context.Context, beaconState *pb.BeaconState
|
|||||||
ctx, span := trace.StartSpan(ctx, "core.ProcessAttestationNoVerify")
|
ctx, span := trace.StartSpan(ctx, "core.ProcessAttestationNoVerify")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
|
if att == nil || att.Data == nil || att.Data.Target == nil {
|
||||||
|
return nil, errors.New("nil attestation data target")
|
||||||
|
}
|
||||||
|
|
||||||
data := att.Data
|
data := att.Data
|
||||||
if data.Target.Epoch != helpers.PrevEpoch(beaconState) && data.Target.Epoch != helpers.CurrentEpoch(beaconState) {
|
if data.Target.Epoch != helpers.PrevEpoch(beaconState) && data.Target.Epoch != helpers.CurrentEpoch(beaconState) {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
|
37
beacon-chain/core/blocks/block_operations_fuzz_test.go
Normal file
37
beacon-chain/core/blocks/block_operations_fuzz_test.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package blocks_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
fuzz "github.com/google/gofuzz"
|
||||||
|
eth "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||||
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
||||||
|
ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFuzzProcessAttestation_10000(t *testing.T) {
|
||||||
|
fuzzer := fuzz.NewWithSeed(0)
|
||||||
|
ctx := context.Background()
|
||||||
|
state := ðereum_beacon_p2p_v1.BeaconState{}
|
||||||
|
att := ð.Attestation{}
|
||||||
|
|
||||||
|
for i := 0; i < 10000; i++ {
|
||||||
|
fuzzer.Fuzz(state)
|
||||||
|
fuzzer.Fuzz(att)
|
||||||
|
_, _ = blocks.ProcessAttestationNoVerify(ctx, state, att)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFuzzProcessBlockHeader_10000(t *testing.T) {
|
||||||
|
fuzzer := fuzz.NewWithSeed(0)
|
||||||
|
state := ðereum_beacon_p2p_v1.BeaconState{}
|
||||||
|
block := ð.BeaconBlock{}
|
||||||
|
|
||||||
|
for i := 0; i < 10000; i++ {
|
||||||
|
fuzzer.Fuzz(state)
|
||||||
|
fuzzer.Fuzz(block)
|
||||||
|
_, _ = blocks.ProcessBlockHeader(state, block)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,12 +14,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrAttestationDataSlotNilState is returned when a nil state argument
|
|
||||||
// is provided to AttestationDataSlot.
|
|
||||||
ErrAttestationDataSlotNilState = errors.New("nil state provided for AttestationDataSlot")
|
|
||||||
// ErrAttestationDataSlotNilData is returned when a nil attestation data
|
|
||||||
// argument is provided to AttestationDataSlot.
|
|
||||||
ErrAttestationDataSlotNilData = errors.New("nil data provided for AttestationDataSlot")
|
|
||||||
// ErrAttestationAggregationBitsOverlap is returned when two attestations aggregation
|
// ErrAttestationAggregationBitsOverlap is returned when two attestations aggregation
|
||||||
// bits overlap with each other.
|
// bits overlap with each other.
|
||||||
ErrAttestationAggregationBitsOverlap = errors.New("overlapping aggregation bits")
|
ErrAttestationAggregationBitsOverlap = errors.New("overlapping aggregation bits")
|
||||||
|
Loading…
Reference in New Issue
Block a user