Search in sources :

Example 16 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class MiscHelpersTest method shuffleList_compareListAndArrayVersions.

@Test
void shuffleList_compareListAndArrayVersions() {
    final SpecConfig specConfig = mock(SpecConfig.class);
    final MiscHelpers miscHelpers = new MiscHelpers(specConfig);
    when(specConfig.getShuffleRoundCount()).thenReturn(10);
    Bytes32 seed = Bytes32.ZERO;
    int index_count = 3333;
    int[] indices = IntStream.range(0, index_count).toArray();
    miscHelpers.shuffleList(indices, seed);
    IntList indexList = IntList.of(IntStream.range(0, index_count).toArray());
    final List<Integer> result = miscHelpers.shuffleList(indexList, seed);
    assertThat(result).containsExactlyElementsOf(Arrays.stream(indices).boxed().collect(Collectors.toList()));
}
Also used : SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Bytes32(org.apache.tuweni.bytes.Bytes32) IntList(it.unimi.dsi.fastutil.ints.IntList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class MiscHelpersTest method computeShuffledIndex_samples.

@Test
void computeShuffledIndex_samples() {
    final SpecConfig specConfig = mock(SpecConfig.class);
    final MiscHelpers miscHelpers = new MiscHelpers(specConfig);
    when(specConfig.getShuffleRoundCount()).thenReturn(90);
    assertThat(miscHelpers.computeShuffledIndex(320, 2048, Bytes32.ZERO)).isEqualTo(0);
    assertThat(miscHelpers.computeShuffledIndex(1291, 2048, Bytes32.ZERO)).isEqualTo(1);
    assertThat(miscHelpers.computeShuffledIndex(933, 2048, Bytes32.ZERO)).isEqualTo(2047);
}
Also used : SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class DepositOptionsTest method shouldUseMaxEffectiveBalanceAsDefaultAmount.

@Test
public void shouldUseMaxEffectiveBalanceAsDefaultAmount() {
    final UInt64 expectedAmount = UInt64.valueOf(12345678);
    final Eth1PrivateKeyOptions eth1PrivateKeyOptions = new Eth1PrivateKeyOptions();
    eth1PrivateKeyOptions.eth1PrivateKey = ETH1_PRIVATE_KEY;
    final DepositOptions depositOptions = new DepositOptions(commandSpec, eth1PrivateKeyOptions, SHUTDOWN_FUNCTION, consoleAdapter);
    final SpecConfig config = SpecConfigLoader.loadConfig(Eth2Network.MAINNET.configName(), builder -> builder.maxEffectiveBalance(expectedAmount));
    assertThat(depositOptions.getAmount(config)).isEqualTo(expectedAmount);
}
Also used : SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Test(org.junit.jupiter.api.Test)

Example 19 with SpecConfig

use of tech.pegasys.teku.spec.config.SpecConfig in project teku by ConsenSys.

the class VoluntaryExitGossipIntegrationTest method shouldGossipVoluntaryExitToPeers.

@Test
public void shouldGossipVoluntaryExitToPeers() throws Exception {
    final GossipEncoding gossipEncoding = GossipEncoding.SSZ_SNAPPY;
    final SpecConfig config = spec.getGenesisSpecConfig();
    final UInt64 blockSlot = config.getShardCommitteePeriod().plus(2).times(config.getSlotsPerEpoch());
    // Set up publishers & consumers
    Set<SignedVoluntaryExit> receivedVoluntaryExits = new HashSet<>();
    final OperationProcessor<SignedVoluntaryExit> operationProcessor = (voluntaryExit) -> {
        receivedVoluntaryExits.add(voluntaryExit);
        return SafeFuture.completedFuture(InternalValidationResult.ACCEPT);
    };
    // Setup network 1
    final Consumer<Eth2P2PNetworkBuilder> networkBuilder = b -> b.gossipEncoding(gossipEncoding);
    NodeManager node1 = createNodeManager(networkBuilder);
    node1.chainUtil().setSlot(blockSlot);
    // Setup network 2
    final Consumer<Eth2P2PNetworkBuilder> networkBuilder2 = b -> b.gossipEncoding(gossipEncoding).gossipedVoluntaryExitProcessor(operationProcessor);
    NodeManager node2 = createNodeManager(networkBuilder2);
    node2.chainUtil().setSlot(blockSlot);
    // Connect networks 1 -> 2
    waitFor(node1.connect(node2));
    // Wait for connections to get set up
    Waiter.waitFor(() -> {
        assertThat(node1.network().getPeerCount()).isEqualTo(1);
        assertThat(node2.network().getPeerCount()).isEqualTo(1);
    });
    // Wait for subscriptions to complete (jvm-libp2p does this asynchronously)
    Thread.sleep(2000);
    // Create voluntary exit
    final SignedBeaconBlock block = node1.chainUtil().createAndImportBlockAtSlot(blockSlot);
    final SafeFuture<Optional<BeaconState>> stateFuture = node1.storageClient().getStore().retrieveBlockState(block.getRoot());
    assertThat(stateFuture).isCompleted();
    final BeaconState state = stateFuture.join().orElseThrow();
    final VoluntaryExitGenerator exitGenerator = new VoluntaryExitGenerator(spec, node1.chainUtil().getValidatorKeys());
    final SignedVoluntaryExit voluntaryExit = exitGenerator.valid(state, 0);
    // Publish voluntary exit
    node1.network().publishVoluntaryExit(voluntaryExit);
    // Verify the expected exit was gossiped across the network
    Waiter.waitFor(() -> assertThat(receivedVoluntaryExits).containsExactly(voluntaryExit));
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperationProcessor(tech.pegasys.teku.networking.eth2.gossip.topics.OperationProcessor) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) HashSet(java.util.HashSet) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Spec(tech.pegasys.teku.spec.Spec) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) VoluntaryExitGenerator(tech.pegasys.teku.core.VoluntaryExitGenerator) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) Set(java.util.Set) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) Waiter.waitFor(tech.pegasys.teku.infrastructure.async.Waiter.waitFor) Waiter(tech.pegasys.teku.infrastructure.async.Waiter) Optional(java.util.Optional) BLSKeyGenerator(tech.pegasys.teku.bls.BLSKeyGenerator) InternalValidationResult(tech.pegasys.teku.statetransition.validation.InternalValidationResult) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) SignedVoluntaryExit(tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit) Optional(java.util.Optional) Eth2P2PNetworkBuilder(tech.pegasys.teku.networking.eth2.Eth2P2PNetworkFactory.Eth2P2PNetworkBuilder) GossipEncoding(tech.pegasys.teku.networking.eth2.gossip.encoding.GossipEncoding) VoluntaryExitGenerator(tech.pegasys.teku.core.VoluntaryExitGenerator) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) SpecConfig(tech.pegasys.teku.spec.config.SpecConfig) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

SpecConfig (tech.pegasys.teku.spec.config.SpecConfig)19 Test (org.junit.jupiter.api.Test)12 Spec (tech.pegasys.teku.spec.Spec)7 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 GetSpecResponse (tech.pegasys.teku.api.response.v1.config.GetSpecResponse)2 SpecConfigLoader (tech.pegasys.teku.spec.config.SpecConfigLoader)2 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1