|
| 1 | +package node |
| 2 | + |
| 3 | +import ( |
| 4 | + "flag" |
| 5 | + "fmt" |
| 6 | + "strconv" |
| 7 | + "testing" |
| 8 | + |
| 9 | + types "github.com/prysmaticlabs/eth2-types" |
| 10 | + "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" |
| 11 | + "github.com/prysmaticlabs/prysm/shared/cmd" |
| 12 | + "github.com/prysmaticlabs/prysm/shared/params" |
| 13 | + "github.com/prysmaticlabs/prysm/shared/testutil/assert" |
| 14 | + "github.com/prysmaticlabs/prysm/shared/testutil/require" |
| 15 | + logTest "github.com/sirupsen/logrus/hooks/test" |
| 16 | + "github.com/urfave/cli/v2" |
| 17 | +) |
| 18 | + |
| 19 | +func TestConfigureHistoricalSlasher(t *testing.T) { |
| 20 | + params.SetupTestConfigCleanup(t) |
| 21 | + hook := logTest.NewGlobal() |
| 22 | + |
| 23 | + app := cli.App{} |
| 24 | + set := flag.NewFlagSet("test", 0) |
| 25 | + set.Bool(flags.HistoricalSlasherNode.Name, true, "") |
| 26 | + cliCtx := cli.NewContext(&app, set, nil) |
| 27 | + |
| 28 | + configureHistoricalSlasher(cliCtx) |
| 29 | + |
| 30 | + assert.Equal(t, params.BeaconConfig().SlotsPerEpoch*4, params.BeaconConfig().SlotsPerArchivedPoint) |
| 31 | + assert.LogsContain(t, hook, |
| 32 | + fmt.Sprintf( |
| 33 | + "Setting %d slots per archive point and %d max RPC page size for historical slasher usage", |
| 34 | + params.BeaconConfig().SlotsPerArchivedPoint, |
| 35 | + int(params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().MaxAttestations))), |
| 36 | + ) |
| 37 | +} |
| 38 | + |
| 39 | +func TestConfigureSlotsPerArchivedPoint(t *testing.T) { |
| 40 | + params.SetupTestConfigCleanup(t) |
| 41 | + |
| 42 | + app := cli.App{} |
| 43 | + set := flag.NewFlagSet("test", 0) |
| 44 | + set.Int(flags.SlotsPerArchivedPoint.Name, 0, "") |
| 45 | + require.NoError(t, set.Set(flags.SlotsPerArchivedPoint.Name, strconv.Itoa(100))) |
| 46 | + cliCtx := cli.NewContext(&app, set, nil) |
| 47 | + |
| 48 | + configureSlotsPerArchivedPoint(cliCtx) |
| 49 | + |
| 50 | + assert.Equal(t, types.Slot(100), params.BeaconConfig().SlotsPerArchivedPoint) |
| 51 | +} |
| 52 | + |
| 53 | +func TestConfigureProofOfWork(t *testing.T) { |
| 54 | + params.SetupTestConfigCleanup(t) |
| 55 | + |
| 56 | + app := cli.App{} |
| 57 | + set := flag.NewFlagSet("test", 0) |
| 58 | + set.Uint64(flags.ChainID.Name, 0, "") |
| 59 | + set.Uint64(flags.NetworkID.Name, 0, "") |
| 60 | + set.String(flags.DepositContractFlag.Name, "", "") |
| 61 | + require.NoError(t, set.Set(flags.ChainID.Name, strconv.Itoa(100))) |
| 62 | + require.NoError(t, set.Set(flags.NetworkID.Name, strconv.Itoa(200))) |
| 63 | + require.NoError(t, set.Set(flags.DepositContractFlag.Name, "deposit")) |
| 64 | + cliCtx := cli.NewContext(&app, set, nil) |
| 65 | + |
| 66 | + configureProofOfWork(cliCtx) |
| 67 | + |
| 68 | + assert.Equal(t, uint64(100), params.BeaconConfig().DepositChainID) |
| 69 | + assert.Equal(t, uint64(200), params.BeaconConfig().DepositNetworkID) |
| 70 | + assert.Equal(t, "deposit", params.BeaconConfig().DepositContractAddress) |
| 71 | +} |
| 72 | + |
| 73 | +func TestConfigureNetwork(t *testing.T) { |
| 74 | + params.SetupTestConfigCleanup(t) |
| 75 | + |
| 76 | + app := cli.App{} |
| 77 | + set := flag.NewFlagSet("test", 0) |
| 78 | + bootstrapNodes := cli.StringSlice{} |
| 79 | + set.Var(&bootstrapNodes, cmd.BootstrapNode.Name, "") |
| 80 | + set.Int(flags.ContractDeploymentBlock.Name, 0, "") |
| 81 | + require.NoError(t, set.Set(cmd.BootstrapNode.Name, "node1")) |
| 82 | + require.NoError(t, set.Set(cmd.BootstrapNode.Name, "node2")) |
| 83 | + require.NoError(t, set.Set(flags.ContractDeploymentBlock.Name, strconv.Itoa(100))) |
| 84 | + cliCtx := cli.NewContext(&app, set, nil) |
| 85 | + |
| 86 | + configureNetwork(cliCtx) |
| 87 | + |
| 88 | + assert.DeepEqual(t, []string{"node1", "node2"}, params.BeaconNetworkConfig().BootstrapNodes) |
| 89 | + assert.Equal(t, uint64(100), params.BeaconNetworkConfig().ContractDeploymentBlock) |
| 90 | +} |
0 commit comments