2020-06-27 00:20:24 +00:00
|
|
|
package params
|
|
|
|
|
2022-05-20 07:16:53 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
2020-06-27 00:20:24 +00:00
|
|
|
|
|
|
|
// SetupTestConfigCleanup preserves configurations allowing to modify them within tests without any
|
|
|
|
// restrictions, everything is restored after the test.
|
2020-09-14 18:42:08 +00:00
|
|
|
func SetupTestConfigCleanup(t testing.TB) {
|
2020-06-27 00:20:24 +00:00
|
|
|
prevDefaultBeaconConfig := mainnetBeaconConfig.Copy()
|
2022-05-20 07:16:53 +00:00
|
|
|
temp := configs.getActive().Copy()
|
|
|
|
undo, err := SetActiveWithUndo(temp)
|
|
|
|
if err != nil {
|
2024-01-23 07:54:30 +00:00
|
|
|
t.Fatal(err)
|
2022-05-20 07:16:53 +00:00
|
|
|
}
|
2021-04-14 07:39:20 +00:00
|
|
|
prevNetworkCfg := networkConfig.Copy()
|
2020-06-27 00:20:24 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
mainnetBeaconConfig = prevDefaultBeaconConfig
|
2022-05-20 07:16:53 +00:00
|
|
|
err = undo()
|
|
|
|
if err != nil {
|
2024-01-23 07:54:30 +00:00
|
|
|
t.Fatal(err)
|
2022-05-20 07:16:53 +00:00
|
|
|
}
|
2021-04-14 07:39:20 +00:00
|
|
|
networkConfig = prevNetworkCfg
|
2020-06-27 00:20:24 +00:00
|
|
|
})
|
|
|
|
}
|
2024-01-23 07:54:30 +00:00
|
|
|
|
|
|
|
// SetActiveTestCleanup sets an active config,
|
|
|
|
// and adds a test cleanup hook to revert to the default config after the test completes.
|
|
|
|
func SetActiveTestCleanup(t *testing.T, cfg *BeaconChainConfig) {
|
|
|
|
undo, err := SetActiveWithUndo(cfg)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Cleanup(func() {
|
|
|
|
err = undo()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|