Exemple #1
0
        public async Task MapsSourceToSearchDocument()
        {
            var mockElasticClient    = new MockElasticClient();
            var mappedSearchDocument = new SearchDocument();

            var indexer = new ElasticIndexer <Source, SearchDocument>("my-index",
                                                                      mockElasticClient.ElasticClient, (tfr) => mappedSearchDocument);

            var source = new Source();

            await indexer.IndexAsync(source);

            Assert.Single(mockElasticClient.BulkRequests);
            var indexedDoc = mockElasticClient.GetFirstBulkOperation().GetBody() as SearchDocument;

            Assert.Same(mappedSearchDocument, indexedDoc);
        }
        public async Task MapsTransactionToSearchDocument()
        {
            var mockElasticClient = new MockElasticClient();

            var indexer = new ElasticTransactionReceiptVOIndexer <SearchDocument>("my-index",
                                                                                  mockElasticClient.ElasticClient, (tx) => new SearchDocument(tx));

            TransactionReceiptVO transaction = IndexerTestData.CreateSampleTransaction();

            await indexer.IndexAsync(transaction);

            Assert.Single(mockElasticClient.BulkRequests);
            var indexedDocument = mockElasticClient.GetFirstBulkOperation().GetBody() as SearchDocument;

            //check mapping
            Assert.Same(transaction, indexedDocument.TransactionReceiptVO);
        }
        public async Task MapsFilterLogToSearchDocument()
        {
            var mockElasticClient = new MockElasticClient();

            var indexer = new ElasticFilterLogIndexer <SearchDocument>("my-index",
                                                                       mockElasticClient.ElasticClient, (tfr) => new SearchDocument(tfr.TransactionHash, tfr.LogIndex));

            var log = TestData.Contracts.StandardContract.SampleTransferLog();

            await indexer.IndexAsync(log);

            Assert.Single(mockElasticClient.BulkRequests);
            var searchDoc = mockElasticClient.GetFirstBulkOperation().GetBody() as SearchDocument;

            Assert.Equal(log.TransactionHash, searchDoc.TransactionHash);
            Assert.Equal(log.LogIndex.Value.ToString(), searchDoc.LogIndex);
        }
        public async Task MapsEventDtoToSearchDocument()
        {
            var mockSearchIndexClient = new MockElasticClient();

            var indexer = new ElasticEventIndexer <TransferEvent, SearchDocument>("transfers",
                                                                                  mockSearchIndexClient.ElasticClient, (tfr) => new SearchDocument(tfr.Log.TransactionHash, tfr.Log.LogIndex));

            var eventLog = TestData.Contracts.StandardContract.SampleTransferEventLog();

            await indexer.IndexAsync(eventLog);

            Assert.Single(mockSearchIndexClient.BulkRequests);
            var actualSearchDocument = mockSearchIndexClient.GetFirstBulkOperation().GetBody() as SearchDocument;

            Assert.Equal(eventLog.Log.TransactionHash, actualSearchDocument.TransactionHash);
            Assert.Equal(eventLog.Log.LogIndex.Value.ToString(), actualSearchDocument.LogIndex);
        }
Exemple #5
0
        public async Task MapsTransactionToGenericSearchDocument()
        {
            var indexDefinition   = new TransactionReceiptVOIndexDefinition("my-transactions");
            var mockElasticClient = new MockElasticClient();

            var indexer = new ElasticTransactionReceiptVOIndexer("my-index",
                                                                 mockElasticClient.ElasticClient, indexDefinition);

            TransactionReceiptVO transaction = IndexerTestData.CreateSampleTransaction();

            await indexer.IndexAsync(transaction);

            Assert.Single(mockElasticClient.BulkRequests);
            var indexedDoc = mockElasticClient.GetFirstBulkOperation().GetBody() as GenericSearchDocument;

            //check generic mapping
            Assert.Equal(transaction.Transaction.BlockNumber.ToString(), indexedDoc[PresetSearchFieldName.tx_block_number.ToString()]);
        }
