コード例 #1
0
        public void FilterLog_Key_Generates_Expected_Value()
        {
            var populatedLog = new FilterLog {
                TransactionHash = "x", LogIndex = new HexBigInteger(0)
            };
            var emptyLog = new FilterLog();

            Assert.Equal("x0x0", populatedLog.Key());
            Assert.Equal(emptyLog.GetHashCode().ToString(), emptyLog.Key());
        }
コード例 #2
0
        public static GenericSearchDocument ToGenericElasticSearchDoc(
            this FilterLog log,
            SearchField[] searchFields)
        {
            var dictionary = new GenericSearchDocument();

            foreach (var field in searchFields)
            {
                var val = field.GetFilterLogValue(log)?.ToElasticSearchFieldValue();
                if (val != null)
                {
                    dictionary.Add(field.Name.ToElasticName(), val);
                }
            }

            var id = log.Key();

            dictionary.SetId(id.ToString());

            return(dictionary);
        }
        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()]);
        }
コード例 #4
0
        public void FilterLog_Merge_Adds_Non_Duplicated_Candidate_Logs()
        {
            var log1 = new FilterLog {
                TransactionHash = "x", LogIndex = new HexBigInteger(0)
            };
            var dupe = new FilterLog {
                TransactionHash = "x", LogIndex = new HexBigInteger(0)
            };
            var log2 = new FilterLog {
                TransactionHash = "y", LogIndex = new HexBigInteger(0)
            };

            var masterList = new Dictionary <string, FilterLog>();

            masterList.Add(log1.Key(), log1);

            var candidates = new[] { dupe, log2 };
            var merged     = masterList.Merge(candidates);

            Assert.Same(merged, masterList);
            Assert.Contains(log1, masterList.Values);
            Assert.Contains(log2, masterList.Values);
            Assert.DoesNotContain(dupe, masterList.Values);
        }
        public async Task MapsFilterLogToGenericSearchDocument()
        {
            var searchIndexClientMock = new SearchIndexClientMock <GenericSearchDocument>();

            var index = FilterLogIndexUtil.Create("my-logs");

            var indexer = new AzureFilterLogIndexer(searchIndexClientMock.SearchIndexClient);

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

            await indexer.IndexAsync(filterLog);

            var indexedBatch = searchIndexClientMock.IndexedBatches.FirstOrDefault();

            Assert.Single(indexedBatch.Actions);
            var action = indexedBatch.Actions.First();

            Assert.Equal(IndexActionType.MergeOrUpload, action.ActionType);
            Assert.Equal(filterLog.Key(), action.Document[PresetSearchFieldName.log_key.ToString()]);
        }
