2021-09-15 01:18:39 +00:00
|
|
|
package features
|
2019-03-21 02:57:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"testing"
|
|
|
|
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
2020-05-31 06:44:34 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-03-21 02:57:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInitFeatureConfig(t *testing.T) {
|
2020-10-22 05:20:56 +00:00
|
|
|
defer Init(&Flags{})
|
2020-01-15 23:41:40 +00:00
|
|
|
cfg := &Flags{
|
2022-07-27 17:01:13 +00:00
|
|
|
EnableSlasher: true,
|
2019-03-21 02:57:25 +00:00
|
|
|
}
|
2020-01-15 23:41:40 +00:00
|
|
|
Init(cfg)
|
2020-07-19 21:08:29 +00:00
|
|
|
c := Get()
|
2022-07-27 17:01:13 +00:00
|
|
|
assert.Equal(t, true, c.EnableSlasher)
|
2020-08-15 15:48:12 +00:00
|
|
|
|
|
|
|
// Reset back to false for the follow up tests.
|
2022-04-15 15:30:32 +00:00
|
|
|
cfg = &Flags{RemoteSlasherProtection: false}
|
2020-08-15 15:48:12 +00:00
|
|
|
Init(cfg)
|
2019-03-21 02:57:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-22 05:20:56 +00:00
|
|
|
func TestInitWithReset(t *testing.T) {
|
|
|
|
defer Init(&Flags{})
|
|
|
|
Init(&Flags{
|
2022-07-27 17:01:13 +00:00
|
|
|
EnableSlasher: true,
|
2020-10-22 05:20:56 +00:00
|
|
|
})
|
2022-07-27 17:01:13 +00:00
|
|
|
assert.Equal(t, true, Get().EnableSlasher)
|
2020-10-22 05:20:56 +00:00
|
|
|
|
|
|
|
// Overwrite previously set value (value that didn't come by default).
|
|
|
|
resetCfg := InitWithReset(&Flags{
|
2022-07-27 17:01:13 +00:00
|
|
|
EnableSlasher: false,
|
2020-10-22 05:20:56 +00:00
|
|
|
})
|
2022-07-27 17:01:13 +00:00
|
|
|
assert.Equal(t, false, Get().EnableSlasher)
|
2020-10-22 05:20:56 +00:00
|
|
|
|
|
|
|
// Reset must get to previously set configuration (not to default config values).
|
|
|
|
resetCfg()
|
2022-07-27 17:01:13 +00:00
|
|
|
assert.Equal(t, true, Get().EnableSlasher)
|
2020-10-22 05:20:56 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 02:57:25 +00:00
|
|
|
func TestConfigureBeaconConfig(t *testing.T) {
|
2020-03-19 21:46:44 +00:00
|
|
|
app := cli.App{}
|
2019-03-21 02:57:25 +00:00
|
|
|
set := flag.NewFlagSet("test", 0)
|
2022-07-27 17:01:13 +00:00
|
|
|
set.Bool(enableSlasherFlag.Name, true, "test")
|
2020-03-19 21:46:44 +00:00
|
|
|
context := cli.NewContext(&app, set, nil)
|
2022-05-20 07:16:53 +00:00
|
|
|
require.NoError(t, ConfigureBeaconChain(context))
|
2020-07-19 21:08:29 +00:00
|
|
|
c := Get()
|
2022-07-27 17:01:13 +00:00
|
|
|
assert.Equal(t, true, c.EnableSlasher)
|
2019-03-21 02:57:25 +00:00
|
|
|
}
|