2020-06-26 17:20:24 -07:00
|
|
|
package params
|
|
|
|
|
2022-05-20 02:16:53 -05:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
2020-06-26 17:20:24 -07:00
|
|
|
|
|
|
|
// SetupTestConfigCleanup preserves configurations allowing to modify them within tests without any
|
|
|
|
// restrictions, everything is restored after the test.
|
2020-09-14 13:42:08 -05:00
|
|
|
func SetupTestConfigCleanup(t testing.TB) {
|
2020-06-26 17:20:24 -07:00
|
|
|
prevDefaultBeaconConfig := mainnetBeaconConfig.Copy()
|
2022-05-20 02:16:53 -05:00
|
|
|
temp := configs.getActive().Copy()
|
|
|
|
undo, err := SetActiveWithUndo(temp)
|
|
|
|
if err != nil {
|
2024-01-23 01:54:30 -06:00
|
|
|
t.Fatal(err)
|
2022-05-20 02:16:53 -05:00
|
|
|
}
|
2021-04-14 09:39:20 +02:00
|
|
|
prevNetworkCfg := networkConfig.Copy()
|
2020-06-26 17:20:24 -07:00
|
|
|
t.Cleanup(func() {
|
|
|
|
mainnetBeaconConfig = prevDefaultBeaconConfig
|
2022-05-20 02:16:53 -05:00
|
|
|
err = undo()
|
|
|
|
if err != nil {
|
2024-01-23 01:54:30 -06:00
|
|
|
t.Fatal(err)
|
2022-05-20 02:16:53 -05:00
|
|
|
}
|
2021-04-14 09:39:20 +02:00
|
|
|
networkConfig = prevNetworkCfg
|
2020-06-26 17:20:24 -07:00
|
|
|
})
|
|
|
|
}
|
2024-01-23 01:54:30 -06: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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|