Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): Introduce node-api E2E testing #1820

Merged
merged 59 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
a3970bd
init
calbera Jul 30, 2024
4a8d0b0
Merge branch 'main' of github.com:berachain/beacon-kit into api-e2e
calbera Jul 30, 2024
43092c7
wip
calbera Jul 30, 2024
9d9072f
Merge branch 'main' of github.com:berachain/beacon-kit into api-e2e
calbera Aug 1, 2024
d3ad59a
comments nit
calbera Aug 1, 2024
e941afa
comments
calbera Aug 1, 2024
0cb2eaa
Merge branch 'main' of github.com:berachain/beacon-kit into api-e2e
calbera Aug 1, 2024
a68b498
wipg
calbera Aug 1, 2024
7b4e19e
Merge branch 'main' of github.com:berachain/beacon-kit into api-e2e
calbera Aug 1, 2024
16564d8
gen
calbera Aug 1, 2024
38c76de
bet
calbera Aug 1, 2024
2a5571b
nilaway
calbera Aug 1, 2024
af96a1d
use e2e build flag
calbera Aug 1, 2024
3cdb28f
cli flags
calbera Aug 1, 2024
b610b28
nil logger
calbera Aug 1, 2024
511e696
tidy && sync
calbera Aug 1, 2024
abbaed2
disable prom on beacon client
calbera Aug 1, 2024
07a3dc0
Remove pruning
calbera Aug 1, 2024
d407ef2
timeout ctx
calbera Aug 1, 2024
da3b96d
tidy sync
calbera Aug 1, 2024
6fba5f5
timeout bump
calbera Aug 1, 2024
41b29da
placeholders
calbera Aug 2, 2024
b23037d
beacon client
calbera Aug 2, 2024
db820e1
Merge branch 'main' of github.com:berachain/beacon-kit into api-e2e
calbera Aug 8, 2024
ee983b3
tidy && sync
calbera Aug 8, 2024
1135563
lint
calbera Aug 8, 2024
495c11c
Merge branch 'main' of github.com:berachain/beacon-kit into api-e2e
calbera Aug 9, 2024
31eeab7
Merge branch 'main' into api-e2e
nidhi-singh02 Aug 11, 2024
a739db1
run api e2e tests
calbera Aug 11, 2024
961acb9
try abs path
calbera Aug 11, 2024
ad2e25d
lint
calbera Aug 11, 2024
2797ec5
move api tests into e2e packaghe
calbera Aug 11, 2024
e7e2b14
go-eth2-client
calbera Aug 11, 2024
dae352a
lint
calbera Aug 11, 2024
1a0f07a
bet
calbera Aug 12, 2024
bc02d82
client
calbera Aug 12, 2024
81ed3a5
tidy sync
calbera Aug 12, 2024
5609fa4
Merge branch 'main' into api-e2e
calbera Aug 12, 2024
3f90efe
remove placeholders
calbera Aug 12, 2024
1e4ff59
nit
calbera Aug 12, 2024
ea9206d
revive placeholders
calbera Aug 12, 2024
980d052
nit
calbera Aug 12, 2024
efb3efc
format
calbera Aug 12, 2024
118e000
remove unimplemented func
calbera Aug 12, 2024
de78375
Merge branch 'main' of github.com:berachain/beacon-kit into api-e2e
calbera Aug 12, 2024
2f85d0d
Merge branch 'main' into api-e2e
calbera Aug 12, 2024
bf85dd1
Merge branch 'main' into api-e2e
calbera Aug 12, 2024
fc73a5f
client
calbera Aug 12, 2024
89b9299
Remove bindings
calbera Aug 12, 2024
4d7ad22
tidy-sync
calbera Aug 12, 2024
cf36833
try test
calbera Aug 12, 2024
002012e
fix
calbera Aug 12, 2024
38c9273
Merge branch 'main' into api-e2e
calbera Aug 13, 2024
eb90992
Merge branch 'main' into api-e2e
calbera Aug 14, 2024
e569d6c
rename
calbera Aug 14, 2024
4bd3be6
bet
calbera Aug 14, 2024
347d0ef
undo
calbera Aug 14, 2024
f30cf3e
Merge branch 'main' of github.com:berachain/beacon-kit into api-e2e
calbera Aug 20, 2024
586a102
Merge branch 'main' into api-e2e
calbera Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions build/scripts/testing.mk
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ test-unit-fuzz: ## run fuzz tests
go test ./mod/payload/pkg/cache/... -fuzz=FuzzPayloadIDCacheConcurrency -fuzztime=${SHORT_FUZZ_TIME}
go test -fuzz=FuzzHashTreeRoot ./mod/primitives/pkg/merkle -fuzztime=${MEDIUM_FUZZ_TIME}





