|
|
@ -21,15 +21,19 @@ import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
|
|
import org.hyperledger.besu.config.BftConfigOptions; |
|
|
|
import org.hyperledger.besu.config.BftConfigOptions; |
|
|
|
|
|
|
|
import org.hyperledger.besu.config.BftFork; |
|
|
|
import org.hyperledger.besu.config.GenesisConfigOptions; |
|
|
|
import org.hyperledger.besu.config.GenesisConfigOptions; |
|
|
|
|
|
|
|
import org.hyperledger.besu.config.TransitionsConfigOptions; |
|
|
|
import org.hyperledger.besu.ethereum.core.Address; |
|
|
|
import org.hyperledger.besu.ethereum.core.Address; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeader; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeader; |
|
|
|
import org.hyperledger.besu.ethereum.core.Wei; |
|
|
|
import org.hyperledger.besu.ethereum.core.Wei; |
|
|
|
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; |
|
|
|
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator; |
|
|
|
|
|
|
|
import org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule; |
|
|
|
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; |
|
|
|
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; |
|
|
|
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; |
|
|
|
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; |
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigInteger; |
|
|
|
import java.math.BigInteger; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
@ -51,6 +55,7 @@ public class BftProtocolScheduleTest { |
|
|
|
when(configOptions.getMiningBeneficiary()).thenReturn(Optional.of(miningBeneficiary)); |
|
|
|
when(configOptions.getMiningBeneficiary()).thenReturn(Optional.of(miningBeneficiary)); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
|
|
|
|
when(genesisConfig.getTransitions()).thenReturn(TransitionsConfigOptions.DEFAULT); |
|
|
|
|
|
|
|
|
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
|
|
|
|
|
|
|
@ -74,7 +79,7 @@ public class BftProtocolScheduleTest { |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(BigInteger.ZERO); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(BigInteger.ZERO); |
|
|
|
|
|
|
|
when(genesisConfig.getTransitions()).thenReturn(TransitionsConfigOptions.DEFAULT); |
|
|
|
assertThatThrownBy( |
|
|
|
assertThatThrownBy( |
|
|
|
() -> |
|
|
|
() -> |
|
|
|
BftProtocolSchedule.create( |
|
|
|
BftProtocolSchedule.create( |
|
|
@ -93,6 +98,7 @@ public class BftProtocolScheduleTest { |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
|
|
|
|
when(genesisConfig.getTransitions()).thenReturn(TransitionsConfigOptions.DEFAULT); |
|
|
|
|
|
|
|
|
|
|
|
final ProtocolSchedule schedule = |
|
|
|
final ProtocolSchedule schedule = |
|
|
|
BftProtocolSchedule.create( |
|
|
|
BftProtocolSchedule.create( |
|
|
@ -116,6 +122,7 @@ public class BftProtocolScheduleTest { |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
|
|
|
|
when(genesisConfig.getTransitions()).thenReturn(TransitionsConfigOptions.DEFAULT); |
|
|
|
|
|
|
|
|
|
|
|
assertThatThrownBy( |
|
|
|
assertThatThrownBy( |
|
|
|
() -> |
|
|
|
() -> |
|
|
@ -135,6 +142,7 @@ public class BftProtocolScheduleTest { |
|
|
|
when(configOptions.getEpochLength()).thenReturn(0L); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(0L); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
|
|
|
|
when(genesisConfig.getTransitions()).thenReturn(TransitionsConfigOptions.DEFAULT); |
|
|
|
|
|
|
|
|
|
|
|
assertThatThrownBy( |
|
|
|
assertThatThrownBy( |
|
|
|
() -> |
|
|
|
() -> |
|
|
@ -154,6 +162,7 @@ public class BftProtocolScheduleTest { |
|
|
|
when(configOptions.getEpochLength()).thenReturn(-3000L); |
|
|
|
when(configOptions.getEpochLength()).thenReturn(-3000L); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
|
|
|
|
when(genesisConfig.getTransitions()).thenReturn(TransitionsConfigOptions.DEFAULT); |
|
|
|
|
|
|
|
|
|
|
|
assertThatThrownBy( |
|
|
|
assertThatThrownBy( |
|
|
|
() -> |
|
|
|
() -> |
|
|
@ -164,4 +173,36 @@ public class BftProtocolScheduleTest { |
|
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
|
.isInstanceOf(IllegalArgumentException.class) |
|
|
|
.hasMessage("Epoch length in config must be greater than zero"); |
|
|
|
.hasMessage("Epoch length in config must be greater than zero"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void blockRewardSpecifiedInTransitionCreatesNewMilestone() { |
|
|
|
|
|
|
|
final BigInteger arbitraryBlockReward = BigInteger.valueOf(5); |
|
|
|
|
|
|
|
final String miningBeneficiary = Address.fromHexString("0x1").toString(); |
|
|
|
|
|
|
|
final BftConfigOptions configOptions = mock(BftConfigOptions.class); |
|
|
|
|
|
|
|
when(configOptions.getMiningBeneficiary()).thenReturn(Optional.of(miningBeneficiary)); |
|
|
|
|
|
|
|
when(configOptions.getBlockRewardWei()).thenReturn(arbitraryBlockReward); |
|
|
|
|
|
|
|
when(configOptions.getEpochLength()).thenReturn(3000L); |
|
|
|
|
|
|
|
when(genesisConfig.getBftConfigOptions()).thenReturn(configOptions); |
|
|
|
|
|
|
|
when(genesisConfig.isIbft2()).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final long transitionBlock = 5L; |
|
|
|
|
|
|
|
final BftFork fork = mock(BftFork.class); |
|
|
|
|
|
|
|
when(fork.getForkBlock()).thenReturn(transitionBlock); |
|
|
|
|
|
|
|
final BigInteger forkBlockReward = arbitraryBlockReward.multiply(BigInteger.valueOf(2)); |
|
|
|
|
|
|
|
when(fork.getBlockRewardWei()).thenReturn(Optional.of(forkBlockReward)); |
|
|
|
|
|
|
|
final TransitionsConfigOptions transitions = mock(TransitionsConfigOptions.class); |
|
|
|
|
|
|
|
when(transitions.getIbftForks()).thenReturn(List.of(fork)); |
|
|
|
|
|
|
|
when(genesisConfig.getTransitions()).thenReturn(transitions); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final MutableProtocolSchedule schedule = |
|
|
|
|
|
|
|
(MutableProtocolSchedule) |
|
|
|
|
|
|
|
BftProtocolSchedule.create( |
|
|
|
|
|
|
|
genesisConfig, BftProtocolScheduleTest::arbitraryRulesetBuilder, bftExtraDataCodec); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(schedule.streamMilestoneBlocks().count()).isEqualTo(2); |
|
|
|
|
|
|
|
assertThat(schedule.getByBlockNumber(0).getBlockReward()) |
|
|
|
|
|
|
|
.isEqualTo(Wei.of(arbitraryBlockReward)); |
|
|
|
|
|
|
|
assertThat(schedule.getByBlockNumber(transitionBlock).getBlockReward()) |
|
|
|
|
|
|
|
.isEqualTo(Wei.of(forkBlockReward)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|