Esempio n. 1
0
        public void GetHeadBlockQuery_Should_Return_Block_With_The_Longest_Length_When_More_Exists_Longest()
        {
            var dbContext = DatabaseHelpers.GetDatabase(a => {
                a.BlockChain.Add(new Block()
                {
                    BlockHashPrevious = "GENESIS",
                    BlockHash         = "BLOCK_1",
                    Length            = 1
                });
                a.SaveChanges();
                a.BlockChain.Add(new Block()
                {
                    BlockHashPrevious = "BLOCK_1",
                    BlockHash         = "BLOCK_2",
                    Length            = 2
                });
                a.SaveChanges();
                a.BlockChain.Add(new Block()
                {
                    BlockHashPrevious = "BLOCK_1",
                    BlockHash         = "BLOCK_3",
                    Length            = 2
                });
                a.SaveChanges();
            });
            var query = new GetHeadBlockQueryHandler(dbContext);

            var block = query.Handle(new GetHeadBlockQuery()
            {
            });

            Assert.True(block.BlockHash == "BLOCK_2" || block.BlockHash == "BLOCK_3");
            Assert.True(block.Length == 2);
            Assert.True(block.BlockHashPrevious == "BLOCK_1");
        }
Esempio n. 2
0
 private static ApplicationDatabase GetDatabase_1()
 {
     return(DatabaseHelpers.GetDatabase(a => {
         a.BlockChain.Add(new Block()
         {
             BlockHashPrevious = "GENESIS",
             BlockHash = "BLOCK_1",
             Length = 1,
             IsInMainChain = true
         });
         a.SaveChanges();
         a.BlockChain.Add(new Block()
         {
             BlockHashPrevious = "BLOCK_1",
             BlockHash = "BLOCK_2",
             Length = 2,
             IsInMainChain = true
         });
         a.SaveChanges();
         a.BlockChain.Add(new Block()
         {
             BlockHashPrevious = "BLOCK_2",
             BlockHash = "BLOCK_3",
             Length = 3
         });
         a.SaveChanges();
         a.BlockChain.Add(new Block()
         {
             BlockHashPrevious = "BLOCK_1",
             BlockHash = "BLOCK_4",
             Length = 2
         });
         a.SaveChanges();
     }));
 }
        private static ApplicationDatabase GetDatabase()
        {
            return(DatabaseHelpers.GetDatabase(a => {
                a.BlockChain.Add(new Block()
                {
                    BlockHashPrevious = "GENESIS",
                    BlockHash = "BLOCK_1",
                    Length = 1
                });
                a.SaveChanges();
                a.BlockChain.Add(new Block()
                {
                    BlockHashPrevious = "BLOCK_1",
                    BlockHash = "BLOCK_2",
                    Length = 2
                });
                a.SaveChanges();

                a.Messages.Add(new EncryptedMessageStore()
                {
                    StoreId = 1,
                    Id = "MSG1",
                    Content = "NO IN BLOCK",
                    Title = "test",
                    From = "fr",
                    To = "to",
                    FromKey = "fk",
                    ToKey = "tk",
                    Nonce = 1,
                    IV = "iv"
                });
                a.Messages.Add(new EncryptedMessageStore()
                {
                    StoreId = 2,
                    Id = "MSG2",
                    Content = "IN BLOCK",
                    Title = "test",
                    From = "fr",
                    To = "to",
                    FromKey = "fk",
                    ToKey = "tk",
                    Nonce = 1,
                    IV = "iv"
                });
                a.SaveChanges();

                a.BlockMessages.Add(new BlockMessages()
                {
                    BlockHash = "BLOCK_1",
                    StoreId = 2
                });
                a.SaveChanges();
            }));
        }
Esempio n. 4
0
        public void GetHeadBlockQuery_Should_Return_Genesis_When_No_Other_Exists()
        {
            var dbContext = DatabaseHelpers.GetDatabase(a => { });
            var query     = new GetHeadBlockQueryHandler(dbContext);

            var block = query.Handle(new GetHeadBlockQuery()
            {
            });

            Assert.True(block.BlockHash == BlockchainConsensus.GenesisBlock.BlockHash);
            Assert.True(block.BlockHashPrevious == BlockchainConsensus.GenesisBlock.BlockHashPrevious);
            Assert.True(block.Timestamp == BlockchainConsensus.GenesisBlock.Timestamp);
            Assert.True(block.Nonce == BlockchainConsensus.GenesisBlock.Nonce);
            Assert.True(block.BlockMessages == BlockchainConsensus.GenesisBlock.BlockMessages);
        }