mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-09 22:07:59 -05:00
Remove Bytes32.ZERO (#4578)
Replace the use of the Bytes32.ZERO constant with a byte array variant. Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
This commit is contained in:
@@ -99,7 +99,7 @@ public class PrivGetPrivateTransactionAcceptanceTest extends ParameterizedEnclav
|
||||
|
||||
@Test
|
||||
public void nonExistentHashReturnsNull() {
|
||||
alice.getBesu().verify(priv.getPrivateTransactionReturnsNull(Hash.ZERO));
|
||||
alice.getBesu().verify(priv.getPrivateTransactionReturnsNull(Hash.ZERO_HASH));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -21,6 +21,7 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.DEFAULT_PRIVACY;
|
||||
|
||||
import org.hyperledger.besu.crypto.KeyPair;
|
||||
@@ -249,8 +250,7 @@ public class MultiTenancyAcceptanceTest extends AcceptanceTestBase {
|
||||
final String privateTxRlp = getRLPOutput(validSignedPrivateTransaction).encoded().toHexString();
|
||||
|
||||
retrieveEeaPrivacyGroupEnclaveStub(validSignedPrivateTransaction);
|
||||
sendEnclaveStub(
|
||||
Bytes32.ZERO.toBase64String()); // can be any value, as we are stubbing the enclave
|
||||
sendEnclaveStub(ZERO_32.toBase64String()); // can be any value, as we are stubbing the enclave
|
||||
receiveEnclaveStubEea(validSignedPrivateTransaction);
|
||||
|
||||
final String privateFrom = validSignedPrivateTransaction.getPrivateFrom().toBase64String();
|
||||
|
||||
@@ -94,10 +94,10 @@ public class BesuControllerBuilderTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString());
|
||||
when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO_HASH.toHexString());
|
||||
when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString());
|
||||
when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString());
|
||||
when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString());
|
||||
when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO_HASH.toHexString());
|
||||
when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1));
|
||||
when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions);
|
||||
when(genesisConfigOptions.getThanosBlockNumber()).thenReturn(OptionalLong.empty());
|
||||
|
||||
@@ -104,17 +104,17 @@ public class MergeBesuControllerBuilderTest {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString());
|
||||
when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO_HASH.toHexString());
|
||||
when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString());
|
||||
when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString());
|
||||
when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString());
|
||||
when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO_HASH.toHexString());
|
||||
when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1));
|
||||
when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions);
|
||||
when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions);
|
||||
when(genesisConfigOptions.getTerminalTotalDifficulty())
|
||||
.thenReturn((Optional.of(UInt256.valueOf(100L))));
|
||||
when(genesisConfigOptions.getThanosBlockNumber()).thenReturn(OptionalLong.empty());
|
||||
when(genesisConfigOptions.getTerminalBlockHash()).thenReturn(Optional.of(Hash.ZERO));
|
||||
when(genesisConfigOptions.getTerminalBlockHash()).thenReturn(Optional.of(Hash.ZERO_HASH));
|
||||
when(genesisConfigOptions.getTerminalBlockNumber()).thenReturn(OptionalLong.of(1L));
|
||||
when(storageProvider.createBlockchainStorage(any()))
|
||||
.thenReturn(
|
||||
|
||||
@@ -94,10 +94,10 @@ public class QbftBesuControllerBuilderTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
// besu controller setup
|
||||
when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString());
|
||||
when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO_HASH.toHexString());
|
||||
when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString());
|
||||
when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString());
|
||||
when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString());
|
||||
when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO_HASH.toHexString());
|
||||
when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1));
|
||||
when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions);
|
||||
when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions);
|
||||
|
||||
@@ -90,7 +90,7 @@ public class BlockHeaderValidationRulesetFactory {
|
||||
}
|
||||
|
||||
var mixHashRule =
|
||||
new ConstantFieldValidationRule<>("MixHash", BlockHeader::getMixHash, Hash.ZERO);
|
||||
new ConstantFieldValidationRule<>("MixHash", BlockHeader::getMixHash, Hash.ZERO_HASH);
|
||||
var voteValidationRule = new VoteValidationRule();
|
||||
var cliqueTimestampRule = new TimestampMoreRecentThanParent(secondsBetweenBlocks);
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ public class CliqueBlockCreator extends AbstractBlockCreator {
|
||||
final BlockHeaderBuilder builder =
|
||||
BlockHeaderBuilder.create()
|
||||
.populateFrom(sealableBlockHeader)
|
||||
.mixHash(Hash.ZERO)
|
||||
.mixHash(Hash.ZERO_HASH)
|
||||
.blockHeaderFunctions(blockHeaderFunctions);
|
||||
|
||||
final Optional<ValidatorVote> vote = determineCliqueVote(sealableBlockHeader);
|
||||
|
||||
@@ -128,15 +128,15 @@ public class CliqueBlockHashingTest {
|
||||
LogsBloomFilter.fromHexString(
|
||||
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
|
||||
builder.coinbase(Address.fromHexString("0x0000000000000000000000000000000000000000"));
|
||||
builder.mixHash(Hash.ZERO);
|
||||
builder.mixHash(Hash.ZERO_HASH);
|
||||
builder.nonce(0);
|
||||
builder.number(0);
|
||||
builder.parentHash(Hash.ZERO);
|
||||
builder.receiptsRoot(Hash.ZERO);
|
||||
builder.ommersHash(Hash.ZERO);
|
||||
builder.stateRoot(Hash.ZERO);
|
||||
builder.parentHash(Hash.ZERO_HASH);
|
||||
builder.receiptsRoot(Hash.ZERO_HASH);
|
||||
builder.ommersHash(Hash.ZERO_HASH);
|
||||
builder.stateRoot(Hash.ZERO_HASH);
|
||||
builder.timestamp(1492009146);
|
||||
builder.transactionsRoot(Hash.ZERO);
|
||||
builder.transactionsRoot(Hash.ZERO_HASH);
|
||||
|
||||
builder.blockHeaderFunctions(new CliqueBlockHeaderFunctions());
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ public class NodeCanProduceNextBlockTest {
|
||||
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
|
||||
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
|
||||
|
||||
headerBuilder.parentHash(Hash.ZERO).number(3);
|
||||
headerBuilder.parentHash(Hash.ZERO_HASH).number(3);
|
||||
final BlockHeader parentHeader =
|
||||
TestHelpers.createCliqueSignedBlockHeader(headerBuilder, otherNodeKeyPair, validatorList);
|
||||
|
||||
@@ -262,7 +262,7 @@ public class NodeCanProduceNextBlockTest {
|
||||
final CliqueContext cliqueContext = new CliqueContext(validatorProvider, null, blockInterface);
|
||||
cliqueProtocolContext = new ProtocolContext(blockChain, null, cliqueContext);
|
||||
|
||||
headerBuilder.parentHash(Hash.ZERO).number(3);
|
||||
headerBuilder.parentHash(Hash.ZERO_HASH).number(3);
|
||||
final BlockHeader parentHeader = headerBuilder.buildHeader();
|
||||
assertThat(
|
||||
CliqueHelpers.addressIsAllowedToProduceNextBlock(
|
||||
|
||||
@@ -85,7 +85,8 @@ public class CliqueMiningCoordinatorTest {
|
||||
public void setup() {
|
||||
|
||||
headerTestFixture.number(1);
|
||||
Block genesisBlock = createEmptyBlock(0, Hash.ZERO, proposerKeys); // not normally signed but ok
|
||||
Block genesisBlock =
|
||||
createEmptyBlock(0, Hash.ZERO_HASH, proposerKeys); // not normally signed but ok
|
||||
blockChain = createInMemoryBlockchain(genesisBlock);
|
||||
|
||||
when(validatorProvider.getValidatorsAfterBlock(any())).thenReturn(validators);
|
||||
|
||||
@@ -72,7 +72,7 @@ public class VoteTallyCacheTest extends VoteTallyCacheTestBase {
|
||||
final VoteTallyCache cache =
|
||||
new VoteTallyCache(blockChain, tallyUpdater, new EpochManager(30_000), blockInterface);
|
||||
|
||||
final Block orphanBlock = createEmptyBlock(4, Hash.ZERO);
|
||||
final Block orphanBlock = createEmptyBlock(4, Hash.ZERO_HASH);
|
||||
|
||||
assertThatExceptionOfType(UncheckedExecutionException.class)
|
||||
.isThrownBy(() -> cache.getVoteTallyAfterBlock(orphanBlock.getHeader()))
|
||||
|
||||
@@ -62,7 +62,7 @@ public class VoteTallyCacheTestBase {
|
||||
}
|
||||
headerBuilder.extraData(Bytes.wrap(new byte[32]));
|
||||
|
||||
genesisBlock = createEmptyBlock(0, Hash.ZERO);
|
||||
genesisBlock = createEmptyBlock(0, Hash.ZERO_HASH);
|
||||
|
||||
blockChain = createInMemoryBlockchain(genesisBlock);
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ public class TestContextBuilder {
|
||||
headerTestFixture.ommersHash(Hash.EMPTY_LIST_HASH);
|
||||
headerTestFixture.nonce(0);
|
||||
headerTestFixture.timestamp(0);
|
||||
headerTestFixture.parentHash(Hash.ZERO);
|
||||
headerTestFixture.parentHash(Hash.ZERO_HASH);
|
||||
headerTestFixture.gasLimit(5000);
|
||||
headerTestFixture.coinbase(coinbase);
|
||||
|
||||
|
||||
@@ -119,13 +119,13 @@ public class SpuriousBehaviourTest {
|
||||
peers.getProposer().injectProposal(roundId, proposedBlock);
|
||||
peers.verifyMessagesReceived(expectedPrepare);
|
||||
|
||||
peers.prepareForNonProposing(roundId, Hash.ZERO);
|
||||
peers.prepareForNonProposing(roundId, Hash.ZERO_HASH);
|
||||
peers.verifyNoMessagesReceived();
|
||||
|
||||
peers.prepareForNonProposing(roundId, proposedBlock.getHash());
|
||||
peers.verifyMessagesReceived(expectedCommit);
|
||||
|
||||
peers.prepareForNonProposing(roundId, Hash.ZERO);
|
||||
peers.prepareForNonProposing(roundId, Hash.ZERO_HASH);
|
||||
assertThat(context.getCurrentChainHeight()).isEqualTo(0);
|
||||
|
||||
peers.commitForNonProposing(roundId, proposedBlock.getHash());
|
||||
@@ -145,7 +145,7 @@ public class SpuriousBehaviourTest {
|
||||
|
||||
// nonProposer-2 will generate an invalid seal
|
||||
final ValidatorPeer badSealPeer = peers.getNonProposing(2);
|
||||
final SECPSignature illegalSeal = badSealPeer.getnodeKey().sign(Hash.ZERO);
|
||||
final SECPSignature illegalSeal = badSealPeer.getnodeKey().sign(Hash.ZERO_HASH);
|
||||
|
||||
badSealPeer.injectCommit(roundId, proposedBlock.getHash(), illegalSeal);
|
||||
assertThat(context.getCurrentChainHeight()).isEqualTo(0);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class IbftGetValidatorsByBlockHashTest {
|
||||
|
||||
private static final String ETH_METHOD = "ibft_getValidatorsByBlockHash";
|
||||
private static final String JSON_RPC_VERSION = "2.0";
|
||||
private static final String ZERO_HASH = String.valueOf(Hash.ZERO);
|
||||
private static final String ZERO_HASH = String.valueOf(Hash.ZERO_HASH);
|
||||
|
||||
@Mock private Blockchain blockchain;
|
||||
@Mock private BlockHeader blockHeader;
|
||||
@@ -62,7 +62,7 @@ public class IbftGetValidatorsByBlockHashTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnListOfValidatorsFromBlock() {
|
||||
when(blockchain.getBlockHeader(Hash.ZERO)).thenReturn(Optional.of(blockHeader));
|
||||
when(blockchain.getBlockHeader(Hash.ZERO_HASH)).thenReturn(Optional.of(blockHeader));
|
||||
final List<Address> addresses = Collections.singletonList(Address.ID);
|
||||
final List<String> expectedOutput = Collections.singletonList(Address.ID.toString());
|
||||
when(bftBlockInterface.validatorsInBlock(blockHeader)).thenReturn(addresses);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class IbftControllerTest {
|
||||
when(bftFinalState.getValidators()).thenReturn(ImmutableList.of(validator));
|
||||
|
||||
when(chainHeadBlockHeader.getNumber()).thenReturn(3L);
|
||||
when(chainHeadBlockHeader.getHash()).thenReturn(Hash.ZERO);
|
||||
when(chainHeadBlockHeader.getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
|
||||
when(blockHeightManager.getParentBlockHeader()).thenReturn(chainHeadBlockHeader);
|
||||
when(blockHeightManager.getChainHeight()).thenReturn(4L); // one great than blockchain
|
||||
@@ -203,7 +203,7 @@ public class IbftControllerTest {
|
||||
ibftController.start();
|
||||
long chainHeadHeight = chainHeadBlockHeader.getNumber();
|
||||
when(nextBlock.getNumber()).thenReturn(chainHeadHeight);
|
||||
when(nextBlock.getHash()).thenReturn(Hash.ZERO);
|
||||
when(nextBlock.getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
final NewChainHead sameHeightBlock = new NewChainHead(nextBlock);
|
||||
ibftController.handleNewBlockEvent(sameHeightBlock);
|
||||
verify(blockHeightManagerFactory, times(1)).create(any()); // initial creation
|
||||
|
||||
@@ -72,7 +72,8 @@ public class SignedDataValidatorTest {
|
||||
|
||||
@Test
|
||||
public void receivingAPrepareMessageBeforeProposalFails() {
|
||||
final Prepare prepareMsg = proposerMessageFactory.createPrepare(roundIdentifier, Hash.ZERO);
|
||||
final Prepare prepareMsg =
|
||||
proposerMessageFactory.createPrepare(roundIdentifier, Hash.ZERO_HASH);
|
||||
|
||||
assertThat(validator.validatePrepare(prepareMsg.getSignedPayload())).isFalse();
|
||||
}
|
||||
@@ -81,7 +82,7 @@ public class SignedDataValidatorTest {
|
||||
public void receivingACommitMessageBeforeProposalFails() {
|
||||
final Commit commitMsg =
|
||||
proposerMessageFactory.createCommit(
|
||||
roundIdentifier, Hash.ZERO, proposerKey.sign(block.getHash()));
|
||||
roundIdentifier, Hash.ZERO_HASH, proposerKey.sign(block.getHash()));
|
||||
|
||||
assertThat(validator.validateCommit(commitMsg.getSignedPayload())).isFalse();
|
||||
}
|
||||
|
||||
@@ -645,7 +645,7 @@ public class MergeCoordinator implements MergeMiningCoordinator, BadChainListene
|
||||
header -> {
|
||||
// if block is PoW, return ZERO hash
|
||||
if (header.getDifficulty().greaterThan(Difficulty.ZERO)) {
|
||||
return Hash.ZERO;
|
||||
return Hash.ZERO_HASH;
|
||||
} else {
|
||||
return header.getHash();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package org.hyperledger.besu.consensus.merge.blockcreation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain;
|
||||
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -190,7 +191,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
coordinator.preparePayload(
|
||||
genesisState.getBlock().getHeader(),
|
||||
System.currentTimeMillis() / 1000,
|
||||
Bytes32.ZERO,
|
||||
ZERO_32,
|
||||
suggestedFeeRecipient);
|
||||
|
||||
ArgumentCaptor<Block> block = ArgumentCaptor.forClass(Block.class);
|
||||
@@ -224,7 +225,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
coordinator.preparePayload(
|
||||
genesisState.getBlock().getHeader(),
|
||||
System.currentTimeMillis() / 1000,
|
||||
Bytes32.ZERO,
|
||||
ZERO_32,
|
||||
suggestedFeeRecipient);
|
||||
|
||||
blockCreationTask.get();
|
||||
@@ -266,7 +267,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
coordinator.preparePayload(
|
||||
genesisState.getBlock().getHeader(),
|
||||
System.currentTimeMillis() / 1000,
|
||||
Bytes32.ZERO,
|
||||
ZERO_32,
|
||||
suggestedFeeRecipient);
|
||||
|
||||
blockCreationTask.get();
|
||||
@@ -296,7 +297,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
coordinator.preparePayload(
|
||||
genesisState.getBlock().getHeader(),
|
||||
System.currentTimeMillis() / 1000,
|
||||
Bytes32.ZERO,
|
||||
ZERO_32,
|
||||
suggestedFeeRecipient);
|
||||
|
||||
try {
|
||||
@@ -337,7 +338,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
coordinator.preparePayload(
|
||||
genesisState.getBlock().getHeader(),
|
||||
System.currentTimeMillis() / 1000,
|
||||
Bytes32.ZERO,
|
||||
ZERO_32,
|
||||
suggestedFeeRecipient);
|
||||
|
||||
waitForBlockCreationInProgress.await();
|
||||
@@ -378,13 +379,13 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
|
||||
var payloadId1 =
|
||||
coordinator.preparePayload(
|
||||
genesisState.getBlock().getHeader(), timestamp, Bytes32.ZERO, suggestedFeeRecipient);
|
||||
genesisState.getBlock().getHeader(), timestamp, ZERO_32, suggestedFeeRecipient);
|
||||
|
||||
final CompletableFuture<Void> task1 = blockCreationTask;
|
||||
|
||||
var payloadId2 =
|
||||
coordinator.preparePayload(
|
||||
genesisState.getBlock().getHeader(), timestamp, Bytes32.ZERO, suggestedFeeRecipient);
|
||||
genesisState.getBlock().getHeader(), timestamp, ZERO_32, suggestedFeeRecipient);
|
||||
|
||||
assertThat(payloadId1).isEqualTo(payloadId2);
|
||||
|
||||
@@ -408,7 +409,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
public void childTimestampExceedsParentsFails() {
|
||||
BlockHeader terminalHeader = terminalPowBlock();
|
||||
sendNewPayloadAndForkchoiceUpdate(
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO);
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO_HASH);
|
||||
|
||||
BlockHeader parentHeader = nextBlockHeader(terminalHeader);
|
||||
Block parent = new Block(parentHeader, BlockBody.empty());
|
||||
@@ -440,7 +441,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
public void latestValidAncestorDescendsFromTerminal() {
|
||||
BlockHeader terminalHeader = terminalPowBlock();
|
||||
sendNewPayloadAndForkchoiceUpdate(
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO);
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO_HASH);
|
||||
|
||||
BlockHeader parentHeader = nextBlockHeader(terminalHeader);
|
||||
Block parent = new Block(parentHeader, BlockBody.empty());
|
||||
@@ -448,7 +449,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
// if latest valid ancestor is PoW, then latest valid hash should be Hash.ZERO
|
||||
var lvh = this.coordinator.getLatestValidAncestor(parentHeader);
|
||||
assertThat(lvh).isPresent();
|
||||
assertThat(lvh.get()).isEqualTo(Hash.ZERO);
|
||||
assertThat(lvh.get()).isEqualTo(Hash.ZERO_HASH);
|
||||
|
||||
sendNewPayloadAndForkchoiceUpdate(parent, Optional.empty(), terminalHeader.getHash());
|
||||
BlockHeader childHeader = nextBlockHeader(parentHeader);
|
||||
@@ -465,7 +466,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
public void latestValidAncestorDescendsFromFinalizedBlock() {
|
||||
BlockHeader terminalHeader = terminalPowBlock();
|
||||
sendNewPayloadAndForkchoiceUpdate(
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO);
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO_HASH);
|
||||
|
||||
BlockHeader grandParentHeader = nextBlockHeader(terminalHeader);
|
||||
Block grandParent = new Block(grandParentHeader, BlockBody.empty());
|
||||
@@ -473,7 +474,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
// if latest valid ancestor is PoW, then latest valid hash should be Hash.ZERO
|
||||
var lvh = this.coordinator.getLatestValidAncestor(grandParentHeader);
|
||||
assertThat(lvh).isPresent();
|
||||
assertThat(lvh.get()).isEqualTo(Hash.ZERO);
|
||||
assertThat(lvh.get()).isEqualTo(Hash.ZERO_HASH);
|
||||
|
||||
sendNewPayloadAndForkchoiceUpdate(grandParent, Optional.empty(), terminalHeader.getHash());
|
||||
BlockHeader parentHeader = nextBlockHeader(grandParentHeader);
|
||||
@@ -499,7 +500,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
public void updateForkChoiceShouldPersistFirstFinalizedBlockHash() {
|
||||
BlockHeader terminalHeader = terminalPowBlock();
|
||||
sendNewPayloadAndForkchoiceUpdate(
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO);
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO_HASH);
|
||||
|
||||
BlockHeader firstFinalizedHeader = nextBlockHeader(terminalHeader);
|
||||
Block firstFinalizedBlock = new Block(firstFinalizedHeader, BlockBody.empty());
|
||||
@@ -570,7 +571,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
public void updateForkChoiceShouldPersistLastFinalizedBlockHash() {
|
||||
BlockHeader terminalHeader = terminalPowBlock();
|
||||
sendNewPayloadAndForkchoiceUpdate(
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO);
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO_HASH);
|
||||
|
||||
BlockHeader prevFinalizedHeader = nextBlockHeader(terminalHeader);
|
||||
Block prevFinalizedBlock = new Block(prevFinalizedHeader, BlockBody.empty());
|
||||
@@ -763,7 +764,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
public void invalidPayloadShouldReturnErrorAndUpdateForkchoiceState() {
|
||||
BlockHeader terminalHeader = terminalPowBlock();
|
||||
sendNewPayloadAndForkchoiceUpdate(
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO);
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO_HASH);
|
||||
|
||||
BlockHeader prevFinalizedHeader = nextBlockHeader(terminalHeader);
|
||||
Block prevFinalizedBlock = new Block(prevFinalizedHeader, BlockBody.empty());
|
||||
@@ -787,7 +788,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
lastFinalizedBlock.getHash(),
|
||||
Optional.of(
|
||||
new PayloadAttributes(
|
||||
headBlockHeader.getTimestamp() - 1, Hash.ZERO, Address.ZERO)));
|
||||
headBlockHeader.getTimestamp() - 1, Hash.ZERO_HASH, Address.ZERO)));
|
||||
|
||||
assertThat(res.isValid()).isFalse();
|
||||
assertThat(res.getStatus()).isEqualTo(ForkchoiceResult.Status.INVALID_PAYLOAD_ATTRIBUTES);
|
||||
@@ -802,7 +803,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
public void forkchoiceUpdateShouldIgnoreAncestorOfChainHead() {
|
||||
BlockHeader terminalHeader = terminalPowBlock();
|
||||
sendNewPayloadAndForkchoiceUpdate(
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO);
|
||||
new Block(terminalHeader, BlockBody.empty()), Optional.empty(), Hash.ZERO_HASH);
|
||||
|
||||
BlockHeader parentHeader = nextBlockHeader(terminalHeader);
|
||||
Block parent = new Block(parentHeader, BlockBody.empty());
|
||||
@@ -815,10 +816,11 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
ForkchoiceResult res =
|
||||
coordinator.updateForkChoice(
|
||||
parentHeader,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
terminalHeader.getHash(),
|
||||
Optional.of(
|
||||
new PayloadAttributes(parentHeader.getTimestamp() + 1, Hash.ZERO, Address.ZERO)));
|
||||
new PayloadAttributes(
|
||||
parentHeader.getTimestamp() + 1, Hash.ZERO_HASH, Address.ZERO)));
|
||||
|
||||
assertThat(res.getStatus()).isEqualTo(ForkchoiceResult.Status.IGNORE_UPDATE_TO_OLD_HEAD);
|
||||
assertThat(res.getNewHead().isEmpty()).isTrue();
|
||||
@@ -837,7 +839,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
coordinator
|
||||
.updateForkChoice(
|
||||
block.getHeader(),
|
||||
finalizedHeader.map(BlockHeader::getHash).orElse(Hash.ZERO),
|
||||
finalizedHeader.map(BlockHeader::getHash).orElse(Hash.ZERO_HASH),
|
||||
safeHash,
|
||||
Optional.empty())
|
||||
.isValid())
|
||||
@@ -894,7 +896,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
.number(0L)
|
||||
.difficulty(hasTerminalPoW ? mockTTD : Difficulty.ZERO)
|
||||
.buildHeader());
|
||||
when(terminal.getParentHash()).thenReturn(Hash.ZERO);
|
||||
when(terminal.getParentHash()).thenReturn(Hash.ZERO_HASH);
|
||||
|
||||
// return decreasing numbered blocks:
|
||||
final var invocations = new AtomicLong(chainDepth);
|
||||
@@ -911,7 +913,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
|
||||
|
||||
// mock total difficulty for isTerminalProofOfWorkBlock invocation:
|
||||
when(mockBlockchain.getTotalDifficultyByHash(any())).thenReturn(Optional.of(Difficulty.ZERO));
|
||||
when(mockBlockchain.getBlockHeader(Hash.ZERO)).thenReturn(Optional.empty());
|
||||
when(mockBlockchain.getBlockHeader(Hash.ZERO_HASH)).thenReturn(Optional.empty());
|
||||
|
||||
var mockContext = mock(MergeContext.class);
|
||||
when(mockContext.getTerminalTotalDifficulty()).thenReturn(mockTTD);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class PayloadIdentifierTest {
|
||||
public void conversionCoverage() {
|
||||
var idTest =
|
||||
PayloadIdentifier.forPayloadParams(
|
||||
Hash.ZERO, 1337L, Bytes32.random(), Address.fromHexString("0x42"));
|
||||
Hash.ZERO_HASH, 1337L, Bytes32.random(), Address.fromHexString("0x42"));
|
||||
assertThat(new PayloadIdentifier(idTest.getAsBigInteger().longValue())).isEqualTo(idTest);
|
||||
assertThat(new PayloadIdentifier(idTest.getAsBigInteger().longValue())).isEqualTo(idTest);
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ public class TestContextBuilder {
|
||||
headerTestFixture.ommersHash(Hash.EMPTY_LIST_HASH);
|
||||
headerTestFixture.nonce(0);
|
||||
headerTestFixture.timestamp(0);
|
||||
headerTestFixture.parentHash(Hash.ZERO);
|
||||
headerTestFixture.parentHash(Hash.ZERO_HASH);
|
||||
headerTestFixture.gasLimit(5000);
|
||||
headerTestFixture.coinbase(coinbase);
|
||||
|
||||
|
||||
@@ -120,13 +120,13 @@ public class SpuriousBehaviourTest {
|
||||
peers.getProposer().injectProposal(roundId, proposedBlock);
|
||||
peers.verifyMessagesReceived(expectedPrepare);
|
||||
|
||||
peers.prepareForNonProposing(roundId, Hash.ZERO);
|
||||
peers.prepareForNonProposing(roundId, Hash.ZERO_HASH);
|
||||
peers.verifyNoMessagesReceived();
|
||||
|
||||
peers.prepareForNonProposing(roundId, proposedBlock.getHash());
|
||||
peers.verifyMessagesReceived(expectedCommit);
|
||||
|
||||
peers.prepareForNonProposing(roundId, Hash.ZERO);
|
||||
peers.prepareForNonProposing(roundId, Hash.ZERO_HASH);
|
||||
assertThat(context.getCurrentChainHeight()).isEqualTo(0);
|
||||
|
||||
peers.commitForNonProposing(roundId, proposedBlock);
|
||||
@@ -146,7 +146,7 @@ public class SpuriousBehaviourTest {
|
||||
|
||||
// nonProposer-2 will generate an invalid seal
|
||||
final ValidatorPeer badSealPeer = peers.getNonProposing(2);
|
||||
final SECPSignature illegalSeal = badSealPeer.getnodeKey().sign(Hash.ZERO);
|
||||
final SECPSignature illegalSeal = badSealPeer.getnodeKey().sign(Hash.ZERO_HASH);
|
||||
|
||||
badSealPeer.injectCommit(roundId, proposedBlock.getHash(), illegalSeal);
|
||||
assertThat(context.getCurrentChainHeight()).isEqualTo(0);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class QbftGetValidatorsByBlockHashTest {
|
||||
|
||||
private static final String ETH_METHOD = "qbft_getValidatorsByBlockHash";
|
||||
private static final String JSON_RPC_VERSION = "2.0";
|
||||
private static final String ZERO_HASH = String.valueOf(Hash.ZERO);
|
||||
private static final String ZERO_HASH = String.valueOf(Hash.ZERO_HASH);
|
||||
|
||||
@Mock private Blockchain blockchain;
|
||||
@Mock private BlockHeader blockHeader;
|
||||
@@ -63,7 +63,7 @@ public class QbftGetValidatorsByBlockHashTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnListOfValidatorsFromBlock() {
|
||||
when(blockchain.getBlockHeader(Hash.ZERO)).thenReturn(Optional.of(blockHeader));
|
||||
when(blockchain.getBlockHeader(Hash.ZERO_HASH)).thenReturn(Optional.of(blockHeader));
|
||||
final List<Address> addresses = Collections.singletonList(Address.ID);
|
||||
final List<String> expectedOutput = Collections.singletonList(Address.ID.toString());
|
||||
when(validatorProvider.getValidatorsForBlock(any())).thenReturn(addresses);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class CommitTest {
|
||||
final CommitPayload commitPayload =
|
||||
new CommitPayload(
|
||||
new ConsensusRoundIdentifier(1, 1),
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
SignatureAlgorithmFactory.getInstance()
|
||||
.createSignature(BigInteger.ONE, BigInteger.ONE, (byte) 0));
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PrepareTest {
|
||||
final Address addr = Util.publicKeyToAddress(nodeKey.getPublicKey());
|
||||
|
||||
final PreparePayload preparePayload =
|
||||
new PreparePayload(new ConsensusRoundIdentifier(1, 1), Hash.ZERO);
|
||||
new PreparePayload(new ConsensusRoundIdentifier(1, 1), Hash.ZERO_HASH);
|
||||
|
||||
final SignedData<PreparePayload> signedPreparePayload =
|
||||
SignedData.create(preparePayload, nodeKey.sign(preparePayload.hashForSignature()));
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.consensus.qbft.messagewrappers;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
|
||||
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
|
||||
@@ -38,7 +39,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProposalTest {
|
||||
@@ -46,7 +46,7 @@ public class ProposalTest {
|
||||
|
||||
private static final BftExtraData extraData =
|
||||
new BftExtraData(
|
||||
Bytes32.ZERO, Collections.emptyList(), Optional.empty(), 1, Collections.emptyList());
|
||||
ZERO_32, Collections.emptyList(), Optional.empty(), 1, Collections.emptyList());
|
||||
|
||||
private static final Block BLOCK =
|
||||
new Block(
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.consensus.qbft.messagewrappers;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.consensus.common.bft.BftExtraData;
|
||||
import org.hyperledger.besu.consensus.common.bft.BftExtraDataCodec;
|
||||
@@ -37,14 +38,13 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RoundChangeTest {
|
||||
private static final BftExtraDataCodec bftExtraDataCodec = new QbftExtraDataCodec();
|
||||
private static final BftExtraData extraData =
|
||||
new BftExtraData(
|
||||
Bytes32.ZERO, Collections.emptyList(), Optional.empty(), 1, Collections.emptyList());
|
||||
ZERO_32, Collections.emptyList(), Optional.empty(), 1, Collections.emptyList());
|
||||
|
||||
private static final Block BLOCK =
|
||||
new Block(
|
||||
|
||||
@@ -108,7 +108,7 @@ public class QbftControllerTest {
|
||||
when(bftFinalState.getValidators()).thenReturn(ImmutableList.of(validator));
|
||||
|
||||
when(chainHeadBlockHeader.getNumber()).thenReturn(3L);
|
||||
when(chainHeadBlockHeader.getHash()).thenReturn(Hash.ZERO);
|
||||
when(chainHeadBlockHeader.getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
|
||||
when(blockHeightManager.getParentBlockHeader()).thenReturn(chainHeadBlockHeader);
|
||||
when(blockHeightManager.getChainHeight()).thenReturn(4L); // one great than blockchain
|
||||
@@ -208,7 +208,7 @@ public class QbftControllerTest {
|
||||
qbftController.start();
|
||||
long chainHeadHeight = chainHeadBlockHeader.getNumber();
|
||||
when(nextBlock.getNumber()).thenReturn(chainHeadHeight);
|
||||
when(nextBlock.getHash()).thenReturn(Hash.ZERO);
|
||||
when(nextBlock.getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
final NewChainHead sameHeightBlock = new NewChainHead(nextBlock);
|
||||
qbftController.handleNewBlockEvent(sameHeightBlock);
|
||||
verify(blockHeightManagerFactory, times(1)).create(any()); // initial creation
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ForkingValidatorProviderTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
headerBuilder.extraData(Bytes.wrap(new byte[32]));
|
||||
Block genesisBlock = createEmptyBlock(0, Hash.ZERO);
|
||||
Block genesisBlock = createEmptyBlock(0, Hash.ZERO_HASH);
|
||||
Block block_1 = createEmptyBlock(1, genesisBlock.getHeader().getHash());
|
||||
Block block_2 = createEmptyBlock(2, block_1.getHeader().getHash());
|
||||
genesisHeader = genesisBlock.getHeader();
|
||||
|
||||
@@ -62,7 +62,7 @@ public class TransactionValidatorProviderTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
forksSchedule = new ForksSchedule<>(List.of(createContractForkSpec(0L, CONTRACT_ADDRESS)));
|
||||
genesisBlock = createEmptyBlock(0, Hash.ZERO);
|
||||
genesisBlock = createEmptyBlock(0, Hash.ZERO_HASH);
|
||||
blockChain = createInMemoryBlockchain(genesisBlock);
|
||||
headerBuilder.extraData(Bytes.wrap(new byte[32]));
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright contributors to Hyperledger Besu
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.datatypes;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
|
||||
public class Constants {
|
||||
|
||||
/** Constant representing uninitialized or emptied storage values */
|
||||
public static final Bytes32 ZERO_32 = Bytes32.wrap(new byte[32]);
|
||||
|
||||
private Constants() {
|
||||
// non-instantiable class
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.datatypes;
|
||||
|
||||
import static org.hyperledger.besu.crypto.Hash.keccak256;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
|
||||
@@ -26,7 +27,7 @@ import org.apache.tuweni.bytes.DelegatingBytes32;
|
||||
/** A 32-bytes hash value as used in Ethereum blocks, that is the result of the KEC algorithm. */
|
||||
public class Hash extends DelegatingBytes32 implements org.hyperledger.besu.plugin.data.Hash {
|
||||
|
||||
public static final Hash ZERO = new Hash(Bytes32.ZERO);
|
||||
public static final Hash ZERO_HASH = new Hash(ZERO_32);
|
||||
|
||||
/**
|
||||
* Hash of an RLP encoded trie hash with no content, or
|
||||
|
||||
@@ -47,7 +47,7 @@ public class EthGetBlockByHashIntegrationTest {
|
||||
private final JsonRpcResponseUtils responseUtils = new JsonRpcResponseUtils();
|
||||
private final String ETH_METHOD = "eth_getBlockByHash";
|
||||
private final String JSON_RPC_VERSION = "2.0";
|
||||
private final String ZERO_HASH = String.valueOf(Hash.ZERO);
|
||||
private final String ZERO_HASH = String.valueOf(Hash.ZERO_HASH);
|
||||
|
||||
@BeforeAll
|
||||
public static void setUpOnce() throws Exception {
|
||||
|
||||
@@ -151,7 +151,7 @@ public class PrivGetPrivateTransactionIntegrationTest {
|
||||
final PrivGetPrivateTransaction privGetPrivateTransaction =
|
||||
new PrivGetPrivateTransaction(privacyController, privacyIdProvider);
|
||||
|
||||
final Hash blockHash = Hash.ZERO;
|
||||
final Hash blockHash = Hash.ZERO_HASH;
|
||||
final Transaction pmt = spy(privateMarkerTransaction());
|
||||
when(blockchain.getTransactionByHash(eq(pmt.getHash()))).thenReturn(Optional.of(pmt));
|
||||
when(blockchain.getTransactionLocation(eq(pmt.getHash())))
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.api.graphql.internal.pojoadapter;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Wei;
|
||||
|
||||
@@ -53,6 +55,6 @@ public class EmptyAccountAdapter extends AccountAdapter {
|
||||
|
||||
@Override
|
||||
public Optional<Bytes32> getStorage(final DataFetchingEnvironment environment) {
|
||||
return Optional.of(Bytes32.ZERO);
|
||||
return Optional.of(ZERO_32);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
|
||||
@@ -86,7 +88,7 @@ public class DebugAccountRange implements JsonRpcMethod {
|
||||
.get()
|
||||
.streamAccounts(Bytes32.fromHexStringLenient(addressHash), maxResults + 1)
|
||||
.collect(Collectors.toList());
|
||||
Bytes32 nextKey = Bytes32.ZERO;
|
||||
Bytes32 nextKey = ZERO_32;
|
||||
if (accounts.size() == maxResults + 1) {
|
||||
nextKey = accounts.get(maxResults).getAddressHash();
|
||||
accounts.remove(maxResults);
|
||||
|
||||
@@ -90,7 +90,7 @@ public class EngineExchangeTransitionConfiguration extends ExecutionEngineJsonRp
|
||||
mergeContextOptional
|
||||
.map(c -> c.getTerminalTotalDifficulty())
|
||||
.orElse(FALLBACK_TTD_DEFAULT),
|
||||
maybeTerminalPoWBlockHeader.map(BlockHeader::getHash).orElse(Hash.ZERO),
|
||||
maybeTerminalPoWBlockHeader.map(BlockHeader::getHash).orElse(Hash.ZERO_HASH),
|
||||
maybeTerminalPoWBlockHeader.map(BlockHeader::getNumber).orElse(0L));
|
||||
|
||||
if (!localTransitionConfiguration
|
||||
|
||||
@@ -94,7 +94,7 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod {
|
||||
INVALID,
|
||||
mergeCoordinator
|
||||
.getLatestValidHashOfBadBlock(forkChoice.getHeadBlockHash())
|
||||
.orElse(Hash.ZERO),
|
||||
.orElse(Hash.ZERO_HASH),
|
||||
null,
|
||||
Optional.of(forkChoice.getHeadBlockHash() + " is an invalid block")));
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class EngineForkchoiceUpdated extends ExecutionEngineJsonRpcMethod {
|
||||
requestId,
|
||||
new EngineUpdateForkchoiceResult(
|
||||
INVALID,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
null,
|
||||
Optional.of(newHead.get() + " did not descend from terminal block")));
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class EngineNewPayload extends ExecutionEngineJsonRpcMethod {
|
||||
blockParam,
|
||||
mergeCoordinator
|
||||
.getLatestValidHashOfBadBlock(blockParam.getBlockHash())
|
||||
.orElse(Hash.ZERO),
|
||||
.orElse(Hash.ZERO_HASH),
|
||||
INVALID,
|
||||
"Block already present in bad block manager.");
|
||||
}
|
||||
@@ -204,7 +204,7 @@ public class EngineNewPayload extends ExecutionEngineJsonRpcMethod {
|
||||
return respondWithInvalid(
|
||||
reqId,
|
||||
blockParam,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
INVALID,
|
||||
newBlockHeader.getHash() + " did not descend from terminal block");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.diff;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace;
|
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.Trace;
|
||||
@@ -65,7 +67,7 @@ public class StateDiffGenerator {
|
||||
.entrySet()) { // FIXME cast
|
||||
final Bytes32 newValue = entry.getValue();
|
||||
if (rootAccount == null) {
|
||||
if (!Bytes32.ZERO.equals(newValue)) {
|
||||
if (!ZERO_32.equals(newValue)) {
|
||||
storageDiff.put(
|
||||
entry.getKey().toHexString(), new DiffNode(null, newValue.toHexString()));
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.ethereum.api.query;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.api.query.cache.TransactionLogBloomCacher.BLOCKS_PER_BLOOM_CACHE;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
@@ -186,7 +187,7 @@ public class BlockchainQueries {
|
||||
public Optional<Bytes32> storageAt(
|
||||
final Address address, final Bytes32 storageIndex, final Hash blockHash) {
|
||||
return fromAccount(
|
||||
address, blockHash, account -> account.getStorageValue(storageIndex), Bytes32.ZERO);
|
||||
address, blockHash, account -> account.getStorageValue(storageIndex), ZERO_32);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.hyperledger.besu.ethereum.api.query;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.config.JsonUtil;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
@@ -107,7 +108,7 @@ public class StateBackupService {
|
||||
this.backupDir = backupDir.orElse(this.backupDir);
|
||||
backupStatus.targetBlock = block;
|
||||
backupStatus.compressed = compress;
|
||||
backupStatus.currentAccount = Bytes32.ZERO;
|
||||
backupStatus.currentAccount = ZERO_32;
|
||||
scheduler.scheduleComputationTask(
|
||||
() -> {
|
||||
try {
|
||||
@@ -185,7 +186,7 @@ public class StateBackupService {
|
||||
"Backup Block must be within blockchain");
|
||||
backupStatus.targetBlock = block;
|
||||
backupStatus.compressed = compress;
|
||||
backupStatus.currentAccount = Bytes32.ZERO;
|
||||
backupStatus.currentAccount = ZERO_32;
|
||||
|
||||
backupChainData();
|
||||
backupLeaves();
|
||||
|
||||
@@ -515,8 +515,8 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
|
||||
final String mockBalance = "0x35";
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.accountBalance(eq(address), eq(Hash.ZERO)))
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.accountBalance(eq(address), eq(Hash.ZERO_HASH)))
|
||||
.thenReturn(Optional.of(Wei.fromHexString(mockBalance)));
|
||||
|
||||
final String id = "123";
|
||||
@@ -549,8 +549,8 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
|
||||
final Wei mockBalance = Wei.of(0);
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.accountBalance(eq(address), eq(Hash.ZERO)))
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.accountBalance(eq(address), eq(Hash.ZERO_HASH)))
|
||||
.thenReturn(Optional.of(mockBalance));
|
||||
|
||||
final String id = "123";
|
||||
@@ -1866,8 +1866,8 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
|
||||
final String mockStorage = "0x0000000000000000000000000000000000000000000000000000000000000001";
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.storageAt(eq(address), eq(UInt256.ZERO), eq(Hash.ZERO)))
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.storageAt(eq(address), eq(UInt256.ZERO), eq(Hash.ZERO_HASH)))
|
||||
.thenReturn(Optional.of(UInt256.fromHexString(mockStorage)));
|
||||
|
||||
final String id = "88";
|
||||
@@ -1903,8 +1903,8 @@ public class JsonRpcHttpServiceTest extends JsonRpcHttpServiceTestBase {
|
||||
final String mockStorage = "0x0000000000000000000000000000000000000000000000000000000000000006";
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.storageAt(eq(address), eq(UInt256.ONE), eq(Hash.ZERO)))
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.storageAt(eq(address), eq(UInt256.ONE), eq(Hash.ZERO_HASH)))
|
||||
.thenReturn(Optional.of(UInt256.fromHexString(mockStorage)));
|
||||
|
||||
final String id = "88";
|
||||
|
||||
@@ -304,8 +304,8 @@ public class FilterManagerLogFilterTest {
|
||||
return new LogWithMetadata(
|
||||
0,
|
||||
100L,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
Address.fromHexString("0x0"),
|
||||
Bytes.EMPTY,
|
||||
|
||||
@@ -79,7 +79,8 @@ class DebugAccountAtTest {
|
||||
void testBlockNotFoundResponse() {
|
||||
Mockito.when(blockchainQueries.blockByHash(any())).thenReturn(Optional.empty());
|
||||
|
||||
final Object[] params = new Object[] {Hash.ZERO.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final Object[] params =
|
||||
new Object[] {Hash.ZERO_HASH.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final JsonRpcRequestContext request =
|
||||
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_accountAt", params));
|
||||
final JsonRpcResponse response = debugAccountAt.response(request);
|
||||
@@ -94,7 +95,8 @@ class DebugAccountAtTest {
|
||||
Mockito.when(blockchainQueries.blockByHash(any())).thenReturn(Optional.of(blockWithMetadata));
|
||||
Mockito.when(blockWithMetadata.getTransactions()).thenReturn(Collections.emptyList());
|
||||
|
||||
final Object[] params = new Object[] {Hash.ZERO.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final Object[] params =
|
||||
new Object[] {Hash.ZERO_HASH.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final JsonRpcRequestContext request =
|
||||
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_accountAt", params));
|
||||
final JsonRpcResponse response = debugAccountAt.response(request);
|
||||
@@ -110,7 +112,8 @@ class DebugAccountAtTest {
|
||||
Mockito.when(blockWithMetadata.getTransactions())
|
||||
.thenReturn(Collections.singletonList(transactionWithMetadata));
|
||||
|
||||
final Object[] params = new Object[] {Hash.ZERO.toHexString(), -1, Address.ZERO.toHexString()};
|
||||
final Object[] params =
|
||||
new Object[] {Hash.ZERO_HASH.toHexString(), -1, Address.ZERO.toHexString()};
|
||||
final JsonRpcRequestContext request =
|
||||
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_accountAt", params));
|
||||
final JsonRpcResponse response = debugAccountAt.response(request);
|
||||
@@ -126,7 +129,8 @@ class DebugAccountAtTest {
|
||||
Mockito.when(blockWithMetadata.getTransactions())
|
||||
.thenReturn(Collections.singletonList(transactionWithMetadata));
|
||||
|
||||
final Object[] params = new Object[] {Hash.ZERO.toHexString(), 2, Address.ZERO.toHexString()};
|
||||
final Object[] params =
|
||||
new Object[] {Hash.ZERO_HASH.toHexString(), 2, Address.ZERO.toHexString()};
|
||||
final JsonRpcRequestContext request =
|
||||
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_accountAt", params));
|
||||
final JsonRpcResponse response = debugAccountAt.response(request);
|
||||
@@ -142,7 +146,8 @@ class DebugAccountAtTest {
|
||||
Mockito.when(blockWithMetadata.getTransactions())
|
||||
.thenReturn(Collections.singletonList(transactionWithMetadata));
|
||||
|
||||
final Object[] params = new Object[] {Hash.ZERO.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final Object[] params =
|
||||
new Object[] {Hash.ZERO_HASH.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final JsonRpcRequestContext request =
|
||||
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_accountAt", params));
|
||||
final JsonRpcResponse response = debugAccountAt.response(request);
|
||||
@@ -156,7 +161,8 @@ class DebugAccountAtTest {
|
||||
void testNoAccountFoundResponse() {
|
||||
setupMockTransaction();
|
||||
|
||||
final Object[] params = new Object[] {Hash.ZERO.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final Object[] params =
|
||||
new Object[] {Hash.ZERO_HASH.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final JsonRpcRequestContext request =
|
||||
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_accountAt", params));
|
||||
|
||||
@@ -185,7 +191,8 @@ class DebugAccountAtTest {
|
||||
Mockito.when(account.getBalance()).thenReturn(balance);
|
||||
Mockito.when(account.getCodeHash()).thenReturn(codeHash);
|
||||
|
||||
final Object[] params = new Object[] {Hash.ZERO.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final Object[] params =
|
||||
new Object[] {Hash.ZERO_HASH.toHexString(), 0, Address.ZERO.toHexString()};
|
||||
final JsonRpcRequestContext request =
|
||||
new JsonRpcRequestContext(new JsonRpcRequest("2.0", "debug_accountAt", params));
|
||||
final JsonRpcSuccessResponse response =
|
||||
@@ -215,6 +222,6 @@ class DebugAccountAtTest {
|
||||
.thenReturn(Collections.singletonList(transactionTrace));
|
||||
Mockito.when(transactionTrace.getTransaction()).thenReturn(transaction);
|
||||
Mockito.when(transactionWithMetadata.getTransaction()).thenReturn(transaction);
|
||||
Mockito.when(transaction.getHash()).thenReturn(Hash.ZERO);
|
||||
Mockito.when(transaction.getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +81,8 @@ public class EthCallTest {
|
||||
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO))
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO_HASH))
|
||||
.thenReturn(Optional.of(mock(BlockHeader.class)));
|
||||
when(transactionSimulator.process(any(), any(), any(), any())).thenReturn(Optional.empty());
|
||||
|
||||
@@ -103,8 +103,8 @@ public class EthCallTest {
|
||||
mockTransactionProcessorSuccessResult(Bytes.of());
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO))
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO_HASH))
|
||||
.thenReturn(Optional.of(mock(BlockHeader.class)));
|
||||
|
||||
final JsonRpcResponse response = method.response(request);
|
||||
@@ -121,8 +121,8 @@ public class EthCallTest {
|
||||
mockTransactionProcessorSuccessResult(Bytes.of(1));
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO))
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO_HASH))
|
||||
.thenReturn(Optional.of(mock(BlockHeader.class)));
|
||||
|
||||
final JsonRpcResponse response = method.response(request);
|
||||
@@ -136,27 +136,27 @@ public class EthCallTest {
|
||||
final JsonRpcRequestContext request = ethCallRequest(callParameter(), "latest");
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO))
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO_HASH))
|
||||
.thenReturn(Optional.of(mock(BlockHeader.class)));
|
||||
when(transactionSimulator.process(any(), any(), any(), any())).thenReturn(Optional.empty());
|
||||
|
||||
method.response(request);
|
||||
|
||||
verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO));
|
||||
verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO_HASH));
|
||||
verify(transactionSimulator).process(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseCorrectBlockNumberWhenEarliest() {
|
||||
final JsonRpcRequestContext request = ethCallRequest(callParameter(), "earliest");
|
||||
when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.ZERO));
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO))
|
||||
when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.ZERO_HASH));
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO_HASH))
|
||||
.thenReturn(Optional.of(mock(BlockHeader.class)));
|
||||
when(transactionSimulator.process(any(), any(), any(), any())).thenReturn(Optional.empty());
|
||||
method.response(request);
|
||||
|
||||
verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO));
|
||||
verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO_HASH));
|
||||
verify(transactionSimulator).process(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@@ -164,14 +164,14 @@ public class EthCallTest {
|
||||
public void shouldUseCorrectBlockNumberWhenSpecified() {
|
||||
final JsonRpcRequestContext request = ethCallRequest(callParameter(), Quantity.create(13L));
|
||||
when(blockchainQueries.headBlockNumber()).thenReturn(14L);
|
||||
when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.ZERO));
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO))
|
||||
when(blockchainQueries.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(Hash.ZERO_HASH));
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO_HASH))
|
||||
.thenReturn(Optional.of(mock(BlockHeader.class)));
|
||||
when(transactionSimulator.process(any(), any(), any(), any())).thenReturn(Optional.empty());
|
||||
|
||||
method.response(request);
|
||||
|
||||
verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO));
|
||||
verify(blockchainQueries).getBlockHeaderByHash(eq(Hash.ZERO_HASH));
|
||||
verify(transactionSimulator).process(any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@@ -233,8 +233,9 @@ public class EthCallTest {
|
||||
when(blockHeader.getBaseFee()).thenReturn(baseFee);
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)).thenReturn(Optional.of(blockHeader));
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO_HASH))
|
||||
.thenReturn(Optional.of(blockHeader));
|
||||
|
||||
method.response(request);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class EthGetBlockByHashTest {
|
||||
private EthGetBlockByHash method;
|
||||
private final String JSON_RPC_VERSION = "2.0";
|
||||
private final String ETH_METHOD = "eth_getBlockByHash";
|
||||
private final String ZERO_HASH = String.valueOf(Hash.ZERO);
|
||||
private final String ZERO_HASH = String.valueOf(Hash.ZERO_HASH);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@@ -109,10 +109,12 @@ public class EthGetFilterChangesTest {
|
||||
@Test
|
||||
public void shouldReturnHashesWhenFilterManagerFindsBlockFilterWithHashes() {
|
||||
final JsonRpcRequestContext request = requestWithParams("0x1");
|
||||
when(filterManager.blockChanges("0x1")).thenReturn(Lists.newArrayList(Hash.ZERO));
|
||||
when(filterManager.blockChanges("0x1")).thenReturn(Lists.newArrayList(Hash.ZERO_HASH));
|
||||
|
||||
final List<String> expectedHashes =
|
||||
Lists.newArrayList(Hash.ZERO).stream().map(Hash::toString).collect(Collectors.toList());
|
||||
Lists.newArrayList(Hash.ZERO_HASH).stream()
|
||||
.map(Hash::toString)
|
||||
.collect(Collectors.toList());
|
||||
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, expectedHashes);
|
||||
|
||||
final JsonRpcResponse response = method.response(request);
|
||||
@@ -136,10 +138,13 @@ public class EthGetFilterChangesTest {
|
||||
public void shouldReturnHashesWhenFilterManagerFindsPendingTransactionFilterWithHashes() {
|
||||
final JsonRpcRequestContext request = requestWithParams("0x1");
|
||||
when(filterManager.blockChanges(anyString())).thenReturn(null);
|
||||
when(filterManager.pendingTransactionChanges("0x1")).thenReturn(Lists.newArrayList(Hash.ZERO));
|
||||
when(filterManager.pendingTransactionChanges("0x1"))
|
||||
.thenReturn(Lists.newArrayList(Hash.ZERO_HASH));
|
||||
|
||||
final List<String> expectedHashes =
|
||||
Lists.newArrayList(Hash.ZERO).stream().map(Hash::toString).collect(Collectors.toList());
|
||||
Lists.newArrayList(Hash.ZERO_HASH).stream()
|
||||
.map(Hash::toString)
|
||||
.collect(Collectors.toList());
|
||||
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, expectedHashes);
|
||||
|
||||
final JsonRpcResponse response = method.response(request);
|
||||
@@ -198,8 +203,8 @@ public class EthGetFilterChangesTest {
|
||||
return new LogWithMetadata(
|
||||
0,
|
||||
100L,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
Address.fromHexString("0x0"),
|
||||
Bytes.EMPTY,
|
||||
|
||||
@@ -132,8 +132,8 @@ public class EthGetFilterLogsTest {
|
||||
new LogWithMetadata(
|
||||
0,
|
||||
100L,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
Address.fromHexString("0x0"),
|
||||
Bytes.EMPTY,
|
||||
|
||||
@@ -86,7 +86,7 @@ class EthGetProofTest {
|
||||
final JsonRpcRequestContext request = requestWithParams(null, null, "latest");
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
|
||||
Assertions.assertThatThrownBy(() -> method.response(request))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
@@ -98,7 +98,7 @@ class EthGetProofTest {
|
||||
final JsonRpcRequestContext request = requestWithParams(address.toString(), null, "latest");
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
|
||||
Assertions.assertThatThrownBy(() -> method.response(request))
|
||||
.isInstanceOf(InvalidJsonRpcParameters.class)
|
||||
|
||||
@@ -134,7 +134,7 @@ public class EthGetTransactionByHashTest {
|
||||
org.hyperledger.besu.ethereum.core.Transaction.readFrom(
|
||||
Bytes.fromHexString(VALID_TRANSACTION));
|
||||
final TransactionWithMetadata transactionWithMetadata =
|
||||
new TransactionWithMetadata(transaction, 1, Optional.empty(), Hash.ZERO, 0);
|
||||
new TransactionWithMetadata(transaction, 1, Optional.empty(), Hash.ZERO_HASH, 0);
|
||||
|
||||
when(pendingTransactions.getTransactionByHash(eq(transaction.getHash())))
|
||||
.thenReturn(Optional.empty());
|
||||
|
||||
@@ -150,7 +150,8 @@ class EthGetTransactionCountTest {
|
||||
private void mockGetTransactionCount(final Address address, final long transactionCount) {
|
||||
when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
|
||||
when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
|
||||
when(blockchainQueries.getTransactionCount(address, Hash.ZERO)).thenReturn(transactionCount);
|
||||
when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO_HASH);
|
||||
when(blockchainQueries.getTransactionCount(address, Hash.ZERO_HASH))
|
||||
.thenReturn(transactionCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class EthGetUncleByBlockHashAndIndexTest {
|
||||
private final TransactionTestFixture transactionTestFixture = new TransactionTestFixture();
|
||||
|
||||
private EthGetUncleByBlockHashAndIndex method;
|
||||
private final Hash zeroHash = Hash.ZERO;
|
||||
private final Hash zeroHash = Hash.ZERO_HASH;
|
||||
|
||||
@Mock private BlockchainQueries blockchainQueries;
|
||||
|
||||
@@ -172,7 +172,7 @@ public class EthGetUncleByBlockHashAndIndexTest {
|
||||
}
|
||||
|
||||
final List<Hash> ommers = new ArrayList<>();
|
||||
ommers.add(Hash.ZERO);
|
||||
ommers.add(Hash.ZERO_HASH);
|
||||
|
||||
return new BlockWithMetadata<>(header, transactions, ommers, header.getDifficulty(), 0);
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class EthGetUncleByBlockNumberAndIndexTest {
|
||||
}
|
||||
|
||||
final List<Hash> ommers = new ArrayList<>();
|
||||
ommers.add(Hash.ZERO);
|
||||
ommers.add(Hash.ZERO_HASH);
|
||||
|
||||
return new BlockWithMetadata<>(header, transactions, ommers, header.getDifficulty(), 0);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class EthNewFilterTest {
|
||||
null,
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
null,
|
||||
null);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -48,7 +49,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.vertx.core.Vertx;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.apache.tuweni.units.bigints.UInt256;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -92,7 +92,7 @@ public class EngineExchangeTransitionConfigurationTest {
|
||||
var response =
|
||||
resp(
|
||||
new EngineExchangeTransitionConfigurationParameter(
|
||||
"0", Hash.ZERO.toHexString(), new UnsignedLongParameter(1L)));
|
||||
"0", Hash.ZERO_HASH.toHexString(), new UnsignedLongParameter(1L)));
|
||||
|
||||
var result = fromSuccessResp(response);
|
||||
assertThat(result.getTerminalTotalDifficulty()).isEqualTo(Difficulty.of(1337L));
|
||||
@@ -109,11 +109,11 @@ public class EngineExchangeTransitionConfigurationTest {
|
||||
var response =
|
||||
resp(
|
||||
new EngineExchangeTransitionConfigurationParameter(
|
||||
"0", Hash.ZERO.toHexString(), new UnsignedLongParameter(0L)));
|
||||
"0", Hash.ZERO_HASH.toHexString(), new UnsignedLongParameter(0L)));
|
||||
|
||||
var result = fromSuccessResp(response);
|
||||
assertThat(result.getTerminalTotalDifficulty()).isEqualTo(Difficulty.of(1337L));
|
||||
assertThat(result.getTerminalBlockHash()).isEqualTo(Hash.ZERO);
|
||||
assertThat(result.getTerminalBlockHash()).isEqualTo(Hash.ZERO_HASH);
|
||||
assertThat(result.getTerminalBlockNumber()).isEqualTo(0L);
|
||||
verify(engineCallListener, times(1)).executionEngineCalled();
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class EngineExchangeTransitionConfigurationTest {
|
||||
var response =
|
||||
resp(
|
||||
new EngineExchangeTransitionConfigurationParameter(
|
||||
"0", Hash.ZERO.toHexString(), new UnsignedLongParameter(0L)));
|
||||
"0", Hash.ZERO_HASH.toHexString(), new UnsignedLongParameter(0L)));
|
||||
|
||||
var result = fromSuccessResp(response);
|
||||
assertThat(result.getTerminalTotalDifficulty())
|
||||
@@ -132,7 +132,7 @@ public class EngineExchangeTransitionConfigurationTest {
|
||||
new BigInteger(
|
||||
"115792089237316195423570985008687907853269984665640564039457584007913129638912",
|
||||
10)));
|
||||
assertThat(result.getTerminalBlockHash()).isEqualTo(Hash.ZERO);
|
||||
assertThat(result.getTerminalBlockHash()).isEqualTo(Hash.ZERO_HASH);
|
||||
assertThat(result.getTerminalBlockNumber()).isEqualTo(0L);
|
||||
verify(engineCallListener, times(1)).executionEngineCalled();
|
||||
}
|
||||
@@ -181,11 +181,11 @@ public class EngineExchangeTransitionConfigurationTest {
|
||||
public void shouldAlwaysReturnResultsInHex() throws JsonProcessingException {
|
||||
var mapper = new ObjectMapper();
|
||||
var mockResult =
|
||||
new EngineExchangeTransitionConfigurationResult(Difficulty.ZERO, Hash.ZERO, 0L);
|
||||
new EngineExchangeTransitionConfigurationResult(Difficulty.ZERO, Hash.ZERO_HASH, 0L);
|
||||
|
||||
assertThat(mockResult.getTerminalBlockNumberAsString()).isEqualTo("0x0");
|
||||
assertThat(mockResult.getTerminalTotalDifficultyAsString()).isEqualTo("0x0");
|
||||
assertThat(mockResult.getTerminalBlockHashAsString()).isEqualTo(Hash.ZERO.toHexString());
|
||||
assertThat(mockResult.getTerminalBlockHashAsString()).isEqualTo(Hash.ZERO_HASH.toHexString());
|
||||
|
||||
String json = mapper.writeValueAsString(mockResult);
|
||||
var res = mapper.readValue(json, Map.class);
|
||||
@@ -199,11 +199,11 @@ public class EngineExchangeTransitionConfigurationTest {
|
||||
public void shouldStripLeadingZeros() throws JsonProcessingException {
|
||||
var mapper = new ObjectMapper();
|
||||
var mockResult =
|
||||
new EngineExchangeTransitionConfigurationResult(Difficulty.ZERO, Hash.ZERO, 100);
|
||||
new EngineExchangeTransitionConfigurationResult(Difficulty.ZERO, Hash.ZERO_HASH, 100);
|
||||
|
||||
assertThat(mockResult.getTerminalBlockNumberAsString()).isEqualTo("0x64");
|
||||
assertThat(mockResult.getTerminalTotalDifficultyAsString()).isEqualTo("0x0");
|
||||
assertThat(mockResult.getTerminalBlockHashAsString()).isEqualTo(Hash.ZERO.toHexString());
|
||||
assertThat(mockResult.getTerminalBlockHashAsString()).isEqualTo(Hash.ZERO_HASH.toHexString());
|
||||
|
||||
String json = mapper.writeValueAsString(mockResult);
|
||||
var res = mapper.readValue(json, Map.class);
|
||||
@@ -247,7 +247,7 @@ public class EngineExchangeTransitionConfigurationTest {
|
||||
0,
|
||||
Bytes.EMPTY,
|
||||
Wei.ZERO,
|
||||
Bytes32.ZERO,
|
||||
ZERO_32,
|
||||
0,
|
||||
new BlockHeaderFunctions() {
|
||||
@Override
|
||||
|
||||
@@ -115,11 +115,11 @@ public class EngineForkchoiceUpdatedTest {
|
||||
.thenReturn(Optional.of(mockHeader));
|
||||
when(mergeCoordinator.latestValidAncestorDescendsFromTerminal(mockHeader)).thenReturn(false);
|
||||
assertSuccessWithPayloadForForkchoiceResult(
|
||||
new EngineForkchoiceUpdatedParameter(mockHeader.getHash(), Hash.ZERO, Hash.ZERO),
|
||||
new EngineForkchoiceUpdatedParameter(mockHeader.getHash(), Hash.ZERO_HASH, Hash.ZERO_HASH),
|
||||
Optional.empty(),
|
||||
mock(ForkchoiceResult.class),
|
||||
INVALID,
|
||||
Optional.of(Hash.ZERO));
|
||||
Optional.of(Hash.ZERO_HASH));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,7 +132,7 @@ public class EngineForkchoiceUpdatedTest {
|
||||
|
||||
assertSuccessWithPayloadForForkchoiceResult(
|
||||
new EngineForkchoiceUpdatedParameter(
|
||||
mockHeader.getHash(), Hash.ZERO, mockHeader.getParentHash()),
|
||||
mockHeader.getHash(), Hash.ZERO_HASH, mockHeader.getParentHash()),
|
||||
Optional.empty(),
|
||||
mock(ForkchoiceResult.class),
|
||||
INVALID,
|
||||
@@ -153,7 +153,7 @@ public class EngineForkchoiceUpdatedTest {
|
||||
when(mergeCoordinator.latestValidAncestorDescendsFromTerminal(mockHeader)).thenReturn(true);
|
||||
|
||||
assertSuccessWithPayloadForForkchoiceResult(
|
||||
new EngineForkchoiceUpdatedParameter(mockHeader.getHash(), Hash.ZERO, Hash.ZERO),
|
||||
new EngineForkchoiceUpdatedParameter(mockHeader.getHash(), Hash.ZERO_HASH, Hash.ZERO_HASH),
|
||||
Optional.empty(),
|
||||
ForkchoiceResult.withResult(Optional.empty(), Optional.of(mockHeader)),
|
||||
VALID);
|
||||
@@ -208,7 +208,8 @@ public class EngineForkchoiceUpdatedTest {
|
||||
when(mergeCoordinator.isDescendantOf(any(), any())).thenReturn(true);
|
||||
|
||||
assertSuccessWithPayloadForForkchoiceResult(
|
||||
new EngineForkchoiceUpdatedParameter(mockHeader.getHash(), Hash.ZERO, mockParent.getHash()),
|
||||
new EngineForkchoiceUpdatedParameter(
|
||||
mockHeader.getHash(), Hash.ZERO_HASH, mockParent.getHash()),
|
||||
Optional.empty(),
|
||||
ForkchoiceResult.withResult(Optional.of(mockParent), Optional.of(mockHeader)),
|
||||
VALID);
|
||||
@@ -239,7 +240,8 @@ public class EngineForkchoiceUpdatedTest {
|
||||
|
||||
var res =
|
||||
assertSuccessWithPayloadForForkchoiceResult(
|
||||
new EngineForkchoiceUpdatedParameter(mockHeader.getHash(), Hash.ZERO, Hash.ZERO),
|
||||
new EngineForkchoiceUpdatedParameter(
|
||||
mockHeader.getHash(), Hash.ZERO_HASH, Hash.ZERO_HASH),
|
||||
Optional.of(payloadParams),
|
||||
ForkchoiceResult.withResult(Optional.empty(), Optional.of(mockHeader)),
|
||||
VALID);
|
||||
@@ -307,7 +309,7 @@ public class EngineForkchoiceUpdatedTest {
|
||||
var resp =
|
||||
resp(
|
||||
new EngineForkchoiceUpdatedParameter(
|
||||
newHead.getBlockHash(), parent.getBlockHash(), Hash.ZERO),
|
||||
newHead.getBlockHash(), parent.getBlockHash(), Hash.ZERO_HASH),
|
||||
Optional.empty());
|
||||
|
||||
assertInvalidForkchoiceState(resp);
|
||||
@@ -415,7 +417,7 @@ public class EngineForkchoiceUpdatedTest {
|
||||
(JsonRpcSuccessResponse)
|
||||
resp(
|
||||
new EngineForkchoiceUpdatedParameter(
|
||||
mockHeader.getBlockHash(), Hash.ZERO, Hash.ZERO),
|
||||
mockHeader.getBlockHash(), Hash.ZERO_HASH, Hash.ZERO_HASH),
|
||||
Optional.of(payloadParams));
|
||||
|
||||
var forkchoiceRes = (EngineUpdateForkchoiceResult) resp.getResult();
|
||||
|
||||
@@ -58,7 +58,7 @@ public class EngineGetPayloadTest {
|
||||
private static final BlockResultFactory factory = new BlockResultFactory();
|
||||
private static final PayloadIdentifier mockPid =
|
||||
PayloadIdentifier.forPayloadParams(
|
||||
Hash.ZERO, 1337L, Bytes32.random(), Address.fromHexString("0x42"));
|
||||
Hash.ZERO_HASH, 1337L, Bytes32.random(), Address.fromHexString("0x42"));
|
||||
private static final BlockHeader mockHeader =
|
||||
new BlockHeaderTestFixture().prevRandao(Bytes32.random()).buildHeader();
|
||||
private static final Block mockBlock =
|
||||
@@ -108,7 +108,7 @@ public class EngineGetPayloadTest {
|
||||
var resp =
|
||||
resp(
|
||||
PayloadIdentifier.forPayloadParams(
|
||||
Hash.ZERO, 0L, Bytes32.random(), Address.fromHexString("0x42")));
|
||||
Hash.ZERO_HASH, 0L, Bytes32.random(), Address.fromHexString("0x42")));
|
||||
assertThat(resp).isInstanceOf(JsonRpcErrorResponse.class);
|
||||
verify(engineCallListener, times(1)).executionEngineCalled();
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public class EngineNewPayloadTest {
|
||||
var resp = resp(mockPayload(mockHeader, Collections.emptyList()));
|
||||
|
||||
EnginePayloadStatusResult res = fromSuccessResp(resp);
|
||||
assertThat(res.getLatestValidHash()).isEqualTo(Optional.of(Hash.ZERO));
|
||||
assertThat(res.getLatestValidHash()).isEqualTo(Optional.of(Hash.ZERO_HASH));
|
||||
assertThat(res.getStatusAsString()).isEqualTo(INVALID.name());
|
||||
verify(mergeCoordinator, atLeastOnce()).addBadBlock(any());
|
||||
verify(engineCallListener, times(1)).executionEngineCalled();
|
||||
@@ -364,7 +364,7 @@ public class EngineNewPayloadTest {
|
||||
var resp = resp(mockPayload(mockHeader, Collections.emptyList()));
|
||||
|
||||
EnginePayloadStatusResult res = fromSuccessResp(resp);
|
||||
assertThat(res.getLatestValidHash()).contains(Hash.ZERO);
|
||||
assertThat(res.getLatestValidHash()).contains(Hash.ZERO_HASH);
|
||||
assertThat(res.getStatusAsString()).isEqualTo(INVALID.name());
|
||||
assertThat(res.getError()).isEqualTo("Block already present in bad block manager.");
|
||||
verify(engineCallListener, times(1)).executionEngineCalled();
|
||||
|
||||
@@ -165,7 +165,7 @@ public class FilterParameterTest {
|
||||
+ ","
|
||||
+ TOPICS_TWO_THREE_ARRAY
|
||||
+ "], \"blockHash\": \""
|
||||
+ Hash.ZERO
|
||||
+ Hash.ZERO_HASH
|
||||
+ "\"}],\"id\":1}";
|
||||
|
||||
final String jsonUsingAlias =
|
||||
@@ -176,7 +176,7 @@ public class FilterParameterTest {
|
||||
+ ","
|
||||
+ TOPICS_TWO_THREE_ARRAY
|
||||
+ "], \"blockhash\": \""
|
||||
+ Hash.ZERO
|
||||
+ Hash.ZERO_HASH
|
||||
+ "\"}],\"id\":1}";
|
||||
|
||||
final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json));
|
||||
@@ -204,7 +204,7 @@ public class FilterParameterTest {
|
||||
+ ","
|
||||
+ TOPICS_TWO_THREE_ARRAY
|
||||
+ "], \"blockHash\": \""
|
||||
+ Hash.ZERO
|
||||
+ Hash.ZERO_HASH
|
||||
+ "\"}],\"id\":1}";
|
||||
|
||||
final String jsonUsingAlias =
|
||||
@@ -215,7 +215,7 @@ public class FilterParameterTest {
|
||||
+ ","
|
||||
+ TOPICS_TWO_THREE_ARRAY
|
||||
+ "], \"blockhash\": \""
|
||||
+ Hash.ZERO
|
||||
+ Hash.ZERO_HASH
|
||||
+ "\"}],\"id\":1}";
|
||||
|
||||
final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json));
|
||||
@@ -228,7 +228,8 @@ public class FilterParameterTest {
|
||||
requestUsingAlias.getRequiredParameter(0, FilterParameter.class);
|
||||
|
||||
assertThat(parsedFilterParameterUsingAlias.isValid()).isTrue();
|
||||
assertThat(parsedFilterParameterUsingAlias.getBlockHash()).isEqualTo(Optional.of(Hash.ZERO));
|
||||
assertThat(parsedFilterParameterUsingAlias.getBlockHash())
|
||||
.isEqualTo(Optional.of(Hash.ZERO_HASH));
|
||||
|
||||
// blockhash and blockHash should end up the same
|
||||
assertThat(parsedFilterParameter)
|
||||
|
||||
@@ -48,7 +48,7 @@ public class PrivGetCodeTest {
|
||||
@Mock private BlockchainQueries mockBlockchainQueries;
|
||||
@Mock private PrivacyIdProvider privacyIdProvider;
|
||||
|
||||
private final Hash latestBlockHash = Hash.ZERO;
|
||||
private final Hash latestBlockHash = Hash.ZERO_HASH;
|
||||
private final String enclavePublicKey = "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=";
|
||||
private final String privacyGroupId = "Ko2bVqD+nNlNYL5EE7y3IdOnviftjiizpjRt+HTuFBs=";
|
||||
private final Address contractAddress =
|
||||
|
||||
@@ -176,8 +176,8 @@ public class PrivGetFilterChangesTest {
|
||||
return new LogWithMetadata(
|
||||
0,
|
||||
100L,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
Address.fromHexString("0x0"),
|
||||
Bytes.EMPTY,
|
||||
|
||||
@@ -145,8 +145,8 @@ public class PrivGetFilterLogsTest {
|
||||
return new LogWithMetadata(
|
||||
0,
|
||||
100L,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
Address.fromHexString("0x0"),
|
||||
Bytes.EMPTY,
|
||||
|
||||
@@ -109,7 +109,7 @@ public class PrivGetLogsTest {
|
||||
null,
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
null,
|
||||
null);
|
||||
|
||||
@@ -218,8 +218,8 @@ public class PrivGetLogsTest {
|
||||
return new LogWithMetadata(
|
||||
logIndex,
|
||||
100L,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
Address.fromHexString("0x0"),
|
||||
Bytes.EMPTY,
|
||||
|
||||
@@ -100,7 +100,7 @@ public class PrivNewFilterTest {
|
||||
null,
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
null,
|
||||
null);
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ public class TransactionTracerTest {
|
||||
when(blockHeader.getNumber()).thenReturn(12L);
|
||||
when(blockHeader.getHash()).thenReturn(blockHash);
|
||||
when(blockHeader.getParentHash()).thenReturn(previousBlockHash);
|
||||
when(previousBlockHeader.getStateRoot()).thenReturn(Hash.ZERO);
|
||||
when(worldStateArchive.getMutable(Hash.ZERO, null, false))
|
||||
when(previousBlockHeader.getStateRoot()).thenReturn(Hash.ZERO_HASH);
|
||||
when(worldStateArchive.getMutable(Hash.ZERO_HASH, null, false))
|
||||
.thenReturn(Optional.of(mutableWorldState));
|
||||
when(protocolSchedule.getByBlockNumber(12)).thenReturn(protocolSpec);
|
||||
when(protocolSpec.getTransactionProcessor()).thenReturn(transactionProcessor);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class TransactionCompleteResultTest {
|
||||
.createTransaction(gen.generateKeyPair()),
|
||||
0L,
|
||||
Optional.of(Wei.of(7L)),
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
0));
|
||||
|
||||
assertThat(zeroPriorityFeeTx.getMaxFeePerGas()).isEqualTo("0x1");
|
||||
@@ -59,7 +59,8 @@ public class TransactionCompleteResultTest {
|
||||
final Transaction transaction = gen.transaction(TransactionType.EIP1559);
|
||||
TransactionCompleteResult tcr =
|
||||
new TransactionCompleteResult(
|
||||
new TransactionWithMetadata(transaction, 0L, Optional.of(Wei.of(7L)), Hash.ZERO, 0));
|
||||
new TransactionWithMetadata(
|
||||
transaction, 0L, Optional.of(Wei.of(7L)), Hash.ZERO_HASH, 0));
|
||||
assertThat(tcr.getMaxFeePerGas()).isNotEmpty();
|
||||
assertThat(tcr.getMaxPriorityFeePerGas()).isNotEmpty();
|
||||
assertThat(tcr.getGasPrice()).isNotEmpty();
|
||||
@@ -73,7 +74,8 @@ public class TransactionCompleteResultTest {
|
||||
final Transaction transaction = gen.transaction(TransactionType.FRONTIER);
|
||||
TransactionCompleteResult tcr =
|
||||
new TransactionCompleteResult(
|
||||
new TransactionWithMetadata(transaction, 0L, Optional.of(Wei.of(7L)), Hash.ZERO, 0));
|
||||
new TransactionWithMetadata(
|
||||
transaction, 0L, Optional.of(Wei.of(7L)), Hash.ZERO_HASH, 0));
|
||||
assertThat(tcr.getMaxFeePerGas()).isNull();
|
||||
assertThat(tcr.getMaxPriorityFeePerGas()).isNull();
|
||||
assertThat(tcr.getGasPrice()).isNotEmpty();
|
||||
@@ -87,7 +89,7 @@ public class TransactionCompleteResultTest {
|
||||
final Transaction transaction = gen.transaction(TransactionType.FRONTIER);
|
||||
TransactionCompleteResult tcr =
|
||||
new TransactionCompleteResult(
|
||||
new TransactionWithMetadata(transaction, 0L, Optional.empty(), Hash.ZERO, 0));
|
||||
new TransactionWithMetadata(transaction, 0L, Optional.empty(), Hash.ZERO_HASH, 0));
|
||||
assertThat(tcr.getMaxFeePerGas()).isNull();
|
||||
assertThat(tcr.getMaxPriorityFeePerGas()).isNull();
|
||||
assertThat(tcr.getGasPrice()).isNotEmpty();
|
||||
|
||||
@@ -454,8 +454,8 @@ public class LogsSubscriptionServiceTest {
|
||||
return new LogWithMetadata(
|
||||
0,
|
||||
100L,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
Address.fromHexString("0x0"),
|
||||
Bytes.EMPTY,
|
||||
|
||||
@@ -359,7 +359,7 @@ public class BlockchainQueriesTest {
|
||||
final BlockchainWithData data = setupBlockchain(3);
|
||||
final BlockchainQueries queries = data.blockchainQueries;
|
||||
List<LogWithMetadata> logs =
|
||||
queries.matchingLogs(Hash.ZERO, new LogsQuery.Builder().build(), () -> true);
|
||||
queries.matchingLogs(Hash.ZERO_HASH, new LogsQuery.Builder().build(), () -> true);
|
||||
assertThat(logs).isEmpty();
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ public class BlockchainQueriesTest {
|
||||
final BlockchainWithData data = setupBlockchain(3);
|
||||
final BlockchainQueries queries = data.blockchainQueries;
|
||||
|
||||
final Optional<BlockHeader> ommerOptional = queries.getOmmer(Hash.ZERO, 0);
|
||||
final Optional<BlockHeader> ommerOptional = queries.getOmmer(Hash.ZERO_HASH, 0);
|
||||
|
||||
assertThat(ommerOptional).isEmpty();
|
||||
}
|
||||
|
||||
@@ -236,7 +236,7 @@ public class PoWBlockCreatorTest {
|
||||
|
||||
final ProcessableBlockHeader header =
|
||||
BlockHeaderBuilder.create()
|
||||
.parentHash(Hash.ZERO)
|
||||
.parentHash(Hash.ZERO_HASH)
|
||||
.coinbase(BLOCK_1_COINBASE)
|
||||
.difficulty(Difficulty.ONE)
|
||||
.number(1)
|
||||
@@ -306,7 +306,7 @@ public class PoWBlockCreatorTest {
|
||||
|
||||
final ProcessableBlockHeader header =
|
||||
BlockHeaderBuilder.create()
|
||||
.parentHash(Hash.ZERO)
|
||||
.parentHash(Hash.ZERO_HASH)
|
||||
.coinbase(BLOCK_1_COINBASE)
|
||||
.difficulty(Difficulty.ONE)
|
||||
.number(1)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.ethereum.blockcreation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_REMOTE_SEALERS_LIMIT;
|
||||
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_REMOTE_SEALERS_TTL;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -28,7 +29,6 @@ import org.hyperledger.besu.ethereum.mainnet.PoWSolution;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class PoWMiningCoordinatorTest {
|
||||
syncState,
|
||||
DEFAULT_REMOTE_SEALERS_LIMIT,
|
||||
DEFAULT_REMOTE_SEALERS_TTL);
|
||||
final PoWSolution solution = new PoWSolution(1L, Hash.EMPTY, null, Bytes32.ZERO);
|
||||
final PoWSolution solution = new PoWSolution(1L, Hash.EMPTY, null, ZERO_32);
|
||||
|
||||
assertThat(miningCoordinator.isMining()).isFalse();
|
||||
assertThat(miningCoordinator.hashesPerSecond()).isEqualTo(Optional.empty());
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.ethereum.vm;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
@@ -65,7 +66,7 @@ public class EntriesFromIntegrationTest {
|
||||
}
|
||||
|
||||
final Map<Bytes32, AccountStorageEntry> values =
|
||||
account.storageEntriesFrom(Bytes32.ZERO, Integer.MAX_VALUE);
|
||||
account.storageEntriesFrom(ZERO_32, Integer.MAX_VALUE);
|
||||
assertThat(values).isEqualTo(expectedValues);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.ethereum.worldstate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
@@ -144,13 +145,12 @@ public class PrunerIntegrationTest {
|
||||
worldStateArchive.get(stateRoot, blockHeader.getHash()).get();
|
||||
// Traverse accounts and make sure all are accessible
|
||||
final int expectedAccounts = accountsPerBlock * i;
|
||||
final long accounts =
|
||||
markedState.streamAccounts(Bytes32.ZERO, expectedAccounts * 2).count();
|
||||
final long accounts = markedState.streamAccounts(ZERO_32, expectedAccounts * 2).count();
|
||||
assertThat(accounts).isEqualTo(expectedAccounts);
|
||||
// Traverse storage to ensure that all storage is accessible
|
||||
markedState
|
||||
.streamAccounts(Bytes32.ZERO, expectedAccounts * 2)
|
||||
.forEach(a -> a.storageEntriesFrom(Bytes32.ZERO, 1000));
|
||||
.streamAccounts(ZERO_32, expectedAccounts * 2)
|
||||
.forEach(a -> a.storageEntriesFrom(ZERO_32, 1000));
|
||||
}
|
||||
|
||||
// All other state roots should have been removed
|
||||
@@ -200,7 +200,7 @@ public class PrunerIntegrationTest {
|
||||
|
||||
// Collect storage roots and code
|
||||
stateTrie
|
||||
.entriesFrom(Bytes32.ZERO, 1000)
|
||||
.entriesFrom(ZERO_32, 1000)
|
||||
.forEach(
|
||||
(key, val) -> {
|
||||
final StateTrieAccountValue accountValue =
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.hyperledger.besu.ethereum.bonsai;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
@@ -125,7 +127,7 @@ public class BonsaiLayeredWorldState implements MutableWorldState, BonsaiWorldVi
|
||||
|
||||
@Override
|
||||
public Bytes32 getStorageValue(final Address address, final Bytes32 key) {
|
||||
return getStorageValueBySlotHash(address, Hash.hash(key)).orElse(Bytes32.ZERO);
|
||||
return getStorageValueBySlotHash(address, Hash.hash(key)).orElse(ZERO_32);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -190,7 +192,7 @@ public class BonsaiLayeredWorldState implements MutableWorldState, BonsaiWorldVi
|
||||
final Account account = currentLayer.getNextWorldView().get().get(address);
|
||||
if (account != null) {
|
||||
account
|
||||
.storageEntriesFrom(Hash.ZERO, Integer.MAX_VALUE)
|
||||
.storageEntriesFrom(Hash.ZERO_HASH, Integer.MAX_VALUE)
|
||||
.forEach(
|
||||
(k, v) -> {
|
||||
if (!results.containsKey(k)) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.hyperledger.besu.ethereum.bonsai;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.bonsai.BonsaiAccount.fromRLP;
|
||||
import static org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage.WORLD_BLOCK_HASH_KEY;
|
||||
import static org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY;
|
||||
@@ -64,7 +65,7 @@ public class BonsaiPersistedWorldState implements MutableWorldState, BonsaiWorld
|
||||
Hash.wrap(
|
||||
Bytes32.wrap(worldStateStorage.getWorldStateRootHash().orElse(Hash.EMPTY_TRIE_HASH)));
|
||||
worldStateBlockHash =
|
||||
Hash.wrap(Bytes32.wrap(worldStateStorage.getWorldStateBlockHash().orElse(Hash.ZERO)));
|
||||
Hash.wrap(Bytes32.wrap(worldStateStorage.getWorldStateBlockHash().orElse(Hash.ZERO_HASH)));
|
||||
updater = new BonsaiWorldStateUpdater(this);
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ public class BonsaiPersistedWorldState implements MutableWorldState, BonsaiWorld
|
||||
oldAccount.getStorageRoot(),
|
||||
Function.identity(),
|
||||
Function.identity());
|
||||
Map<Bytes32, Bytes> entriesToDelete = storageTrie.entriesFrom(Bytes32.ZERO, 256);
|
||||
Map<Bytes32, Bytes> entriesToDelete = storageTrie.entriesFrom(ZERO_32, 256);
|
||||
while (!entriesToDelete.isEmpty()) {
|
||||
entriesToDelete
|
||||
.keySet()
|
||||
@@ -132,7 +133,7 @@ public class BonsaiPersistedWorldState implements MutableWorldState, BonsaiWorld
|
||||
k -> stateUpdater.removeStorageValueBySlotHash(Hash.hash(address), Hash.wrap(k)));
|
||||
if (entriesToDelete.size() == 256) {
|
||||
entriesToDelete.keySet().forEach(storageTrie::remove);
|
||||
entriesToDelete = storageTrie.entriesFrom(Bytes32.ZERO, 256);
|
||||
entriesToDelete = storageTrie.entriesFrom(ZERO_32, 256);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
@@ -164,7 +165,7 @@ public class BonsaiPersistedWorldState implements MutableWorldState, BonsaiWorld
|
||||
storageAccountUpdate.getValue().entrySet()) {
|
||||
final Hash keyHash = storageUpdate.getKey();
|
||||
final Bytes32 updatedStorage = storageUpdate.getValue().getUpdated();
|
||||
if (updatedStorage == null || updatedStorage.equals(Bytes32.ZERO)) {
|
||||
if (updatedStorage == null || updatedStorage.equals(ZERO_32)) {
|
||||
stateUpdater.removeStorageValueBySlotHash(updatedAddressHash, keyHash);
|
||||
storageTrie.remove(keyHash);
|
||||
} else {
|
||||
@@ -372,7 +373,7 @@ public class BonsaiPersistedWorldState implements MutableWorldState, BonsaiWorld
|
||||
|
||||
@Override
|
||||
public Bytes32 getStorageValue(final Address address, final Bytes32 storageKey) {
|
||||
return getStorageValueBySlotHash(address, Hash.hash(storageKey)).orElse(Bytes32.ZERO);
|
||||
return getStorageValueBySlotHash(address, Hash.hash(storageKey)).orElse(ZERO_32);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -395,6 +396,6 @@ public class BonsaiPersistedWorldState implements MutableWorldState, BonsaiWorld
|
||||
rootHash,
|
||||
Function.identity(),
|
||||
Function.identity());
|
||||
return storageTrie.entriesFrom(Bytes32.ZERO, Integer.MAX_VALUE);
|
||||
return storageTrie.entriesFrom(ZERO_32, Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.hyperledger.besu.ethereum.bonsai;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.datatypes.Wei;
|
||||
@@ -283,7 +285,7 @@ public class BonsaiWorldStateUpdater extends AbstractWorldUpdater<BonsaiWorldVie
|
||||
public Bytes32 getStorageValue(final Address address, final Bytes32 storageKey) {
|
||||
// TODO maybe log the read into the trie layer?
|
||||
final Hash slotHashBytes = Hash.hash(storageKey);
|
||||
return getStorageValueBySlotHash(address, slotHashBytes).orElse(Bytes32.ZERO);
|
||||
return getStorageValueBySlotHash(address, slotHashBytes).orElse(ZERO_32);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -314,7 +316,7 @@ public class BonsaiWorldStateUpdater extends AbstractWorldUpdater<BonsaiWorldVie
|
||||
final BonsaiValue<Bytes32> value = localAccountStorage.get(slotHash);
|
||||
if (value != null) {
|
||||
if (value.isCleared()) {
|
||||
return Bytes32.ZERO;
|
||||
return ZERO_32;
|
||||
}
|
||||
final Bytes32 updated = value.getUpdated();
|
||||
if (updated != null) {
|
||||
@@ -327,7 +329,7 @@ public class BonsaiWorldStateUpdater extends AbstractWorldUpdater<BonsaiWorldVie
|
||||
}
|
||||
}
|
||||
if (storageToClear.contains(address)) {
|
||||
return Bytes32.ZERO;
|
||||
return ZERO_32;
|
||||
}
|
||||
return getStorageValue(address, storageKey);
|
||||
}
|
||||
@@ -629,9 +631,9 @@ public class BonsaiWorldStateUpdater extends AbstractWorldUpdater<BonsaiWorldVie
|
||||
}
|
||||
|
||||
private boolean isSlotEquals(final Bytes32 expectedValue, final Bytes32 existingSlotValue) {
|
||||
final Bytes32 sanitizedExpectedValue = (expectedValue == null) ? Bytes32.ZERO : expectedValue;
|
||||
final Bytes32 sanitizedExpectedValue = (expectedValue == null) ? ZERO_32 : expectedValue;
|
||||
final Bytes32 sanitizedExistingSlotValue =
|
||||
(existingSlotValue == null) ? Bytes32.ZERO : existingSlotValue;
|
||||
(existingSlotValue == null) ? ZERO_32 : existingSlotValue;
|
||||
return Objects.equals(sanitizedExpectedValue, sanitizedExistingSlotValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.core;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.plugin.data.Quantity;
|
||||
|
||||
import java.math.BigInteger;
|
||||
@@ -29,7 +31,7 @@ public final class Difficulty extends BaseUInt256Value<Difficulty> implements Qu
|
||||
|
||||
public static final Difficulty ONE = of(1);
|
||||
|
||||
public static final Difficulty MAX_VALUE = wrap(Bytes32.ZERO.not());
|
||||
public static final Difficulty MAX_VALUE = wrap(ZERO_32.not());
|
||||
|
||||
Difficulty(final UInt256 value) {
|
||||
super(value, Difficulty::new);
|
||||
|
||||
@@ -135,7 +135,7 @@ public class PrivateTransactionSimulator {
|
||||
publicWorldState.updater(),
|
||||
disposablePrivateState.updater(),
|
||||
header,
|
||||
Hash.ZERO, // Corresponding PMT hash not needed as this private transaction doesn't
|
||||
Hash.ZERO_HASH, // Corresponding PMT hash not needed as this private transaction doesn't
|
||||
// exist
|
||||
transaction,
|
||||
protocolSpec.getMiningBeneficiaryCalculator().calculateBeneficiary(header),
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.privacy;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult;
|
||||
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
|
||||
import org.hyperledger.besu.ethereum.rlp.RLPException;
|
||||
@@ -34,7 +36,7 @@ public class VersionedPrivateTransaction {
|
||||
privateTransaction,
|
||||
result
|
||||
.map(value -> Bytes32.fromHexStringLenient(value.getOutput().toHexString()))
|
||||
.orElse(Bytes32.ZERO));
|
||||
.orElse(ZERO_32));
|
||||
}
|
||||
|
||||
public VersionedPrivateTransaction(
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.proof;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.ethereum.rlp.RLP;
|
||||
import org.hyperledger.besu.ethereum.trie.Proof;
|
||||
import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue;
|
||||
@@ -59,7 +61,7 @@ public class WorldStateProof {
|
||||
public Bytes32 getStorageValue(final Bytes32 key) {
|
||||
Optional<Bytes> value = storageProofs.get(key).getValue();
|
||||
if (value.isEmpty()) {
|
||||
return Bytes32.ZERO;
|
||||
return ZERO_32;
|
||||
} else {
|
||||
return RLP.input(value.get()).readBytes32Scalar();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.vm;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Hash.ZERO;
|
||||
import static org.hyperledger.besu.datatypes.Hash.ZERO_HASH;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.ethereum.chain.Blockchain;
|
||||
@@ -57,6 +57,6 @@ public class BlockHashLookup implements Function<Long, Hash> {
|
||||
hashByNumber.put(searchStartHeader.getNumber() - 1, searchStartHeader.getParentHash());
|
||||
}
|
||||
}
|
||||
return hashByNumber.getOrDefault(blockNumber, ZERO);
|
||||
return hashByNumber.getOrDefault(blockNumber, ZERO_HASH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.worldstate;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Hash;
|
||||
import org.hyperledger.besu.datatypes.Wei;
|
||||
@@ -302,7 +304,7 @@ public class DefaultMutableWorldState implements MutableWorldState {
|
||||
return storageTrie()
|
||||
.get(Hash.hash(key))
|
||||
.map(DefaultMutableWorldState::convertToBytes32)
|
||||
.orElse(Bytes32.ZERO);
|
||||
.orElse(ZERO_32);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -226,7 +226,7 @@ public class BlockDataGenerator {
|
||||
final List<Address> accountsToSetup,
|
||||
final List<Bytes32> storageKeys) {
|
||||
final long blockNumber = BlockHeader.GENESIS_BLOCK_NUMBER;
|
||||
final Hash parentHash = Hash.ZERO;
|
||||
final Hash parentHash = Hash.ZERO_HASH;
|
||||
return blockSequence(
|
||||
count, blockNumber, parentHash, worldStateArchive, accountsToSetup, storageKeys);
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public class BlockDataGenerator {
|
||||
options
|
||||
.setBlockNumber(BlockHeader.GENESIS_BLOCK_NUMBER)
|
||||
.setStateRoot(Hash.EMPTY_TRIE_HASH)
|
||||
.setParentHash(Hash.ZERO);
|
||||
.setParentHash(Hash.ZERO_HASH);
|
||||
return block(options);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.ethereum.core;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.DEFAULT_PRIVACY;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.FLEXIBLE_PRIVACY;
|
||||
|
||||
@@ -168,7 +169,7 @@ public class PrivateTransactionDataFixture {
|
||||
public static ReceiveResponse generateVersionedReceiveResponse(
|
||||
final PrivateTransaction privateTransaction) {
|
||||
final VersionedPrivateTransaction versionedPrivateTransaction =
|
||||
new VersionedPrivateTransaction(privateTransaction, Bytes32.ZERO);
|
||||
new VersionedPrivateTransaction(privateTransaction, ZERO_32);
|
||||
final BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
|
||||
versionedPrivateTransaction.writeTo(rlpOutput);
|
||||
return new ReceiveResponse(
|
||||
@@ -200,7 +201,7 @@ public class PrivateTransactionDataFixture {
|
||||
final PrivateTransactionWithMetadata privateTransactionWithMetadata =
|
||||
new PrivateTransactionWithMetadata(
|
||||
privateTransaction,
|
||||
new PrivateTransactionMetadata(markerTransaction.getHash(), Hash.ZERO));
|
||||
new PrivateTransactionMetadata(markerTransaction.getHash(), Hash.ZERO_HASH));
|
||||
return Collections.singletonList(privateTransactionWithMetadata);
|
||||
}
|
||||
|
||||
@@ -226,7 +227,7 @@ public class PrivateTransactionDataFixture {
|
||||
privateTransaction.writeTo(output);
|
||||
} else {
|
||||
final VersionedPrivateTransaction versionedPrivateTransaction =
|
||||
new VersionedPrivateTransaction(privateTransaction, Bytes32.ZERO);
|
||||
new VersionedPrivateTransaction(privateTransaction, ZERO_32);
|
||||
versionedPrivateTransaction.writeTo(output);
|
||||
}
|
||||
return output.encoded();
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.core;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.crypto.KeyPair;
|
||||
import org.hyperledger.besu.datatypes.Address;
|
||||
import org.hyperledger.besu.datatypes.Wei;
|
||||
@@ -27,7 +29,6 @@ import java.util.Optional;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
|
||||
public class PrivateTransactionTestFixture {
|
||||
|
||||
@@ -90,7 +91,7 @@ public class PrivateTransactionTestFixture {
|
||||
|
||||
public VersionedPrivateTransaction createVersionedPrivateTransaction(final KeyPair keyPair) {
|
||||
final PrivateTransaction transaction = createTransaction(keyPair);
|
||||
return new VersionedPrivateTransaction(transaction, Bytes32.ZERO);
|
||||
return new VersionedPrivateTransaction(transaction, ZERO_32);
|
||||
}
|
||||
|
||||
public PrivateTransactionTestFixture nonce(final long nonce) {
|
||||
|
||||
@@ -44,7 +44,6 @@ import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolCo
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.sorter.AbstractPendingTransactionsSorter;
|
||||
import org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter;
|
||||
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
|
||||
import org.hyperledger.besu.ethereum.mainnet.MiningBeneficiaryCalculator;
|
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
|
||||
import org.hyperledger.besu.ethereum.storage.StorageProvider;
|
||||
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier;
|
||||
@@ -398,7 +397,7 @@ public class BonsaiSnapshotIsolationTests {
|
||||
protected BlockHeader createFinalBlockHeader(final SealableBlockHeader sealableBlockHeader) {
|
||||
return BlockHeaderBuilder.create()
|
||||
.difficulty(Difficulty.ZERO)
|
||||
.mixHash(Hash.ZERO)
|
||||
.mixHash(Hash.ZERO_HASH)
|
||||
.populateFrom(sealableBlockHeader)
|
||||
.nonce(0L)
|
||||
.blockHeaderFunctions(blockHeaderFunctions)
|
||||
|
||||
@@ -153,7 +153,7 @@ public class BonsaiWorldStateArchiveTest {
|
||||
.containsInstanceOf(BonsaiPersistedWorldState.class);
|
||||
|
||||
// verify is trying to get the trie log layer to rollback
|
||||
verify(layeredWorldStatesByHash).containsKey(Hash.ZERO);
|
||||
verify(layeredWorldStatesByHash).containsKey(Hash.ZERO_HASH);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@@ -181,7 +181,7 @@ public class BonsaiWorldStateArchiveTest {
|
||||
final BlockHeader blockHeader = blockBuilder.number(0).buildHeader();
|
||||
|
||||
when(blockchain.getBlockHeader(eq(blockHeader.getHash()))).thenReturn(Optional.of(blockHeader));
|
||||
when(blockchain.getBlockHeader(eq(Hash.ZERO))).thenReturn(Optional.of(blockHeader));
|
||||
when(blockchain.getBlockHeader(eq(Hash.ZERO_HASH))).thenReturn(Optional.of(blockHeader));
|
||||
|
||||
assertThat(bonsaiWorldStateArchive.getMutable(null, blockHeader.getHash()))
|
||||
.containsInstanceOf(BonsaiPersistedWorldState.class);
|
||||
@@ -224,7 +224,7 @@ public class BonsaiWorldStateArchiveTest {
|
||||
when(bonsaiWorldStateArchive.getUpdaterFromPersistedState(worldState)).thenReturn(updater);
|
||||
|
||||
// initial persisted state hash key
|
||||
when(blockchain.getBlockHeader(eq(Hash.ZERO))).thenReturn(Optional.of(blockHeaderChainA));
|
||||
when(blockchain.getBlockHeader(eq(Hash.ZERO_HASH))).thenReturn(Optional.of(blockHeaderChainA));
|
||||
when(blockchain.getBlockHeader(eq(blockHeaderChainB.getHash())))
|
||||
.thenReturn(Optional.of(blockHeaderChainB));
|
||||
when(blockchain.getBlockHeader(eq(genesis.getHash()))).thenReturn(Optional.of(genesis));
|
||||
@@ -276,7 +276,7 @@ public class BonsaiWorldStateArchiveTest {
|
||||
when(bonsaiWorldStateArchive.getUpdaterFromPersistedState(worldState)).thenReturn(updater);
|
||||
|
||||
// initial persisted state hash key
|
||||
when(blockchain.getBlockHeader(eq(Hash.ZERO))).thenReturn(Optional.of(blockHeaderChainA));
|
||||
when(blockchain.getBlockHeader(eq(Hash.ZERO_HASH))).thenReturn(Optional.of(blockHeaderChainA));
|
||||
// fake trie log layer
|
||||
final BytesValueRLPOutput rlpLogBlockB = new BytesValueRLPOutput();
|
||||
final TrieLogLayer trieLogLayerBlockB = new TrieLogLayer();
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.ethereum.bonsai;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.bonsai.BonsaiWorldStateKeyValueStorage.WORLD_ROOT_HASH_KEY;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -171,7 +172,8 @@ public class BonsaiWorldStateKeyValueStorageTest {
|
||||
MerklePatriciaTrie<Bytes32, Bytes> trie = TrieGenerator.generateTrie(storage, 1);
|
||||
final TreeMap<Bytes32, Bytes> accounts =
|
||||
(TreeMap<Bytes32, Bytes>)
|
||||
trie.entriesFrom(root -> StorageEntriesCollector.collectEntries(root, Hash.ZERO, 1));
|
||||
trie.entriesFrom(
|
||||
root -> StorageEntriesCollector.collectEntries(root, Hash.ZERO_HASH, 1));
|
||||
|
||||
// save world state root hash
|
||||
final BonsaiWorldStateKeyValueStorage.BonsaiUpdater updater = storage.updater();
|
||||
@@ -195,7 +197,8 @@ public class BonsaiWorldStateKeyValueStorageTest {
|
||||
final MerklePatriciaTrie<Bytes32, Bytes> trie = TrieGenerator.generateTrie(storage, 1);
|
||||
final TreeMap<Bytes32, Bytes> accounts =
|
||||
(TreeMap<Bytes32, Bytes>)
|
||||
trie.entriesFrom(root -> StorageEntriesCollector.collectEntries(root, Hash.ZERO, 1));
|
||||
trie.entriesFrom(
|
||||
root -> StorageEntriesCollector.collectEntries(root, Hash.ZERO_HASH, 1));
|
||||
|
||||
final StateTrieAccountValue stateTrieAccountValue =
|
||||
StateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue()));
|
||||
@@ -211,7 +214,7 @@ public class BonsaiWorldStateKeyValueStorageTest {
|
||||
final TreeMap<Bytes32, Bytes> slots =
|
||||
(TreeMap<Bytes32, Bytes>)
|
||||
storageTrie.entriesFrom(
|
||||
root -> StorageEntriesCollector.collectEntries(root, Hash.ZERO, 1));
|
||||
root -> StorageEntriesCollector.collectEntries(root, Hash.ZERO_HASH, 1));
|
||||
|
||||
// save world state root hash
|
||||
final BonsaiWorldStateKeyValueStorage.BonsaiUpdater updater = storage.updater();
|
||||
@@ -326,7 +329,7 @@ public class BonsaiWorldStateKeyValueStorageTest {
|
||||
|
||||
PeerTrieNodeFinder peerTrieNodeFinder = mock(PeerTrieNodeFinder.class);
|
||||
|
||||
final Hash account = Hash.hash(Bytes32.ZERO);
|
||||
final Hash account = Hash.hash(ZERO_32);
|
||||
final Bytes location = Bytes.fromHexString("0x01");
|
||||
final Bytes bytesInDB = Bytes.fromHexString("0x123456");
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class LogRollingTests {
|
||||
|
||||
private static final BlockHeader headerOne =
|
||||
new BlockHeader(
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
Hash.EMPTY_LIST_HASH,
|
||||
Address.ZERO,
|
||||
Hash.fromHexString("0x0ecfa454ddfe6b740f4af7b7f4c61b5c6bac2854efd2b07b27b1f53dba9bb46c"),
|
||||
@@ -83,7 +83,7 @@ public class LogRollingTests {
|
||||
0,
|
||||
Bytes.EMPTY,
|
||||
Wei.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
new MainnetBlockHeaderFunctions());
|
||||
private static final BlockHeader headerTwo =
|
||||
@@ -102,7 +102,7 @@ public class LogRollingTests {
|
||||
0,
|
||||
Bytes.EMPTY,
|
||||
Wei.ZERO,
|
||||
Hash.ZERO,
|
||||
Hash.ZERO_HASH,
|
||||
0,
|
||||
new MainnetBlockHeaderFunctions());
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ public class DefaultBlockchainTest {
|
||||
final DefaultBlockchain blockchain = createMutableBlockchain(kvStore, genesisBlock);
|
||||
|
||||
final BlockDataGenerator.BlockOptions options =
|
||||
new BlockDataGenerator.BlockOptions().setBlockNumber(1L).setParentHash(Hash.ZERO);
|
||||
new BlockDataGenerator.BlockOptions().setBlockNumber(1L).setParentHash(Hash.ZERO_HASH);
|
||||
final Block newBlock = gen.block(options);
|
||||
final List<TransactionReceipt> receipts = gen.receipts(newBlock);
|
||||
assertThatThrownBy(() -> blockchain.appendBlock(newBlock, receipts))
|
||||
|
||||
@@ -60,7 +60,7 @@ public final class GenesisStateTest {
|
||||
assertThat(header.getReceiptsRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH);
|
||||
assertThat(header.getOmmersHash()).isEqualTo(Hash.EMPTY_LIST_HASH);
|
||||
assertThat(header.getExtraData()).isEqualTo(Bytes.EMPTY);
|
||||
assertThat(header.getParentHash()).isEqualTo(Hash.ZERO);
|
||||
assertThat(header.getParentHash()).isEqualTo(Hash.ZERO_HASH);
|
||||
final MutableWorldState worldState = InMemoryKeyValueStorageProvider.createInMemoryWorldState();
|
||||
genesisState.writeStateTo(worldState);
|
||||
final Account first =
|
||||
@@ -85,7 +85,7 @@ public final class GenesisStateTest {
|
||||
assertThat(header.getReceiptsRoot()).isEqualTo(Hash.EMPTY_TRIE_HASH);
|
||||
assertThat(header.getOmmersHash()).isEqualTo(Hash.EMPTY_LIST_HASH);
|
||||
assertThat(header.getExtraData()).isEqualTo(Bytes.EMPTY);
|
||||
assertThat(header.getParentHash()).isEqualTo(Hash.ZERO);
|
||||
assertThat(header.getParentHash()).isEqualTo(Hash.ZERO_HASH);
|
||||
}
|
||||
|
||||
private void assertContractInvariants(final String sourceFile, final String blockHash)
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
*/
|
||||
package org.hyperledger.besu.ethereum.core;
|
||||
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
|
||||
import org.hyperledger.besu.crypto.KeyPair;
|
||||
import org.hyperledger.besu.crypto.SignatureAlgorithm;
|
||||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
|
||||
@@ -42,7 +44,7 @@ public class TransactionEIP1559Test {
|
||||
List.of(
|
||||
new AccessListEntry(
|
||||
Address.fromHexString("0x000000000000000000000000000000000000aaaa"),
|
||||
List.of(Bytes32.ZERO)));
|
||||
List.of(ZERO_32)));
|
||||
final Transaction tx =
|
||||
Transaction.builder()
|
||||
.chainId(new BigInteger("1559", 10))
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package org.hyperledger.besu.ethereum.mainnet;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivateTransactionDataFixture.VALID_BASE64_ENCLAVE_KEY;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
@@ -52,7 +53,6 @@ import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
import org.apache.tuweni.bytes.Bytes32;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -96,7 +96,7 @@ public class PrivacyBlockProcessorTest {
|
||||
final Blockchain blockchain = mock(Blockchain.class);
|
||||
final MutableWorldState mutableWorldState = mock(MutableWorldState.class);
|
||||
final PrivacyGroupHeadBlockMap expected =
|
||||
new PrivacyGroupHeadBlockMap(Collections.singletonMap(Bytes32.ZERO, Hash.EMPTY));
|
||||
new PrivacyGroupHeadBlockMap(Collections.singletonMap(ZERO_32, Hash.EMPTY));
|
||||
final Block firstBlock = blockDataGenerator.block();
|
||||
final Block secondBlock =
|
||||
blockDataGenerator.block(
|
||||
@@ -190,7 +190,7 @@ public class PrivacyBlockProcessorTest {
|
||||
when(mockWrappedEvmAccount.getMutable()).thenReturn(mockMutableAccount);
|
||||
when(mockWorldUpdater.createAccount(any())).thenReturn(mockWrappedEvmAccount);
|
||||
when(mockPrivateState.updater()).thenReturn(mockWorldUpdater);
|
||||
when(mockPrivateState.rootHash()).thenReturn(Hash.ZERO);
|
||||
when(mockPrivateState.rootHash()).thenReturn(Hash.ZERO_HASH);
|
||||
return mockPrivateState;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ConstantFieldValidationRuleTest {
|
||||
|
||||
assertThat(uut.validate(header, null)).isTrue();
|
||||
|
||||
blockHeaderBuilder.ommersHash(Hash.ZERO);
|
||||
blockHeaderBuilder.ommersHash(Hash.ZERO_HASH);
|
||||
header = blockHeaderBuilder.buildHeader();
|
||||
assertThat(uut.validate(header, null)).isFalse();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ChainHeadPrivateNonceProviderTest {
|
||||
@Test
|
||||
public void determineNonceForPrivacyGroupRequestWhenPrivateStateDoesNotExist() {
|
||||
when(privateStateRootResolver.resolveLastStateRoot(any(Bytes32.class), any(Hash.class)))
|
||||
.thenReturn(Hash.ZERO);
|
||||
.thenReturn(Hash.ZERO_HASH);
|
||||
when(privateWorldStateArchive.get(any(Hash.class), any(Hash.class)))
|
||||
.thenReturn(Optional.empty());
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ChainHeadPrivateNonceProviderTest {
|
||||
when(account.getNonce()).thenReturn(4L);
|
||||
when(worldState.get(any(Address.class))).thenReturn(account);
|
||||
when(privateStateRootResolver.resolveLastStateRoot(any(Bytes32.class), any(Hash.class)))
|
||||
.thenReturn(Hash.ZERO);
|
||||
.thenReturn(Hash.ZERO_HASH);
|
||||
when(privateWorldStateArchive.get(any(Hash.class), any(Hash.class)))
|
||||
.thenReturn(Optional.of(worldState));
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ChainHeadPrivateNonceProviderTest {
|
||||
@Test
|
||||
public void determineNonceForPrivacyGroupRequestWhenAccountDoesNotExist() {
|
||||
when(privateStateRootResolver.resolveLastStateRoot(any(Bytes32.class), any(Hash.class)))
|
||||
.thenReturn(Hash.ZERO);
|
||||
.thenReturn(Hash.ZERO_HASH);
|
||||
when(privateWorldStateArchive.get(any(Hash.class), any(Hash.class)))
|
||||
.thenReturn(Optional.of(worldState));
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.hyperledger.besu.ethereum.privacy;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.INCORRECT_PRIVATE_NONCE;
|
||||
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.PRIVATE_NONCE_TOO_LOW;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -231,7 +232,7 @@ public class FlexiblePrivacyControllerTest {
|
||||
Collections.emptyList(),
|
||||
0,
|
||||
0,
|
||||
Bytes32.ZERO,
|
||||
ZERO_32,
|
||||
ValidationResult.valid(),
|
||||
Optional.empty());
|
||||
when(privateTransactionSimulator.process(any(), any()))
|
||||
@@ -339,7 +340,7 @@ public class FlexiblePrivacyControllerTest {
|
||||
private void mockingForFindPrivacyGroupByMembers() {
|
||||
final PrivacyGroupHeadBlockMap privacyGroupHeadBlockMap =
|
||||
new PrivacyGroupHeadBlockMap(
|
||||
Map.of(Bytes32.wrap(Bytes.fromBase64String(PRIVACY_GROUP_ID)), Hash.ZERO));
|
||||
Map.of(Bytes32.wrap(Bytes.fromBase64String(PRIVACY_GROUP_ID)), Hash.ZERO_HASH));
|
||||
when(privateStateStorage.getPrivacyGroupHeadBlockMap(any()))
|
||||
.thenReturn(Optional.of(privacyGroupHeadBlockMap));
|
||||
}
|
||||
@@ -363,14 +364,14 @@ public class FlexiblePrivacyControllerTest {
|
||||
when(enclave.send(any(), any(), anyList())).thenReturn(key);
|
||||
final Map<Bytes32, Hash> bytes32HashMap = new HashMap<>();
|
||||
final Bytes32 pgBytes = Bytes32.wrap(Base64.decode(PRIVACY_GROUP_ID));
|
||||
bytes32HashMap.put(pgBytes, Hash.ZERO);
|
||||
when(blockchain.getChainHeadHash()).thenReturn(Hash.ZERO);
|
||||
bytes32HashMap.put(pgBytes, Hash.ZERO_HASH);
|
||||
when(blockchain.getChainHeadHash()).thenReturn(Hash.ZERO_HASH);
|
||||
final Optional<PrivacyGroupHeadBlockMap> privacyGroupHeadBlockMap =
|
||||
Optional.of(new PrivacyGroupHeadBlockMap(bytes32HashMap));
|
||||
when(privateStateStorage.getPrivacyGroupHeadBlockMap(Hash.ZERO))
|
||||
when(privateStateStorage.getPrivacyGroupHeadBlockMap(Hash.ZERO_HASH))
|
||||
.thenReturn(privacyGroupHeadBlockMap);
|
||||
final List<PrivateTransactionMetadata> privateTransactionMetadata =
|
||||
List.of(new PrivateTransactionMetadata(Hash.ZERO, Hash.ZERO));
|
||||
List.of(new PrivateTransactionMetadata(Hash.ZERO_HASH, Hash.ZERO_HASH));
|
||||
final PrivateBlockMetadata privateBlockMetadata =
|
||||
new PrivateBlockMetadata(privateTransactionMetadata);
|
||||
when(privateStateStorage.getPrivateBlockMetadata(any(), eq(pgBytes)))
|
||||
@@ -395,7 +396,7 @@ public class FlexiblePrivacyControllerTest {
|
||||
final PrivateTransactionWithMetadata privateTransactionWithMetadata =
|
||||
new PrivateTransactionWithMetadata(
|
||||
buildPrivateTransaction(3).signAndBuild(KEY_PAIR),
|
||||
new PrivateTransactionMetadata(Hash.ZERO, Hash.ZERO));
|
||||
new PrivateTransactionMetadata(Hash.ZERO_HASH, Hash.ZERO_HASH));
|
||||
final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
|
||||
privateTransactionWithMetadata.writeTo(bytesValueRLPOutput);
|
||||
final byte[] txPayload =
|
||||
|
||||
@@ -297,7 +297,7 @@ public class MultiTenancyPrivacyControllerTest {
|
||||
|
||||
final Optional<Bytes> result =
|
||||
multiTenancyPrivacyController.getContractCode(
|
||||
PRIVACY_GROUP_ID, Address.ZERO, Hash.ZERO, ENCLAVE_PUBLIC_KEY1);
|
||||
PRIVACY_GROUP_ID, Address.ZERO, Hash.ZERO_HASH, ENCLAVE_PUBLIC_KEY1);
|
||||
|
||||
assertThat(result).isPresent().hasValue(contractCode);
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public class MultiTenancyPrivacyControllerTest {
|
||||
assertThatThrownBy(
|
||||
() ->
|
||||
multiTenancyPrivacyController.getContractCode(
|
||||
PRIVACY_GROUP_ID, Address.ZERO, Hash.ZERO, ENCLAVE_PUBLIC_KEY2))
|
||||
PRIVACY_GROUP_ID, Address.ZERO, Hash.ZERO_HASH, ENCLAVE_PUBLIC_KEY2))
|
||||
.hasMessage("Privacy group must contain the enclave public key");
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class PrivateMetadataUpdaterTest {
|
||||
public void before() {
|
||||
blockHeader = mock(BlockHeader.class);
|
||||
privateStateStorage = new InMemoryPrivacyStorageProvider().createPrivateStateStorage();
|
||||
final Hash hashBlockZero = Hash.ZERO;
|
||||
final Hash hashBlockZero = Hash.ZERO_HASH;
|
||||
when(blockHeader.getParentHash()).thenReturn(hashBlockZero);
|
||||
updater = new PrivateMetadataUpdater(blockHeader, privateStateStorage);
|
||||
hashBlockOne =
|
||||
@@ -69,7 +69,7 @@ public class PrivateMetadataUpdaterTest {
|
||||
@Test
|
||||
public void addingMetadataSuccessfull() {
|
||||
when(blockHeader.getHash()).thenReturn(hashBlockOne);
|
||||
pmtHash = Hash.ZERO;
|
||||
pmtHash = Hash.ZERO_HASH;
|
||||
final PrivateTransactionMetadata expected = new PrivateTransactionMetadata(pmtHash, stateRoot);
|
||||
updater.addPrivateTransactionMetadata(privacyGroupId, expected);
|
||||
updater.commit();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.hyperledger.besu.ethereum.privacy;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hyperledger.besu.datatypes.Constants.ZERO_32;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.DEFAULT_FLEXIBLE_PRIVACY_MANAGEMENT;
|
||||
import static org.hyperledger.besu.ethereum.core.PrivacyParameters.FLEXIBLE_PRIVACY_PROXY;
|
||||
import static org.hyperledger.besu.ethereum.privacy.group.FlexibleGroupManagement.DEFAULT_GROUP_MANAGEMENT_RUNTIME_BYTECODE;
|
||||
@@ -146,7 +147,7 @@ public class PrivateStateGenesisAllocatorTest {
|
||||
private void assertManagementContractApplied() {
|
||||
Account managementProxy = worldState.get(FLEXIBLE_PRIVACY_PROXY);
|
||||
assertThat(managementProxy.getCode()).isEqualTo(PROXY_RUNTIME_BYTECODE);
|
||||
assertThat(managementProxy.getStorageValue(Bytes32.ZERO))
|
||||
assertThat(managementProxy.getStorageValue(ZERO_32))
|
||||
.isEqualTo(Bytes32.leftPad(DEFAULT_FLEXIBLE_PRIVACY_MANAGEMENT));
|
||||
|
||||
Account managementContract = worldState.get(DEFAULT_FLEXIBLE_PRIVACY_MANAGEMENT);
|
||||
|
||||
@@ -52,8 +52,8 @@ public class PrivateWorldStateReaderTest {
|
||||
Bytes32.wrap(Bytes.fromBase64String(PRIVACY_GROUP_ID));
|
||||
private final Bytes contractCode = Bytes.fromBase64String("ZXhhbXBsZQ==");
|
||||
private final Address contractAddress = Address.ZERO;
|
||||
private final Hash blockHash = Hash.ZERO;
|
||||
private final Hash stateRootHash = Hash.ZERO;
|
||||
private final Hash blockHash = Hash.ZERO_HASH;
|
||||
private final Hash stateRootHash = Hash.ZERO_HASH;
|
||||
|
||||
@Mock private PrivateStateRootResolver privateStateRootResolver;
|
||||
@Mock private WorldStateArchive privateWorldStateArchive;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user