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()));
}
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);
}
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);
}
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));
}
Aggregations