コード例 #6
0
        public void BuildsExpectedIndexForCodeGeneratedEventDto()
        {
            var searchIndex = new EventIndexDefinition <DepositedEventDTO>();

            var depositedEventDto = new DepositedEventDTO
            {
                NewBalance = new HexBigInteger("100"),
                Value      = new HexBigInteger("10"),
                Sender     = "adsfadsfasdfasdf",
                Detail     = new DepositDetailDTO
                {
                    Currency   = "GBP",
                    Timestamp  = DateTimeOffset.UnixEpoch.ToUnixTimeSeconds(),
                    Categories = new List <CategoryDTO>
                    {
                        new CategoryDTO {
                            Name = "Dodgy"
                        },
                        new CategoryDTO {
                            Name = "International"
                        }
                    },
                    Tags = new List <string> {
                        "A", "B"
                    }
                }
            };

            var filterLog = new FilterLog
            {
                Type             = "type",
                Address          = "address",
                BlockHash        = "block_hash",
                BlockNumber      = new HexBigInteger(101),
                TransactionHash  = "transaction_hash",
                TransactionIndex = new HexBigInteger(3),
                LogIndex         = new HexBigInteger(9),
                Removed          = false
            };

            var eventLog = new EventLog <DepositedEventDTO>(depositedEventDto, filterLog);

            Assert.Equal("Deposited", searchIndex.IndexName);
            Assert.Equal(18, searchIndex.Fields.Length);

            searchIndex
            .Assertions(eventLog)
            .HasField(nameof(depositedEventDto.Sender),
                      f => f.IsString(),
                      f => f.HasFlags(isSearchable: true, isFacetable: true, isFilterable: true, isSortable: true),
                      f => f.ReturnsValue(depositedEventDto.Sender))
            .HasField(nameof(depositedEventDto.Value),
                      f => f.DataType <BigInteger>(),
                      f => f.HasFlags(),
                      f => f.ReturnsValue(depositedEventDto.Value))
            .HasField(nameof(depositedEventDto.NewBalance),
                      f => f.DataType <BigInteger>(),
                      f => f.HasFlags(),
                      f => f.ReturnsValue(depositedEventDto.NewBalance))
            .HasField("Detail.Currency",
                      f => f.IsString(),
                      f => f.HasFlags(isSearchable: true, isFilterable: true, isFacetable: true),
                      f => f.ReturnsValue(depositedEventDto.Detail.Currency))
            .HasField("Detail.Categories.Name",
                      f => f.IsString(),
                      f => f.ReturnsValue <string[]>(categoryNameArray =>
            {
                var x = depositedEventDto.Detail.Categories.Select(cat => cat.Name).ToCommaSeparatedString();
                var y = categoryNameArray.ToCommaSeparatedString();
                return(x, y);
            }))
            .HasField("Detail.Tags",
                      f => f.DataType <List <string> >(),
                      f => f.HasFlags(isCollection: true),
                      f => f.ReturnsValue <string[]>(tags =>
            {
                var x = depositedEventDto.Detail.Tags.ToCommaSeparatedString();
                var y = tags.ToCommaSeparatedString();
                return(x, y);
            }))
            .HasField(PresetSearchFieldName.log_key,
                      f => f.IsString(),
                      f => f.HasFlags(isKey: true, isSortable: true),
                      f => f.ReturnsValue(filterLog.Key()))
            .HasField(PresetSearchFieldName.log_removed,
                      f => f.DataType <bool>(),
                      f => f.HasFlags(isFilterable: true, isSortable: true),
                      f => f.ReturnsValue(filterLog.Removed))
            .HasField(PresetSearchFieldName.log_type,
                      f => f.IsString(),
                      f => f.HasFlags(isFilterable: true, isSortable: true),
                      f => f.ReturnsValue(filterLog.Type))
            .HasField(PresetSearchFieldName.log_log_index,
                      f => f.IsHexBigInteger(),
                      f => f.HasFlags(isFilterable: true),
                      f => f.ReturnsValue(filterLog.LogIndex))
            .HasField(PresetSearchFieldName.log_transaction_hash,
                      f => f.IsString(),
                      f => f.HasFlags(isSearchable: true, isFilterable: true, isFacetable: true),
                      f => f.ReturnsValue(filterLog.TransactionHash))
            .HasField(PresetSearchFieldName.log_transaction_index,
                      f => f.IsHexBigInteger(),
                      f => f.HasFlags(isFilterable: true),
                      f => f.ReturnsValue(filterLog.TransactionIndex))
            .HasField(PresetSearchFieldName.log_block_hash,
                      f => f.IsString(),
                      f => f.HasFlags(),
                      f => f.ReturnsValue(filterLog.BlockHash))
            .HasField(PresetSearchFieldName.log_block_number,
                      f => f.IsHexBigInteger(),
                      f => f.HasFlags(isFilterable: true, isSearchable: true, isSortable: true, isFacetable: true),
                      f => f.ReturnsValue(filterLog.BlockNumber))
            .HasField(PresetSearchFieldName.log_address,
                      f => f.IsString(),
                      f => f.HasFlags(isFilterable: true, isSearchable: true, isSortable: true, isFacetable: true),
                      f => f.ReturnsValue(filterLog.Address))
            .HasField(PresetSearchFieldName.log_topics,
                      f => f.IsString(),
                      f => f.HasFlags(isFilterable: true, isSearchable: true, isFacetable: true, isCollection: true),
                      f => f.ReturnsValue(filterLog.Topics));
        }