diff --git a/tests/mocking/mock_blocks.nim b/tests/mocking/mock_blocks.nim index f5969092c..0893161ad 100644 --- a/tests/mocking/mock_blocks.nim +++ b/tests/mocking/mock_blocks.nim @@ -45,14 +45,17 @@ proc signMockBlock*(state: ForkedHashedBeaconState, b: var ForkedSignedBeaconBlo privkey).toValidatorSig() # https://github.com/ethereum/consensus-specs/blob/v1.1.0-beta.4/tests/core/pyspec/eth2spec/test/helpers/block.py#L75-L105 -proc mockBlock*(state: ForkedHashedBeaconState, slot: Slot): ForkedSignedBeaconBlock = +proc mockBlock*( + state: ForkedHashedBeaconState, + slot: Slot, + cfg = defaultRuntimeConfig): ForkedSignedBeaconBlock = ## TODO don't do this gradual construction, for exception safety ## Mock a BeaconBlock for the specific slot var cache = StateCache() var rewards = RewardInfo() var tmpState = assignClone(state) - doAssert process_slots(defaultRuntimeConfig, tmpState[], slot, cache, rewards, flags = {}) + doAssert process_slots(cfg, tmpState[], slot, cache, rewards, flags = {}) var previous_block_header = getStateField(tmpState[], latest_block_header) if previous_block_header.state_root == ZERO_HASH: diff --git a/tests/mocking/mock_genesis.nim b/tests/mocking/mock_genesis.nim index 05f88a7db..503d9cb4e 100644 --- a/tests/mocking/mock_genesis.nim +++ b/tests/mocking/mock_genesis.nim @@ -17,18 +17,14 @@ import ./mock_deposits proc initGenesisState*( - num_validators: uint64 = 8'u64 * SLOTS_PER_EPOCH, - beaconStateFork: BeaconStateFork = forkPhase0): ref ForkedHashedBeaconState = + num_validators = 8'u64 * SLOTS_PER_EPOCH, + cfg = defaultRuntimeConfig): ref ForkedHashedBeaconState = let deposits = mockGenesisBalancedDeposits( validatorCount = num_validators, amountInEth = 32, # We create canonical validators with 32 Eth flags = {} ) - var cfg = defaultRuntimeConfig - if beaconStateFork >= forkAltair: - cfg.ALTAIR_FORK_EPOCH = GENESIS_EPOCH - result = (ref ForkedHashedBeaconState)( beaconStateFork: forkPhase0, hbsPhase0: initialize_hashed_beacon_state_from_eth1( @@ -36,8 +32,6 @@ proc initGenesisState*( maybeUpgradeStateToAltair(cfg, result[]) - doAssert result.beaconStateFork == beaconStateFork - when isMainModule: # Smoke test let state = initGenesisState(num_validators = SLOTS_PER_EPOCH) diff --git a/tests/testblockutil.nim b/tests/testblockutil.nim index b67846a31..beb4f263b 100644 --- a/tests/testblockutil.nim +++ b/tests/testblockutil.nim @@ -36,7 +36,7 @@ func hackPrivKey*(v: Validator): ValidatorPrivKey = let i = int(uint64.fromBytesLE(bytes)) makeFakeValidatorPrivKey(i) -func makeDeposit*(i: int, flags: UpdateFlags = {}): DepositData = +func makeDeposit*(i: int, flags: UpdateFlags = {}, cfg = defaultRuntimeConfig): DepositData = ## Ugly hack for now: we stick the private key in withdrawal_credentials ## which means we can repro private key and randao reveal from this data, ## for testing :) @@ -51,13 +51,12 @@ func makeDeposit*(i: int, flags: UpdateFlags = {}): DepositData = amount: MAX_EFFECTIVE_BALANCE) if skipBLSValidation notin flags: - result.signature = get_deposit_signature( - defaultRuntimeConfig, result, privkey).toValidatorSig() + result.signature = get_deposit_signature(cfg, result, privkey).toValidatorSig() func makeInitialDeposits*( - n = SLOTS_PER_EPOCH, flags: UpdateFlags = {}): seq[DepositData] = + n = SLOTS_PER_EPOCH, flags: UpdateFlags = {}, cfg = defaultRuntimeConfig): seq[DepositData] = for i in 0..