use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class GoQuorumSendRawPrivateTransactionTest method rlpEncodeTransaction.
private static String rlpEncodeTransaction(final PrivateTransaction.Builder privateTransactionBuilder) {
final KeyPair keyPair = SIGNATURE_ALGORITHM.get().createKeyPair(SIGNATURE_ALGORITHM.get().createPrivateKey(new BigInteger("8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63", 16)));
final PrivateTransaction privateTransaction = privateTransactionBuilder.signAndBuild(keyPair);
final BytesValueRLPOutput bvrlp = new BytesValueRLPOutput();
privateTransaction.writeTo(bvrlp);
return bvrlp.encoded().toHexString();
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class IbftBlockHeaderValidationRulesetFactoryTest method ibftValidateHeaderFails.
@Test
public void ibftValidateHeaderFails() {
final KeyPair proposerKeyPair = SIGNATURE_ALGORITHM.get().generateKeyPair();
final Address proposerAddress = Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
final List<Address> validators = singletonList(proposerAddress);
final BlockHeader parentHeader = buildBlockHeader(1, proposerKeyPair, validators, null);
final BlockHeader blockHeader = buildBlockHeader(2, proposerKeyPair, validators, null);
final BlockHeaderValidator validator = IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5, 0).build();
assertThat(validator.validateHeader(blockHeader, parentHeader, setupContextWithValidators(validators), HeaderValidationMode.FULL)).isFalse();
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class BftBlockCreatorTest method headerProducedPassesValidationRules.
@Test
public void headerProducedPassesValidationRules() {
// Construct a parent block.
final BlockHeaderTestFixture blockHeaderBuilder = new BlockHeaderTestFixture();
// required to pass validation rule checks.
blockHeaderBuilder.gasLimit(5000);
final BlockHeader parentHeader = blockHeaderBuilder.buildHeader();
final Optional<BlockHeader> optionalHeader = Optional.of(parentHeader);
// Construct a block chain and world state
final MutableBlockchain blockchain = mock(MutableBlockchain.class);
when(blockchain.getChainHeadHash()).thenReturn(parentHeader.getHash());
when(blockchain.getBlockHeader(any())).thenReturn(optionalHeader);
final BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getBaseFee()).thenReturn(Optional.empty());
when(blockchain.getChainHeadHeader()).thenReturn(blockHeader);
final KeyPair nodeKeys = SignatureAlgorithmFactory.getInstance().generateKeyPair();
// Add the local node as a validator (can't propose a block if node is not a validator).
final Address localAddr = Address.extract(Hash.hash(nodeKeys.getPublicKey().getEncodedBytes()));
final List<Address> initialValidatorList = Arrays.asList(Address.fromHexString(String.format("%020d", 1)), Address.fromHexString(String.format("%020d", 2)), Address.fromHexString(String.format("%020d", 3)), Address.fromHexString(String.format("%020d", 4)), localAddr);
final ProtocolSchedule protocolSchedule = IbftProtocolSchedule.create(GenesisConfigFile.fromConfig("{\"config\": {\"spuriousDragonBlock\":0}}").getConfigOptions(), false, EvmConfiguration.DEFAULT);
final ProtocolContext protContext = new ProtocolContext(blockchain, createInMemoryWorldStateArchive(), setupContextWithValidators(initialValidatorList));
final IbftBlockCreator blockCreator = new IbftBlockCreator(Address.fromHexString(String.format("%020d", 0)), () -> Optional.of(10_000_000L), parent -> new IbftExtraData(Bytes.wrap(new byte[32]), Lists.newArrayList(), null, initialValidatorList).encode(), new GasPricePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, blockchain::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP), protContext, protocolSchedule, nodeKeys, Wei.ZERO, 0.8, parentHeader);
final Block block = blockCreator.createBlock(Instant.now().getEpochSecond());
final BlockHeaderValidator rules = IbftBlockHeaderValidationRulesetFactory.ibftProposedBlockValidator(0).build();
final boolean validationResult = rules.validateHeader(block.getHeader(), parentHeader, protContext, HeaderValidationMode.FULL);
assertThat(validationResult).isTrue();
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class BftExtraDataValidationRuleTest method outOfOrderValidatorListFailsValidation.
@Test
public void outOfOrderValidatorListFailsValidation() {
final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
// must NOT be block 0, as that should not contain seals at all
builder.number(1);
final KeyPair proposerKeyPair = signatureAlgorithm.generateKeyPair();
final Address proposerAddress = Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
final List<Address> validators = Lists.newArrayList(AddressHelpers.calculateAddressWithRespectTo(proposerAddress, 1), proposerAddress);
final ProtocolContext context = new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule = new IbftExtraDataValidationRule(true, 0);
BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators);
// Insert an extraData block with committer seals.
final IbftExtraData commitedExtraData = createExtraDataWithCommitSeals(header, singletonList(proposerKeyPair));
builder.extraData(commitedExtraData.encode());
header = builder.buildHeader();
assertThat(extraDataValidationRule.validate(header, null, context)).isFalse();
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class BftExtraDataValidationRuleTest method correctlyConstructedHeaderPassesValidation.
@Test
public void correctlyConstructedHeaderPassesValidation() {
final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
// must NOT be block 0, as that should not contain seals at all
builder.number(1);
final KeyPair proposerKeyPair = signatureAlgorithm.generateKeyPair();
final Address proposerAddress = Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
final List<Address> validators = singletonList(proposerAddress);
final ProtocolContext context = new ProtocolContext(null, null, setupContextWithValidators(validators));
final IbftExtraDataValidationRule extraDataValidationRule = new IbftExtraDataValidationRule(true, 0);
BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators);
// Insert an extraData block with committer seals.
final IbftExtraData commitedExtraData = createExtraDataWithCommitSeals(header, singletonList(proposerKeyPair));
builder.extraData(commitedExtraData.encode());
header = builder.buildHeader();
assertThat(extraDataValidationRule.validate(header, null, context)).isTrue();
}
Aggregations