github.com/prysmaticlabs/prysm@v1.4.4/shared/params/config_test.go (about) 1 package params_test 2 3 import ( 4 "testing" 5 6 "github.com/prysmaticlabs/prysm/shared/params" 7 ) 8 9 // Test cases can be executed in an arbitrary order. TestOverrideBeaconConfigTestTeardown checks 10 // that there's no state mutation leak from the previous test, therefore we need a sentinel flag, 11 // to make sure that previous test case has already been completed and check can be run. 12 var testOverrideBeaconConfigExecuted bool 13 14 func TestConfig_OverrideBeaconConfig(t *testing.T) { 15 // Ensure that param modifications are safe. 16 params.SetupTestConfigCleanup(t) 17 cfg := params.BeaconConfig() 18 cfg.SlotsPerEpoch = 5 19 params.OverrideBeaconConfig(cfg) 20 if c := params.BeaconConfig(); c.SlotsPerEpoch != 5 { 21 t.Errorf("Shardcount in BeaconConfig incorrect. Wanted %d, got %d", 5, c.SlotsPerEpoch) 22 } 23 testOverrideBeaconConfigExecuted = true 24 } 25 26 func TestConfig_OverrideBeaconConfigTestTeardown(t *testing.T) { 27 if !testOverrideBeaconConfigExecuted { 28 t.Skip("State leak can occur only if state mutating test has already completed") 29 } 30 cfg := params.BeaconConfig() 31 if cfg.SlotsPerEpoch == 5 { 32 t.Fatal("Parameter update has been leaked out of previous test") 33 } 34 } 35 36 func TestConfig_DataRace(t *testing.T) { 37 for i := 0; i < 10; i++ { 38 go func() { 39 cfg := params.BeaconConfig() 40 params.OverrideBeaconConfig(cfg) 41 }() 42 go func() uint64 { 43 return params.BeaconConfig().MaxDeposits 44 }() 45 } 46 }