Ejemplo n.º 1
0
        public async Task GenesisWithEmptyParametersTimeShouldReject()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider();

            ChainConstants chainConstants = testServiceProvider.GetService <ChainConstants>();
            IOptionsMonitor <MiscellaneousParameters> miscellaneousParameterOptions = testServiceProvider.GetService <IOptionsMonitor <MiscellaneousParameters> >();
            IOptionsMonitor <GweiValues>              gweiValueOptions               = testServiceProvider.GetService <IOptionsMonitor <GweiValues> >();
            IOptionsMonitor <InitialValues>           initialValueOptions            = testServiceProvider.GetService <IOptionsMonitor <InitialValues> >();
            IOptionsMonitor <TimeParameters>          timeParameterOptions           = testServiceProvider.GetService <IOptionsMonitor <TimeParameters> >();
            IOptionsMonitor <StateListLengths>        stateListLengthOptions         = testServiceProvider.GetService <IOptionsMonitor <StateListLengths> >();
            IOptionsMonitor <RewardsAndPenalties>     rewardsAndPenaltiesOptions     = testServiceProvider.GetService <IOptionsMonitor <RewardsAndPenalties> >();
            IOptionsMonitor <MaxOperationsPerBlock>   maxOperationsPerBlockOptions   = testServiceProvider.GetService <IOptionsMonitor <MaxOperationsPerBlock> >();
            IOptionsMonitor <ForkChoiceConfiguration> forkChoiceConfigurationOptions = testServiceProvider.GetService <IOptionsMonitor <ForkChoiceConfiguration> >();
            IOptionsMonitor <SignatureDomains>        signatureDomainOptions         = testServiceProvider.GetService <IOptionsMonitor <SignatureDomains> >();

            miscellaneousParameterOptions.CurrentValue.MinimumGenesisActiveValidatorCount = 2;

            LoggerFactory loggerFactory = new LoggerFactory(new[] {
                new ConsoleLoggerProvider(TestOptionsMonitor.Create(new ConsoleLoggerOptions()))
            });

            ICryptographyService cryptographyService = testServiceProvider.GetService <ICryptographyService>();

            BeaconChainUtility beaconChainUtility = new BeaconChainUtility(loggerFactory.CreateLogger <BeaconChainUtility>(),
                                                                           miscellaneousParameterOptions, gweiValueOptions, timeParameterOptions,
                                                                           cryptographyService);
            BeaconStateAccessor beaconStateAccessor = new BeaconStateAccessor(miscellaneousParameterOptions, initialValueOptions, timeParameterOptions, stateListLengthOptions, signatureDomainOptions,
                                                                              cryptographyService, beaconChainUtility);
            BeaconStateMutator beaconStateMutator = new BeaconStateMutator(chainConstants, timeParameterOptions, stateListLengthOptions, rewardsAndPenaltiesOptions,
                                                                           beaconChainUtility, beaconStateAccessor);
            BeaconStateTransition beaconStateTransition = new BeaconStateTransition(loggerFactory.CreateLogger <BeaconStateTransition>(),
                                                                                    chainConstants, miscellaneousParameterOptions, gweiValueOptions, initialValueOptions, timeParameterOptions, stateListLengthOptions, rewardsAndPenaltiesOptions, maxOperationsPerBlockOptions, signatureDomainOptions,
                                                                                    cryptographyService, beaconChainUtility, beaconStateAccessor, beaconStateMutator);

            BeaconNode.Genesis beaconChain = new BeaconNode.Genesis(loggerFactory.CreateLogger <BeaconNode.Genesis>(),
                                                                    chainConstants, miscellaneousParameterOptions,
                                                                    gweiValueOptions, initialValueOptions, timeParameterOptions, stateListLengthOptions, maxOperationsPerBlockOptions,
                                                                    cryptographyService, beaconStateAccessor, beaconStateTransition);
            MemoryStoreProvider storeProvider = new MemoryStoreProvider(loggerFactory, timeParameterOptions);
            ForkChoice          forkChoice    = new ForkChoice(loggerFactory.CreateLogger <ForkChoice>(),
                                                               miscellaneousParameterOptions, initialValueOptions, timeParameterOptions, stateListLengthOptions, maxOperationsPerBlockOptions, forkChoiceConfigurationOptions, signatureDomainOptions,
                                                               cryptographyService, beaconChainUtility, beaconStateAccessor, beaconStateTransition, storeProvider);
            ChainStart chainStart = new ChainStart(loggerFactory.CreateLogger <ChainStart>(), beaconChain, forkChoice);

            // Act
            Hash32 eth1BlockHash = Hash32.Zero;
            ulong  eth1Timestamp = 106185600uL; // 1973-05-14

            Deposit[] deposits = Array.Empty <Deposit>();
            bool      success  = await chainStart.TryGenesisAsync(eth1BlockHash, eth1Timestamp, deposits);

            // Assert
            success.ShouldBeFalse();
        }
 public override async Task <bool> HandleMessageAsync(Message message, IMessageContext context)
 {
     if (MatchMessage(message, context))
     {
         if (ChainStart != null)
         {
             await ChainStart.ApplyStateAsync(message, context);
         }
         return(true);
     }
     else if (ChainStart != null && !(await context.StateRepository.GetStateAsync(message.Chat.Id, message.From.Id)).IsEmpty)
     {
         return(await ChainStart.HandleMessageAsync(message, context));
     }
     return(false);
 }
Ejemplo n.º 3
0
        public int CompareTo(object obj)
        {
            ChainStart objCS = (ChainStart)obj;

            if (v.x < objCS.v.x)
            {
                return(-1);
            }
            else if (v.x == objCS.v.x)
            {
                if (v.y < objCS.v.y)
                {
                    return(-1);
                }
            }
            return(1);
        }