public async Task TestGenerationOfFirstValidator() { // Arrange var overrideConfiguration = new Dictionary <string, string> { ["QuickStart:GenesisTime"] = "1578009600", ["QuickStart:ValidatorCount"] = "1", ["BeaconChain:MiscellaneousParameters:MinimumGenesisActiveValidatorCount"] = "1" }; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(overrideConfiguration); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); // Act Eth1BridgeWorker eth1BridgeWorker = testServiceProvider.GetServices <IHostedService>().OfType <Eth1BridgeWorker>().First(); await eth1BridgeWorker.ExecuteEth1GenesisAsync(CancellationToken.None); // Assert testServiceProvider.GetService <IEth1GenesisProvider>().ShouldBeOfType <QuickStartMockEth1GenesisProvider>(); IStore store = testServiceProvider.GetService <IStore>(); BeaconState state = await store.GetBlockStateAsync(store.FinalizedCheckpoint.Root); BlsPublicKey expectedKey0 = new BlsPublicKey(_testDataItems[0].PublicKey); state.Validators[0].PublicKey.ShouldBe(expectedKey0); }
public async Task TestValidatorKeyGeneration64() { // Arrange var overrideConfiguration = new Dictionary <string, string> { ["QuickStart:GenesisTime"] = "1578009600", ["QuickStart:ValidatorCount"] = "64" }; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(overrideConfiguration); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); // Act Eth1BridgeWorker eth1BridgeWorker = testServiceProvider.GetServices <IHostedService>().OfType <Eth1BridgeWorker>().First(); await eth1BridgeWorker.ExecuteEth1GenesisAsync(CancellationToken.None); // Assert testServiceProvider.GetService <IEth1GenesisProvider>().ShouldBeOfType <QuickStartMockEth1GenesisProvider>(); IStore store = testServiceProvider.GetService <IStore>(); BeaconState state = await store.GetBlockStateAsync(store.FinalizedCheckpoint.Root); state.Validators.Count.ShouldBe(64); }
public async Task BasicNewBlock() { // Arrange int numberOfValidators = 64; int genesisTime = 1578009600; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true); IConfigurationRoot configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["QuickStart:ValidatorCount"] = $"{numberOfValidators}", ["QuickStart:GenesisTime"] = $"{genesisTime}" }) .Build(); testServiceCollection.AddBeaconNodeQuickStart(configuration); testServiceCollection.AddBeaconNodeEth1Bridge(configuration); testServiceCollection.AddSingleton <IHostEnvironment>(Substitute.For <IHostEnvironment>()); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); Eth1BridgeWorker eth1BridgeWorker = testServiceProvider.GetServices <IHostedService>().OfType <Eth1BridgeWorker>().First(); await eth1BridgeWorker.ExecuteEth1GenesisAsync(CancellationToken.None); IBeaconNodeApi beaconNode = testServiceProvider.GetService <IBeaconNodeApi>(); ApiResponse <Fork> forkResponse = await beaconNode.GetNodeForkAsync(CancellationToken.None); Fork fork = forkResponse.Content; fork.CurrentVersion.ShouldBe(new ForkVersion(new byte[4] { 0x00, 0x00, 0x00, 0x01 })); // Act BlockProducer blockProducer = testServiceProvider.GetService <BlockProducer>(); Slot targetSlot = new Slot(1); // With QuickStart64, proposer for Slot 1 is validator index 29, 0xa98ed496... QuickStartMockEth1GenesisProvider quickStartMockEth1GenesisProvider = (QuickStartMockEth1GenesisProvider)testServiceProvider.GetService <IEth1GenesisProvider>(); byte[] privateKey = quickStartMockEth1GenesisProvider.GeneratePrivateKey(29); BlsSignature randaoReveal = GetEpochSignature(testServiceProvider, privateKey, fork.CurrentVersion, targetSlot); // value for quickstart 20/64, fork 0, slot 1 randaoReveal.ToString().StartsWith("0x932f8730"); BeaconBlock newBlock = await blockProducer.NewBlockAsync(targetSlot, randaoReveal, CancellationToken.None); // Assert newBlock.Slot.ShouldBe(targetSlot); newBlock.Body.RandaoReveal.ShouldBe(randaoReveal); newBlock.ParentRoot.ToString().ShouldStartWith("0x4d4e9a16"); newBlock.Body.Eth1Data.DepositCount.ShouldBe((ulong)numberOfValidators); newBlock.Body.Eth1Data.DepositRoot.ToString().ShouldStartWith("0x66687aad"); newBlock.StateRoot.ToString().ShouldStartWith("0x0138b69f"); newBlock.Body.Attestations.Count.ShouldBe(0); newBlock.Body.Deposits.Count.ShouldBe(0); }
public async Task QuickStart64DutiesForEpochZeroHaveExactlyOneProposerPerSlot() { // Arrange int numberOfValidators = 64; int genesisTime = 1578009600; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true); IConfigurationRoot configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["QuickStart:ValidatorCount"] = $"{numberOfValidators}", ["QuickStart:GenesisTime"] = $"{genesisTime}" }) .Build(); testServiceCollection.AddBeaconNodeEth1Bridge(configuration); testServiceCollection.AddBeaconNodeQuickStart(configuration); testServiceCollection.AddSingleton <IHostEnvironment>(Substitute.For <IHostEnvironment>()); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); Eth1BridgeWorker eth1BridgeWorker = testServiceProvider.GetServices <IHostedService>().OfType <Eth1BridgeWorker>().First(); await eth1BridgeWorker.ExecuteEth1GenesisAsync(CancellationToken.None); IStore store = testServiceProvider.GetService <IStore>(); BeaconState state = await store !.GetBlockStateAsync(store.FinalizedCheckpoint.Root); // Act Epoch targetEpoch = new Epoch(0); var validatorPublicKeys = state !.Validators.Select(x => x.PublicKey).ToList(); IBeaconNodeApi beaconNode = testServiceProvider.GetService <IBeaconNodeApi>(); beaconNode.ShouldBeOfType(typeof(BeaconNodeFacade)); int validatorDutyIndex = 0; List <ValidatorDuty> validatorDuties = new List <ValidatorDuty>(); var validatorDutiesResponse = await beaconNode.ValidatorDutiesAsync(validatorPublicKeys, targetEpoch, CancellationToken.None); foreach (ValidatorDuty validatorDuty in validatorDutiesResponse.Content) { validatorDuties.Add(validatorDuty); Console.WriteLine("Index [{0}], Epoch {1}, Validator {2}, : attestation slot {3}, shard {4}, proposal slot {5}", validatorDutyIndex, targetEpoch, validatorDuty.ValidatorPublicKey, validatorDuty.AttestationSlot, (ulong)validatorDuty.AttestationShard, validatorDuty.BlockProposalSlot); validatorDutyIndex++; } Console.WriteLine(); Console.WriteLine("** ValidatorDuty summary"); foreach (ValidatorDuty validatorDuty in validatorDuties) { Console.WriteLine("Index [{0}], Epoch {1}, Validator {2}, : attestation slot {3}, shard {4}, proposal slot {5}", validatorDutyIndex, targetEpoch, validatorDuty.ValidatorPublicKey, validatorDuty.AttestationSlot, (ulong)validatorDuty.AttestationShard, validatorDuty.BlockProposalSlot); } // Assert Dictionary <Slot, IGrouping <Slot, ValidatorDuty> > groupsByProposalSlot = validatorDuties .Where(x => x.BlockProposalSlot.HasValue) .GroupBy(x => x.BlockProposalSlot !.Value) .ToDictionary(x => x.Key, x => x); groupsByProposalSlot[new Slot(0)].Count().ShouldBe(1); groupsByProposalSlot[new Slot(1)].Count().ShouldBe(1); groupsByProposalSlot[new Slot(2)].Count().ShouldBe(1); groupsByProposalSlot[new Slot(3)].Count().ShouldBe(1); groupsByProposalSlot[new Slot(4)].Count().ShouldBe(1); groupsByProposalSlot[new Slot(5)].Count().ShouldBe(1); groupsByProposalSlot[new Slot(6)].Count().ShouldBe(1); //groupsByProposalSlot[new Slot(7)].Count().ShouldBe(1); //groupsByProposalSlot[Slot.None].Count().ShouldBe(numberOfValidators - 8); }