test-e2e: ## run e2e tests
@$(MAKE) build-docker VERSION=kurtosis-local test-e2e-no-build

Expand Down
3 changes: 3 additions & 0 deletions kurtosis/src/nodes/consensus/beacond/launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ COMETBFT_REST_PORT_NUM = 1317
COMETBFT_PPROF_PORT_NUM = 6060
METRICS_PORT_NUM = 26660
ENGINE_RPC_PORT_NUM = 8551
NODE_API_PORT_NUM = 3500

# Port IDs
COMETBFT_RPC_PORT_ID = "cometbft-rpc"
Expand All @@ -19,6 +20,7 @@ COMETBFT_PPROF_PORT_ID = "cometbft-pprof"
ENGINE_RPC_PORT_ID = "engine-rpc"
METRICS_PORT_ID = "metrics"
METRICS_PATH = "/metrics"
NODE_API_PORT_ID = "node-api"

USED_PORTS = {
COMETBFT_RPC_PORT_ID: shared_utils.new_port_spec(COMETBFT_RPC_PORT_NUM, shared_utils.TCP_PROTOCOL),
Expand All @@ -27,6 +29,7 @@ USED_PORTS = {
COMETBFT_PPROF_PORT_ID: shared_utils.new_port_spec(COMETBFT_PPROF_PORT_NUM, shared_utils.TCP_PROTOCOL),
# ENGINE_RPC_PORT_ID: shared_utils.new_port_spec(ENGINE_RPC_PORT_NUM, shared_utils.TCP_PROTOCOL),
METRICS_PORT_ID: shared_utils.new_port_spec(METRICS_PORT_NUM, shared_utils.TCP_PROTOCOL, wait = None),
NODE_API_PORT_ID: shared_utils.new_port_spec(NODE_API_PORT_NUM, shared_utils.TCP_PROTOCOL),
}

def get_config(node_struct, engine_dial_url, entrypoint = [], cmd = [], persistent_peers = "", expose_ports = True, jwt_file = None, kzg_trusted_setup_file = None):
Expand Down
3 changes: 3 additions & 0 deletions kurtosis/src/nodes/consensus/beacond/node.star
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def start(persistent_peers, is_seed, validator_index, config_settings, app_setti
--beacon-kit.kzg.implementation={} \
--beacon-kit.engine.rpc-dial-url {} \
--rpc.laddr tcp://0.0.0.0:26657 --api.address tcp://0.0.0.0:1317 \
--beacon-kit.block-store-service.enabled \
--beacon-kit.node-api.enabled --beacon-kit.node-api.logging \
--pruning=nothing \
--api.enable {} {}".format(kzg_impl, "$BEACOND_ENGINE_DIAL_URL", seed_option, persistent_peers_option)

return "{} && {} && {}".format(mv_genesis, set_config, start_node)
Expand Down
2 changes: 1 addition & 1 deletion mod/node-api/backend/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (b Backend[
Index: index.Unwrap(),
Balance: balance.Unwrap(),
},
Status: "active", // TODO: fix
Status: "active_ongoing", // TODO: fix
Validator: validator,
}, nil
}
Expand Down
4 changes: 4 additions & 0 deletions mod/node-api/engines/echo/vaildator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import (
"github.com/labstack/echo/v4"
)

// TODO: these validators need to be un-janked to 1) not use `FieldLevel` for
// repeated `.Field().String()` calls and 2) strongly type the allowed IDs,
// putting validation logic on each type.
calbera marked this conversation as resolved.
Show resolved Hide resolved

// CustomValidator is a custom validator for the API.
type CustomValidator struct {
Validator *validator.Validate
Expand Down
2 changes: 1 addition & 1 deletion mod/node-api/handlers/node/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Handler[ContextT context.Context] struct {

func NewHandler[ContextT context.Context]() *Handler[ContextT] {
h := &Handler[ContextT]{
BaseHandler: handlers.NewBaseHandler[ContextT](
BaseHandler: handlers.NewBaseHandler(
handlers.NewRouteSet[ContextT](""),
),
}
Expand Down
61 changes: 61 additions & 0 deletions mod/node-api/handlers/node/placeholders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package node

// Syncing is a placeholder so that beacon API clients don't break.
//
// TODO: Implement with real data.
calbera marked this conversation as resolved.
Show resolved Hide resolved
func (h *Handler[ContextT]) Syncing(ContextT) (any, error) {
type SyncingResponse struct {
Data struct {
HeadSlot string `json:"head_slot"`
SyncDistance string `json:"sync_distance"`
IsSyncing bool `json:"is_syncing"`
IsOptimistic bool `json:"is_optimistic"`
ELOffline bool `json:"el_offline"`
} `json:"data"`
}

response := SyncingResponse{}
response.Data.HeadSlot = "0"
response.Data.SyncDistance = "1"
response.Data.IsSyncing = false
response.Data.IsOptimistic = true
response.Data.ELOffline = false

return response, nil
}

// Version is a placeholder so that beacon API clients don't break.
//
// TODO: Implement with real data.
calbera marked this conversation as resolved.
Show resolved Hide resolved
func (h *Handler[ContextT]) Version(ContextT) (any, error) {
type VersionResponse struct {
Data struct {
Version string `json:"version"`
} `json:"data"`
}

response := VersionResponse{}
response.Data.Version = "1.0.0"

return response, nil
}
4 changes: 2 additions & 2 deletions mod/node-api/handlers/node/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func (h *Handler[ContextT]) RegisterRoutes(
{
Method: http.MethodGet,
Path: "/eth/v1/node/version",
Handler: h.NotImplemented,
Handler: h.Version,
},
{
Method: http.MethodGet,
Path: "/eth/v1/node/syncing",
Handler: h.NotImplemented,
Handler: h.Syncing,
},
{
Method: http.MethodGet,
Expand Down
4 changes: 4 additions & 0 deletions mod/node-api/handlers/utils/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

// TODO: define unique types for each of the query-able IDs (state & block from
// spec, execution unique to beacon-kit). For each type define validation
// functions and resolvers to slot number.

// SlotFromStateID returns a slot from the state ID.
//
// NOTE: Right now, `stateID` only supports querying by "head" (all of "head",
Expand Down
33 changes: 33 additions & 0 deletions testing/e2e/config/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package config

// Consensus clients.
const (
DefaultClient = "cl-validator-beaconkit-0"
AlternateClient = "cl-validator-beaconkit-1"
)

// Deposits.
const (
DepositContractAddress = "0x4242424242424242424242424242424242424242"
NumDepositsLoad = 500
)
53 changes: 53 additions & 0 deletions testing/e2e/e2e_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package e2e_test

import (
"fmt"

beaconapi "github.com/attestantio/go-eth2-client/api"
"github.com/berachain/beacon-kit/mod/node-api/handlers/utils"
"github.com/berachain/beacon-kit/testing/e2e/config"
)

// TestBeaconAPISuite tests that the api test suite is setup correctly with a
// working beacon node-api client.
func (s *BeaconKitE2ESuite) TestBeaconAPIStartup() {
// Wait for execution block 5.
err := s.WaitForFinalizedBlockNumber(5)
s.Require().NoError(err)

// Get the consensus client.
client := s.ConsensusClients()[config.DefaultClient]
s.Require().NotNil(client)

// Ensure the state root is not nil.
stateRootResp, err := client.BeaconStateRoot(
s.Ctx(),
&beaconapi.BeaconStateRootOpts{
State: utils.StateIDHead,
},
)
s.Require().NoError(err)
s.Require().NotEmpty(stateRootResp)
fmt.Println("stateRootResp data", *stateRootResp.Data)
s.Require().False(stateRootResp.Data.IsZero())
}
calbera marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 11 additions & 16 deletions testing/e2e/e2e_staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,19 @@ import (
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
"github.com/berachain/beacon-kit/mod/geth-primitives/pkg/deposit"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/testing/e2e/config"
"github.com/berachain/beacon-kit/testing/e2e/suite"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
gethcommon "github.com/ethereum/go-ethereum/common"
coretypes "github.com/ethereum/go-ethereum/core/types"
)

const (
// DepositContractAddress is the address of the deposit contract.
DepositContractAddress = "0x4242424242424242424242424242424242424242"
DefaultClient = "cl-validator-beaconkit-0"
AlternateClient = "cl-validator-beaconkit-1"
NumDepositsLoad = 500
)

func (s *BeaconKitE2ESuite) TestDepositRobustness() {
// Get the consensus client.
client := s.ConsensusClients()[DefaultClient]
client := s.ConsensusClients()[config.DefaultClient]
s.Require().NotNil(client)

client2 := s.ConsensusClients()[AlternateClient]
client2 := s.ConsensusClients()[config.AlternateClient]
s.Require().NotNil(client2)

// Sender account
Expand Down Expand Up @@ -80,7 +73,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() {

// Bind the deposit contract.
dc, err := deposit.NewBeaconDepositContract(
gethcommon.HexToAddress(DepositContractAddress),
gethcommon.HexToAddress(config.DepositContractAddress),
s.JSONRPCBalancer(),
)
s.Require().NoError(err)
Expand All @@ -99,7 +92,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() {
tx, err = dc.AllowDeposit(&bind.TransactOpts{
From: genesisAccount.Address(),
Signer: genesisAccount.SignerFunc(chainID),
}, sender.Address(), NumDepositsLoad)
}, sender.Address(), config.NumDepositsLoad)
s.Require().NoError(err)

// Wait for the transaction to be mined.
Expand All @@ -115,7 +108,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() {
)
s.Require().NoError(err)

for i := range NumDepositsLoad {
for i := range config.NumDepositsLoad {
// Create a deposit transaction.
tx, err = s.generateNewDepositTx(
dc,
Expand All @@ -126,7 +119,7 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() {
s.Require().NoError(err)
s.Logger().
Info("Deposit transaction created", "txHash", tx.Hash().Hex())
if i == NumDepositsLoad-1 {
if i == config.NumDepositsLoad-1 {
s.Logger().Info(
"Waiting for deposit transaction to be mined", "txHash",
tx.Hash().Hex(),
Expand Down Expand Up @@ -158,7 +151,9 @@ func (s *BeaconKitE2ESuite) TestDepositRobustness() {
// upper bound: 32ether * 500 + 1ether
// lower bound: 32ether * 500
oneEther := big.NewInt(1e18)
totalAmt := new(big.Int).Mul(oneEther, big.NewInt(NumDepositsLoad*32))
totalAmt := new(big.Int).Mul(
oneEther, big.NewInt(config.NumDepositsLoad*32),
)
upperBound := new(big.Int).Add(totalAmt, oneEther)
amtSpent := new(big.Int).Sub(balance, postDepositBalance)

Expand Down Expand Up @@ -197,7 +192,7 @@ func (s *BeaconKitE2ESuite) generateNewDepositTx(
nonce *big.Int,
) (*coretypes.Transaction, error) {
// Get the consensus client.
client := s.ConsensusClients()[DefaultClient]
client := s.ConsensusClients()[config.DefaultClient]
s.Require().NotNil(client)

pubkey, err := client.GetPubKey(s.Ctx())
Expand Down
1 change: 1 addition & 0 deletions testing/e2e/suite/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (s *KurtosisE2ESuite) SetupSuiteWithOptions(opts ...Option) {
"num_full_nodes",
len(s.cfg.NetworkConfiguration.FullNodes.Nodes),
)

result, err := s.enclave.RunStarlarkPackageBlocking(
s.ctx,
"../../kurtosis",
Expand Down
Loading
Loading