Ejemplo n.º 1
0
 public BlockPolicyTest(ITestOutputHelper output)
 {
     _fx     = new DefaultStoreFixture();
     _output = output;
     _policy = new BlockPolicy <DumbAction>(
         null,
         TimeSpan.FromHours(3),
         1024,
         128);
     _chain = new BlockChain <DumbAction>(
         _policy,
         _fx.Store,
         _fx.StateStore,
         _fx.GenesisBlock);
     _emptyTransaction = new List <Transaction <DumbAction> >();
     _genesis          = _chain.Genesis;
     _validNext        = Block <DumbAction> .Mine(
         1,
         1024,
         _genesis.TotalDifficulty,
         _genesis.Miner.Value,
         _genesis.Hash,
         _genesis.Timestamp.AddSeconds(1),
         _emptyTransaction);
 }
Ejemplo n.º 2
0
 public MineBlock()
 {
     _fx         = new LiteDBStoreFixture();
     _blockChain = new BlockChain <DumbAction>(
         new NullPolicy <DumbAction>(),
         _fx.Store
         );
 }
Ejemplo n.º 3
0
 public void SetupChain()
 {
     _fx         = new DefaultStoreFixture();
     _blockChain = new BlockChain <DumbAction>(new NullPolicy <DumbAction>(), _fx.Store);
     for (var i = 0; i < 500; i++)
     {
         _blockChain.MineBlock(_fx.Address1).Wait();
     }
 }
Ejemplo n.º 4
0
 public MineBlock()
 {
     _fx         = new DefaultStoreFixture();
     _blockChain = new BlockChain <DumbAction>(
         new NullPolicy <DumbAction>(),
         _fx.Store,
         _fx.GenesisBlock
         );
 }
            public LocalFixture()
            {
                Fixture = CommonFixture.GetNewFixture();

                StoreRepositoryMock = new StoreRepositoryMock(Fixture);

                StoreItemAvailabilityFixture = new StoreItemAvailabilityFixture(CommonFixture);
                StoreSectionFixture          = new StoreSectionFixture(CommonFixture);
                StoreFixture = new StoreFixture(CommonFixture);
            }
        protected override (IStore, Entities.Store) CreateTestObjects()
        {
            var commonFixture = new CommonFixture();
            var storeFixture  = new StoreFixture(commonFixture);

            var source      = storeFixture.CreateValid();
            var destination = GetDestination(source);

            return(source, destination);
        }
            public IStore CreateStore(StoreId storeId, SectionId sectionId)
            {
                var sectionDef = StoreSectionDefinition.FromId(sectionId);

                var storeDef = new StoreDefinition
                {
                    Id       = storeId,
                    Sections = StoreSectionFixture.CreateMany(sectionDef, 1)
                };

                return(StoreFixture.CreateValid(storeDef));
            }
            public IStore CreateStore(IShoppingList shoppingList, SectionId sectionId)
            {
                var sectionDef = StoreSectionDefinition.FromId(sectionId);
                var section    = StoreSectionFixture.Create(sectionDef);

                var storeDef = new StoreDefinition
                {
                    Id       = shoppingList.StoreId,
                    Sections = section.ToMonoList()
                };

                return(StoreFixture.CreateValid(storeDef));
            }
            public LocalFixture()
            {
                Fixture = CommonFixture.GetNewFixture();

                StoreItemAvailabilityFixture = new StoreItemAvailabilityFixture(CommonFixture);
                StoreItemFixture             = new StoreItemFixture(StoreItemAvailabilityFixture, CommonFixture);
                StoreSectionFixture          = new StoreSectionFixture(CommonFixture);
                StoreFixture        = new StoreFixture(CommonFixture);
                ItemCategoryFixture = new ItemCategoryFixture(CommonFixture);
                ManufacturerFixture = new ManufacturerFixture(CommonFixture);

                ItemCategoryRepositoryMock = new ItemCategoryRepositoryMock(Fixture);
                ManufacturerRepositoryMock = new ManufacturerRepositoryMock(Fixture);
            }
        public ConvertAsyncTestData()
        {
            commonFixture       = new CommonFixture();
            manufaturerFixture  = new ManufacturerFixture(commonFixture);
            itemCategoryFixture = new ItemCategoryFixture(commonFixture);
            storeFixture        = new StoreFixture(commonFixture);

            storeItemAvailabilityFixture = new StoreItemAvailabilityFixture(commonFixture);
            storeItemFixture             = new StoreItemFixture(storeItemAvailabilityFixture, commonFixture);

            shoppingListFixture        = new ShoppingListFixture(commonFixture);
            shoppingListSectionFixture = new ShoppingListSectionFixture(commonFixture);
            shoppingListItemFixture    = new ShoppingListItemFixture(commonFixture);
        }
