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

#191: test reject #200

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@
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;
import org.ethereum.beacon.schedulers.Schedulers;
import org.junit.Assert;
import org.junit.Test;
import tech.pegasys.artemis.ethereum.core.Hash32;
import tech.pegasys.artemis.util.uint.UInt64;

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

import static org.assertj.core.api.Assertions.assertThat;

public class DefaultBeaconChainTest {

@Test
Expand Down Expand Up @@ -119,4 +125,36 @@ public BeaconStateEx apply(BeaconStateEx stateEx) {
chainStorage,
schedulers);
}

@Test
public void testRejectBlocks() {
ControlledSchedulers schedulers = Schedulers.createControlled();
long currentTime = schedulers.getCurrentTime();

BeaconChainSpec spec =
BeaconChainSpec.Builder.createWithDefaultParams()
.withComputableGenesisTime(false)
.withVerifyDepositProof(false)
.build();

StateTransition<BeaconStateEx> perSlotTransition =
StateTransitionTestUtil.createNextSlotTransition();

MutableBeaconChain beaconChain = createBeaconChain(spec, perSlotTransition, schedulers);
beaconChain.init();
BeaconTuple parent = beaconChain.getRecentlyProcessed();

// assert block.slot <= get_current_slot(store.time) + 1
schedulers.addTime(Duration.of(1, ChronoUnit.DAYS));
BeaconState state = perSlotTransition.apply(new BeaconStateExImpl(parent.getState()));
SlotNumber currentSlot = spec.get_current_slot(parent.getState(), schedulers.getCurrentTime());
SlotNumber nextToCurrentSlot = spec.get_current_slot(state, schedulers.getCurrentTime()).increment();
final boolean actual = nextToCurrentSlot.greaterEqual(currentSlot);

// assert store.time >= pre_state.genesis_time + block.slot * SECONDS_PER_SLOT
final long expectedTime = parent.getState().getGenesisTime().longValue() + currentSlot.longValue() * spec.getConstants().getSecondsPerSlot().longValue();
final boolean expected = currentTime >= expectedTime;

assertThat(actual).isEqualTo(expected);
}
}