|
| 1 | +/* |
| 2 | + * Copyright Consensys Software Inc., 2025 |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | + * the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +package tech.pegasys.teku.spec; |
| 15 | + |
| 16 | +import static org.assertj.core.api.Assertions.assertThat; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | +import java.util.Optional; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | +import tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState; |
| 22 | +import tech.pegasys.teku.spec.generator.ChainBuilder; |
| 23 | +import tech.pegasys.teku.spec.util.DataStructureUtil; |
| 24 | +import tech.pegasys.teku.storage.server.StateStorageMode; |
| 25 | +import tech.pegasys.teku.storage.storageSystem.InMemoryStorageSystemBuilder; |
| 26 | +import tech.pegasys.teku.storage.storageSystem.StorageSystem; |
| 27 | + |
| 28 | +class SpecTest { |
| 29 | + final Spec spec = TestSpecFactory.createMinimalAltair(); |
| 30 | + final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec); |
| 31 | + private final StorageSystem storageSystem = |
| 32 | + InMemoryStorageSystemBuilder.buildDefault(StateStorageMode.PRUNE, spec); |
| 33 | + private final ChainBuilder chainBuilder = storageSystem.chainBuilder(); |
| 34 | + |
| 35 | + @Test |
| 36 | + void shouldWindStateForwardIfOutsidePeriod() { |
| 37 | + chainBuilder.generateGenesis(); |
| 38 | + chainBuilder.generateBlocksUpToSlot(8); |
| 39 | + final List<SignedBlockAndState> chain = chainBuilder.finalizeCurrentChain(Optional.empty()); |
| 40 | + |
| 41 | + // the important thing here is that we get a response, we don't fail, even though slot 100 is |
| 42 | + // well beyond the finalized slot (in epoch 4) |
| 43 | + assertThat( |
| 44 | + spec.computeSubnetForAttestation( |
| 45 | + chain.getLast().getState(), dataStructureUtil.randomAttestation(100))) |
| 46 | + .isEqualTo(48); |
| 47 | + } |
| 48 | +} |
0 commit comments