Ejemplo n.º 1
0
        private void Assert(IEnumerable <Action <FilterBuilder> > filterBuilders,
                            IEnumerable <Action <ReceiptBuilder> > receiptBuilders,
                            Action <IEnumerable <FilterLog> > logsAssertion)
        {
            var filters  = new List <FilterBase>();
            var receipts = new List <TxReceipt>();

            foreach (var filterBuilder in filterBuilders)
            {
                filters.Add(BuildFilter(filterBuilder));
            }

            foreach (var receiptBuilder in receiptBuilders)
            {
                receipts.Add(BuildReceipt(receiptBuilder));
            }

            // adding always a simple block filter and test
            Block       block       = Build.A.Block.TestObject;
            BlockFilter blockFilter = new BlockFilter(_currentFilterId++, 0);

            filters.Add(blockFilter);

            _filterStore.GetFilters <LogFilter>().Returns(filters.OfType <LogFilter>().ToArray());
            _filterStore.GetFilters <BlockFilter>().Returns(filters.OfType <BlockFilter>().ToArray());
            _filterManager = new FilterManager(_filterStore, _blockProcessor, _txPool, _logManager);

            _blockProcessor.BlockProcessed += Raise.EventWith(_blockProcessor, new BlockProcessedEventArgs(block));

            var index = 1;

            foreach (var receipt in receipts)
            {
                _blockProcessor.TransactionProcessed += Raise.EventWith(_blockProcessor,
                                                                        new TxProcessedEventArgs(index, Build.A.Transaction.TestObject, receipt));
                index++;
            }

            NUnit.Framework.Assert.Multiple(() =>
            {
                foreach (var filter in filters.OfType <LogFilter>())
                {
                    var logs = _filterManager.GetLogs(filter.Id);
                    logsAssertion(logs);
                }

                var hashes = _filterManager.GetBlocksHashes(blockFilter.Id);
                NUnit.Framework.Assert.AreEqual(1, hashes.Length);
            });
        }
Ejemplo n.º 2
0
        private void OnNewPendingTransaction(object sender, TxEventArgs e)
        {
            var filters = _filterStore.GetFilters <PendingTransactionFilter>();

            if (filters == null || filters.Length == 0)
            {
                return;
            }

            for (var i = 0; i < filters.Length; i++)
            {
                var filterId     = filters[i].Id;
                var transactions = _pendingTransactions.GetOrAdd(filterId, _ => new List <Keccak>());
                transactions.Add(e.Transaction.Hash);
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Filter with id: '{filterId}' contains {transactions.Count} transactions.");
                }
            }
        }