mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
30 lines
721 B
Go
30 lines
721 B
Go
package params
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// SetupTestConfigCleanup preserves configurations allowing to modify them within tests without any
|
|
// restrictions, everything is restored after the test.
|
|
func SetupTestConfigCleanup(t testing.TB) {
|
|
prevDefaultBeaconConfig := mainnetBeaconConfig.Copy()
|
|
temp := configs.getActive().Copy()
|
|
undo, err := SetActiveWithUndo(temp)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
prevNetworkCfg := networkConfig.Copy()
|
|
t.Cleanup(func() {
|
|
mainnetBeaconConfig = prevDefaultBeaconConfig
|
|
// Lock the config, when cleaning up
|
|
// otherwise the race detector is triggered.
|
|
cfgrw.Lock()
|
|
err = undo()
|
|
cfgrw.Unlock()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
networkConfig = prevNetworkCfg
|
|
})
|
|
}
|