Ejemplo n.º 11
0
        public ActionEvaluatorTest(ITestOutputHelper output)
        {
            Log.Logger = _logger = new LoggerConfiguration()
                                   .MinimumLevel.Verbose()
                                   .Enrich.WithThreadId()
                                   .WriteTo.TestOutput(output)
                                   .CreateLogger()
                                   .ForContext <ActionEvaluatorTest>();

            _policy = new BlockPolicy <DumbAction>(
                blockAction: new MinerReward(1),
                getMaxBlockBytes: _ => 50 * 1024);
            _storeFx = new DefaultStoreFixture(memory: true, blockAction: _policy.BlockAction);
            _txFx    = new TxFixture(null);
        }
Ejemplo n.º 12
0
 public BlockPolicyTest(ITestOutputHelper output)
 {
     _fx     = new DefaultStoreFixture();
     _output = output;
     _policy = new BlockPolicy <DumbAction>(
         null,
         TimeSpan.FromHours(3),
         1024,
         128);
     _chain = new BlockChain <DumbAction>(
         _policy,
         _fx.Store,
         _fx.StateStore,
         _fx.GenesisBlock);
 }
Ejemplo n.º 13
0
 public BlockPolicyTest(ITestOutputHelper output)
 {
     _fx     = new MemoryStoreFixture();
     _output = output;
     _policy = new BlockPolicy <DumbAction>(
         blockAction: null,
         blockInterval: TimeSpan.FromMilliseconds(3 * 60 * 60 * 1000));
     _stagePolicy = new VolatileStagePolicy <DumbAction>();
     _chain       = new BlockChain <DumbAction>(
         _policy,
         _stagePolicy,
         _fx.Store,
         _fx.StateStore,
         _fx.GenesisBlock);
 }
Ejemplo n.º 14
0
        public void SetupChain()
        {
            _fx         = new DefaultStoreFixture();
            _blockChain = new BlockChain <DumbAction>(
                new NullBlockPolicy <DumbAction>(),
                new VolatileStagePolicy <DumbAction>(),
                _fx.Store,
                _fx.StateStore,
                _fx.GenesisBlock);
            var key = new PrivateKey();

            for (var i = 0; i < 500; i++)
            {
                _blockChain.MineBlock(key).Wait();
            }
        }
Ejemplo n.º 15
0
        public SwarmTest(ITestOutputHelper output)
        {
            const string outputTemplate =
                "{Timestamp:HH:mm:ss}[@{SwarmId}][{ThreadId}] - {Message}";

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .Enrich.WithThreadId()
                         .WriteTo.TestOutput(output, outputTemplate: outputTemplate)
                         .CreateLogger()
                         .ForContext <SwarmTest>();

            _output = output;

            var policy = new BlockPolicy <DumbAction>(new MinerReward(1));

            _fx1 = new LiteDBStoreFixture();
            _fx2 = new LiteDBStoreFixture();
            _fx3 = new LiteDBStoreFixture();

            _blockchains = new List <BlockChain <DumbAction> >
            {
                new BlockChain <DumbAction>(policy, _fx1.Store),
                new BlockChain <DumbAction>(policy, _fx2.Store),
                new BlockChain <DumbAction>(policy, _fx3.Store),
            };

            _swarms = new List <Swarm <DumbAction> >
            {
                new Swarm <DumbAction>(
                    _blockchains[0],
                    new PrivateKey(),
                    appProtocolVersion: 1,
                    host: IPAddress.Loopback.ToString()),
                new Swarm <DumbAction>(
                    _blockchains[1],
                    new PrivateKey(),
                    appProtocolVersion: 1,
                    host: IPAddress.Loopback.ToString()),
                new Swarm <DumbAction>(
                    _blockchains[2],
                    new PrivateKey(),
                    appProtocolVersion: 1,
                    host: IPAddress.Loopback.ToString()),
            };
        }
            public LocalFixture()
            {
                Fixture = CommonFixture.GetNewFixture();

                ShoppingListFixture          = new ShoppingListFixture(CommonFixture);
                ShoppingListMockFixture      = new ShoppingListMockFixture(CommonFixture, ShoppingListFixture);
                ShoppingListSectionFixture   = new ShoppingListSectionFixture(CommonFixture);
                ShoppingListItemFixture      = new ShoppingListItemFixture(CommonFixture);
                StoreItemAvailabilityFixture = new StoreItemAvailabilityFixture(CommonFixture);
                StoreItemFixture             = new StoreItemFixture(StoreItemAvailabilityFixture, CommonFixture);
                StoreSectionFixture          = new StoreSectionFixture(CommonFixture);
                StoreFixture = new StoreFixture(CommonFixture);

                ShoppingListSectionFactoryMock = new ShoppingListSectionFactoryMock(Fixture);
                StoreRepositoryMock            = new StoreRepositoryMock(Fixture);
                ItemRepositoryMock             = new ItemRepositoryMock(Fixture);
                ShoppingListItemFactoryMock    = new ShoppingListItemFactoryMock(Fixture);
            }
