use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.
the class AbstractDatabaseTest method slotAndBlock_shouldStoreAndRetrieve.
@Test
public void slotAndBlock_shouldStoreAndRetrieve() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
final Bytes32 stateRoot = dataStructureUtil.randomBytes32();
final SlotAndBlockRoot slotAndBlockRoot = new SlotAndBlockRoot(dataStructureUtil.randomUInt64(), dataStructureUtil.randomBytes32());
database.addHotStateRoots(Map.of(stateRoot, slotAndBlockRoot));
final Optional<SlotAndBlockRoot> fromStorage = database.getSlotAndBlockRootFromStateRoot(stateRoot);
assertThat(fromStorage.isPresent()).isTrue();
assertThat(fromStorage.get()).isEqualTo(slotAndBlockRoot);
}
use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.
the class AbstractDatabaseTest method slotAndBlock_shouldPurgeToSlot.
@Test
public void slotAndBlock_shouldPurgeToSlot() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
insertRandomSlotAndBlock(0L, dataStructureUtil);
insertRandomSlotAndBlock(1L, dataStructureUtil);
final Bytes32 twoStateRoot = insertRandomSlotAndBlock(2L, dataStructureUtil);
final Bytes32 threeStateRoot = insertRandomSlotAndBlock(3L, dataStructureUtil);
database.pruneHotStateRoots(database.getStateRootsBeforeSlot(UInt64.valueOf(2L)));
assertThat(database.getStateRootsBeforeSlot(UInt64.valueOf(10L))).containsExactlyInAnyOrder(twoStateRoot, threeStateRoot);
}
use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.
the class AbstractKvStoreDatabaseTest method shouldThrowIfTransactionModifiedAfterDatabaseIsClosed_updateEth1Dao.
@Test
public void shouldThrowIfTransactionModifiedAfterDatabaseIsClosed_updateEth1Dao() throws Exception {
database.storeInitialAnchor(genesisAnchor);
final DataStructureUtil dataStructureUtil = new DataStructureUtil();
try (final KvStoreEth1Dao.Eth1Updater updater = ((KvStoreDatabase) database).eth1Dao.eth1Updater()) {
final MinGenesisTimeBlockEvent genesisTimeBlockEvent = dataStructureUtil.randomMinGenesisTimeBlockEvent(1);
database.close();
assertThatThrownBy(() -> updater.addMinGenesisTimeBlock(genesisTimeBlockEvent)).isInstanceOf(ShuttingDownException.class);
}
}
use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.
the class AbstractDatabaseTest method slotAndBlock_shouldGetStateRootsBeforeSlot.
@Test
public void slotAndBlock_shouldGetStateRootsBeforeSlot() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
final Bytes32 zeroStateRoot = insertRandomSlotAndBlock(0L, dataStructureUtil);
final Bytes32 oneStateRoot = insertRandomSlotAndBlock(1L, dataStructureUtil);
insertRandomSlotAndBlock(2L, dataStructureUtil);
insertRandomSlotAndBlock(3L, dataStructureUtil);
assertThat(database.getStateRootsBeforeSlot(UInt64.valueOf(2L))).containsExactlyInAnyOrder(zeroStateRoot, oneStateRoot);
}
use of tech.pegasys.teku.spec.util.DataStructureUtil in project teku by ConsenSys.
the class AbstractDatabaseTest method shouldStoreAndRetrieveVotes.
@Test
void shouldStoreAndRetrieveVotes() {
final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
createStorage(StateStorageMode.PRUNE);
assertThat(database.getVotes()).isEmpty();
final Map<UInt64, VoteTracker> voteBatch1 = Map.of(UInt64.valueOf(10), dataStructureUtil.randomVoteTracker(), UInt64.valueOf(11), dataStructureUtil.randomVoteTracker(), UInt64.valueOf(12), dataStructureUtil.randomVoteTracker());
database.storeVotes(voteBatch1);
assertThat(database.getVotes()).isEqualTo(voteBatch1);
final Map<UInt64, VoteTracker> voteBatch2 = Map.of(UInt64.valueOf(10), dataStructureUtil.randomVoteTracker(), UInt64.valueOf(13), dataStructureUtil.randomVoteTracker());
database.storeVotes(voteBatch2);
final Map<UInt64, VoteTracker> expected = new HashMap<>(voteBatch1);
expected.putAll(voteBatch2);
assertThat(database.getVotes()).isEqualTo(expected);
}
Aggregations