Exemple #6
0
        public async Task MapsEventDtoToGenericSearchDocument()
        {
            var indexDefinition   = new EventIndexDefinition <TransferEvent>();
            var mockElasticClient = new MockElasticClient();

            var indexer = new ElasticEventIndexer <TransferEvent>(
                "Transfers", mockElasticClient.ElasticClient, indexDefinition);

            var eventLog = TestData.Contracts.StandardContract.SampleTransferEventLog();

            await indexer.IndexAsync(eventLog);

            Assert.Single(mockElasticClient.BulkRequests);
            var actualOperation = mockElasticClient.GetFirstBulkOperation();

            Assert.NotNull(actualOperation);
            Assert.Equal("index", actualOperation.Operation);
            Assert.Equal(typeof(GenericSearchDocument), actualOperation.ClrType);
        }
        public async Task MapsFunctionDtoToSearchDocument()
        {
            var mockElasticClient = new MockElasticClient();

            var indexer = new ElasticFunctionIndexer <TransferFunction, SearchDocument>("my-index",
                                                                                        mockElasticClient.ElasticClient, (tx) => new SearchDocument(tx));

            TransactionForFunctionVO <TransferFunction> transactionForFunction = IndexerTestData.CreateSampleTransactionForFunction();

            await indexer.IndexAsync(transactionForFunction);

            Assert.Single(mockElasticClient.BulkRequests);
            var indexedDoc = mockElasticClient.GetFirstBulkOperation().GetBody() as SearchDocument;

            //check function message mapping
            Assert.Equal(transactionForFunction.Transaction.TransactionHash, indexedDoc.TransactionHash);
            Assert.Equal(transactionForFunction.FunctionMessage.To, indexedDoc.To);
            Assert.Equal(transactionForFunction.FunctionMessage.Value.ToString(), indexedDoc.Value);
        }
Exemple #8
0
        public async Task MapsFunctionDtoToGenericSearchDocument()
        {
            var indexDefinition       = new FunctionIndexDefinition <TransferFunction>();
            var mockSearchIndexClient = new MockElasticClient();

            var indexer = new ElasticFunctionIndexer <TransferFunction>("transfer-functions",
                                                                        mockSearchIndexClient.ElasticClient, indexDefinition);

            TransactionForFunctionVO <TransferFunction> transactionForFunction = IndexerTestData.CreateSampleTransactionForFunction();

            await indexer.IndexAsync(transactionForFunction);

            Assert.Single(mockSearchIndexClient.BulkRequests);
            var indexedDoc = mockSearchIndexClient.GetFirstBulkOperation().GetBody() as GenericSearchDocument;

            //check generic mapping
            Assert.Equal(transactionForFunction.Transaction.BlockNumber.ToString(), indexedDoc[PresetSearchFieldName.tx_block_number.ToString()]);
            //check function message mapping
            Assert.Equal(transactionForFunction.FunctionMessage.To, indexedDoc["to"]);
            Assert.Equal(transactionForFunction.FunctionMessage.Value.ToString(), indexedDoc["value"]);
        }
        public async Task MapsFilterLogToGenericSearchDocument()
        {
            var mockElasticClient = new MockElasticClient();

            var indexer = new ElasticFilterLogIndexer("my-index", mockElasticClient.ElasticClient);

            var filterLog = new FilterLog
            {
                BlockNumber     = new Hex.HexTypes.HexBigInteger(4309),
                TransactionHash = "0x3C81039C578811A85742F2476DA90E363A88CA93763DB4A194E35367D9A72FD8",
                LogIndex        = new Hex.HexTypes.HexBigInteger(9)
            };

            await indexer.IndexAsync(filterLog);

            var bulkRequest = mockElasticClient.BulkRequests.FirstOrDefault();

            Assert.Single(bulkRequest.Operations);
            var searchDocument = bulkRequest.Operations.First().GetBody() as GenericSearchDocument;

            Assert.Equal(filterLog.Key(), searchDocument[PresetSearchFieldName.log_key.ToString()]);
        }