public void MapsFilterLogIntoDictionary() { var sourceLog = TestData.Contracts.StandardContract.SampleTransferLog(); sourceLog.Type = "x"; //often null - so we're giving it a value to test mapping var mapped = FilterLogIndexUtil.Map(sourceLog); Assert.Equal(sourceLog.Key(), mapped[PresetSearchFieldName.log_key.ToString()]); Assert.Equal(sourceLog.Removed, mapped[PresetSearchFieldName.log_removed.ToString()]); Assert.Equal(sourceLog.Type, mapped[PresetSearchFieldName.log_type.ToString()]); Assert.Equal(sourceLog.LogIndex.Value.ToString(), mapped[PresetSearchFieldName.log_log_index.ToString()]); Assert.Equal(sourceLog.TransactionHash, mapped[PresetSearchFieldName.log_transaction_hash.ToString()]); Assert.Equal(sourceLog.TransactionIndex.Value.ToString(), mapped[PresetSearchFieldName.log_transaction_index.ToString()]); Assert.Equal(sourceLog.BlockHash, mapped[PresetSearchFieldName.log_block_hash.ToString()]); Assert.Equal(sourceLog.BlockNumber.Value.ToString(), mapped[PresetSearchFieldName.log_block_number.ToString()]); Assert.Equal(sourceLog.Address, mapped[PresetSearchFieldName.log_address.ToString()]); Assert.Equal(sourceLog.Data, mapped[PresetSearchFieldName.log_data.ToString()]); var actualTopics = mapped[PresetSearchFieldName.log_topics.ToString()] as object[]; for (var i = 0; i < sourceLog.Topics.Length; i++) { Assert.Equal(sourceLog.Topics[i], actualTopics[i]); } }
public void RetrievableFields() { var index = FilterLogIndexUtil.Create("my-index"); var allFieldCount = Enum.GetNames(typeof(PresetSearchFieldName)).Where(n => n.StartsWith("log_")).Count(); Assert.Equal(allFieldCount, index.Fields.Count(f => f.IsRetrievable ?? false)); }
public void CreatesExpectedKeyField() { var index = FilterLogIndexUtil.Create("my-index"); var keyFields = index.Fields.Where(f => f.IsKey ?? false).ToArray(); Assert.Single(keyFields); Assert.Contains(keyFields, f => f.Name == PresetSearchFieldName.log_key.ToString()); }
public void CreatesAnAzureIndexDefinitionContainingAllFilterLogFields() { var index = FilterLogIndexUtil.Create("my-index"); foreach (var fieldName in Enum.GetNames(typeof(PresetSearchFieldName)).Where(n => n.StartsWith("log_"))) { Assert.Contains(index.Fields, f => f.Name == fieldName); } }
public void SearchableFields() { var index = FilterLogIndexUtil.Create("my-index"); var searchableFields = index.Fields.Where(f => f.IsSearchable ?? false).ToArray(); var expectedFields = new[] { PresetSearchFieldName.log_address, PresetSearchFieldName.log_block_number, PresetSearchFieldName.log_transaction_hash, PresetSearchFieldName.log_topics }; CheckFields(searchableFields, expectedFields); }
public void FilterableFields() { var index = FilterLogIndexUtil.Create("my-index"); var filterableFields = index.Fields.Where(f => f.IsFilterable).ToArray(); var expectedFields = new[] { PresetSearchFieldName.log_removed, PresetSearchFieldName.log_type, PresetSearchFieldName.log_log_index, PresetSearchFieldName.log_transaction_hash, PresetSearchFieldName.log_transaction_index, PresetSearchFieldName.log_block_number, PresetSearchFieldName.log_address, PresetSearchFieldName.log_topics }; CheckFields(filterableFields, expectedFields); }
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()]); }