Search in sources :

Example 16 with DataStructureUtil

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);
}
Also used : SlotAndBlockRoot(tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot) Bytes32(org.apache.tuweni.bytes.Bytes32) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 17 with DataStructureUtil

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);
}
Also used : Bytes32(org.apache.tuweni.bytes.Bytes32) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 18 with DataStructureUtil

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);
    }
}
Also used : KvStoreEth1Dao(tech.pegasys.teku.storage.server.kvstore.dataaccess.KvStoreEth1Dao) MinGenesisTimeBlockEvent(tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) AbstractStorageBackedDatabaseTest(tech.pegasys.teku.storage.server.AbstractStorageBackedDatabaseTest) Test(org.junit.jupiter.api.Test)

Example 19 with DataStructureUtil

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);
}
Also used : Bytes32(org.apache.tuweni.bytes.Bytes32) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Example 20 with DataStructureUtil

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);
}
Also used : VoteTracker(tech.pegasys.teku.spec.datastructures.forkchoice.VoteTracker) HashMap(java.util.HashMap) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Aggregations

DataStructureUtil (tech.pegasys.teku.spec.util.DataStructureUtil)45 Test (org.junit.jupiter.api.Test)33 Spec (tech.pegasys.teku.spec.Spec)11 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)8 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)7 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 List (java.util.List)4 Bytes (org.apache.tuweni.bytes.Bytes)4 StubMetricsSystem (tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem)4 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)4 AnchorPoint (tech.pegasys.teku.spec.datastructures.state.AnchorPoint)4 Response (okhttp3.Response)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 PostDataFailureResponse (tech.pegasys.teku.api.response.v1.beacon.PostDataFailureResponse)3 BLSSignature (tech.pegasys.teku.api.schema.BLSSignature)3 SyncCommitteeMessage (tech.pegasys.teku.api.schema.altair.SyncCommitteeMessage)3 AbstractDataBackedRestAPIIntegrationTest (tech.pegasys.teku.beaconrestapi.AbstractDataBackedRestAPIIntegrationTest)3 BLSSignature (tech.pegasys.teku.bls.BLSSignature)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 WeakSubjectivityConfig (tech.pegasys.teku.weaksubjectivity.config.WeakSubjectivityConfig)3