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);
}
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));
}
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);
}
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);
}
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));
}
Aggregations