From 2447e6b92b838efc52b8240b1631d4172400e232 Mon Sep 17 00:00:00 2001 From: Eugene Ustimenko Date: Thu, 19 Sep 2019 13:53:10 +0300 Subject: [PATCH] #191: test reject --- .../beacon/chain/DefaultBeaconChainTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/chain/src/test/java/org/ethereum/beacon/chain/DefaultBeaconChainTest.java b/chain/src/test/java/org/ethereum/beacon/chain/DefaultBeaconChainTest.java index 561e78255..5bd035718 100644 --- a/chain/src/test/java/org/ethereum/beacon/chain/DefaultBeaconChainTest.java +++ b/chain/src/test/java/org/ethereum/beacon/chain/DefaultBeaconChainTest.java @@ -26,12 +26,15 @@ import org.ethereum.beacon.core.types.BLSSignature; 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.Instant; +import java.time.temporal.ChronoUnit; import java.util.Collections; import java.util.stream.IntStream; @@ -119,4 +122,30 @@ public BeaconStateEx apply(BeaconStateEx stateEx) { chainStorage, schedulers); } + + @Test + public void testRejectBlocks() { + ControlledSchedulers schedulers = Schedulers.createControlled(); + schedulers.setCurrentTime(Instant.now().plus(1, ChronoUnit.DAYS).toEpochMilli()); + + BeaconChainSpec spec = + BeaconChainSpec.Builder.createWithDefaultParams() + .withComputableGenesisTime(false) + .withVerifyDepositProof(false) + .build(); + StateTransition perSlotTransition = + StateTransitionTestUtil.createNextSlotTransition(); + MutableBeaconChain beaconChain = createBeaconChain(spec, perSlotTransition, schedulers); + + beaconChain.init(); + BeaconTuple initialTuple = beaconChain.getRecentlyProcessed(); + Assert.assertEquals(spec.getConstants().getGenesisSlot(), initialTuple.getBlock().getSlot()); + + BeaconTuple recentlyProcessed = beaconChain.getRecentlyProcessed(); + BeaconBlock aBlock = + createBlock(recentlyProcessed, spec, schedulers.getCurrentTime(), perSlotTransition); + + Assert.assertEquals(ImportResult.ExpiredBlock, beaconChain.insert(aBlock)); + Assert.assertEquals(aBlock, beaconChain.getRecentlyProcessed().getBlock()); + } }