Skip to content

Commit

Permalink
#191: correct time
Browse files Browse the repository at this point in the history
  • Loading branch information
eustimenko committed Sep 20, 2019
1 parent 2447e6b commit ea8650b
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.ethereum.beacon.core.BeaconState;
import org.ethereum.beacon.core.state.Eth1Data;
import org.ethereum.beacon.core.types.BLSSignature;
import org.ethereum.beacon.core.types.SlotNumber;
import org.ethereum.beacon.core.types.Time;
import org.ethereum.beacon.db.Database;
import org.ethereum.beacon.schedulers.ControlledSchedulers;
Expand All @@ -34,12 +35,13 @@
import tech.pegasys.artemis.util.uint.UInt64;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.stream.IntStream;

public class DefaultBeaconChainTest {

private static final long SECONDS_PER_SLOT = 6;

@Test
public void insertAChain() {
Schedulers schedulers = Schedulers.createDefault();
Expand Down Expand Up @@ -126,7 +128,6 @@ public BeaconStateEx apply(BeaconStateEx stateEx) {
@Test
public void testRejectBlocks() {
ControlledSchedulers schedulers = Schedulers.createControlled();
schedulers.setCurrentTime(Instant.now().plus(1, ChronoUnit.DAYS).toEpochMilli());

BeaconChainSpec spec =
BeaconChainSpec.Builder.createWithDefaultParams()
Expand All @@ -142,6 +143,11 @@ public void testRejectBlocks() {
Assert.assertEquals(spec.getConstants().getGenesisSlot(), initialTuple.getBlock().getSlot());

BeaconTuple recentlyProcessed = beaconChain.getRecentlyProcessed();

final SlotNumber currentSlot = spec.get_current_slot(recentlyProcessed.getState(), Instant.now().toEpochMilli());
final Time validBlockTime = recentlyProcessed.getState().getGenesisTime().plus(Time.of(currentSlot.longValue() * SECONDS_PER_SLOT)); // pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
schedulers.setCurrentTime(validBlockTime.increment().longValue());

BeaconBlock aBlock =
createBlock(recentlyProcessed, spec, schedulers.getCurrentTime(), perSlotTransition);

Expand Down

0 comments on commit ea8650b

Please sign in to comment.