prysm-pulse/beacon-chain/node/node_test.go

300 lines
11 KiB
Go
Raw Normal View History

package node
import (
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
"context"
"flag"
"fmt"
"net/http"
"net/http/httptest"
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
"os"
"path/filepath"
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
"strconv"
"testing"
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
"time"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/builder"
statefeed "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/db/filesystem"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/execution"
mockExecution "github.com/prysmaticlabs/prysm/v5/beacon-chain/execution/testing"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/monitor"
"github.com/prysmaticlabs/prysm/v5/cmd"
"github.com/prysmaticlabs/prysm/v5/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/v5/config/features"
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
"github.com/prysmaticlabs/prysm/v5/config/params"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/runtime"
"github.com/prysmaticlabs/prysm/v5/runtime/interop"
"github.com/prysmaticlabs/prysm/v5/testing/assert"
"github.com/prysmaticlabs/prysm/v5/testing/require"
logTest "github.com/sirupsen/logrus/hooks/test"
Refactor dependencies, make Prysm "go gettable" (#6053) * Fix a few deps to work with go.mod, check in generated files * Update Gossipsub to 1.1 (#5998) * update libs * add new validators * add new deps * new set of deps * tls * further fix gossip update * get everything to build * clean up * gaz * fix build * fix all tests * add deps to images * imports Co-authored-by: rauljordan <raul@prysmaticlabs.com> * Beacon chain builds with go build * fix bazel * fix dep * lint * Add github action for testing go * on PR for any branch * fix libp2p test failure * Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test * Revert "Fix TestProcessBlock_PassesProcessingConditions by updating the proposer index in test" This reverts commit 43676894ab01f03fe90a9b8ee3ecfbc2ec1ec4e4. * Compute and set proposer index instead of hard code * Add back go mod/sum, fix deps * go build ./... * Temporarily skip two tests * Fix kafka confluent patch * Fix kafka confluent patch * fix kafka build * fix kafka * Add info in DEPENDENCIES. Added a stub link for Why Bazel? until https://github.com/prysmaticlabs/documentation/issues/138 * Update fuzz ssz files as well * Update fuzz ssz files as well * getting closer * rollback rules_go and gazelle * fix gogo protobuf * install librdkafka-dev as part of github actions * Update kafka to a recent version where librkafkfa is not required for go modules * clarify comment * fix kafka build * disable go tests * comment * Fix geth dependencies for end to end * rename word * lint * fix docker Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: rauljordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2020-05-31 06:44:34 +00:00
"github.com/urfave/cli/v2"
)
// Ensure BeaconNode implements interfaces.
var _ statefeed.Notifier = (*BeaconNode)(nil)
func newCliContextWithCancel(app *cli.App, set *flag.FlagSet) (*cli.Context, context.CancelFunc) {
context, cancel := context.WithCancel(context.Background())
parent := &cli.Context{Context: context}
return cli.NewContext(app, set, parent), cancel
}
// Test that beacon chain node can close.
func TestNodeClose_OK(t *testing.T) {
hook := logTest.NewGlobal()
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.Bool("test-skip-pow", true, "skip pow dial")
set.String("datadir", tmp, "node data directory")
set.String("p2p-encoding", "ssz", "p2p encoding scheme")
set.Bool("demo-config", true, "demo configuration")
set.String("deposit-contract", "0x0000000000000000000000000000000000000000", "deposit contract address")
Improvement to Fee Recipient UX (#11307) * updating mock * adding new internal api * adding generated code * converting validator index to pubkey * adding new API endpoint * fixing mock related new API * fixing unit tests * preventing failure on startup, replacing with warnings * improving log message * changing warn log to error log * fixing error formatting * improve log on beacon node side on startup * fixing deepsource issue * improving logs * fixing unit tests * fixing more tests * adding error check * adding in new case for fee recipient to avoid conflicts on changing beacon node suggested fee recipient * adding default fee recipient check for gas limit as well * adding improved unit tests * accidently checked in tmp folder * adding more unit tests * fixing gas limit unit test * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/config.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/config.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update proto/prysm/v1alpha1/validator.proto Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/client/runner.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * addressing comments * updating proto generated files * fixing linting and addressign review comments * fixing unit test * improve error handling * accidently added tmp folder * improving function error returns * realizing i am wrapping error incorrectly * fixing unit test * addressing review comment * fixing linting * fixing unit test * improving ux around enable builder Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2022-09-22 16:35:35 +00:00
set.String("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A", "fee recipient")
require.NoError(t, set.Set("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A"))
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
cmd.ValidatorMonitorIndicesFlag.Value = &cli.IntSlice{}
cmd.ValidatorMonitorIndicesFlag.Value.SetInt(1)
ctx, cancel := newCliContextWithCancel(&app, set)
Blob filesystem add pruning at startup (#13253) * Add Save blob and tests * Remove locks * Remove test cleanup * Fix go mod * Cleanup * Add checksum * Add file hashing to fileutil * Move test * Check data when exists * Add one more test * Rename * Gaz * Add packaged level comment * Fix block proposals in the REST validator client (#13116) * Fix block proposals in the REST validator client * fix graffiti test * return empty graffiti * fallback to old endpoints * logs * handle 404 * everything passes * review from James * log undecoded value * test fixes and additions --------- Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> * fix head slot in log (#13139) * zig: Update zig to recent main branch commit (#13142) Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> * Fix Pending Queue Deadline Bug (#13145) * rearrange deadline * naming * Add pruning * Gaz * Gaz * Update pruning * Cleanup * Making a mess * Benchmarking * Forgot to add the file + fixes * Fixes * Pruning from DB fixed * Add prune by file data * Fix pruning * Prune fixes * Cleanup db blockRoot filter * Handle file close error * Fix deletion * Change read at + remove retentionEpich from bs * Gaz * Seperate logic + add detailed comments * Add tests * Add retention slot when creating blobStorage * Fix tests * Gaz * Fix testonly import * Add pruning at startup * Add nil check * Fix merge errors * Fix test * Fix test --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com> Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com> Co-authored-by: Nishant Das <nishdas93@gmail.com>
2023-12-11 17:08:52 +00:00
node, err := New(ctx, cancel, WithBlobStorage(filesystem.NewEphemeralBlobStorage(t)))
Apply testutils assertions: final cleanup (#7003) * slasher/beaconclient tests * slasher/db/kv tests * Merge branch 'master' into apply-testutils-assertions-to-slasher * fix build * slasher/detection tests * rest of the tests * misc tests * tools tests * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'master' into apply-testutils-assertions-misc * agg tests * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'master' into apply-testutils-assertions-misc * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * updates aggregated_test * beacon-chain/operations/attestations/kv/* tests updated * beacon-chain/operations/attestations tests updated * beacon-chain/operations/slashings tests updated * Merge branch 'master' into apply-testutils-assertions-misc * gazelle * beacon-chain/core tests updated * fixes test * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * beacon-chain/rpc tests updated * beacon-chain/sync/initial-sync tests * misc tests * optimizes error message parsing in testutils * Merge branch 'assertutils-optimize-processing' into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * endtoend tests * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * gazelle * Merge refs/heads/master into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * beacon-chain/blockchain tests updated * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * beacon-chain/state/stategen tests updated * beacon-chain all left-over tests are done * Merge refs/heads/master into apply-testutils-assertions-misc * validator tests updated * slasher tests * Merge branch 'master' into apply-testutils-assertions-misc * gofmt * gazelle * Merge refs/heads/master into apply-testutils-assertions-misc * shared upd * end2end tests deps fixed * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc * Merge refs/heads/master into apply-testutils-assertions-misc * misc * all tests are updated * Merge branch 'apply-testutils-assertions-misc' of github.com:prysmaticlabs/prysm into apply-testutils-assertions-misc
2020-08-25 15:23:06 +00:00
require.NoError(t, err)
node.Close()
require.LogsContain(t, hook, "Stopping beacon node")
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
}
func TestNodeStart_Ok(t *testing.T) {
hook := logTest.NewGlobal()
app := cli.App{}
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
set := flag.NewFlagSet("test", 0)
set.String("datadir", tmp, "node data directory")
Improvement to Fee Recipient UX (#11307) * updating mock * adding new internal api * adding generated code * converting validator index to pubkey * adding new API endpoint * fixing mock related new API * fixing unit tests * preventing failure on startup, replacing with warnings * improving log message * changing warn log to error log * fixing error formatting * improve log on beacon node side on startup * fixing deepsource issue * improving logs * fixing unit tests * fixing more tests * adding error check * adding in new case for fee recipient to avoid conflicts on changing beacon node suggested fee recipient * adding default fee recipient check for gas limit as well * adding improved unit tests * accidently checked in tmp folder * adding more unit tests * fixing gas limit unit test * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/config.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/config.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update proto/prysm/v1alpha1/validator.proto Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/client/runner.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * addressing comments * updating proto generated files * fixing linting and addressign review comments * fixing unit test * improve error handling * accidently added tmp folder * improving function error returns * realizing i am wrapping error incorrectly * fixing unit test * addressing review comment * fixing linting * fixing unit test * improving ux around enable builder Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2022-09-22 16:35:35 +00:00
set.String("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A", "fee recipient")
require.NoError(t, set.Set("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A"))
ctx, cancel := newCliContextWithCancel(&app, set)
node, err := New(ctx, cancel, WithBlockchainFlagOptions([]blockchain.Option{}),
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
WithBuilderFlagOptions([]builder.Option{}),
WithExecutionChainOptions([]execution.Option{}),
WithBlobStorage(filesystem.NewEphemeralBlobStorage(t)))
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
require.NoError(t, err)
node.services = &runtime.ServiceRegistry{}
go func() {
node.Start()
}()
time.Sleep(3 * time.Second)
node.Close()
require.LogsContain(t, hook, "Starting beacon node")
}
func TestNodeStart_SyncChecker(t *testing.T) {
hook := logTest.NewGlobal()
app := cli.App{}
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
set := flag.NewFlagSet("test", 0)
set.String("datadir", tmp, "node data directory")
set.String("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A", "fee recipient")
require.NoError(t, set.Set("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A"))
ctx, cancel := newCliContextWithCancel(&app, set)
node, err := New(ctx, cancel, WithBlockchainFlagOptions([]blockchain.Option{}),
WithBuilderFlagOptions([]builder.Option{}),
WithExecutionChainOptions([]execution.Option{}),
WithBlobStorage(filesystem.NewEphemeralBlobStorage(t)))
require.NoError(t, err)
go func() {
node.Start()
}()
time.Sleep(3 * time.Second)
assert.NotNil(t, node.syncChecker.Svc)
node.Close()
require.LogsContain(t, hook, "Starting beacon node")
}
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
func TestNodeStart_Ok_registerDeterministicGenesisService(t *testing.T) {
numValidators := uint64(1)
hook := logTest.NewGlobal()
app := cli.App{}
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
set := flag.NewFlagSet("test", 0)
set.String("datadir", tmp, "node data directory")
set.Uint64(flags.InteropNumValidatorsFlag.Name, numValidators, "")
Improvement to Fee Recipient UX (#11307) * updating mock * adding new internal api * adding generated code * converting validator index to pubkey * adding new API endpoint * fixing mock related new API * fixing unit tests * preventing failure on startup, replacing with warnings * improving log message * changing warn log to error log * fixing error formatting * improve log on beacon node side on startup * fixing deepsource issue * improving logs * fixing unit tests * fixing more tests * adding error check * adding in new case for fee recipient to avoid conflicts on changing beacon node suggested fee recipient * adding default fee recipient check for gas limit as well * adding improved unit tests * accidently checked in tmp folder * adding more unit tests * fixing gas limit unit test * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/config.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/config.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update proto/prysm/v1alpha1/validator.proto Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/client/runner.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * addressing comments * updating proto generated files * fixing linting and addressign review comments * fixing unit test * improve error handling * accidently added tmp folder * improving function error returns * realizing i am wrapping error incorrectly * fixing unit test * addressing review comment * fixing linting * fixing unit test * improving ux around enable builder Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2022-09-22 16:35:35 +00:00
set.String("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A", "fee recipient")
require.NoError(t, set.Set("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A"))
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
genesisState, _, err := interop.GenerateGenesisState(context.Background(), 0, numValidators)
require.NoError(t, err, "Could not generate genesis beacon state")
for i := uint64(1); i < 2; i++ {
var someRoot [32]byte
var someKey [fieldparams.BLSPubkeyLength]byte
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
copy(someRoot[:], strconv.Itoa(int(i)))
copy(someKey[:], strconv.Itoa(int(i)))
genesisState.Validators = append(genesisState.Validators, &ethpb.Validator{
PublicKey: someKey[:],
WithdrawalCredentials: someRoot[:],
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
Slashed: false,
ActivationEligibilityEpoch: 1,
ActivationEpoch: 1,
ExitEpoch: 1,
WithdrawableEpoch: 1,
})
genesisState.Balances = append(genesisState.Balances, params.BeaconConfig().MaxEffectiveBalance)
}
genesisBytes, err := genesisState.MarshalSSZ()
require.NoError(t, err)
require.NoError(t, os.WriteFile("genesis_ssz.json", genesisBytes, 0666))
set.String("genesis-state", "genesis_ssz.json", "")
ctx, cancel := newCliContextWithCancel(&app, set)
node, err := New(ctx, cancel, WithBlockchainFlagOptions([]blockchain.Option{}),
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
WithBuilderFlagOptions([]builder.Option{}),
Blob filesystem add pruning at startup (#13253) * Add Save blob and tests * Remove locks * Remove test cleanup * Fix go mod * Cleanup * Add checksum * Add file hashing to fileutil * Move test * Check data when exists * Add one more test * Rename * Gaz * Add packaged level comment * Fix block proposals in the REST validator client (#13116) * Fix block proposals in the REST validator client * fix graffiti test * return empty graffiti * fallback to old endpoints * logs * handle 404 * everything passes * review from James * log undecoded value * test fixes and additions --------- Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> * fix head slot in log (#13139) * zig: Update zig to recent main branch commit (#13142) Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> * Fix Pending Queue Deadline Bug (#13145) * rearrange deadline * naming * Add pruning * Gaz * Gaz * Update pruning * Cleanup * Making a mess * Benchmarking * Forgot to add the file + fixes * Fixes * Pruning from DB fixed * Add prune by file data * Fix pruning * Prune fixes * Cleanup db blockRoot filter * Handle file close error * Fix deletion * Change read at + remove retentionEpich from bs * Gaz * Seperate logic + add detailed comments * Add tests * Add retention slot when creating blobStorage * Fix tests * Gaz * Fix testonly import * Add pruning at startup * Add nil check * Fix merge errors * Fix test * Fix test --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com> Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com> Co-authored-by: Nishant Das <nishdas93@gmail.com>
2023-12-11 17:08:52 +00:00
WithExecutionChainOptions([]execution.Option{}),
WithBlobStorage(filesystem.NewEphemeralBlobStorage(t)))
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
require.NoError(t, err)
node.services = &runtime.ServiceRegistry{}
go func() {
node.Start()
}()
time.Sleep(3 * time.Second)
node.Close()
require.LogsContain(t, hook, "Starting beacon node")
require.NoError(t, os.Remove("genesis_ssz.json"))
}
Add flag to allow reading bootstrap nodes from a file (#6351) * parent c837dfb2f26d82abf4dfbd184189d57c5b0ddedf author dv8silencer <dv8silencer+github@gmail.com> 1592805180 -0500 committer dv8silencer <dv8silencer+github@gmail.com> 1592855989 -0500 Create a bootstrap-node-file flag which reads nodes from a YAML file and make the flag mutually exclusive to the bootstrap-node flag * Merge branch 'master' into dv8s-iss6316 * Refactor so that boot node reading is in its own function. Added test * Added period Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Merge branch 'master' into dv8s-iss6316 * Edit Bazel to include go-yaml dep * Help Bazel build successfully * Merge branch 'master' into dv8s-iss6316 * bazel run //:gazella -- fix * Handle error from YAML parser to address build checks * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Updated flags.go to refine the Usage for the BootStrapNodeFile flag Co-authored-by: Nishant Das <nish1993@hotmail.com> * Merge branch 'master' into dv8s-iss6316 * Utilize stdlib TempFile to avoid polluting * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * merge master into this branch * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Merge branch 'master' into dv8s-iss6316 * Changed bootstrap-node to StringSlice flag to allow multiple nodes to be passed. Each value can be .enr file which will be YAML parsed to extract nodes * Refactored to create separate readbootNodes function and added a test for it. * More cleaning up * Changed wording in the cli help for --bootstrap-node * Merge branch 'master' into dv8s-iss6316 * Since we are taking YAML files, got rid of .enr check and instead we check for the string prefix of a enr record or not to determine if file. * Merge with dv8silencer/tempissue6316 * Correct spacing Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Changed how we check for YAML file vs CLI-direct ENR * Minor: Changed to 1 string from concatenating 2 * Merge branch 'master' into dv8s-iss6316
2020-06-26 11:23:38 +00:00
// TestClearDB tests clearing the database
func TestClearDB(t *testing.T) {
hook := logTest.NewGlobal()
srv, endpoint, err := mockExecution.SetupRPCServer()
require.NoError(t, err)
t.Cleanup(func() {
srv.Stop()
})
tmp := filepath.Join(t.TempDir(), "datadirtest")
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String("datadir", tmp, "node data directory")
set.Bool(cmd.ForceClearDB.Name, true, "force clear db")
Improvement to Fee Recipient UX (#11307) * updating mock * adding new internal api * adding generated code * converting validator index to pubkey * adding new API endpoint * fixing mock related new API * fixing unit tests * preventing failure on startup, replacing with warnings * improving log message * changing warn log to error log * fixing error formatting * improve log on beacon node side on startup * fixing deepsource issue * improving logs * fixing unit tests * fixing more tests * adding error check * adding in new case for fee recipient to avoid conflicts on changing beacon node suggested fee recipient * adding default fee recipient check for gas limit as well * adding improved unit tests * accidently checked in tmp folder * adding more unit tests * fixing gas limit unit test * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/config.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/node/config.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update proto/prysm/v1alpha1/validator.proto Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/rpc/standard_api.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update validator/client/runner.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * addressing comments * updating proto generated files * fixing linting and addressign review comments * fixing unit test * improve error handling * accidently added tmp folder * improving function error returns * realizing i am wrapping error incorrectly * fixing unit test * addressing review comment * fixing linting * fixing unit test * improving ux around enable builder Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2022-09-22 16:35:35 +00:00
set.String("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A", "fee recipient")
require.NoError(t, set.Set("suggested-fee-recipient", "0x6e35733c5af9B61374A128e6F85f553aF09ff89A"))
context, cancel := newCliContextWithCancel(&app, set)
options := []Option{
WithExecutionChainOptions([]execution.Option{execution.WithHttpEndpoint(endpoint)}),
WithBlobStorage(filesystem.NewEphemeralBlobStorage(t)),
}
_, err = New(context, cancel, options...)
require.NoError(t, err)
require.LogsContain(t, hook, "Removing database")
}
func TestMonitor_RegisteredCorrectly(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)
require.NoError(t, cmd.ValidatorMonitorIndicesFlag.Apply(set))
cliCtx := cli.NewContext(&app, set, nil)
require.NoError(t, cliCtx.Set(cmd.ValidatorMonitorIndicesFlag.Name, "1,2"))
n := &BeaconNode{ctx: context.Background(), cliCtx: cliCtx, services: runtime.NewServiceRegistry()}
require.NoError(t, n.services.RegisterService(&blockchain.Service{}))
Replace statefeed Initialize (#12285) * refactor initialization to blocking startup method * require genesisSetter in blockchain, fix tests * work-around gazelle weirdness * fix dep gazelle ignores * only call SetGenesis once * fix typo * validator test setup and fix to return right error * move waitForChainStart to Start * wire up sync Service.genesisWaiter * fix p2p genesisWaiter plumbing * remove extra clock type, integrate into genesis and rename * use time.Now when no Nower is specified * remove unused ClockSetter * simplify rpc context checking * fix typo * use clock everywhere in sync; [32]byte val root * don't use DeepEqual to compare [32]byte and []byte * don't use clock in init sync, not wired up yet * use clock waiter in blockchain as well * use cancelable contexts in tests with goroutines * missed a reference to WithClockSetter * Update beacon-chain/startup/genesis.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * Update beacon-chain/blockchain/service_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * more clear docs * doc for NewClock * move clock typedef to more logical file name * adding documentation * gaz * fixes for capella * reducing test raciness * fix races in committee cache tests * lint * add tests on Duration slot math helper * startup package test coverage * fix bad merge * set non-zero genesis time in tests that call Start * happy deepsource, happy me-epsource * replace Synced event with channel * remove unused error * remove accidental wip commit * gaz! * remove unused event constants * remove sync statefeed subscription to fix deadlock * remove state notifier * fix build --------- Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
2023-05-03 04:34:01 +00:00
require.NoError(t, n.registerValidatorMonitorService(make(chan struct{})))
var mService *monitor.Service
require.NoError(t, n.services.FetchService(&mService))
require.Equal(t, true, mService.TrackedValidators[1])
require.Equal(t, true, mService.TrackedValidators[2])
require.Equal(t, false, mService.TrackedValidators[100])
}
func Test_hasNetworkFlag(t *testing.T) {
tests := []struct {
name string
networkName string
networkValue string
want bool
}{
{
name: "Prater testnet",
networkName: features.PraterTestnet.Name,
networkValue: "prater",
want: true,
},
{
name: "Mainnet",
networkName: features.Mainnet.Name,
networkValue: "mainnet",
want: true,
},
{
name: "No network flag",
networkName: "",
networkValue: "",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.String(tt.networkName, tt.networkValue, tt.name)
cliCtx := cli.NewContext(&cli.App{}, set, nil)
err := cliCtx.Set(tt.networkName, tt.networkValue)
require.NoError(t, err)
if got := hasNetworkFlag(cliCtx); got != tt.want {
t.Errorf("hasNetworkFlag() = %v, want %v", got, tt.want)
}
})
}
}
func TestCORS(t *testing.T) {
// Mock CLI context with a test CORS domain
app := cli.App{}
set := flag.NewFlagSet("test", 0)
set.String(flags.GPRCGatewayCorsDomain.Name, "http://allowed-example.com", "")
cliCtx := cli.NewContext(&app, set, nil)
require.NoError(t, cliCtx.Set(flags.GPRCGatewayCorsDomain.Name, "http://allowed-example.com"))
router := newRouter(cliCtx)
// Ensure a test route exists
router.HandleFunc("/some-path", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}).Methods(http.MethodGet)
// Define test cases
tests := []struct {
name string
origin string
expectAllow bool
}{
{"AllowedOrigin", "http://allowed-example.com", true},
{"DisallowedOrigin", "http://disallowed-example.com", false},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
// Create a request and response recorder
req := httptest.NewRequest("GET", "http://example.com/some-path", nil)
req.Header.Set("Origin", tc.origin)
rr := httptest.NewRecorder()
// Serve HTTP
router.ServeHTTP(rr, req)
// Check the CORS headers based on the expected outcome
if tc.expectAllow && rr.Header().Get("Access-Control-Allow-Origin") != tc.origin {
t.Errorf("Expected Access-Control-Allow-Origin header to be %v, got %v", tc.origin, rr.Header().Get("Access-Control-Allow-Origin"))
}
if !tc.expectAllow && rr.Header().Get("Access-Control-Allow-Origin") != "" {
t.Errorf("Expected Access-Control-Allow-Origin header to be empty for disallowed origin, got %v", rr.Header().Get("Access-Control-Allow-Origin"))
}
})
}
}