Example #1
0
        public EventMatcherFactoryTest()
        {
            _mockParameterConditionRepository       = new Mock <IParameterConditionRepository>();
            _mockEventSubscriptionAddressRepository = new Mock <IEventSubscriptionAddressRepository>();
            _mockSubscriberContractRepository       = new Mock <ISubscriberContractRepository>();

            _factory = new EventMatcherFactory(
                _mockParameterConditionRepository.Object,
                _mockEventSubscriptionAddressRepository.Object,
                _mockSubscriberContractRepository.Object);

            _subscriberOneConfig = new SubscriberDto {
                Id = 1
            };
            _contractDto = new SubscriberContractDto
            {
                Id           = 1,
                SubscriberId = _subscriberOneConfig.Id,
                Abi          = TestData.Contracts.StandardContract.Abi,
                Name         = "Transfer"
            };
            _eventSubscriptionConfig = new EventSubscriptionDto
            {
                Id              = 1,
                SubscriberId    = _subscriberOneConfig.Id,
                ContractId      = _contractDto.Id,
                EventSignatures = new[] { TestData.Contracts.StandardContract.TransferEventSignature }.ToList()
            };
            _addressesConfig = new EventSubscriptionAddressDto
            {
                Id                  = 1,
                Address             = "",
                EventSubscriptionId = _eventSubscriptionConfig.Id
            };
            _parameterConditionConfig = new ParameterConditionDto
            {
                Id = 1,
                EventSubscriptionId = _eventSubscriptionConfig.Id,
                ParameterOrder      = 1,
                Operator            = ParameterConditionOperator.Equals,
                Value = "xyz"
            };

            _mockSubscriberContractRepository.Setup(d => d.GetAsync(_subscriberOneConfig.Id, _contractDto.Id)).ReturnsAsync(_contractDto);
            _mockEventSubscriptionAddressRepository.Setup(d => d.GetManyAsync(_eventSubscriptionConfig.Id)).ReturnsAsync(new[] { _addressesConfig });
            _mockParameterConditionRepository.Setup(d => d.GetManyAsync(_eventSubscriptionConfig.Id)).ReturnsAsync(new[] { _parameterConditionConfig });
        }
Example #2
0
        public async Task SubscriberContracts()
        {
            var contract1 = new SubscriberContractDto
            {
                Id           = 1,
                SubscriberId = 99,
                Abi          = "abi1",
                Name         = "StandardContract"
            };

            var contract2 = new SubscriberContractDto
            {
                Id           = 2,
                SubscriberId = 99
            };


            var contract3 = new SubscriberContractDto
            {
                Id           = 3,
                SubscriberId = 100
            };


            await Fixture.ConfigRepo.SubscriberContracts.UpsertAsync(contract1);

            await Fixture.ConfigRepo.SubscriberContracts.UpsertAsync(contract2);

            await Fixture.ConfigRepo.SubscriberContracts.UpsertAsync(contract3);

            var contract1FromRepo = await Fixture.ConfigRepo.SubscriberContracts.GetAsync(subscriberId : 99, id : 1);

            var contract2FromRepo = await Fixture.ConfigRepo.SubscriberContracts.GetAsync(subscriberId : 99, id : 2);

            var contract3FromRepo = await Fixture.ConfigRepo.SubscriberContracts.GetAsync(subscriberId : 100, id : 3);


            Assert.NotNull(contract1FromRepo);
            Assert.Equal(contract1.Abi, contract1FromRepo.Abi);
            Assert.Equal(contract1.Name, contract1FromRepo.Name);
            Assert.NotNull(contract2FromRepo);
            Assert.NotNull(contract3FromRepo);
        }
 public SubscriberContractDto Add(SubscriberContractDto dto)
 {
     Contracts.Add(dto);
     return(dto);
 }
Example #4
0
        public async Task ContractQueries()
        {
            var contractDto = new SubscriberContractDto
            {
                SubscriberId = 999,
                Id           = 1001,
                Abi          = "{}",
                Name         = "StandardContract"
            };

            //dummy values - purely to ensure the repo returns all expected values
            //not meant to be actually consistent with a typical record
            var contractQuery = new ContractQueryDto
            {
                ContractId      = contractDto.Id,
                ContractAddress = "ContractAddress",
                ContractAddressParameterNumber   = 2,
                ContractAddressSource            = ContractAddressSource.EventParameter,
                ContractAddressStateVariableName = "ContractAddressStateVariableName",
                EventHandlerId              = 200,
                EventStateOutputName        = "EventStateOutputName",
                FunctionSignature           = "FunctionSignature",
                SubscriptionStateOutputName = "SubscriptionStateOutputName"
            };

            var queryParam1 = new ContractQueryParameterDto
            {
                ContractQueryId      = contractQuery.EventHandlerId,
                EventParameterNumber = 1,
                Order          = 1,
                EventStateName = "EventStateName",
                Id             = 567,
                Source         = EventValueSource.EventParameters,
                Value          = "Value"
            };

            var queryParam2 = new ContractQueryParameterDto
            {
                ContractQueryId      = contractQuery.EventHandlerId,
                EventParameterNumber = 2,
                Order          = 2,
                EventStateName = "EventStateName",
                Id             = 568,
                Source         = EventValueSource.EventParameters,
                Value          = "Value"
            };

            var queryParameterDtos = new[] { queryParam1, queryParam2 };

            await Fixture.ConfigRepo.SubscriberContracts.UpsertAsync(contractDto);

            await Fixture.ConfigRepo.ContractQueries.UpsertAsync(contractQuery);

            await Fixture.ConfigRepo.ContractQueryParameters.UpsertAsync(queryParam1);

            await Fixture.ConfigRepo.ContractQueryParameters.UpsertAsync(queryParam2);

            var configFromRepo = await Fixture.ConfigRepo.EventContractQueries.GetAsync(contractDto.SubscriberId, contractQuery.EventHandlerId);

            Assert.Equal(contractDto.Abi, configFromRepo.Contract.Abi);
            Assert.Equal(contractQuery.ContractAddress, configFromRepo.Query.ContractAddress);
            Assert.Equal(contractQuery.ContractAddressParameterNumber, configFromRepo.Query.ContractAddressParameterNumber);
            Assert.Equal(contractQuery.ContractAddressSource, configFromRepo.Query.ContractAddressSource);
            Assert.Equal(contractQuery.ContractAddressStateVariableName, configFromRepo.Query.ContractAddressStateVariableName);
            Assert.Equal(contractQuery.EventStateOutputName, configFromRepo.Query.EventStateOutputName);
            Assert.Equal(contractQuery.FunctionSignature, configFromRepo.Query.FunctionSignature);
            Assert.Equal(contractQuery.SubscriptionStateOutputName, configFromRepo.Query.SubscriptionStateOutputName);

            Assert.Equal(queryParameterDtos.Length, configFromRepo.Parameters.Length);

            for (var i = 0; i < queryParameterDtos.Length; i++)
            {
                var dto    = queryParameterDtos[i];
                var actual = configFromRepo.Parameters[i];

                Assert.Equal(dto.EventParameterNumber, actual.EventParameterNumber);
                Assert.Equal(dto.EventStateName, actual.EventStateName);
                Assert.Equal(dto.Order, actual.Order);
                Assert.Equal(dto.Source, actual.Source);
                Assert.Equal(dto.Value, actual.Value);
            }
        }