public async Task BlockStorageProcessing()
        {
            var repoFactory = new AzureTablesRepositoryFactory(_azureConnectionString, "bspsamples");

            try
            {
                //create our processor
                var processor = _web3.Processing.Blocks.CreateBlockStorageProcessor(repoFactory);

                //if we need to stop the processor mid execution - call cancel on the token
                var cancellationToken = new CancellationToken();

                //crawl the required block range
                await processor.ExecuteAsync(
                    toBlockNumber : new BigInteger(2830144),
                    cancellationToken : cancellationToken,
                    startAtBlockNumberIfNotProcessed : new BigInteger(2830144));

                var block = await repoFactory.CreateBlockRepository().FindByBlockNumberAsync(new HexBigInteger(2830144));

                Assert.NotNull(block);
            }
            finally
            {
                await repoFactory.DeleteAllTables();
            }
        }
        public AzureTablesFixture()
        {
            ConfigurationUtils.SetEnvironmentAsDevelopment();
            var appConfig        = ConfigurationUtils.Build(CommandLineArgs, UserSecretsId);
            var connectionString = appConfig["AzureStorageConnectionString"];

            Factory = new AzureTablesRepositoryFactory(connectionString, "UnitTest");
        }
 private AzureTablesRepositoryFactory GetCloudTableSetup(string tablePrefix)
 {
     if (!_cloudTableSetups.TryGetValue(tablePrefix, out AzureTablesRepositoryFactory setup))
     {
         setup = new AzureTablesRepositoryFactory(AzureStorageConnectionString, tablePrefix);
         _cloudTableSetups.Add(tablePrefix, setup);
     }
     return(setup);
 }
        public AzureTablesFixture()
        {
            /*
             * To run the tests setup the connection string in the user secrets
             * In the command line navigate to folder: Nethereum.BlockchainStorage\src\Nethereum.BlockchainStore.AzureTables.Tests
             * Set the connection string using the syntax below
             * dotnet user-secrets set "AzureStorageConnectionString" "CONNECTION_STRING"
             */

            ConfigurationUtils.SetEnvironmentAsDevelopment();
            var appConfig        = ConfigurationUtils.Build(CommandLineArgs, UserSecretsId);
            var connectionString = appConfig["AzureStorageConnectionString"];

            Factory = new AzureTablesRepositoryFactory(connectionString, "UnitTest");
        }
Esempio n. 5
0
        private async Task ClearDown(
            EventProcessingConfigContext repo,
            AzureTablesRepositoryFactory cloudTableSetup,
            IAzureSearchService searchService,
            AzureStorageQueueFactory subscriberQueueFactory,
            AzureTablesSubscriberRepositoryFactory azureTablesSubscriberRepositoryFactory)
        {
            foreach (var index in repo.SubscriberSearchIndexes)
            {
                await searchService.DeleteIndexAsync(index.Name);
            }

            foreach (var queue in repo.SubscriberSearchIndexes)
            {
                await subscriberQueueFactory.DeleteQueueAsync(queue.Name);
            }

            await cloudTableSetup.GetCountersTable().DeleteIfExistsAsync();

            await azureTablesSubscriberRepositoryFactory.DeleteTablesAsync();
        }
Esempio n. 6
0
        public async Task WebJobExample()
        {
            var    config = TestConfiguration.LoadConfig();
            string azureStorageConnectionString = config["AzureStorageConnectionString"];
            string azureSearchKey = config["AzureSearchApiKey"];

            var configurationContext = EventProcessingConfigMock.Create(PARTITION, out IdGenerator idGenerator);
            IEventProcessingConfigurationRepository configurationRepository = configurationContext.CreateMockRepository(idGenerator);

            var web3 = new Web3.Web3(TestConfiguration.BlockchainUrls.Infura.Rinkeby);

            // search components
            var searchService = new AzureSearchService(serviceName: AZURE_SEARCH_SERVICE_NAME, searchApiKey: azureSearchKey);

            var subscriberSearchIndexFactory = new SubscriberSearchIndexFactory(async indexName =>
            {
                if (await searchService.IndexExistsAsync(indexName) == false)
                {
                    //TODO: REPLACE THIS WITH Nethereum.BlockchainStore.Search.Azure.EventToGenericSearchDocMapper

                    await searchService.CreateIndexAsync(EventToGenericSearchDocMapper.CreateAzureIndexDefinition(indexName));
                }

                return(searchService.CreateIndexer <DecodedEvent, GenericSearchDocument>(
                           indexName, decodedEvent => EventToGenericSearchDocMapper.Map(decodedEvent, decodedEvent.State)));
            });

            // queue components
            //AzureStorageQueueFactory
            var azureQueueFactory = new AzureStorageQueueFactory(azureStorageConnectionString);

            var subscriberQueueFactory = new SubscriberQueueFactory(
                queueName => azureQueueFactory.GetOrCreateQueueAsync(queueName));

            // subscriber repository
            var repositoryFactory = new AzureTablesSubscriberRepositoryFactory(azureStorageConnectionString);

            // load subscribers and event subscriptions
            var eventSubscriptionFactory = new EventSubscriptionFactory(
                web3, configurationRepository, subscriberQueueFactory, subscriberSearchIndexFactory, repositoryFactory);

            var eventSubscriptions = await eventSubscriptionFactory.LoadAsync(PARTITION);

            // progress repo (dictates which block ranges to process next)
            // maintain separate progress per partition via a prefix
            var storageCloudSetup = new AzureTablesRepositoryFactory(azureStorageConnectionString, prefix: $"Partition{PARTITION}");
            var blockProgressRepo = storageCloudSetup.CreateBlockProgressRepository();

            var logProcessor = web3.Processing.Logs.CreateProcessor(
                logProcessors: eventSubscriptions, blockProgressRepository: blockProgressRepo);

            // execute
            try
            {
                var ctx = new System.Threading.CancellationTokenSource();
                await logProcessor.ExecuteAsync(BLOCK_TO, ctx.Token, BLOCK_FROM);
            }
            finally
            {
                await ClearDown(configurationContext, storageCloudSetup, searchService, azureQueueFactory, repositoryFactory);
            }

            // save event subscription state
            await configurationRepository.EventSubscriptionStates.UpsertAsync(eventSubscriptions.Select(s => s.State));

            // assertions

            var subscriptionState1 = configurationContext.GetEventSubscriptionState(eventSubscriptionId: 1); // interested in transfers with contract queries and aggregations
            var subscriptionState2 = configurationContext.GetEventSubscriptionState(eventSubscriptionId: 2); // interested in transfers with simple aggregation
            var subscriptionState3 = configurationContext.GetEventSubscriptionState(eventSubscriptionId: 3); // interested in any event for a specific address

            Assert.Equal("4009000000002040652615", subscriptionState1.Values["RunningTotalForTransferValue"].ToString());
            Assert.Equal((uint)19, subscriptionState2.Values["CurrentTransferCount"]);

            var txForSpecificAddress = (List <string>)subscriptionState3.Values["AllTransactionHashes"];

            Assert.Equal("0x362bcbc78a5cc6156e8d24d95bee6b8f53d7821083940434d2191feba477ae0e", txForSpecificAddress[0]);
            Assert.Equal("0xe63e9422dedf84d0ce13f9f75ebfd86333ce917b2572925fbdd51b51caf89b77", txForSpecificAddress[1]);

            var blockNumbersForSpecificAddress = (List <HexBigInteger>)subscriptionState3.Values["AllBlockNumbers"];

            Assert.Equal(4063362, blockNumbersForSpecificAddress[0].Value);
            Assert.Equal(4063362, blockNumbersForSpecificAddress[1].Value);
        }