prysm-pulse/cmd/validator/flags/flags_test.go
james-prysm e0eee87bf4
Improve beacon chain coverage Part 1 (#11080)
* first node test

* adding in configuration flags for code coverage

* adding line to remove file on unit test

* adding new test for compressed field trie but is currently broken

* changing limit on trie

* adding new trie length coverage

* adding in test for empty copy of trie

* adding more trie tests

* adding new field trie

* adding more field trie tests

* adding clarity to chunking equation

* fixing linting

* clarifying function for limit

* updating native state settings to improve ease of future unit tests

* improving unit test

* fixing unit tests

* adding more tests and fixing linting

* adding more coverage and removing unused file

* increasing node coverage

* adding new test for checking config for booleans

* fixing db test

* fixing linting

* adding signing root test

* fixing linting

* removing accidently created beacondata

* switching not non native state

* reverting back to proto use for spec test

* reverting back to proto for some tests

* turning off native state on some tests

* switching more to proto state

* rolling back disablenativestate

* switching to native state in the state-native package for tests

* fixing linting

* fixing deepsource complaint

* fixing some tests to native state and removing some unused flag checks

* convert to native state

* fixing linting

* issues are being triggered by deleting the db this way so reverting change in hopes of changing this

* rolling back testing util

* rolling back some tests from native state

* rolling back db deletion

* test switching native state off after test runs

* fixing hasher test

* fixing altair and bellatrix hashers for native state

* Update beacon-chain/node/node_test.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* Update validator/rpc/auth_token_test.go

Co-authored-by: Radosław Kapka <rkapka@wp.pl>

* fixing imports

* adding altair proof test

Co-authored-by: Radosław Kapka <rkapka@wp.pl>
2022-08-16 16:19:01 +00:00

86 lines
2.5 KiB
Go

package flags
import (
"flag"
"fmt"
"os"
"strings"
"testing"
"github.com/prysmaticlabs/prysm/v3/cmd"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/urfave/cli/v2"
)
func TestLoadFlagsFromConfig_PreProcessing_Web3signer(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
context := cli.NewContext(&app, set, nil)
pubkey1 := "0xbd36226746676565cd40141a7f0fe1445b9a3fbeb222288b226392c4b230ed0b"
pubkey2 := "0xbd36226746676565cd40141a7f0fe1445b9a3fbeb222288b226392c4b230ed0a"
require.NoError(t, os.WriteFile("flags_test.yaml", []byte(fmt.Sprintf("%s:\n - %s\n - %s\n", Web3SignerPublicValidatorKeysFlag.Name,
pubkey1,
pubkey2)), 0666))
require.NoError(t, set.Parse([]string{"test-command", "--" + cmd.ConfigFileFlag.Name, "flags_test.yaml"}))
command := &cli.Command{
Name: "test-command",
Flags: cmd.WrapFlags([]cli.Flag{
&cli.StringFlag{
Name: cmd.ConfigFileFlag.Name,
},
&cli.StringSliceFlag{
Name: Web3SignerPublicValidatorKeysFlag.Name,
},
}),
Before: func(cliCtx *cli.Context) error {
return cmd.LoadFlagsFromConfig(cliCtx, cliCtx.Command.Flags)
},
Action: func(cliCtx *cli.Context) error {
//TODO: https://github.com/urfave/cli/issues/1197 right now does not set flag
require.Equal(t, false, cliCtx.IsSet(Web3SignerPublicValidatorKeysFlag.Name))
require.Equal(t, strings.Join([]string{pubkey1, pubkey2}, ","),
strings.Join(cliCtx.StringSlice(Web3SignerPublicValidatorKeysFlag.Name), ","))
return nil
},
}
require.NoError(t, command.Run(context))
require.NoError(t, os.Remove("flags_test.yaml"))
}
func TestLoadFlagsFromConfig_EnableBuilderHasDefaultValue(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
context := cli.NewContext(&app, set, nil)
require.NoError(t, os.WriteFile("flags_test.yaml", []byte("---\nenable-builder: true"), 0666))
require.NoError(t, set.Parse([]string{"test-command", "--" + cmd.ConfigFileFlag.Name, "flags_test.yaml"}))
command := &cli.Command{
Name: "test-command",
Flags: cmd.WrapFlags([]cli.Flag{
&cli.StringFlag{
Name: cmd.ConfigFileFlag.Name,
},
&cli.BoolFlag{
Name: EnableBuilderFlag.Name,
Value: false,
},
}),
Before: func(cliCtx *cli.Context) error {
return cmd.LoadFlagsFromConfig(cliCtx, cliCtx.Command.Flags)
},
Action: func(cliCtx *cli.Context) error {
require.Equal(t, true,
cliCtx.Bool(EnableBuilderFlag.Name))
return nil
},
}
require.NoError(t, command.Run(context))
require.NoError(t, os.Remove("flags_test.yaml"))
}