예제 #1
0
        public void Setup()
        {
            _depositNodesHandlerFactory = Substitute.For <IDepositNodesHandlerFactory>();
            _sessionManager             = Substitute.For <ISessionManager>();
            _receiptsPolicies           = Substitute.For <IReceiptsPolicies>();
            _receiptProcessor           = Substitute.For <IReceiptProcessor>();
            _paymentClaimProcessor      = Substitute.For <IPaymentClaimProcessor>();
            _consumerRepository         = Substitute.For <IConsumerRepository>();
            _paymentClaimRepository     = Substitute.For <IPaymentClaimRepository>();
            _sessionRepository          = Substitute.For <IProviderSessionRepository>();
            _sessionRepository.BrowseAsync(Arg.Any <GetProviderSessions>()).Returns(PagedResult <ProviderSession> .Empty);
            _receiptRepository = Substitute.For <IReceiptRepository>();
            var unixTime = UnixTime.FromSeconds(100);

            _timestamper = Substitute.For <ITimestamper>();
            _timestamper.UnixTime.Returns(unixTime);
            _gasPriceService     = Substitute.For <IGasPriceService>();
            _logManager          = Substitute.For <ILogManager>();
            _wallet              = Substitute.For <IWallet>();
            _address             = Address.Zero;
            _consumer            = Address.Zero;
            _depositNodesHandler = new InMemoryDepositNodesHandler(Keccak.Zero, _consumer, DataAssetUnitType.Unit, 0,
                                                                   100, 0,
                                                                   0, 0, 0, 0, 0, 0, null, null, 0);
            _depositNodesHandlerFactory.CreateInMemory(Arg.Any <Keccak>(), _consumer, Arg.Any <DataAssetUnitType>(),
                                                       Arg.Any <uint>(), Arg.Any <uint>(), Arg.Any <UInt256>(), Arg.Any <uint>(), Arg.Any <uint>(), Arg.Any <uint>(),
                                                       Arg.Any <uint>(), Arg.Any <uint>(), Arg.Any <uint>(), Arg.Any <PaymentClaim>(),
                                                       Arg.Any <IEnumerable <DataDeliveryReceiptDetails> >(), Arg.Any <uint>()).Returns(_depositNodesHandler);
            _depositManager = new DepositManager(_depositNodesHandlerFactory, _sessionManager, _receiptsPolicies,
                                                 _wallet, _address, _receiptProcessor, _paymentClaimProcessor, _consumerRepository,
                                                 _paymentClaimRepository, _receiptRepository, _sessionRepository, _timestamper, _gasPriceService,
                                                 _logManager);
        }
        public void Parent_timestamp_is_used_consistently()
        {
            ITimestamper      timestamper       = new IncrementalTimestamper(DateTime.UnixEpoch, TimeSpan.FromSeconds(1));
            ProducerUnderTest producerUnderTest = new ProducerUnderTest(
                EmptyTxSource.Instance,
                Substitute.For <IBlockchainProcessor>(),
                NullSealEngine.Instance,
                Build.A.BlockTree().TestObject,
                Substitute.For <IBlockProcessingQueue>(),
                Substitute.For <IStateProvider>(),
                Substitute.For <IGasLimitCalculator>(),
                timestamper,
                LimboLogs.Instance);

            ulong futureTime = UnixTime.FromSeconds(TimeSpan.FromDays(1).TotalSeconds).Seconds;
            Block block      = producerUnderTest.Prepare(Build.A.BlockHeader.WithTimestamp(futureTime).TestObject);

            block.Timestamp.Should().BeEquivalentTo(block.Difficulty);
        }
예제 #3
0
        /// <summary>
        /// Searches the set of packet attributes for the first attribute with
        /// the specified type and returns its value as a TEXT string.
        /// </summary>
        /// <param name="type">The desired attribute type.</param>
        /// <param name="value">This will be filled in with the attribute value.</param>
        /// <returns><c>true</c> if the attribute was found.</returns>
        public bool GetAttributeAsTime(RadiusAttributeType type, out DateTime value)
        {
            for (int i = 0; i < this.Attributes.Count; i++)
            {
                if (this.Attributes[i].Type == type)
                {
                    int pos = 0;
                    int time;

                    time  = Helper.ReadInt32(this.Attributes[i].Value, ref pos);
                    value = UnixTime.FromSeconds(time);

                    return(true);
                }
            }

            value = UnixTime.TimeZero;
            return(false);
        }
        public void transactions_are_addable_to_block_after_sealing()
        {
            int chainId     = 5;
            var blockHeader = Build.A.BlockHeader.TestObject;
            var tx1         = Build.A.GeneratedTransaction.WithSenderAddress(TestItem.AddressA).TestObject;
            var tx2         = Build.A.GeneratedTransaction.WithSenderAddress(TestItem.AddressA).TestObject;
            var timestamper = Substitute.For <ITimestamper>();
            var stateReader = Substitute.For <IStateReader>();
            var nodeAddress = TestItem.AddressA;

            UInt256 expectedNonce = 10;

            stateReader.GetNonce(blockHeader.StateRoot, nodeAddress).Returns(expectedNonce);

            ulong expectedTimeStamp = 100;

            timestamper.UnixTime.Returns(UnixTime.FromSeconds(expectedTimeStamp));

            var gasLimit      = 200;
            var innerTxSource = Substitute.For <ITxSource>();

            innerTxSource.GetTransactions(blockHeader, gasLimit).Returns(new[] { tx1, tx2 });

            TxSealer txSealer          = new TxSealer(new Signer((ulong)chainId, Build.A.PrivateKey.TestObject, LimboLogs.Instance), timestamper);
            var      transactionFiller = new GeneratedTxSource(innerTxSource, txSealer, stateReader, LimboLogs.Instance);

            var sealedTxs = transactionFiller.GetTransactions(blockHeader, gasLimit).ToArray();
            var sealedTx1 = sealedTxs.First();
            var sealedTx2 = sealedTxs.Skip(1).First();

            sealedTx1.IsSigned.Should().BeTrue();
            sealedTx1.Nonce.Should().Be(expectedNonce);
            sealedTx1.Hash.Should().Be(tx1.CalculateHash());
            sealedTx1.Timestamp.Should().Be(expectedTimeStamp);

            sealedTx2.IsSigned.Should().BeTrue();
            sealedTx2.Nonce.Should().Be(expectedNonce + 1);
            sealedTx2.Hash.Should().NotBe(tx1.CalculateHash());
            sealedTx2.Timestamp.Should().Be(expectedTimeStamp);
        }