Search in sources :

Example 1 with DepositsFromBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent in project teku by ConsenSys.

the class DepositProviderTest method shouldNotifyEth1DataCacheOfDepositBlocks.

@Test
void shouldNotifyEth1DataCacheOfDepositBlocks() {
    setup(16);
    final tech.pegasys.teku.ethereum.pow.api.Deposit deposit = dataStructureUtil.randomDepositEvent(UInt64.ZERO);
    final DepositsFromBlockEvent event = DepositsFromBlockEvent.create(dataStructureUtil.randomUInt64(), dataStructureUtil.randomBytes32(), dataStructureUtil.randomUInt64(), Stream.of(deposit));
    depositProvider.onDepositsFromBlock(event);
    depositMerkleTree.add(depositUtil.convertDepositEventToOperationDeposit(deposit).getData().hashTreeRoot());
    verify(eth1DataCache).onBlockWithDeposit(event.getBlockTimestamp(), new Eth1Data(depositMerkleTree.getRoot(), UInt64.ONE, event.getBlockHash()));
}
Also used : Eth1Data(tech.pegasys.teku.spec.datastructures.blocks.Eth1Data) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) Test(org.junit.jupiter.api.Test)

Example 2 with DepositsFromBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent in project teku by ConsenSys.

the class DepositProviderTest method mockDepositsFromEth1Block.

private void mockDepositsFromEth1Block(int startIndex, int n) {
    allSeenDepositsList.subList(startIndex, n).stream().map(depositUtil::convertDepositEventToOperationDeposit).map(Deposit::getData).map(DepositData::hashTreeRoot).forEachOrdered(depositMerkleTree::add);
    DepositsFromBlockEvent depositsFromBlockEvent = mock(DepositsFromBlockEvent.class);
    when(depositsFromBlockEvent.getDeposits()).thenReturn(allSeenDepositsList.subList(startIndex, startIndex + n));
    when(depositsFromBlockEvent.getBlockHash()).thenReturn(Bytes32.ZERO);
    depositProvider.onDepositsFromBlock(depositsFromBlockEvent);
}
Also used : Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent)

Example 3 with DepositsFromBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent in project teku by ConsenSys.

the class GenesisHandlerTest method onDepositsFromBlock_shouldInitializeGenesis.

@Test
public void onDepositsFromBlock_shouldInitializeGenesis() {
    final UInt64 genesisTime = specConfig.getMinGenesisTime();
    final int batchSize = initialDepositData.size() / 2;
    final DepositsFromBlockEvent event1 = DepositsFromBlockEvent.create(UInt64.valueOf(100), dataStructureUtil.randomBytes32(), UInt64.ZERO, initialDeposits.stream().limit(batchSize));
    final DepositsFromBlockEvent event2 = DepositsFromBlockEvent.create(UInt64.valueOf(100), dataStructureUtil.randomBytes32(), genesisTime, initialDeposits.stream().skip(batchSize));
    assertThat(storageSystem.recentChainData().isPreGenesis()).isTrue();
    genesisHandler.onDepositsFromBlock(event1);
    assertThat(storageSystem.recentChainData().isPreGenesis()).isTrue();
    genesisHandler.onDepositsFromBlock(event2);
    assertThat(storageSystem.recentChainData().isPreGenesis()).isFalse();
}
Also used : UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) Test(org.junit.jupiter.api.Test)

Example 4 with DepositsFromBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent in project teku by ConsenSys.

the class ValidatingEth1EventsPublisherTest method onDepositsFromBlock_latestIndexSetConsistently.

@Test
public void onDepositsFromBlock_latestIndexSetConsistently() {
    final DepositsFromBlockEvent event2 = dataStructureUtil.randomDepositsFromBlockEvent(2, 10, 11);
    final DepositsFromBlockEvent event3 = dataStructureUtil.randomDepositsFromBlockEvent(3, 11, 15);
    publisher.setLatestPublishedDeposit(UInt64.valueOf(9));
    publisher.onDepositsFromBlock(event2);
    verify(delegate).onDepositsFromBlock(event2);
    publisher.onDepositsFromBlock(event3);
    verify(delegate).onDepositsFromBlock(event3);
}
Also used : DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) Test(org.junit.jupiter.api.Test)

Example 5 with DepositsFromBlockEvent

use of tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent in project teku by ConsenSys.

the class ValidatingEth1EventsPublisherTest method onDepositsFromBlock_missingDeposit.

@Test
public void onDepositsFromBlock_missingDeposit() {
    final DepositsFromBlockEvent event1 = dataStructureUtil.randomDepositsFromBlockEvent(1, 0, 10);
    final DepositsFromBlockEvent event3 = dataStructureUtil.randomDepositsFromBlockEvent(3, 11, 15);
    publisher.onDepositsFromBlock(event1);
    assertThatThrownBy(() -> publisher.onDepositsFromBlock(event3)).isInstanceOf(InvalidDepositEventsException.class).hasMessageContaining("Expected next deposit at index 10, but got 11");
}
Also used : InvalidDepositEventsException(tech.pegasys.teku.ethereum.pow.api.InvalidDepositEventsException) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) Test(org.junit.jupiter.api.Test)

Aggregations

DepositsFromBlockEvent (tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent)20 Test (org.junit.jupiter.api.Test)15 InvalidDepositEventsException (tech.pegasys.teku.ethereum.pow.api.InvalidDepositEventsException)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)3 ReplayDepositsResult (tech.pegasys.teku.storage.api.schema.ReplayDepositsResult)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 Deposit (tech.pegasys.teku.ethereum.pow.api.Deposit)1 Eth1Data (tech.pegasys.teku.spec.datastructures.blocks.Eth1Data)1 Deposit (tech.pegasys.teku.spec.datastructures.operations.Deposit)1