Ejemplo n.º 17
0
        /*Section="CustomCodeRegion"*/
        #region Customized

        private void startHelpDeskProcess(DataModels.Helpdesk.HelpdeskRequest dataModel, IDAL dal)
        {
            bool            yardimciMalzeme     = (dataModel.ProcessName == "YardimMasasiYardimciMalzeme");
            bool            bilgislem           = (dataModel.ProcessName == "YardimMasasiAriza");
            int             processDefinitionId = _parameterReader.ReadPublicParameter <int>(dataModel.ProcessName, dataModel.Process);
            var             store  = dal.Read <Store>(dataModel.Store);
            var             branch = dal.Read <Branch>(store.OrganizationBranch);
            GroupOperations gop    = new GroupOperations(dal);

            IProcessInstance processInstance = new ProcessInstance(processDefinitionId, OTApplication.Context.User.Id);

            //Set Process Variables
            processInstance.AddProcessVariable("user", OTApplication.Context.User.Id);
            processInstance.AddProcessVariable("screenReference", "Helpdesk#HelpdeskRequestListComponent#" + dataModel.HelpdeskRequestId);
            processInstance.AddProcessVariable("branch", store.OrganizationBranch);
            processInstance.AddProcessVariable("region", branch.Parent);
            processInstance.AddProcessVariable("requestId", dataModel.HelpdeskRequestId);
            if (yardimciMalzeme)
            {
                Overtech.DataModels.Security.Group g = gop.FindGroup("Satın Alma");
                processInstance.AddProcessVariable("purchasingGroup", g.GroupId);
                g = gop.FindGroup("Depo Sorumlusu");
                processInstance.AddProcessVariable("warehouseGroup", g.GroupId);
                g = gop.FindGroup("İdari İşler");
                processInstance.AddProcessVariable("executiveStaffGroup", g.GroupId);
            }
            else if (bilgislem)
            {
                Overtech.DataModels.Security.Group g = gop.FindGroup("Momende");
                processInstance.AddProcessVariable("momendeGroup", g.GroupId);
                g = gop.FindGroup("Bilgi Sistemleri Kullanıcıları");
                processInstance.AddProcessVariable("bilgiIslemGroup", g.GroupId);
            }
            processInstance.AddProcessVariable("description", dataModel.RequestDescription);
            string storeName = dal.List <Store>("STR_LST_STORE_SP").Where(s => s.StoreId == dataModel.Store)
                               .Select(s => s.Name)
                               .FirstOrDefault();

            processInstance.AddProcessVariable("storeName", storeName);
            string definitionName = dal.List <RequestDefinition>("HDK_LST_REQUESTDEF_SP").Where(rd => rd.RequestDefinitionId == dataModel.RequestDefinition)
                                    .Select(rd => rd.RequestDefinitionName)
                                    .FirstOrDefault();

            processInstance.AddProcessVariable("definition", definitionName);
            string deviceNo = "-";
            IEnumerable <DataModels.Helpdesk.RequestAttribute> deviceAttributeList = dal.List <DataModels.Helpdesk.RequestAttribute>("HDK_LST_ATTRIBUTE_SP")
                                                                                     .Where(a => a.AttributeType > 4 && a.RequestDefinition == dataModel.RequestDefinition);

            dataModel.RequestDetailList.ForEach(rd =>
            {
                if (deviceNo == "-")
                {
                    for (int i = 0; i < deviceAttributeList.Count(); i++)
                    {
                        DataModels.Helpdesk.RequestAttribute da = deviceAttributeList.ElementAt(i);
                        if (da.RequestAttributeId == rd.Attribute)
                        {
                            string deviceName;
                            string serialNo;
                            switch (da.AttributeType)
                            {
                            case 5:     // TERAZI
                                StoreScales scale = dal.Read <StoreScales>(Int32.Parse(rd.AttributeValue));
                                deviceName        = scale.BrandName ?? "";
                                serialNo          = scale.SerialNumber ?? "";
                                i = deviceAttributeList.Count();
                                break;

                            case 6:      // YAZARKASA
                                StoreCashRegister cashRegister = dal.Read <StoreCashRegister>(Int32.Parse(rd.AttributeValue));
                                deviceName = cashRegister.BrandName ?? "";
                                serialNo   = cashRegister.SerialNo ?? "";
                                i          = deviceAttributeList.Count();
                                break;

                            case 7:      // DEMIRBAS
                                StoreFixture fixture = dal.Read <StoreFixture>(Int32.Parse(rd.AttributeValue));
                                deviceName           = fixture.FixtureName ?? "";
                                serialNo             = fixture.SerialNo ?? "";
                                i = deviceAttributeList.Count();
                                break;

                            default:
                                deviceName = "";
                                serialNo   = "";
                                i          = deviceAttributeList.Count();
                                break;
                            }

                            deviceNo = deviceName + (serialNo.Length > 0 ? "-" + serialNo : "");
                        }
                    }
                    ;
                }
            });
            processInstance.AddProcessVariable("deviceNo", deviceNo);

            //Set Action Varibles
            processInstance.AddActionVariable("user", OTApplication.Context.User.Id);
            //processInstance.AddActionVariable("description", $"{store.Name} - {product.Name}");

            //Start Process
            var processId = processInstance.Start(dataModel.HelpdeskRequestId.ToString());

            dataModel.ProcessInstance = processId;
            dataModel.StatusCode      = 1;
            dal.Update(dataModel);
        }
Ejemplo n.º 18
0
 public StoreTests()
 {
     commonFixture = new CommonFixture();
     storeFixture  = new StoreFixture(commonFixture);
 }
Ejemplo n.º 19
0
        public async Task PreloadFromNominer()
        {
            Swarm <DumbAction> minerSwarm    = _swarms[0];
            Swarm <DumbAction> receiverSwarm = _swarms[1];
            var fxForNominers = new StoreFixture[2];

            fxForNominers[0] = new DefaultStoreFixture(memory: true);
            fxForNominers[1] = new DefaultStoreFixture(memory: true);
            var policy = new BlockPolicy <DumbAction>();
            var blockChainsForNominers = new[]
            {
                TestUtils.MakeBlockChain(policy, fxForNominers[0].Store),
                TestUtils.MakeBlockChain(policy, fxForNominers[1].Store),
            };
            var nominerSwarm0 = CreateSwarm(blockChainsForNominers[0]);
            var nominerSwarm1 = CreateSwarm(blockChainsForNominers[1]);

            BlockChain <DumbAction> minerChain    = _blockchains[0];
            BlockChain <DumbAction> receiverChain = _blockchains[1];

            foreach (int i in Enumerable.Range(0, 10))
            {
                await minerChain.MineBlock(_fx1.Address1);
            }

            var actualStates = new List <PreloadState>();
            var progress     = new Progress <PreloadState>(state =>
            {
                lock (actualStates)
                {
                    actualStates.Add(state);
                }
            });

            try
            {
                await StartAsync(minerSwarm);
                await StartAsync(nominerSwarm0);
                await StartAsync(nominerSwarm1);

                minerSwarm.FindNextHashesChunkSize    = 2;
                nominerSwarm0.FindNextHashesChunkSize = 2;
                nominerSwarm1.FindNextHashesChunkSize = 2;

                await nominerSwarm0.AddPeersAsync(new[] { minerSwarm.AsPeer }, null);

                await nominerSwarm0.PreloadAsync();

                await nominerSwarm1.AddPeersAsync(new[] { nominerSwarm0.AsPeer }, null);

                await nominerSwarm1.PreloadAsync();

                await receiverSwarm.AddPeersAsync(new[] { nominerSwarm1.AsPeer }, null);

                await receiverSwarm.PreloadAsync(TimeSpan.FromSeconds(15), progress);

                // Await 1 second to make sure all progresses is reported.
                await Task.Delay(1000);

                Assert.Equal(minerChain.BlockHashes, receiverChain.BlockHashes);

                var expectedStates = new List <PreloadState>();

                for (var i = 1; i < minerChain.Count; i++)
                {
                    var state = new BlockHashDownloadState
                    {
                        EstimatedTotalBlockHashCount = 10,
                        ReceivedBlockHashCount       = i,
                        SourcePeer = nominerSwarm1.AsPeer as BoundPeer,
                    };
                    expectedStates.Add(state);
                }

                for (var i = 1; i < minerChain.Count; i++)
                {
                    var state = new BlockDownloadState
                    {
                        ReceivedBlockHash  = minerChain[i].Hash,
                        TotalBlockCount    = 10,
                        ReceivedBlockCount = i,
                        SourcePeer         = nominerSwarm1.AsPeer as BoundPeer,
                    };
                    expectedStates.Add(state);
                }

                for (var i = 1; i < minerChain.Count; i++)
                {
                    var state = new BlockVerificationState
                    {
                        VerifiedBlockHash  = minerChain[i].Hash,
                        TotalBlockCount    = 10,
                        VerifiedBlockCount = i,
                    };
                    expectedStates.Add(state);
                }

                for (var i = 1; i < minerChain.Count; i++)
                {
                    var state = new ActionExecutionState
                    {
                        ExecutedBlockHash  = minerChain[i].Hash,
                        TotalBlockCount    = 10,
                        ExecutedBlockCount = i,
                    };
                    expectedStates.Add(state);
                }

                // FIXME: this test does not ensures block download in order
                Assert.Equal(
                    expectedStates.ToHashSet(),
                    actualStates.ToHashSet()
                    );
            }
            finally
            {
                await StopAsync(minerSwarm);
                await StopAsync(nominerSwarm0);
                await StopAsync(nominerSwarm1);
                await StopAsync(receiverSwarm);

                nominerSwarm0.Dispose();
                nominerSwarm1.Dispose();

                fxForNominers[0].Dispose();
                fxForNominers[1].Dispose();
            }
        }
 public StoreItemAvailabilityFixture(CommonFixture commonFixture)
 {
     this.commonFixture = commonFixture;
     storeFixture       = new StoreFixture(commonFixture);
 }
