unexport various parts of tests/ and remove unused code (#2794)

This commit is contained in:
tersec 2021-08-18 13:58:43 +00:00 committed by GitHub
parent 9caf852dd4
commit a060985abc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 56 deletions

View File

@ -390,10 +390,6 @@ func init(
let let
prev_epoch = state.data.get_previous_epoch() prev_epoch = state.data.get_previous_epoch()
cur_epoch = state.data.get_current_epoch() cur_epoch = state.data.get_current_epoch()
prev_epoch_committees_per_slot = get_committee_count_per_slot(
state.data, prev_epoch, cache)
cur_epoch_committees_per_slot = get_committee_count_per_slot(
state.data, cur_epoch, cache)
template update_attestation_pool_cache( template update_attestation_pool_cache(
epoch: Epoch, slot: Slot, participation_bitmap: untyped) = epoch: Epoch, slot: Slot, participation_bitmap: untyped) =

View File

@ -38,10 +38,10 @@ type
signing_root {.defaultVal: "".}: string signing_root {.defaultVal: "".}: string
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/altair/validator.md#eth1block # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/altair/validator.md#eth1block
Eth1Block* = object Eth1Block = object
timestamp*: uint64 timestamp: uint64
deposit_root*: Eth2Digest deposit_root: Eth2Digest
deposit_count*: uint64 deposit_count: uint64
# All other eth1 block fields # All other eth1 block fields
# Note this only tracks HashTreeRoot # Note this only tracks HashTreeRoot

View File

@ -38,10 +38,10 @@ type
signing_root {.defaultVal: "".}: string signing_root {.defaultVal: "".}: string
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/validator.md#eth1block # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/validator.md#eth1block
Eth1Block* = object Eth1Block = object
timestamp*: uint64 timestamp: uint64
deposit_root*: Eth2Digest deposit_root: Eth2Digest
deposit_count*: uint64 deposit_count: uint64
# All other eth1 block fields # All other eth1 block fields
# Note this only tracks HashTreeRoot # Note this only tracks HashTreeRoot

View File

@ -19,28 +19,28 @@ import
./fixtures_utils ./fixtures_utils
type type
BLSPrivToPub* = object BLSPrivToPub = object
input*: ValidatorPrivKey input: ValidatorPrivKey
output*: ValidatorPubKey output: ValidatorPubKey
BLSSignMsgInput = object BLSSignMsgInput = object
privkey*: ValidatorPrivKey privkey: ValidatorPrivKey
message*: seq[byte] message: seq[byte]
domain*: Eth2Domain domain: Eth2Domain
BLSSignMsg* = object BLSSignMsg = object
input*: BLSSignMsgInput input: BLSSignMsgInput
output*: Signature output: Signature
BLSAggSig* = object BLSAggSig = object
input*: seq[Signature] input: seq[Signature]
output*: Signature output: Signature
BLSAggPubKey* = object BLSAggPubKey = object
input*: seq[ValidatorPubKey] input: seq[ValidatorPubKey]
output*: ValidatorPubKey output: ValidatorPubKey
proc readValue*(r: var JsonReader, a: var Eth2Domain) = proc readValue(r: var JsonReader, a: var Eth2Domain) =
## Custom deserializer for Eth2Domain ## Custom deserializer for Eth2Domain
# Furthermore Nim parseHex doesn't support uint # Furthermore Nim parseHex doesn't support uint
# until https://github.com/nim-lang/Nim/pull/11067 # until https://github.com/nim-lang/Nim/pull/11067

View File

@ -139,8 +139,6 @@ proc runTest(identifier: string) =
# The tests produce a lot of log noise # The tests produce a lot of log noise
echo "\n\n===========================================\n\n" echo "\n\n===========================================\n\n"
let testCase = InterchangeTestsDir / identifier
test "Slashing test: " & identifier: test "Slashing test: " & identifier:
let t = parseTest(InterchangeTestsDir/identifier, Json, TestInterchange) let t = parseTest(InterchangeTestsDir/identifier, Json, TestInterchange)

View File

@ -26,11 +26,6 @@ func fakeRoot(index: SomeInteger): Eth2Digest =
## We prevent zero hash special case via a power of 2 prefix ## We prevent zero hash special case via a power of 2 prefix
result.data[0 ..< 8] = (1'u64 shl 32 + index.uint64).toBytesBE() result.data[0 ..< 8] = (1'u64 shl 32 + index.uint64).toBytesBE()
func fakeValidator(index: SomeInteger): ValidatorPubKey =
## Create fake validator public key
result = ValidatorPubKey()
result.blob[0 ..< 8] = (1'u64 shl 48 + index.uint64).toBytesBE()
func hexToDigest(hex: string): Eth2Digest = func hexToDigest(hex: string): Eth2Digest =
result = Eth2Digest.fromHex(hex) result = Eth2Digest.fromHex(hex)

View File

@ -8,12 +8,12 @@ import
../beacon_chain/networking/[eth2_network, eth2_discovery], ../beacon_chain/networking/[eth2_network, eth2_discovery],
./testutil ./testutil
template asyncTest*(name, body: untyped) = template asyncTest(name, body: untyped) =
test name: test name:
proc scenario {.async.} = {.gcsafe.}: body proc scenario {.async.} = {.gcsafe.}: body
waitFor scenario() waitFor scenario()
proc new*(T: type Eth2DiscoveryProtocol, proc new(T: type Eth2DiscoveryProtocol,
pk: keys.PrivateKey, pk: keys.PrivateKey,
enrIp: Option[ValidIpAddress], enrTcpPort, enrUdpPort: Option[Port], enrIp: Option[ValidIpAddress], enrTcpPort, enrUdpPort: Option[Port],
bindPort: Port, bindIp: ValidIpAddress, bindPort: Port, bindIp: ValidIpAddress,

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH # Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -18,7 +18,7 @@ import
from strutils import replace from strutils import replace
func isEqual*(a, b: ValidatorPrivKey): bool = func isEqual(a, b: ValidatorPrivKey): bool =
# `==` on secret keys is not allowed # `==` on secret keys is not allowed
let pa = cast[ptr UncheckedArray[byte]](a.unsafeAddr) let pa = cast[ptr UncheckedArray[byte]](a.unsafeAddr)
let pb = cast[ptr UncheckedArray[byte]](b.unsafeAddr) let pb = cast[ptr UncheckedArray[byte]](b.unsafeAddr)

View File

@ -20,7 +20,7 @@ type SparseMerkleTree[Depth: static int] = object
# There is an extra "depth" layer to store leaf nodes # There is an extra "depth" layer to store leaf nodes
# This stores leaves at depth = 0 # This stores leaves at depth = 0
# and the root hash at the last depth # and the root hash at the last depth
nnznodes*: array[Depth+1, seq[Eth2Digest]] # nodes that leads to non-zero leaves nnznodes: array[Depth+1, seq[Eth2Digest]] # nodes that leads to non-zero leaves
func merkleTreeFromLeaves( func merkleTreeFromLeaves(
values: openArray[Eth2Digest], values: openArray[Eth2Digest],
@ -77,7 +77,7 @@ func getMerkleProof[Depth: static int](tree: SparseMerkleTree[Depth],
# in the next Merkle tree layer calculated # in the next Merkle tree layer calculated
depthLen = (depthLen + 1) div 2 depthLen = (depthLen + 1) div 2
proc testMerkleMinimal*(): bool = proc testMerkleMinimal(): bool =
proc toDigest[N: static int](x: array[N, byte]): Eth2Digest = proc toDigest[N: static int](x: array[N, byte]): Eth2Digest =
result.data[0 .. N-1] = x result.data[0 .. N-1] = x

View File

@ -11,7 +11,7 @@ import ../beacon_chain/gossip_processing/block_processor,
type type
SomeTPeer = ref object SomeTPeer = ref object
proc `$`*(peer: SomeTPeer): string = proc `$`(peer: SomeTPeer): string =
"SomeTPeer" "SomeTPeer"
proc updateScore(peer: SomeTPeer, score: int) = proc updateScore(peer: SomeTPeer, score: int) =

View File

@ -220,7 +220,7 @@ func makeAttestation*(
signature: sig signature: sig
) )
func find_beacon_committee*( func find_beacon_committee(
state: ForkedHashedBeaconState, validator_index: ValidatorIndex, state: ForkedHashedBeaconState, validator_index: ValidatorIndex,
cache: var StateCache): auto = cache: var StateCache): auto =
let epoch = compute_epoch_at_slot(getStateField(state, slot)) let epoch = compute_epoch_at_slot(getStateField(state, slot))
@ -285,18 +285,7 @@ func makeFullAttestations*(
attestation.signature = agg.finish().toValidatorSig() attestation.signature = agg.finish().toValidatorSig()
result.add attestation result.add attestation
func makeFullAttestations*( iterator makeTestBlocks(
state: phase0.HashedBeaconState, beacon_block_root: Eth2Digest, slot: Slot,
cache: var StateCache,
flags: UpdateFlags = {}): seq[Attestation] =
# TODO this only supports phase 0 currently. Either expand that to
# Altair here or use the ForkedHashedBeaconState version only
makeFullAttestations(
(ref ForkedHashedBeaconState)(
beaconStateFork: forkPhase0, hbsPhase0: state)[],
beacon_block_root, slot, cache, flags)
iterator makeTestBlocks*(
state: phase0.HashedBeaconState, state: phase0.HashedBeaconState,
parent_root: Eth2Digest, parent_root: Eth2Digest,
cache: var StateCache, cache: var StateCache,
@ -323,7 +312,7 @@ iterator makeTestBlocks*(state: ForkedHashedBeaconState; parent_root: Eth2Digest
for blck in makeTestBlocks(state.hbsPhase0, parent_root, cache, blocks, attested): for blck in makeTestBlocks(state.hbsPhase0, parent_root, cache, blocks, attested):
yield blck yield blck
proc getAttestationsforTestBlock*( proc getAttestationsForTestBlock*(
pool: var AttestationPool, stateData: StateData, cache: var StateCache): pool: var AttestationPool, stateData: StateData, cache: var StateCache):
seq[Attestation] = seq[Attestation] =
case stateData.data.beaconStateFork: case stateData.data.beaconStateFork: