mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 17:22:18 +00:00
12403d249f
* HTTP proxy server for Eth2 APIs (#8904) * Implement API HTTP proxy server * cleanup + more comments * gateway will no longer be dependent on beaconv1 * handle error during ErrorJson type assertion * simplify handling of endpoint data * fix mux v1 route * use URL encoding for all requests * comment fieldProcessor * fix failing test * change proxy port to not interfere with e2e * gzl * simplify conditional expression * Move appending custom error header to grpcutils package * add api-middleware-port flag * fix documentation for processField * modify e2e port * change field processing error message * better error message for field processing * simplify base64ToHexProcessor * fix json structs * Run several new endpoints through API middleware (#8922) * Implement API HTTP proxy server * cleanup + more comments * gateway will no longer be dependent on beaconv1 * handle error during ErrorJson type assertion * simplify handling of endpoint data * fix mux v1 route * use URL encoding for all requests * comment fieldProcessor * fix failing test * change proxy port to not interfere with e2e * gzl * simplify conditional expression * Move appending custom error header to grpcutils package * add api-middleware-port flag * fix documentation for processField * modify e2e port * change field processing error message * better error message for field processing * simplify base64ToHexProcessor * fix json structs * /eth/v1/beacon/states/{state_id}/validators * /eth/v1/beacon/states/{state_id}/validators/{validator_id} * /eth/v1/beacon/states/{state_id}/validator_balances * /eth/v1/beacon/states/{state_id}/committees * allow skipping base64-encoding for query params * /eth/v1/beacon/pool/attestations * replace break with continue * Remove unused functions (#8924) Co-authored-by: terence tsao <terence@prysmaticlabs.com> * Process SSZ-serialized beacon state through API middleware (#8925) * update field names * Process SSZ-serialized beacon state through API middleware * revert changes to go.mod and go.sum * Revert "Merge branch '__develop' into feature/api-middleware" This reverts commit 7c739a8fd71e2c1e3a14be85abd29a59b57ae9b5, reversing changes made to 2d0f8e012ecb006888ed8e826b45625a3edc2eeb. * update ethereumapis * update validator field name * update deps.bzl * update json tags (#8942) * Run `/node/syncing` through API Middleware (#8944) * add IsSyncing field to grpc response * run /node/syncing through the middleware Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Return HTTP status codes other than 200 and 500 from node and debug endpoints (#8937) * error codes for node endpoints * error codes for debug endpoints * better comment about headers * gzl * review comments * comment on return value * update fakeChecker used for fuzz tests * fix failing tests * Allow to pass URL params literally, without encoding to base64 (#8938) * Allow to pass URL params literally, without encoding to base64 * fix compile error Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Process SSZ-serialized beacon state through API middleware (#8925) * update field names * Process SSZ-serialized beacon state through API middleware * revert changes to go.mod and go.sum * Revert "Merge branch '__develop' into feature/api-middleware" This reverts commit 7c739a8fd71e2c1e3a14be85abd29a59b57ae9b5, reversing changes made to 2d0f8e012ecb006888ed8e826b45625a3edc2eeb. * update ethereumapis * update validator field name * update deps.bzl * update json tags (#8942) * Run `/node/syncing` through API Middleware (#8944) * add IsSyncing field to grpc response * run /node/syncing through the middleware Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Return HTTP status codes other than 200 and 500 from node and debug endpoints (#8937) * error codes for node endpoints * error codes for debug endpoints * better comment about headers * gzl * review comments * comment on return value * update fakeChecker used for fuzz tests * fix failing tests * Allow to pass URL params literally, without encoding to base64 (#8938) * Allow to pass URL params literally, without encoding to base64 * fix compile error Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * unused import * Return correct status codes from beacon endpoints (#8960) * Various API Middleware fixes (#8963) * Return correct status codes from `/states` endpoints * better error messages in debug and node * better error messages in state * returning correct error codes from validator endpoints * correct error codes for getting a block header * gzl * fix err variable name * fix nil block comparison * test fixes * make status enum test better * fix ineffectual assignment * make PR unstuck * return proper status codes * return uppercase keys from /config/spec * return lowercase validator status * convert requested enum values to uppercase * validator fixes * Implement `/beacon/headers` endpoint (#8966) * Refactor API Middleware into more manageable code (#8984) * move endpoint registration out of shared package * divide main function into smaller components * return early on error * implement hooks * implement custom handlers and add documentation * fix test compile error * restrict package visibility * remove redundant error checking * rename file * API Middleware unit tests (#8998) * move endpoint registration out of shared package * divide main function into smaller components * return early on error * implement hooks * implement custom handlers and add documentation * fix test compile error * restrict package visibility * remove redundant error checking * rename file * api_middleware_processing * endpoints * gzl * remove gazelle:ignore * merge * Implement SSZ version of `/blocks/{block_id}` (#8970) * Implement SSZ version of `/blocks/{block_id}` * add dependencies back * fix indentation in deps.bzl * parameterize ssz functions * get block ssz * update ethereumapis dependency * gzl * Do not reuse `Endpoint` structs between API calls (#9007) * code refactor * implement endpoint factory * fix test * fmt * include pbs * gaz * test naming fixes * remove unused code * radek comments * revert endpoint test * bring back bytes test case * move `signedBeaconBlock` to `migration` package * change `fmt.Errorf` to `errors.Wrap` * capitalize SSZ * capitalize URL * more review feedback * rename `handleGetBlockSSZ` to `handleGetBeaconBlockSSZ` * rename `IndexOutOfRangeError` to `ValidatorIndexOutOfRangeError` * simplify parameter names * test header * more corrections * properly allocate array capacity Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Nishant Das <nishdas93@gmail.com>
286 lines
9.0 KiB
Go
286 lines
9.0 KiB
Go
package beaconv1
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
func TestGetSpec(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
config := params.BeaconConfig()
|
|
|
|
config.ConfigName = "ConfigName"
|
|
config.MaxCommitteesPerSlot = 1
|
|
config.TargetCommitteeSize = 2
|
|
config.MaxValidatorsPerCommittee = 3
|
|
config.MinPerEpochChurnLimit = 4
|
|
config.ChurnLimitQuotient = 5
|
|
config.ShuffleRoundCount = 6
|
|
config.MinGenesisActiveValidatorCount = 7
|
|
config.MinGenesisTime = 8
|
|
config.HysteresisQuotient = 9
|
|
config.HysteresisDownwardMultiplier = 10
|
|
config.HysteresisUpwardMultiplier = 11
|
|
config.SafeSlotsToUpdateJustified = 12
|
|
config.Eth1FollowDistance = 13
|
|
config.TargetAggregatorsPerCommittee = 14
|
|
config.RandomSubnetsPerValidator = 15
|
|
config.EpochsPerRandomSubnetSubscription = 16
|
|
config.SecondsPerETH1Block = 17
|
|
config.DepositChainID = 18
|
|
config.DepositNetworkID = 19
|
|
config.DepositContractAddress = "DepositContractAddress"
|
|
config.MinDepositAmount = 20
|
|
config.MaxEffectiveBalance = 21
|
|
config.EjectionBalance = 22
|
|
config.EffectiveBalanceIncrement = 23
|
|
config.GenesisForkVersion = []byte("GenesisForkVersion")
|
|
config.BLSWithdrawalPrefixByte = byte('b')
|
|
config.GenesisDelay = 24
|
|
config.SecondsPerSlot = 25
|
|
config.MinAttestationInclusionDelay = 26
|
|
config.SlotsPerEpoch = 27
|
|
config.MinSeedLookahead = 28
|
|
config.MaxSeedLookahead = 29
|
|
config.EpochsPerEth1VotingPeriod = 30
|
|
config.SlotsPerHistoricalRoot = 31
|
|
config.MinValidatorWithdrawabilityDelay = 32
|
|
config.ShardCommitteePeriod = 33
|
|
config.MinEpochsToInactivityPenalty = 34
|
|
config.EpochsPerHistoricalVector = 35
|
|
config.EpochsPerSlashingsVector = 36
|
|
config.HistoricalRootsLimit = 37
|
|
config.ValidatorRegistryLimit = 38
|
|
config.BaseRewardFactor = 39
|
|
config.WhistleBlowerRewardQuotient = 40
|
|
config.ProposerRewardQuotient = 41
|
|
config.InactivityPenaltyQuotient = 42
|
|
config.MinSlashingPenaltyQuotient = 43
|
|
config.ProportionalSlashingMultiplier = 44
|
|
config.MaxProposerSlashings = 45
|
|
config.MaxAttesterSlashings = 46
|
|
config.MaxAttestations = 47
|
|
config.MaxDeposits = 48
|
|
config.MaxVoluntaryExits = 49
|
|
|
|
var dbp [4]byte
|
|
copy(dbp[:], []byte{'0', '0', '0', '1'})
|
|
config.DomainBeaconProposer = dbp
|
|
var dba [4]byte
|
|
copy(dba[:], []byte{'0', '0', '0', '2'})
|
|
config.DomainBeaconAttester = dba
|
|
var dr [4]byte
|
|
copy(dr[:], []byte{'0', '0', '0', '3'})
|
|
config.DomainRandao = dr
|
|
var dd [4]byte
|
|
copy(dd[:], []byte{'0', '0', '0', '4'})
|
|
config.DomainDeposit = dd
|
|
var dve [4]byte
|
|
copy(dve[:], []byte{'0', '0', '0', '5'})
|
|
config.DomainVoluntaryExit = dve
|
|
var dsp [4]byte
|
|
copy(dsp[:], []byte{'0', '0', '0', '6'})
|
|
config.DomainSelectionProof = dsp
|
|
var daap [4]byte
|
|
copy(daap[:], []byte{'0', '0', '0', '7'})
|
|
config.DomainAggregateAndProof = daap
|
|
|
|
params.OverrideBeaconConfig(config)
|
|
|
|
server := &Server{}
|
|
resp, err := server.GetSpec(context.Background(), &emptypb.Empty{})
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, 60, len(resp.Data))
|
|
for k, v := range resp.Data {
|
|
switch k {
|
|
case "CONFIG_NAME":
|
|
assert.Equal(t, "ConfigName", v)
|
|
case "MAX_COMMITTEES_PER_SLOT":
|
|
assert.Equal(t, "1", v)
|
|
case "TARGET_COMMITTEE_SIZE":
|
|
assert.Equal(t, "2", v)
|
|
case "MAX_VALIDATORS_PER_COMMITTEE":
|
|
assert.Equal(t, "3", v)
|
|
case "MIN_PER_EPOCH_CHURN_LIMIT":
|
|
assert.Equal(t, "4", v)
|
|
case "CHURN_LIMIT_QUOTIENT":
|
|
assert.Equal(t, "5", v)
|
|
case "SHUFFLE_ROUND_COUNT":
|
|
assert.Equal(t, "6", v)
|
|
case "MIN_GENESIS_ACTIVE_VALIDATOR_COUNT":
|
|
assert.Equal(t, "7", v)
|
|
case "MIN_GENESIS_TIME":
|
|
assert.Equal(t, "8", v)
|
|
case "HYSTERESIS_QUOTIENT":
|
|
assert.Equal(t, "9", v)
|
|
case "HYSTERESIS_DOWNWARD_MULTIPLIER":
|
|
assert.Equal(t, "10", v)
|
|
case "HYSTERESIS_UPWARD_MULTIPLIER":
|
|
assert.Equal(t, "11", v)
|
|
case "SAFE_SLOTS_TO_UPDATE_JUSTIFIED":
|
|
assert.Equal(t, "12", v)
|
|
case "ETH1_FOLLOW_DISTANCE":
|
|
assert.Equal(t, "13", v)
|
|
case "TARGET_AGGREGATORS_PER_COMMITTEE":
|
|
assert.Equal(t, "14", v)
|
|
case "RANDOM_SUBNETS_PER_VALIDATOR":
|
|
assert.Equal(t, "15", v)
|
|
case "EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION":
|
|
assert.Equal(t, "16", v)
|
|
case "SECONDS_PER_ETH1_BLOCK":
|
|
assert.Equal(t, "17", v)
|
|
case "DEPOSIT_CHAIN_ID":
|
|
assert.Equal(t, "18", v)
|
|
case "DEPOSIT_NETWORK_ID":
|
|
assert.Equal(t, "19", v)
|
|
case "DEPOSIT_CONTRACT_ADDRESS":
|
|
assert.Equal(t, "DepositContractAddress", v)
|
|
case "MIN_DEPOSIT_AMOUNT":
|
|
assert.Equal(t, "20", v)
|
|
case "MAX_EFFECTIVE_BALANCE":
|
|
assert.Equal(t, "21", v)
|
|
case "EJECTION_BALANCE":
|
|
assert.Equal(t, "22", v)
|
|
case "EFFECTIVE_BALANCE_INCREMENT":
|
|
assert.Equal(t, "23", v)
|
|
case "GENESIS_FORK_VERSION":
|
|
assert.Equal(t, "0x47656e65736973466f726b56657273696f6e", v)
|
|
case "BLS_WITHDRAWAL_PREFIX":
|
|
assert.Equal(t, "0x62", v)
|
|
case "GENESIS_DELAY":
|
|
assert.Equal(t, "24", v)
|
|
case "SECONDS_PER_SLOT":
|
|
assert.Equal(t, "25", v)
|
|
case "MIN_ATTESTATION_INCLUSION_DELAY":
|
|
assert.Equal(t, "26", v)
|
|
case "SLOTS_PER_EPOCH":
|
|
assert.Equal(t, "27", v)
|
|
case "MIN_SEED_LOOKAHEAD":
|
|
assert.Equal(t, "28", v)
|
|
case "MAX_SEED_LOOKAHEAD":
|
|
assert.Equal(t, "29", v)
|
|
case "EPOCHS_PER_ETH1_VOTING_PERIOD":
|
|
assert.Equal(t, "30", v)
|
|
case "SLOTS_PER_HISTORICAL_ROOT":
|
|
assert.Equal(t, "31", v)
|
|
case "MIN_VALIDATOR_WITHDRAWABILITY_DELAY":
|
|
assert.Equal(t, "32", v)
|
|
case "SHARD_COMMITTEE_PERIOD":
|
|
assert.Equal(t, "33", v)
|
|
case "MIN_EPOCHS_TO_INACTIVITY_PENALTY":
|
|
assert.Equal(t, "34", v)
|
|
case "EPOCHS_PER_HISTORICAL_VECTOR":
|
|
assert.Equal(t, "35", v)
|
|
case "EPOCHS_PER_SLASHINGS_VECTOR":
|
|
assert.Equal(t, "36", v)
|
|
case "HISTORICAL_ROOTS_LIMIT":
|
|
assert.Equal(t, "37", v)
|
|
case "VALIDATOR_REGISTRY_LIMIT":
|
|
assert.Equal(t, "38", v)
|
|
case "BASE_REWARD_FACTOR":
|
|
assert.Equal(t, "39", v)
|
|
case "WHISTLEBLOWER_REWARD_QUOTIENT":
|
|
assert.Equal(t, "40", v)
|
|
case "PROPOSER_REWARD_QUOTIENT":
|
|
assert.Equal(t, "41", v)
|
|
case "INACTIVITY_PENALTY_QUOTIENT":
|
|
assert.Equal(t, "42", v)
|
|
case "MIN_SLASHING_PENALTY_QUOTIENT":
|
|
assert.Equal(t, "43", v)
|
|
case "PROPORTIONAL_SLASHING_MULTIPLIER":
|
|
assert.Equal(t, "44", v)
|
|
case "MAX_PROPOSER_SLASHINGS":
|
|
assert.Equal(t, "45", v)
|
|
case "MAX_ATTESTER_SLASHINGS":
|
|
assert.Equal(t, "46", v)
|
|
case "MAX_ATTESTATIONS":
|
|
assert.Equal(t, "47", v)
|
|
case "MAX_DEPOSITS":
|
|
assert.Equal(t, "48", v)
|
|
case "MAX_VOLUNTARY_EXITS":
|
|
assert.Equal(t, "49", v)
|
|
case "DOMAIN_BEACON_PROPOSER":
|
|
assert.Equal(t, "0x30303031", v)
|
|
case "DOMAIN_BEACON_ATTESTER":
|
|
assert.Equal(t, "0x30303032", v)
|
|
case "DOMAIN_RANDAO":
|
|
assert.Equal(t, "0x30303033", v)
|
|
case "DOMAIN_DEPOSIT":
|
|
assert.Equal(t, "0x30303034", v)
|
|
case "DOMAIN_VOLUNTARY_EXIT":
|
|
assert.Equal(t, "0x30303035", v)
|
|
case "DOMAIN_SELECTION_PROOF":
|
|
assert.Equal(t, "0x30303036", v)
|
|
case "DOMAIN_AGGREGATE_AND_PROOF":
|
|
assert.Equal(t, "0x30303037", v)
|
|
default:
|
|
t.Errorf("Incorrect key: %s", k)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetDepositContract(t *testing.T) {
|
|
const chainId = 99
|
|
const address = "0x0000000000000000000000000000000000000009"
|
|
params.SetupTestConfigCleanup(t)
|
|
config := params.BeaconConfig()
|
|
config.DepositChainID = chainId
|
|
config.DepositContractAddress = address
|
|
params.OverrideBeaconConfig(config)
|
|
|
|
s := Server{}
|
|
resp, err := s.GetDepositContract(context.Background(), &emptypb.Empty{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, uint64(chainId), resp.Data.ChainId)
|
|
assert.Equal(t, address, resp.Data.Address)
|
|
}
|
|
|
|
func TestForkSchedule_Ok(t *testing.T) {
|
|
genesisForkVersion := []byte("Genesis")
|
|
firstForkVersion, firstForkEpoch := []byte("First"), types.Epoch(100)
|
|
secondForkVersion, secondForkEpoch := []byte("Second"), types.Epoch(200)
|
|
thirdForkVersion, thirdForkEpoch := []byte("Third"), types.Epoch(300)
|
|
|
|
params.SetupTestConfigCleanup(t)
|
|
config := params.BeaconConfig()
|
|
config.GenesisForkVersion = genesisForkVersion
|
|
// Create fork schedule adding keys in non-sorted order.
|
|
schedule := make(map[types.Epoch][]byte, 3)
|
|
schedule[secondForkEpoch] = secondForkVersion
|
|
schedule[firstForkEpoch] = firstForkVersion
|
|
schedule[thirdForkEpoch] = thirdForkVersion
|
|
config.ForkVersionSchedule = schedule
|
|
params.OverrideBeaconConfig(config)
|
|
|
|
s := &Server{}
|
|
resp, err := s.GetForkSchedule(context.Background(), &emptypb.Empty{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, 3, len(resp.Data))
|
|
fork := resp.Data[0]
|
|
assert.DeepEqual(t, genesisForkVersion, fork.PreviousVersion)
|
|
assert.DeepEqual(t, firstForkVersion, fork.CurrentVersion)
|
|
assert.Equal(t, firstForkEpoch, fork.Epoch)
|
|
fork = resp.Data[1]
|
|
assert.DeepEqual(t, firstForkVersion, fork.PreviousVersion)
|
|
assert.DeepEqual(t, secondForkVersion, fork.CurrentVersion)
|
|
assert.Equal(t, secondForkEpoch, fork.Epoch)
|
|
fork = resp.Data[2]
|
|
assert.DeepEqual(t, secondForkVersion, fork.PreviousVersion)
|
|
assert.DeepEqual(t, thirdForkVersion, fork.CurrentVersion)
|
|
assert.Equal(t, thirdForkEpoch, fork.Epoch)
|
|
}
|
|
|
|
func TestForkSchedule_NoForks(t *testing.T) {
|
|
s := &Server{}
|
|
resp, err := s.GetForkSchedule(context.Background(), &emptypb.Empty{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 0, len(resp.Data))
|
|
}
|