Search in sources :

Example 1 with BftFork

use of org.hyperledger.besu.config.BftFork in project besu by hyperledger.

the class BftForksScheduleFactoryTest method throwsErrorIfHasForksWithDuplicateBlock.

@Test
@SuppressWarnings("unchecked")
public void throwsErrorIfHasForksWithDuplicateBlock() {
    final BftConfigOptions genesisConfigOptions = JsonBftConfigOptions.DEFAULT;
    final BftFork fork1 = createFork(1, 10);
    final BftFork fork2 = createFork(1, 20);
    final BftFork fork3 = createFork(2, 30);
    final BftSpecCreator<BftConfigOptions, BftFork> specCreator = Mockito.mock(BftSpecCreator.class);
    assertThatThrownBy(() -> BftForksScheduleFactory.create(genesisConfigOptions, List.of(fork1, fork2, fork3), specCreator)).hasMessage("Duplicate transitions cannot be created for the same block");
}
Also used : JsonBftConfigOptions(org.hyperledger.besu.config.JsonBftConfigOptions) BftConfigOptions(org.hyperledger.besu.config.BftConfigOptions) BftFork(org.hyperledger.besu.config.BftFork) Test(org.junit.Test)

Example 2 with BftFork

use of org.hyperledger.besu.config.BftFork in project besu by hyperledger.

the class TransitionsTest method transitionsBlockPeriod.

@Test
public void transitionsBlockPeriod() throws InterruptedException {
    final TestClock clock = new TestClock(Instant.EPOCH);
    final List<BftFork> bftForks = List.of(new BftFork(JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 1, BftFork.BLOCK_PERIOD_SECONDS_KEY, 10))), new BftFork(JsonUtil.objectNodeFromMap(Map.of(BftFork.FORK_BLOCK_KEY, 2, BftFork.BLOCK_PERIOD_SECONDS_KEY, 20))));
    final BftEventQueue bftEventQueue = new BftEventQueue(TestContextBuilder.MESSAGE_QUEUE_LIMIT);
    final TestContext context = new TestContextBuilder().indexOfFirstLocallyProposedBlock(0).validatorCount(1).clock(clock).bftForks(bftForks).eventQueue(bftEventQueue).buildAndStart();
    clock.stepMillis(10_000);
    context.getEventMultiplexer().handleBftEvent(bftEventQueue.poll(1, TimeUnit.SECONDS));
    context.getController().handleNewBlockEvent(new NewChainHead(context.getBlockchain().getChainHeadHeader()));
    clock.stepMillis(20_000);
    context.getEventMultiplexer().handleBftEvent(bftEventQueue.poll(1, TimeUnit.SECONDS));
    final BlockHeader genesisBlock = context.getBlockchain().getBlockHeader(0).get();
    final BlockHeader blockHeader1 = context.getBlockchain().getBlockHeader(1).get();
    final BlockHeader blockHeader2 = context.getBlockchain().getBlockHeader(2).get();
    assertThat(blockHeader1.getTimestamp()).isEqualTo(genesisBlock.getTimestamp() + 10);
    assertThat(blockHeader2.getTimestamp()).isEqualTo(blockHeader1.getTimestamp() + 20);
}
Also used : TestClock(org.hyperledger.besu.testutil.TestClock) TestContext(org.hyperledger.besu.consensus.ibft.support.TestContext) TestContextBuilder(org.hyperledger.besu.consensus.ibft.support.TestContextBuilder) NewChainHead(org.hyperledger.besu.consensus.common.bft.events.NewChainHead) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) BftEventQueue(org.hyperledger.besu.consensus.common.bft.BftEventQueue) BftFork(org.hyperledger.besu.config.BftFork) Test(org.junit.jupiter.api.Test)

Example 3 with BftFork

use of org.hyperledger.besu.config.BftFork in project besu by hyperledger.

the class BftForksScheduleFactoryTest method createsScheduleUsingSpecCreator.

@SuppressWarnings("unchecked")
@Test
public void createsScheduleUsingSpecCreator() {
    final BftConfigOptions genesisConfigOptions = JsonBftConfigOptions.DEFAULT;
    final ForkSpec<BftConfigOptions> genesisForkSpec = new ForkSpec<>(0, genesisConfigOptions);
    final BftFork fork1 = createFork(1, 10);
    final BftFork fork2 = createFork(2, 20);
    final BftSpecCreator<BftConfigOptions, BftFork> specCreator = Mockito.mock(BftSpecCreator.class);
    final BftConfigOptions configOptions1 = createBftConfigOptions(10);
    final BftConfigOptions configOptions2 = createBftConfigOptions(20);
    when(specCreator.create(genesisForkSpec, fork1)).thenReturn(configOptions1);
    when(specCreator.create(new ForkSpec<>(1, configOptions1), fork2)).thenReturn(configOptions2);
    final ForksSchedule<BftConfigOptions> schedule = BftForksScheduleFactory.create(genesisConfigOptions, List.of(fork1, fork2), specCreator);
    assertThat(schedule.getFork(0)).isEqualTo(genesisForkSpec);
    assertThat(schedule.getFork(1)).isEqualTo(new ForkSpec<>(1, configOptions1));
    assertThat(schedule.getFork(2)).isEqualTo(new ForkSpec<>(2, configOptions2));
}
Also used : ForkSpec(org.hyperledger.besu.consensus.common.ForkSpec) JsonBftConfigOptions(org.hyperledger.besu.config.JsonBftConfigOptions) BftConfigOptions(org.hyperledger.besu.config.BftConfigOptions) BftFork(org.hyperledger.besu.config.BftFork) Test(org.junit.Test)

Example 4 with BftFork

use of org.hyperledger.besu.config.BftFork in project besu by hyperledger.

the class BftForksScheduleFactoryTest method throwsErrorIfHasForkForGenesisBlock.

@Test
@SuppressWarnings("unchecked")
public void throwsErrorIfHasForkForGenesisBlock() {
    final BftConfigOptions genesisConfigOptions = JsonBftConfigOptions.DEFAULT;
    final BftFork fork = createFork(0, 10);
    final BftSpecCreator<BftConfigOptions, BftFork> specCreator = Mockito.mock(BftSpecCreator.class);
    assertThatThrownBy(() -> BftForksScheduleFactory.create(genesisConfigOptions, List.of(fork), specCreator)).hasMessage("Transition cannot be created for genesis block");
}
Also used : JsonBftConfigOptions(org.hyperledger.besu.config.JsonBftConfigOptions) BftConfigOptions(org.hyperledger.besu.config.BftConfigOptions) BftFork(org.hyperledger.besu.config.BftFork) Test(org.junit.Test)

Aggregations

BftFork (org.hyperledger.besu.config.BftFork)4 BftConfigOptions (org.hyperledger.besu.config.BftConfigOptions)3 JsonBftConfigOptions (org.hyperledger.besu.config.JsonBftConfigOptions)3 Test (org.junit.Test)3 ForkSpec (org.hyperledger.besu.consensus.common.ForkSpec)1 BftEventQueue (org.hyperledger.besu.consensus.common.bft.BftEventQueue)1 NewChainHead (org.hyperledger.besu.consensus.common.bft.events.NewChainHead)1 TestContext (org.hyperledger.besu.consensus.ibft.support.TestContext)1 TestContextBuilder (org.hyperledger.besu.consensus.ibft.support.TestContextBuilder)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 TestClock (org.hyperledger.besu.testutil.TestClock)1 Test (org.junit.jupiter.api.Test)1