@ -19,7 +19,8 @@ import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.hyperledger.besu.consensus.ibft.IbftContextBuilder.setupContextWithValidators ;
import org.hyperledger.besu.crypto.SECP256K1.KeyPair ;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey ;
import org.hyperledger.besu.crypto.NodeKey ;
import org.hyperledger.besu.ethereum.ProtocolContext ;
import org.hyperledger.besu.ethereum.core.Address ;
import org.hyperledger.besu.ethereum.core.BlockHeader ;
@ -45,15 +46,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderPasses ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader ) . buildHeader ( ) ;
final BlockHeaderValidator < IbftContext > validator =
IbftBlockHeaderValidationRulesetFactory . ibftBlockHeaderValidator ( 5 ) ;
@ -66,15 +67,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnExtraData ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , emptyList ( ) , parentHeader ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 2 , proposerNode Key , emptyList ( ) , parentHeader ) . buildHeader ( ) ;
final BlockHeaderValidator < IbftContext > validator =
IbftBlockHeaderValidationRulesetFactory . ibftBlockHeaderValidator ( 5 ) ;
@ -87,17 +88,18 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnCoinbaseData ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final Address nonProposerAddress = Util . publicKeyToAddress ( KeyPair . generate ( ) . getPublicKey ( ) ) ;
final Address nonProposerAddress =
Util . publicKeyToAddress ( BouncyCastleNodeKey . generate ( ) . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader )
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader )
. coinbase ( nonProposerAddress )
. buildHeader ( ) ;
@ -112,15 +114,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnNonce ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader ) . nonce ( 3 ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader ) . nonce ( 3 ) . buildHeader ( ) ;
final BlockHeaderValidator < IbftContext > validator =
IbftBlockHeaderValidationRulesetFactory . ibftBlockHeaderValidator ( 5 ) ;
@ -133,15 +135,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnTimestamp ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader )
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader )
. timestamp ( 100 )
. buildHeader ( ) ;
@ -156,15 +158,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnMixHash ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader )
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader )
. mixHash ( Hash . EMPTY_TRIE_HASH )
. buildHeader ( ) ;
@ -179,15 +181,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnOmmers ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader )
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader )
. ommersHash ( Hash . EMPTY_TRIE_HASH )
. buildHeader ( ) ;
@ -202,15 +204,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnDifficulty ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader )
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader )
. difficulty ( Difficulty . of ( 5 ) )
. buildHeader ( ) ;
@ -225,15 +227,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnAncestor ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeaderValidator < IbftContext > validator =
IbftBlockHeaderValidationRulesetFactory . ibftBlockHeaderValidator ( 5 ) ;
@ -246,15 +248,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnGasUsage ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader )
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader )
. gasLimit ( 5_000 )
. gasUsed ( 6_000 )
. buildHeader ( ) ;
@ -270,15 +272,15 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnGasLimitRange ( ) {
final KeyPair proposerKeyPair = KeyPair . generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ;
final Node Key proposerNode Key = BouncyCastleNode Key. generate ( ) ;
final Address proposerAddress = Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ;
final List < Address > validators = singletonList ( proposerAddress ) ;
final BlockHeader parentHeader =
getPresetHeaderBuilder ( 1 , proposerKeyPair , validators , null ) . buildHeader ( ) ;
getPresetHeaderBuilder ( 1 , proposerNode Key , validators , null ) . buildHeader ( ) ;
final BlockHeader blockHeader =
getPresetHeaderBuilder ( 2 , proposerKeyPair , validators , parentHeader )
getPresetHeaderBuilder ( 2 , proposerNode Key , validators , parentHeader )
. gasLimit ( 4999 )
. buildHeader ( ) ;
@ -293,7 +295,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
private BlockHeaderTestFixture getPresetHeaderBuilder (
final long number ,
final KeyPair proposerKeyPair ,
final Node Key proposerNode Key ,
final List < Address > validators ,
final BlockHeader parent ) {
final BlockHeaderTestFixture builder = new BlockHeaderTestFixture ( ) ;
@ -309,7 +311,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
builder . ommersHash ( Hash . EMPTY_LIST_HASH ) ;
builder . nonce ( 0 ) ;
builder . difficulty ( Difficulty . ONE ) ;
builder . coinbase ( Util . publicKeyToAddress ( proposerKeyPair . getPublicKey ( ) ) ) ;
builder . coinbase ( Util . publicKeyToAddress ( proposerNode Key . getPublicKey ( ) ) ) ;
final IbftExtraData ibftExtraData =
IbftExtraDataFixture . createExtraData (
@ -317,7 +319,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
Bytes . wrap ( new byte [ IbftExtraData . EXTRA_VANITY_LENGTH ] ) ,
Optional . of ( Vote . authVote ( Address . fromHexString ( "1" ) ) ) ,
validators ,
singletonList ( proposerKeyPair ) ,
singletonList ( proposerNode Key ) ,
0xDEADBEEF ) ;
builder . extraData ( ibftExtraData . encode ( ) ) ;