github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/core/state/transition_fuzz_test.go (about)

     1  package state
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	fuzz "github.com/google/gofuzz"
     8  	types "github.com/prysmaticlabs/eth2-types"
     9  	"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
    10  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
    11  	"github.com/prysmaticlabs/prysm/proto/eth/v1alpha1/wrapper"
    12  )
    13  
    14  func TestFuzzExecuteStateTransition_1000(t *testing.T) {
    15  	SkipSlotCache.Disable()
    16  	defer SkipSlotCache.Enable()
    17  	ctx := context.Background()
    18  	state := &v1.BeaconState{}
    19  	sb := &ethpb.SignedBeaconBlock{}
    20  	fuzzer := fuzz.NewWithSeed(0)
    21  	fuzzer.NilChance(0.1)
    22  	for i := 0; i < 1000; i++ {
    23  		fuzzer.Fuzz(state)
    24  		fuzzer.Fuzz(sb)
    25  		s, err := ExecuteStateTransition(ctx, state, wrapper.WrappedPhase0SignedBeaconBlock(sb))
    26  		if err != nil && s != nil {
    27  			t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v and signed block: %v", s, err, state, sb)
    28  		}
    29  	}
    30  }
    31  
    32  func TestFuzzCalculateStateRoot_1000(t *testing.T) {
    33  	SkipSlotCache.Disable()
    34  	defer SkipSlotCache.Enable()
    35  	ctx := context.Background()
    36  	state := &v1.BeaconState{}
    37  	sb := &ethpb.SignedBeaconBlock{}
    38  	fuzzer := fuzz.NewWithSeed(0)
    39  	fuzzer.NilChance(0.1)
    40  	for i := 0; i < 1000; i++ {
    41  		fuzzer.Fuzz(state)
    42  		fuzzer.Fuzz(sb)
    43  		stateRoot, err := CalculateStateRoot(ctx, state, wrapper.WrappedPhase0SignedBeaconBlock(sb))
    44  		if err != nil && stateRoot != [32]byte{} {
    45  			t.Fatalf("state root should be empty on err. found: %v on error: %v for signed block: %v", stateRoot, err, sb)
    46  		}
    47  	}
    48  }
    49  
    50  func TestFuzzProcessSlot_1000(t *testing.T) {
    51  	SkipSlotCache.Disable()
    52  	defer SkipSlotCache.Enable()
    53  	ctx := context.Background()
    54  	state := &v1.BeaconState{}
    55  	fuzzer := fuzz.NewWithSeed(0)
    56  	fuzzer.NilChance(0.1)
    57  	for i := 0; i < 1000; i++ {
    58  		fuzzer.Fuzz(state)
    59  		s, err := ProcessSlot(ctx, state)
    60  		if err != nil && s != nil {
    61  			t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v", s, err, state)
    62  		}
    63  	}
    64  }
    65  
    66  func TestFuzzProcessSlots_1000(t *testing.T) {
    67  	SkipSlotCache.Disable()
    68  	defer SkipSlotCache.Enable()
    69  	ctx := context.Background()
    70  	state := &v1.BeaconState{}
    71  	slot := types.Slot(0)
    72  	fuzzer := fuzz.NewWithSeed(0)
    73  	fuzzer.NilChance(0.1)
    74  	for i := 0; i < 1000; i++ {
    75  		fuzzer.Fuzz(state)
    76  		fuzzer.Fuzz(&slot)
    77  		s, err := ProcessSlots(ctx, state, slot)
    78  		if err != nil && s != nil {
    79  			t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v", s, err, state)
    80  		}
    81  	}
    82  }
    83  
    84  func TestFuzzProcessBlock_1000(t *testing.T) {
    85  	SkipSlotCache.Disable()
    86  	defer SkipSlotCache.Enable()
    87  	ctx := context.Background()
    88  	state := &v1.BeaconState{}
    89  	sb := &ethpb.SignedBeaconBlock{}
    90  	fuzzer := fuzz.NewWithSeed(0)
    91  	fuzzer.NilChance(0.1)
    92  	for i := 0; i < 1000; i++ {
    93  		fuzzer.Fuzz(state)
    94  		fuzzer.Fuzz(sb)
    95  		s, err := ProcessBlock(ctx, state, wrapper.WrappedPhase0SignedBeaconBlock(sb))
    96  		if err != nil && s != nil {
    97  			t.Fatalf("state should be nil on err. found: %v on error: %v for signed block: %v", s, err, sb)
    98  		}
    99  	}
   100  }
   101  
   102  func TestFuzzProcessOperations_1000(t *testing.T) {
   103  	SkipSlotCache.Disable()
   104  	defer SkipSlotCache.Enable()
   105  	ctx := context.Background()
   106  	state := &v1.BeaconState{}
   107  	bb := &ethpb.SignedBeaconBlock{}
   108  	fuzzer := fuzz.NewWithSeed(0)
   109  	fuzzer.NilChance(0.1)
   110  	for i := 0; i < 1000; i++ {
   111  		fuzzer.Fuzz(state)
   112  		fuzzer.Fuzz(bb)
   113  		s, err := ProcessBlock(ctx, state, wrapper.WrappedPhase0SignedBeaconBlock(bb))
   114  		if err != nil && s != nil {
   115  			t.Fatalf("state should be nil on err. found: %v on error: %v for block body: %v", s, err, bb)
   116  		}
   117  	}
   118  }
   119  
   120  func TestFuzzprocessOperationsNoVerify_1000(t *testing.T) {
   121  	SkipSlotCache.Disable()
   122  	defer SkipSlotCache.Enable()
   123  	ctx := context.Background()
   124  	state := &v1.BeaconState{}
   125  	bb := &ethpb.SignedBeaconBlock{}
   126  	fuzzer := fuzz.NewWithSeed(0)
   127  	fuzzer.NilChance(0.1)
   128  	for i := 0; i < 1000; i++ {
   129  		fuzzer.Fuzz(state)
   130  		fuzzer.Fuzz(bb)
   131  		s, err := ProcessOperationsNoVerifyAttsSigs(ctx, state, wrapper.WrappedPhase0SignedBeaconBlock(bb))
   132  		if err != nil && s != nil {
   133  			t.Fatalf("state should be nil on err. found: %v on error: %v for block body: %v", s, err, bb)
   134  		}
   135  	}
   136  }
   137  
   138  func TestFuzzverifyOperationLengths_10000(t *testing.T) {
   139  	SkipSlotCache.Disable()
   140  	defer SkipSlotCache.Enable()
   141  	state := &v1.BeaconState{}
   142  	bb := &ethpb.SignedBeaconBlock{}
   143  	fuzzer := fuzz.NewWithSeed(0)
   144  	fuzzer.NilChance(0.1)
   145  	for i := 0; i < 10000; i++ {
   146  		fuzzer.Fuzz(state)
   147  		fuzzer.Fuzz(bb)
   148  		_, err := VerifyOperationLengths(context.Background(), state, wrapper.WrappedPhase0SignedBeaconBlock(bb))
   149  		_ = err
   150  	}
   151  }
   152  
   153  func TestFuzzCanProcessEpoch_10000(t *testing.T) {
   154  	SkipSlotCache.Disable()
   155  	defer SkipSlotCache.Enable()
   156  	state := &v1.BeaconState{}
   157  	fuzzer := fuzz.NewWithSeed(0)
   158  	fuzzer.NilChance(0.1)
   159  	for i := 0; i < 10000; i++ {
   160  		fuzzer.Fuzz(state)
   161  		CanProcessEpoch(state)
   162  	}
   163  }
   164  
   165  func TestFuzzProcessEpochPrecompute_1000(t *testing.T) {
   166  	SkipSlotCache.Disable()
   167  	defer SkipSlotCache.Enable()
   168  	ctx := context.Background()
   169  	state := &v1.BeaconState{}
   170  	fuzzer := fuzz.NewWithSeed(0)
   171  	fuzzer.NilChance(0.1)
   172  	for i := 0; i < 1000; i++ {
   173  		fuzzer.Fuzz(state)
   174  		s, err := ProcessEpochPrecompute(ctx, state)
   175  		if err != nil && s != nil {
   176  			t.Fatalf("state should be nil on err. found: %v on error: %v for state: %v", s, err, state)
   177  		}
   178  	}
   179  }
   180  
   181  func TestFuzzProcessBlockForStateRoot_1000(t *testing.T) {
   182  	SkipSlotCache.Disable()
   183  	defer SkipSlotCache.Enable()
   184  	ctx := context.Background()
   185  	state := &v1.BeaconState{}
   186  	sb := &ethpb.SignedBeaconBlock{}
   187  	fuzzer := fuzz.NewWithSeed(0)
   188  	fuzzer.NilChance(0.1)
   189  	for i := 0; i < 1000; i++ {
   190  		fuzzer.Fuzz(state)
   191  		fuzzer.Fuzz(sb)
   192  		s, err := ProcessBlockForStateRoot(ctx, state, wrapper.WrappedPhase0SignedBeaconBlock(sb))
   193  		if err != nil && s != nil {
   194  			t.Fatalf("state should be nil on err. found: %v on error: %v for signed block: %v", s, err, sb)
   195  		}
   196  	}
   197  }