Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 committed Mar 7, 2023
1 parent b21e023 commit ca53f1a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;

import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -193,7 +194,12 @@ public static BackwardChain inMemoryBackwardChain() {
final GenericKeyValueStorageFacade<Hash, Hash> chainStorage =
new GenericKeyValueStorageFacade<>(
Hash::toArrayUnsafe, new HashConvertor(), new InMemoryKeyValueStorage());
return new BackwardChain(headersStorage, blocksStorage, chainStorage);
final GenericKeyValueStorageFacade<String, BlockHeader> variablesStorage =
new GenericKeyValueStorageFacade<>(
key -> key.getBytes(StandardCharsets.UTF_8),
BlocksHeadersConvertor.of(new MainnetBlockHeaderFunctions()),
new InMemoryKeyValueStorage());
return new BackwardChain(headersStorage, blocksStorage, chainStorage, variablesStorage);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -73,6 +74,7 @@ public class BackwardSyncStepTest {
GenericKeyValueStorageFacade<Hash, BlockHeader> headersStorage;
GenericKeyValueStorageFacade<Hash, Block> blocksStorage;
GenericKeyValueStorageFacade<Hash, Hash> chainStorage;
GenericKeyValueStorageFacade<String, BlockHeader> variablesStorage;

@Before
public void setup() {
Expand All @@ -86,10 +88,14 @@ public void setup() {
Hash::toArrayUnsafe,
new BlocksConvertor(new MainnetBlockHeaderFunctions()),
new InMemoryKeyValueStorage());

chainStorage =
new GenericKeyValueStorageFacade<>(
Hash::toArrayUnsafe, new HashConvertor(), new InMemoryKeyValueStorage());
variablesStorage =
new GenericKeyValueStorageFacade<>(
key -> key.getBytes(StandardCharsets.UTF_8),
new BlocksHeadersConvertor(new MainnetBlockHeaderFunctions()),
new InMemoryKeyValueStorage());

Block genesisBlock = blockDataGenerator.genesisBlock();
remoteBlockchain = createInMemoryBlockchain(genesisBlock);
Expand Down Expand Up @@ -234,7 +240,7 @@ private BackwardChain createBackwardChain(final int from, final int until) {
@Nonnull
private BackwardChain createBackwardChain(final int number) {
final BackwardChain backwardChain =
new BackwardChain(headersStorage, blocksStorage, chainStorage);
new BackwardChain(headersStorage, blocksStorage, chainStorage, variablesStorage);
backwardChain.appendTrustedBlock(remoteBlockchain.getBlockByNumber(number).orElseThrow());
return backwardChain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;

import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -73,8 +74,8 @@ public class ForwardSyncStepTest {
private MutableBlockchain localBlockchain;
GenericKeyValueStorageFacade<Hash, BlockHeader> headersStorage;
GenericKeyValueStorageFacade<Hash, Block> blocksStorage;

GenericKeyValueStorageFacade<Hash, Hash> chainStorage;
GenericKeyValueStorageFacade<String, BlockHeader> variablesStorage;

@Before
public void setup() {
Expand All @@ -91,6 +92,11 @@ public void setup() {
chainStorage =
new GenericKeyValueStorageFacade<>(
Hash::toArrayUnsafe, new HashConvertor(), new InMemoryKeyValueStorage());
variablesStorage =
new GenericKeyValueStorageFacade<>(
key -> key.getBytes(StandardCharsets.UTF_8),
new BlocksHeadersConvertor(new MainnetBlockHeaderFunctions()),
new InMemoryKeyValueStorage());

Block genesisBlock = blockDataGenerator.genesisBlock();
remoteBlockchain = createInMemoryBlockchain(genesisBlock);
Expand Down Expand Up @@ -197,7 +203,7 @@ private BackwardChain createBackwardChain(final int from, final int until) {
@Nonnull
private BackwardChain backwardChainFromBlock(final int number) {
final BackwardChain backwardChain =
new BackwardChain(headersStorage, blocksStorage, chainStorage);
new BackwardChain(headersStorage, blocksStorage, chainStorage, variablesStorage);
backwardChain.appendTrustedBlock(remoteBlockchain.getBlockByNumber(number).orElseThrow());
return backwardChain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nonnull;
Expand All @@ -45,6 +46,7 @@ public class InMemoryBackwardChainTest {
GenericKeyValueStorageFacade<Hash, BlockHeader> headersStorage;
GenericKeyValueStorageFacade<Hash, Block> blocksStorage;
GenericKeyValueStorageFacade<Hash, Hash> chainStorage;
GenericKeyValueStorageFacade<String, BlockHeader> variablesStorage;

@Before
public void prepareData() {
Expand All @@ -61,6 +63,11 @@ public void prepareData() {
chainStorage =
new GenericKeyValueStorageFacade<>(
Hash::toArrayUnsafe, new HashConvertor(), new InMemoryKeyValueStorage());
variablesStorage =
new GenericKeyValueStorageFacade<>(
key -> key.getBytes(StandardCharsets.UTF_8),
new BlocksHeadersConvertor(new MainnetBlockHeaderFunctions()),
new InMemoryKeyValueStorage());

blocks = prepareChain(ELEMENTS, HEIGHT);
}
Expand All @@ -78,7 +85,7 @@ public void shouldReturnFirstHeaderCorrectly() {
@Nonnull
private BackwardChain createChainFromBlock(final Block pivot) {
final BackwardChain backwardChain =
new BackwardChain(headersStorage, blocksStorage, chainStorage);
new BackwardChain(headersStorage, blocksStorage, chainStorage, variablesStorage);
backwardChain.appendTrustedBlock(pivot);
return backwardChain;
}
Expand Down Expand Up @@ -138,15 +145,15 @@ public void shouldAddHeaderToQueue() {
firstHash = backwardChain.getFirstHashToAppend();
assertThat(firstHash).isPresent();
assertThat(firstHash.orElseThrow()).isEqualTo(blocks.get(7).getHash());
backwardChain.processing(firstHash.get());
backwardChain.removeFromHashToAppend(firstHash.get());
firstHash = backwardChain.getFirstHashToAppend();
assertThat(firstHash).isPresent();
assertThat(firstHash.orElseThrow()).isEqualTo(blocks.get(9).getHash());
backwardChain.processing(firstHash.get());
backwardChain.removeFromHashToAppend(firstHash.get());
firstHash = backwardChain.getFirstHashToAppend();
assertThat(firstHash).isPresent();
assertThat(firstHash.orElseThrow()).isEqualTo(blocks.get(11).getHash());
backwardChain.processing(firstHash.get());
backwardChain.removeFromHashToAppend(firstHash.get());
}

@Test
Expand Down

0 comments on commit ca53f1a

Please sign in to comment.