Ejemplo n.º 21
0
        public async Task BroadcastTxAsyncMany()
        {
            int size = 5;

            var policy = new BlockPolicy <DumbAction>();

            StoreFixture[]            fxs         = new StoreFixture[size];
            BlockChain <DumbAction>[] blockChains = new BlockChain <DumbAction> [size];
            Swarm <DumbAction>[]      swarms      = new Swarm <DumbAction> [size];

            for (int i = 0; i < size; i++)
            {
                fxs[i]         = new DefaultStoreFixture(memory: true);
                blockChains[i] = new BlockChain <DumbAction>(
                    policy,
                    new VolatileStagePolicy <DumbAction>(),
                    fxs[i].Store,
                    fxs[i].StateStore,
                    fxs[i].GenesisBlock
                    );
                swarms[i] = CreateSwarm(blockChains[i]);
            }

            Transaction <DumbAction> tx = Transaction <DumbAction> .Create(
                0,
                new PrivateKey(),
                blockChains[size - 1].Genesis.Hash,
                new DumbAction[] { }
                );

            blockChains[size - 1].StageTransaction(tx);

            try
            {
                for (int i = 0; i < size; i++)
                {
                    await StartAsync(swarms[i]);
                }

                List <Task> tasks = new List <Task>();
                for (int i = 1; i < size; i++)
                {
                    await BootstrapAsync(swarms[i], swarms[0].AsPeer);
                }

                for (int i = 0; i < size - 1; i++)
                {
                    tasks.Add(swarms[i].TxReceived.WaitAsync());
                }

                await Task.WhenAll(tasks);

                for (int i = 0; i < size; i++)
                {
                    Assert.Equal(tx, blockChains[i].GetTransaction(tx.Id));
                }
            }
            finally
            {
                for (int i = 0; i < size; i++)
                {
                    await StopAsync(swarms[i]);

                    fxs[i].Dispose();
                    swarms[i].Dispose();
                }
            }
        }
Ejemplo n.º 22
0
 public void InitializeFixture()
 {
     _fx    = new DefaultStoreFixture();
     _store = _fx.Store;
 }
 public IStore CreateStore()
 {
     return(StoreFixture.CreateValid());
 }
Ejemplo n.º 24
0
 public void InitializeFixture()
 {
     _fx    = new LiteDBStoreFixture();
     _store = _fx.Store;
 }