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

test(node-api): Introduce E2E tests for existing beacon endpoints #1983

Open
wants to merge 106 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
c0ac57d
add test for fork and others
nidhi-singh02 Aug 29, 2024
fa09476
clean
calbera Aug 29, 2024
23c153f
fix
calbera Aug 29, 2024
b313f6f
nit
calbera Aug 29, 2024
4204be8
uint64 -> math.Epoch
calbera Aug 29, 2024
adca130
undo
calbera Aug 29, 2024
2f56ea6
clean
calbera Aug 29, 2024
4069654
Add route
calbera Aug 29, 2024
a148aa6
route
calbera Aug 29, 2024
d3e2b2f
func for each endpoint
nidhi-singh02 Aug 30, 2024
65e4595
override fix
calbera Sep 3, 2024
0b3cfef
create func in consensus clients
nidhi-singh02 Sep 3, 2024
e7c4bea
adding validatorBalances in interface
nidhi-singh02 Sep 4, 2024
0648791
build is working now
nidhi-singh02 Sep 4, 2024
5a6d460
pass body to val balance
nidhi-singh02 Sep 4, 2024
d773ac3
validator balancer api working directly
nidhi-singh02 Sep 6, 2024
fb35087
randao response
nidhi-singh02 Sep 6, 2024
ca5cec3
enhance in rando - workingg
nidhi-singh02 Sep 6, 2024
f617612
validator status bug resolved
nidhi-singh02 Sep 6, 2024
45f66a3
nilaway go awayyy
nidhi-singh02 Sep 6, 2024
9b7be70
linter are you happy
nidhi-singh02 Sep 6, 2024
31f1e84
why are you suprising me linter
nidhi-singh02 Sep 6, 2024
9bab8a4
validator bal - correct tags
nidhi-singh02 Sep 6, 2024
af9a6e8
create customFork struct
nidhi-singh02 Sep 7, 2024
38b3e49
lint lint linter
nidhi-singh02 Sep 7, 2024
b599c2e
validator data format
nidhi-singh02 Sep 7, 2024
b4f095e
few optimization in val
nidhi-singh02 Sep 7, 2024
13bf5fa
tidy sync
nidhi-singh02 Sep 7, 2024
1d52853
directly use ValidatorData
nidhi-singh02 Sep 7, 2024
e7193ff
linting
nidhi-singh02 Sep 7, 2024
c0ba37c
bet
nidhi-singh02 Sep 7, 2024
674a627
refactor code
nidhi-singh02 Sep 7, 2024
aa44929
enchancements in fork
nidhi-singh02 Sep 8, 2024
09438ee
request type changes - cleanup
nidhi-singh02 Sep 8, 2024
76b432e
refactor validators bal
nidhi-singh02 Sep 8, 2024
294981f
more test assertions added
nidhi-singh02 Sep 8, 2024
05de47b
linter
nidhi-singh02 Sep 8, 2024
1ce1ee9
nits comments
nidhi-singh02 Sep 9, 2024
4b333b9
create interface type for fork
nidhi-singh02 Sep 10, 2024
942ad39
asserting to interface for ForkT
nidhi-singh02 Sep 10, 2024
6c32e57
Fork interface correct impl
nidhi-singh02 Sep 10, 2024
d87a851
generate check
nidhi-singh02 Sep 10, 2024
4ed066a
linter
nidhi-singh02 Sep 10, 2024
318739a
use fork wrapper
nidhi-singh02 Sep 10, 2024
77cfd3e
remove fork generic
calbera Sep 10, 2024
6f0a5d6
Remove custom MarshalJSON function in favor of json string tags
calbera Sep 10, 2024
a556242
make new func part of Fork interface
nidhi-singh02 Sep 10, 2024
f3020be
using fork interface
nidhi-singh02 Sep 10, 2024
8179a31
Revert "Remove custom MarshalJSON function in favor of json string tags"
nidhi-singh02 Sep 10, 2024
35c7e92
Merge branch 'main' into e2e-node-api
nidhi-singh02 Sep 12, 2024
84a170a
tidy sync
nidhi-singh02 Sep 7, 2024
4f31cb8
bet
nidhi-singh02 Sep 7, 2024
c2d62c6
validator using MarshalJSON
nidhi-singh02 Sep 12, 2024
c65706b
refactor - getters
nidhi-singh02 Sep 12, 2024
6205ab4
cleanup
nidhi-singh02 Sep 12, 2024
b9f9e95
Merge branch 'main' into e2e-node-api
nidhi-singh02 Sep 13, 2024
e739cde
few enhancements
nidhi-singh02 Sep 13, 2024
3187ef2
lint
nidhi-singh02 Sep 13, 2024
af1cd47
use types.Wrap and few enhancements
nidhi-singh02 Sep 13, 2024
a9e4cf3
linter fix
nidhi-singh02 Sep 13, 2024
34329f3
validator balance marshal as no tag
nidhi-singh02 Sep 13, 2024
0d965da
Merge branch 'main' into e2e-node-api
nidhi-singh02 Sep 14, 2024
b745f33
use ValidataData for response
nidhi-singh02 Sep 14, 2024
0e19a55
ValidatorT redundant - cleanup
nidhi-singh02 Sep 14, 2024
43d42c0
directly use validator
nidhi-singh02 Sep 14, 2024
759e772
validator generics
calbera Sep 16, 2024
101e3e1
gen
calbera Sep 16, 2024
3baca83
Merge branch 'main' of github.com:berachain/beacon-kit into e2e-node-api
calbera Sep 16, 2024
16b4232
undo
calbera Sep 16, 2024
23c994d
define type outside generic method
nidhi-singh02 Sep 17, 2024
79e09f7
generate check
nidhi-singh02 Sep 17, 2024
9a81b69
Update mod/node-api/handlers/debug/routes.go
calbera Sep 17, 2024
030b3bf
pointer
calbera Sep 17, 2024
01ee136
Merge branch 'main' of github.com:berachain/beacon-kit into e2e-node-api
calbera Sep 17, 2024
9107176
same pattern
calbera Sep 17, 2024
f374565
remove unneeded changes
calbera Sep 17, 2024
51e5376
pick constants from same package and use ptr
nidhi-singh02 Sep 20, 2024
5669ecf
do not use wrap - unnecessary changes remove
nidhi-singh02 Sep 23, 2024
f232fa8
make withdrawCredentails revert
nidhi-singh02 Sep 23, 2024
6850e67
generate check
nidhi-singh02 Sep 23, 2024
5413aa1
add comment for validator interface
nidhi-singh02 Sep 23, 2024
078ab60
rename fork
nidhi-singh02 Sep 23, 2024
db5e599
reverted constants changes in echo
nidhi-singh02 Sep 24, 2024
3aa512b
use validator with generic type
nidhi-singh02 Sep 24, 2024
81c9088
Merge branch 'main' into e2e-node-api
nidhi-singh02 Sep 24, 2024
2c8e6c3
generate check
nidhi-singh02 Sep 24, 2024
1b2792b
validator with generic type
nidhi-singh02 Sep 24, 2024
e3cec53
WithdrawalCredentialsT generic introduce - wip
nidhi-singh02 Sep 24, 2024
e10df63
withdrawal credentials building
calbera Sep 24, 2024
f6e5cdd
nits
nidhi-singh02 Sep 24, 2024
494d9d6
linter and generate
nidhi-singh02 Sep 24, 2024
d525150
comments
nidhi-singh02 Sep 24, 2024
a1d3834
Merge branch 'main' into e2e-node-api
nidhi-singh02 Sep 25, 2024
89ca105
Merge branch 'main' into e2e-node-api
nidhi-singh02 Sep 26, 2024
f4be7e8
Merge branch 'main' into e2e-node-api
nidhi-singh02 Sep 27, 2024
c1c5e46
Merge branch 'main' into e2e-node-api
nidhi-singh02 Sep 30, 2024
0dc0c1c
generate check
nidhi-singh02 Sep 30, 2024
c028c65
Merge branch 'main' into e2e-node-api
nidhi-singh02 Oct 1, 2024
99af839
Merge branch 'main' into e2e-node-api
nidhi-singh02 Oct 3, 2024
068f3c6
Merge branch 'main' into e2e-node-api
nidhi-singh02 Oct 4, 2024
30de37e
generate check
nidhi-singh02 Oct 4, 2024
d4caf1d
Merge branch 'main' into e2e-node-api
nidhi-singh02 Oct 8, 2024
dccfde1
Merge branch 'main' into e2e-node-api
nidhi-singh02 Oct 17, 2024
61a4afa
Merge branch 'main' into e2e-node-api
nidhi-singh02 Oct 24, 2024
5130094
Merge branch 'main' into e2e-node-api
nidhi-singh02 Nov 4, 2024
25af9f3
Merge branch 'main' into e2e-node-api
nidhi-singh02 Nov 6, 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
20 changes: 15 additions & 5 deletions examples/berad/pkg/consensus-types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ type Validator struct {
// Pubkey is the validator's 48-byte BLS public key.
Pubkey crypto.BLSPubkey `json:"pubkey"`
// WithdrawalCredentials are an address that controls the validator.
WithdrawalCredentials types.WithdrawalCredentials `json:"withdrawalCredentials"`
WithdrawalCredentials types.WithdrawalCredentials `json:"withdrawal_credentials"`
nidhi-singh02 marked this conversation as resolved.
Show resolved Hide resolved
// EffectiveBalance is the validator's current effective balance in gwei.
EffectiveBalance math.Gwei `json:"effectiveBalance"`
EffectiveBalance math.Gwei `json:"effective_balance"`
// ActivationEpoch is the epoch in which the validator activated.
ActivationEpoch math.Epoch `json:"activationEpoch"`
ActivationEpoch math.Epoch `json:"activation_epoch"`
nidhi-singh02 marked this conversation as resolved.
Show resolved Hide resolved
// ExitEpoch is the epoch in which the validator exited.
ExitEpoch math.Epoch `json:"exitEpoch"`
ExitEpoch math.Epoch `json:"exit_epoch"`
// WithdrawableEpoch is the epoch in which the validator can withdraw.
WithdrawableEpoch math.Epoch `json:"withdrawableEpoch"`
WithdrawableEpoch math.Epoch `json:"withdrawable_epoch"`
}

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -233,3 +233,13 @@ func (v Validator) GetWithdrawableEpoch() math.Epoch {
func (v Validator) GetWithdrawalCredentials() types.WithdrawalCredentials {
return v.WithdrawalCredentials
}

// GetActivationEpoch returns the activation epoch of the validator.
func (v *Validator) GetActivationEpoch() math.Epoch {
return v.ActivationEpoch
}

// GetExitEpoch returns the exit epoch of the validator.
func (v *Validator) GetExitEpoch() math.Epoch {
return v.ExitEpoch
}
2 changes: 1 addition & 1 deletion mod/consensus-types/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23.0

require (
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240705193247-d464364483df
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570
github.com/ferranbt/fastssz v0.1.4-0.20240629094022-eac385e6ee79
github.com/holiman/uint256 v1.3.1
Expand Down
4 changes: 2 additions & 2 deletions mod/consensus-types/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483d
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df/go.mod h1:bTFB4Rdvm7D/WdwPYkqQ+8T0XOMBv0pzXfp1E46BFX8=
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197 h1:wVWkiiERY/7kaXvE/VNPPUtYp/l8ky6QSuKM3ThVMXU=
github.com/berachain/beacon-kit/mod/engine-primitives v0.0.0-20240808194557-e72e74f58197/go.mod h1:LiOiqrJhhLH/GPo0XE5fel3EYyi7X6dwBOyTqZakTeQ=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240705193247-d464364483df h1:6MJllcmMFt6dtvftM5zmdl1WVDpqZkNy3hFXVZtNV0s=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240705193247-d464364483df/go.mod h1:yRD7rmnyaaqgq/6+eIVqvSkFJXuLXpBddUu59HUOrtc=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0 h1:kCSrkb/uVXfMKJPKjf0c7nlJkwn5cNwMxtzRW4zNq2A=
github.com/berachain/beacon-kit/mod/errors v0.0.0-20240806211103-d1105603bfc0/go.mod h1:og0jtHZosPDTyhge9tMBlRItoZ4Iv3aZFM9n4QDpcdo=
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e h1:0/FDBXtagMkpta/f4J2uAah2NM1G+0dqxngzMzrmbw4=
github.com/berachain/beacon-kit/mod/geth-primitives v0.0.0-20240806160829-cde2d1347e7e/go.mod h1:7/SXz8S5VpFl2thcKuBdu1OId+SgI1o4N+S1FB92Zw8=
github.com/berachain/beacon-kit/mod/primitives v0.0.0-20240911165923-82f71ec86570 h1:w0Gkg31VQRFDv0EJjYgVtlpza7kSaJq7U28zxZjfZeE=
Expand Down
21 changes: 20 additions & 1 deletion mod/consensus-types/pkg/types/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (f *Fork) HashTreeRootWith(hh fastssz.HashWalker) error {
hh.PutBytes(f.CurrentVersion[:])

// Field (2) 'Epoch'
hh.PutUint64(uint64(f.Epoch))
hh.PutUint64(f.Epoch.Unwrap())

hh.Merkleize(indx)
return nil
Expand All @@ -139,3 +139,22 @@ func (f *Fork) HashTreeRootWith(hh fastssz.HashWalker) error {
func (f *Fork) GetTree() (*fastssz.Node, error) {
return fastssz.ProofTree(f)
}
nidhi-singh02 marked this conversation as resolved.
Show resolved Hide resolved

/* -------------------------------------------------------------------------- */
/* Getters */
/* -------------------------------------------------------------------------- */

// GetPreviousVersion returns the previous version of the fork.
func (f *Fork) GetPreviousVersion() common.Version {
return f.PreviousVersion
}

// GetCurrentVersion returns the current version of the fork.
func (f *Fork) GetCurrentVersion() common.Version {
return f.CurrentVersion
}

// GetEpoch returns the epoch at which the fork occurred.
func (f *Fork) GetEpoch() math.Epoch {
return f.Epoch
}
12 changes: 8 additions & 4 deletions mod/consensus-types/pkg/types/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ func generateValidBeaconState() *types.BeaconState[
},
Validators: []*types.Validator{
{
Pubkey: [48]byte{0x01},
WithdrawalCredentials: [32]byte{0x02},
Pubkey: [48]byte{0x01},
WithdrawalCredentials: types.NewCredentialsFromExecutionAddress(
common.ExecutionAddress{0x02},
),
EffectiveBalance: 32000000000,
Slashed: false,
ActivationEligibilityEpoch: 1,
Expand All @@ -88,8 +90,10 @@ func generateValidBeaconState() *types.BeaconState[
WithdrawableEpoch: 18446744073709551615,
},
{
Pubkey: [48]byte{0x03},
WithdrawalCredentials: [32]byte{0x04},
Pubkey: [48]byte{0x03},
WithdrawalCredentials: types.NewCredentialsFromExecutionAddress(
common.ExecutionAddress{0x04},
),
EffectiveBalance: 31000000000,
Slashed: true,
ActivationEligibilityEpoch: 3,
Expand Down
50 changes: 33 additions & 17 deletions mod/consensus-types/pkg/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ type Validator struct {
// Pubkey is the validator's 48-byte BLS public key.
Pubkey crypto.BLSPubkey `json:"pubkey"`
// WithdrawalCredentials are an address that controls the validator.
WithdrawalCredentials WithdrawalCredentials `json:"withdrawalCredentials"`
WithdrawalCredentials WithdrawalCredentials `json:"withdrawal_credentials"`
// EffectiveBalance is the validator's current effective balance in gwei.
EffectiveBalance math.Gwei `json:"effectiveBalance"`
EffectiveBalance math.Gwei `json:"effective_balance"`
// Slashed indicates whether the validator has been slashed.
Slashed bool `json:"slashed"`
// ActivationEligibilityEpoch is the epoch in which the validator became
// eligible for activation.
ActivationEligibilityEpoch math.Epoch `json:"activationEligibilityEpoch"`
ActivationEligibilityEpoch math.Epoch `json:"activation_eligibility_epoch"`
// ActivationEpoch is the epoch in which the validator activated.
ActivationEpoch math.Epoch `json:"activationEpoch"`
ActivationEpoch math.Epoch `json:"activation_epoch"`
// ExitEpoch is the epoch in which the validator exited.
ExitEpoch math.Epoch `json:"exitEpoch"`
ExitEpoch math.Epoch `json:"exit_epoch"`
// WithdrawableEpoch is the epoch in which the validator can withdraw.
WithdrawableEpoch math.Epoch `json:"withdrawableEpoch"`
WithdrawableEpoch math.Epoch `json:"withdrawable_epoch"`
}

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -226,15 +226,15 @@ func (v *Validator) GetEffectiveBalance() math.Gwei {
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#is_active_validator
//
//nolint:lll
func (v Validator) IsActive(epoch math.Epoch) bool {
func (v *Validator) IsActive(epoch math.Epoch) bool {
return v.ActivationEpoch <= epoch && epoch < v.ExitEpoch
}

// IsEligibleForActivation as defined in the Ethereum 2.0 Spec
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue
//
//nolint:lll
func (v Validator) IsEligibleForActivation(
func (v *Validator) IsEligibleForActivation(
finalizedEpoch math.Epoch,
) bool {
return v.ActivationEligibilityEpoch <= finalizedEpoch &&
Expand All @@ -245,7 +245,7 @@ func (v Validator) IsEligibleForActivation(
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue
//
//nolint:lll
func (v Validator) IsEligibleForActivationQueue(
func (v *Validator) IsEligibleForActivationQueue(
maxEffectiveBalance math.Gwei,
) bool {
return v.ActivationEligibilityEpoch == math.Epoch(
Expand All @@ -258,21 +258,21 @@ func (v Validator) IsEligibleForActivationQueue(
// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#is_slashable_validator
//
//nolint:lll
func (v Validator) IsSlashable(epoch math.Epoch) bool {
func (v *Validator) IsSlashable(epoch math.Epoch) bool {
return !v.Slashed && v.ActivationEpoch <= epoch &&
epoch < v.WithdrawableEpoch
}

// IsSlashed returns whether the validator has been slashed.
func (v Validator) IsSlashed() bool {
func (v *Validator) IsSlashed() bool {
return v.Slashed
}

// IsFullyWithdrawable as defined in the Ethereum 2.0 specification:
// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#is_fully_withdrawable_validator
//
//nolint:lll
func (v Validator) IsFullyWithdrawable(
func (v *Validator) IsFullyWithdrawable(
balance math.Gwei,
epoch math.Epoch,
) bool {
Expand All @@ -284,7 +284,7 @@ func (v Validator) IsFullyWithdrawable(
// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#is_partially_withdrawable_validator
//
//nolint:lll
func (v Validator) IsPartiallyWithdrawable(
func (v *Validator) IsPartiallyWithdrawable(
balance, maxEffectiveBalance math.Gwei,
) bool {
hasExcessBalance := balance > maxEffectiveBalance
Expand All @@ -296,13 +296,13 @@ func (v Validator) IsPartiallyWithdrawable(
// https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#has_eth1_withdrawal_credential
//
//nolint:lll
func (v Validator) HasEth1WithdrawalCredentials() bool {
func (v *Validator) HasEth1WithdrawalCredentials() bool {
return v.WithdrawalCredentials[0] == EthSecp256k1CredentialPrefix
}

// HasMaxEffectiveBalance determines if the validator has the maximum effective
// balance.
func (v Validator) HasMaxEffectiveBalance(
func (v *Validator) HasMaxEffectiveBalance(
maxEffectiveBalance math.Gwei,
) bool {
return v.EffectiveBalance == maxEffectiveBalance
Expand All @@ -314,11 +314,27 @@ func (v *Validator) SetEffectiveBalance(balance math.Gwei) {
}

// GetWithdrawableEpoch returns the epoch when the validator can withdraw.
func (v Validator) GetWithdrawableEpoch() math.Epoch {
func (v *Validator) GetWithdrawableEpoch() math.Epoch {
return v.WithdrawableEpoch
}

// GetWithdrawalCredentials returns the withdrawal credentials of the validator.
func (v Validator) GetWithdrawalCredentials() WithdrawalCredentials {
func (v *Validator) GetWithdrawalCredentials() WithdrawalCredentials {
return v.WithdrawalCredentials
}

// GetActivationEligibilityEpoch returns the activation eligibility
// epoch of the validator.
func (v *Validator) GetActivationEligibilityEpoch() math.Epoch {
return v.ActivationEligibilityEpoch
}

// GetActivationEpoch returns the activation epoch of the validator.
func (v *Validator) GetActivationEpoch() math.Epoch {
return v.ActivationEpoch
}

// GetExitEpoch returns the exit epoch of the validator.
func (v *Validator) GetExitEpoch() math.Epoch {
return v.ExitEpoch
}
nidhi-singh02 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions mod/consensus-types/pkg/types/withdrawal_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ func (wc WithdrawalCredentials) MarshalText() ([]byte, error) {
func (wc *WithdrawalCredentials) UnmarshalText(text []byte) error {
return (*common.Bytes32)(wc).UnmarshalText(text)
}

// Bytes returns the raw byte representation of the withdrawal credentials.
func (wc WithdrawalCredentials) Bytes() []byte {
return wc[:]
}
nidhi-singh02 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading