public async Task Should_Configure_Get_Logs_Filter_For_Address()
        {
            var          currentBlockOnChain  = 100;
            var          blockFrom            = new BigInteger(0);
            var          blockTo              = new BigInteger(0);
            const int    logsPerTransaction   = 1;
            const int    transactionsPerBlock = 1;
            const string contractAddress      = "0x243e72b69141f6af525a9a5fd939668ee9f2b354";

            //set up mock
            var logRpcMock = new LogProcessingRpcMock(Web3Mock);

            logRpcMock.SetupGetCurrentBlockNumber(currentBlockOnChain);
            logRpcMock.SetupGetLogsToReturnDummyFilterLogs(blockFrom, blockTo, logsPerTransaction, transactionsPerBlock);

            var logsHandled = new List <FilterLog>();

            var logProcessor = Web3.Processing.Logs.CreateProcessorForContract(
                contractAddress,
                filterLog =>
            {
                logsHandled.Add(filterLog);
            });

            //act
            await logProcessor.ExecuteAsync(blockTo, startAtBlockNumberIfNotProcessed : blockFrom);

            //assert
            var expectedLogCount = ((blockTo - blockFrom) + 1) * transactionsPerBlock * logsPerTransaction;

            var actualGetLogsFilter = logRpcMock.GetLogsFiltersInvoked.FirstOrDefault();

            Assert.Equal(contractAddress, actualGetLogsFilter.Address[0]);
            Assert.Equal(expectedLogCount, logsHandled.Count);
        }
Ejemplo n.º 2
0
        public async Task Retries_Log_Retrieval_On_Error()
        {
            var logRpcMock = new LogProcessingRpcMock(Web3Mock);

            //parameters
            var currentBlockOnChain = 100;
            var blockFrom           = new BigInteger(0);
            var blockTo             = new BigInteger(1);
            var blocksInRange       = (blockTo - blockFrom) + 1;

            //set up mock
            var logsPerTransaction   = 10;
            var transactionsPerBlock = 10;

            logRpcMock.SetupGetCurrentBlockNumber(currentBlockOnChain);

            for (var block = blockFrom; block <= blockTo; block++)
            {
                logRpcMock.SetupLogsToReturn(block, transactionsPerBlock, logsPerTransaction);
            }

            var logsExpected = blocksInRange * (transactionsPerBlock * logsPerTransaction);

            var logsHandled = new List <FilterLog>();

            var logProcessor = Web3.Processing.Logs.CreateProcessor(filterLog => logsHandled.Add(filterLog));

            await logProcessor.ExecuteAsync(blockTo, startAtBlockNumberIfNotProcessed : blockFrom);

            Assert.Equal(logsExpected, logsHandled.Count);
            Assert.Equal(1, logRpcMock.GetLogRequestCount);
        }
Ejemplo n.º 3
0
        public async Task Should_Accept_Event_Specific_Criteria()
        {
            var       currentBlockOnChain  = 100;
            var       blockFrom            = new BigInteger(0);
            var       blockTo              = new BigInteger(0);
            var       blocksInRange        = (blockTo - blockFrom) + 1;
            const int logsPerTransaction   = 10;
            const int transactionsPerBlock = 10;

            //set up mock
            var logRpcMock = new LogProcessingRpcMock(Web3Mock);

            logRpcMock.SetupGetCurrentBlockNumber(currentBlockOnChain);
            logRpcMock.SetupGetLogsToReturnDummyERC20Transfers(blockFrom, blockTo, logsPerTransaction, transactionsPerBlock);

            var transfersHandled = new List <EventLog <TransferEventDTO> >();

            var logProcessor = Web3.Processing.Logs.CreateProcessor <TransferEventDTO>(
                //action
                action: transferEventLog => {
                transfersHandled.Add(transferEventLog); return(Task.CompletedTask);
            },
                //criteria
                criteria: transferEventLog => {
                var match = transferEventLog.Event.Value > 9999999999999;
                return(Task.FromResult(match));
            });

            //act
            await logProcessor.ExecuteAsync(blockTo, startAtBlockNumberIfNotProcessed : blockFrom);

            //assert
            Assert.Empty(transfersHandled);
        }
Ejemplo n.º 4
0
        public async Task Should_Match_Event_And_Invoke_Handler()
        {
            //setup
            var       currentBlockOnChain  = 100;
            var       blockFrom            = new BigInteger(0);
            var       blockTo              = new BigInteger(0);
            var       blocksInRange        = (blockTo - blockFrom) + 1;
            const int logsPerTransaction   = 10;
            const int transactionsPerBlock = 10;

            //set up mock
            var logRpcMock = new LogProcessingRpcMock(Web3Mock);

            logRpcMock.SetupGetCurrentBlockNumber(currentBlockOnChain);
            logRpcMock.SetupGetLogsToReturnDummyERC20Transfers(blockFrom, blockTo, logsPerTransaction, transactionsPerBlock);

            var transfersHandled = new List <EventLog <TransferEventDTO> >();

            var logProcessor = Web3.Processing.Logs.CreateProcessor <TransferEventDTO>(
                transferEvent => transfersHandled.Add(transferEvent));

            //act
            await logProcessor.ExecuteAsync(blockTo, startAtBlockNumberIfNotProcessed : blockFrom);

            //assert
            var logsExpected = blocksInRange * (transactionsPerBlock * logsPerTransaction);

            Assert.Equal(logsExpected, transfersHandled.Count);
        }
Ejemplo n.º 5
0
        public async Task Get_Logs_Request_Will_Filter_Specifically_For_This_Event()
        {
            var       currentBlockOnChain  = 100;
            var       blockFrom            = new BigInteger(0);
            var       blockTo              = new BigInteger(0);
            const int logsPerTransaction   = 1;
            const int transactionsPerBlock = 1;

            //set up mock
            var logRpcMock = new LogProcessingRpcMock(Web3Mock);

            logRpcMock.SetupGetCurrentBlockNumber(currentBlockOnChain);
            logRpcMock.SetupGetLogsToReturnDummyERC20Transfers(blockFrom, blockTo, logsPerTransaction, transactionsPerBlock);

            var transfersHandled = new List <EventLog <TransferEventDTO> >();

            var logProcessor = Web3.Processing.Logs.CreateProcessor <TransferEventDTO>(
                transferEventLog =>
            {
                transfersHandled.Add(transferEventLog); return(Task.CompletedTask);
            });

            //act
            await logProcessor.ExecuteAsync(blockTo, startAtBlockNumberIfNotProcessed : blockFrom);

            //assert
            var expectedGetLogsFilter = new FilterInputBuilder <TransferEventDTO>().Build();
            var actualGetLogsFilter   = logRpcMock.GetLogsFiltersInvoked.FirstOrDefault();

            Assert.Equal(expectedGetLogsFilter.Topics[0], actualGetLogsFilter.Topics[0]);
        }
Ejemplo n.º 6
0
        public async Task Should_Configure_Get_Logs_Filter_For_Address_And_Event()
        {
            var          currentBlockOnChain  = 100;
            var          blockFrom            = new BigInteger(0);
            var          blockTo              = new BigInteger(0);
            const int    logsPerTransaction   = 1;
            const int    transactionsPerBlock = 1;
            const string contractAddress1     = "0x243e72b69141f6af525a9a5fd939668ee9f2b354";
            const string contractAddress2     = "0x343e72b69141f6af525a9a5fd939668ee9f2b354";
            var          contractAddresses    = new[] { contractAddress1, contractAddress2 };

            //set up mock
            var logRpcMock = new LogProcessingRpcMock(Web3Mock);

            logRpcMock.SetupGetCurrentBlockNumber(currentBlockOnChain);
            logRpcMock.SetupGetLogsToReturnDummyERC20Transfers(blockFrom, blockTo, logsPerTransaction, transactionsPerBlock);

            var transfersHandled = new List <EventLog <TransferEventDTO> >();

            var logProcessor = Web3.Processing.Logs.CreateProcessorForContracts <TransferEventDTO>(
                contractAddresses,
                transferEventLog =>
            {
                transfersHandled.Add(transferEventLog);
            });

            //act
            await logProcessor.ExecuteAsync(blockTo, startAtBlockNumberIfNotProcessed : blockFrom);

            //assert
            var expectedGetLogsFilter = new FilterInputBuilder <TransferEventDTO>().Build(contractAddresses);
            var actualGetLogsFilter   = logRpcMock.GetLogsFiltersInvoked.FirstOrDefault();
            var expectedLogCount      = ((blockTo - blockFrom) + 1) * transactionsPerBlock * logsPerTransaction;

            Assert.Equal(expectedGetLogsFilter.Topics[0], actualGetLogsFilter.Topics[0]);
            Assert.Equal(expectedGetLogsFilter.Address, actualGetLogsFilter.Address);
            Assert.Equal(expectedLogCount, transfersHandled.Count);
        }
Ejemplo n.º 7
0
        public async Task Should_Not_Match_Other_Events()
        {
            var       currentBlockOnChain  = 100;
            var       blockFrom            = new BigInteger(0);
            var       blockTo              = new BigInteger(0);
            const int logsPerTransaction   = 10;
            const int transactionsPerBlock = 10;

            //set up mock
            var logRpcMock = new LogProcessingRpcMock(Web3Mock);

            logRpcMock.SetupGetCurrentBlockNumber(currentBlockOnChain);
            logRpcMock.SetupGetLogsToReturnDummyERC20Transfers(blockFrom, blockTo, logsPerTransaction, transactionsPerBlock);

            var approvalsHandled = new List <EventLog <ApprovalEventDTO> >();

            var logProcessor = Web3.Processing.Logs.CreateProcessor <ApprovalEventDTO>(
                approvalEvent => approvalsHandled.Add(approvalEvent));

            await logProcessor.ExecuteAsync(blockTo, startAtBlockNumberIfNotProcessed : blockFrom);

            Assert.Empty(approvalsHandled);
        }