Search in sources :

Example 1 with BftQueryService

use of org.hyperledger.besu.plugin.services.query.BftQueryService in project besu by hyperledger.

the class BftQueryServiceImplTest method getSignersReturnsAddressesOfSignersInBlock.

@Test
public void getSignersReturnsAddressesOfSignersInBlock() {
    final BftQueryService service = new BftQueryServiceImpl(bftBlockInterface, blockchain, validatorProvider, null, null);
    final List<Address> signers = signingKeys.stream().map(nodeKey -> Util.publicKeyToAddress(nodeKey.getPublicKey())).collect(Collectors.toList());
    when(bftBlockInterface.getCommitters(any())).thenReturn(signers);
    assertThat(service.getSignersFrom(blockHeader)).containsExactlyElementsOf(signers);
}
Also used : AssertionsForClassTypes.assertThatExceptionOfType(org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Util(org.hyperledger.besu.ethereum.core.Util) BftBlockHeaderFunctions(org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions) Lists(com.google.common.collect.Lists) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) BftExtraDataCodec(org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec) NoSuchElementException(java.util.NoSuchElementException) Before(org.junit.Before) NonBesuBlockHeader(org.hyperledger.besu.ethereum.core.NonBesuBlockHeader) NodeKeyUtils(org.hyperledger.besu.crypto.NodeKeyUtils) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Collectors(java.util.stream.Collectors) List(java.util.List) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) NodeKey(org.hyperledger.besu.crypto.NodeKey) Hash(org.hyperledger.besu.datatypes.Hash) Address(org.hyperledger.besu.datatypes.Address) BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) Test(org.junit.Test)

Example 2 with BftQueryService

use of org.hyperledger.besu.plugin.services.query.BftQueryService in project besu by hyperledger.

the class BftQueryServiceImplTest method getSignersThrowsIfBlockIsNotOnTheChain.

@Test
public void getSignersThrowsIfBlockIsNotOnTheChain() {
    final NonBesuBlockHeader header = new NonBesuBlockHeader(Hash.EMPTY, Bytes.EMPTY);
    final BftQueryService service = new BftQueryServiceImpl(bftBlockInterface, blockchain, validatorProvider, null, null);
    assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> service.getSignersFrom(header));
}
Also used : NonBesuBlockHeader(org.hyperledger.besu.ethereum.core.NonBesuBlockHeader) BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 3 with BftQueryService

use of org.hyperledger.besu.plugin.services.query.BftQueryService in project besu by hyperledger.

the class BftQueryServiceImplTest method getValidatorsReturnsAddresses.

@Test
public void getValidatorsReturnsAddresses() {
    final BftQueryService service = new BftQueryServiceImpl(bftBlockInterface, blockchain, validatorProvider, null, null);
    final List<Address> validators = signingKeys.stream().map(nodeKey -> Util.publicKeyToAddress(nodeKey.getPublicKey())).collect(Collectors.toList());
    when(validatorProvider.getValidatorsAtHead()).thenReturn(validators);
    assertThat(service.getValidatorsForLatestBlock()).containsExactlyElementsOf(validators);
}
Also used : AssertionsForClassTypes.assertThatExceptionOfType(org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Util(org.hyperledger.besu.ethereum.core.Util) BftBlockHeaderFunctions(org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions) Lists(com.google.common.collect.Lists) BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) BftExtraDataCodec(org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec) NoSuchElementException(java.util.NoSuchElementException) Before(org.junit.Before) NonBesuBlockHeader(org.hyperledger.besu.ethereum.core.NonBesuBlockHeader) NodeKeyUtils(org.hyperledger.besu.crypto.NodeKeyUtils) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) Collectors(java.util.stream.Collectors) List(java.util.List) ValidatorProvider(org.hyperledger.besu.consensus.common.validator.ValidatorProvider) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) NodeKey(org.hyperledger.besu.crypto.NodeKey) Hash(org.hyperledger.besu.datatypes.Hash) Address(org.hyperledger.besu.datatypes.Address) BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) Test(org.junit.Test)

Example 4 with BftQueryService

use of org.hyperledger.besu.plugin.services.query.BftQueryService in project besu by hyperledger.

the class BftQueryServiceImplTest method roundNumberFromBlockIsReturned.

@Test
public void roundNumberFromBlockIsReturned() {
    final BftQueryService service = new BftQueryServiceImpl(bftBlockInterface, blockchain, validatorProvider, null, null);
    final int roundNumberInBlock = 5;
    final BftExtraData extraData = new BftExtraData(Bytes.EMPTY, List.of(), Optional.empty(), roundNumberInBlock, List.of());
    when(bftBlockInterface.getExtraData(blockHeader)).thenReturn(extraData);
    assertThat(service.getRoundNumberFrom(blockHeader)).isEqualTo(roundNumberInBlock);
}
Also used : BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData) Test(org.junit.Test)

Example 5 with BftQueryService

use of org.hyperledger.besu.plugin.services.query.BftQueryService in project besu by hyperledger.

the class BftQueryServiceImplTest method getRoundNumberThrowsIfBlockIsNotOnTheChain.

@Test
public void getRoundNumberThrowsIfBlockIsNotOnTheChain() {
    final NonBesuBlockHeader header = new NonBesuBlockHeader(Hash.EMPTY, Bytes.EMPTY);
    final BftQueryService service = new BftQueryServiceImpl(new BftBlockInterface(bftExtraDataCodec), blockchain, validatorProvider, null, null);
    assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> service.getRoundNumberFrom(header));
}
Also used : BftBlockInterface(org.hyperledger.besu.consensus.common.bft.BftBlockInterface) NonBesuBlockHeader(org.hyperledger.besu.ethereum.core.NonBesuBlockHeader) BftQueryService(org.hyperledger.besu.plugin.services.query.BftQueryService) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Aggregations

BftQueryService (org.hyperledger.besu.plugin.services.query.BftQueryService)6 Test (org.junit.Test)6 NoSuchElementException (java.util.NoSuchElementException)4 BftBlockInterface (org.hyperledger.besu.consensus.common.bft.BftBlockInterface)4 NonBesuBlockHeader (org.hyperledger.besu.ethereum.core.NonBesuBlockHeader)4 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Bytes (org.apache.tuweni.bytes.Bytes)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 AssertionsForClassTypes.assertThatExceptionOfType (org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType)2 BftBlockHeaderFunctions (org.hyperledger.besu.consensus.common.bft.BftBlockHeaderFunctions)2 BftExtraDataCodec (org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec)2 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)2 NodeKey (org.hyperledger.besu.crypto.NodeKey)2 NodeKeyUtils (org.hyperledger.besu.crypto.NodeKeyUtils)2 Address (org.hyperledger.besu.datatypes.Address)2 Hash (org.hyperledger.besu.datatypes.Hash)2