Esempio n. 1
0
        public void AddFiftyBlocksAndCheckRangeRetrieval()
        {
            foreach (IChainStorageProvider store in stores)
            {
                ResetStore(store);

                var Node = new BlockChainNode(new System.Security.Cryptography.SHA512Managed());
                Node.Initiate(null, store);

                for (int i = 0; i < 50; i++)
                {
                    Node.SubmitData($"Block number {i+1}");
                }

                List <Block> blockList = Node.RetrieveMany(22, 5);

                Assert.Equal(5, blockList.Count);
                // the reason we expect this to be block with data "21"
                //  is because of the additional geness block
                for (int i = 0; i <= 4; i++)
                {
                    Assert.Equal($"Block number 2{i+1}", blockList[i].Data);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var Node = new BlockChainNode();

            Node.Initiate();
            var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node);

            HttpHost.Start();
            Console.WriteLine("Server running, press any key to quit");
            Console.ReadLine();
        }
Esempio n. 3
0
        public void BlockChainNodeTests()
        {
            foreach (IChainStorageProvider store in stores)
            {
                ResetStore(store);

                var Node = new BlockChainNode();
                Node.Initiate(null, store);
                Node.SubmitData("This is my first block of data! :-)");
                Assert.Equal(2, Node.GetChainSize()); // (2 may seem unintuative but this includes the genesis block created as part of initiation
            }
        }
Esempio n. 4
0
        public void CreateHostAndCheckResponsive()
        {
            var Node = new BlockChainNode();

            Node.Initiate();
            var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node);

            HttpHost.Start();
            using (var client = new HttpClient())
            {
                var response = client.PostAsync("http://localhost:8080/count/", null).Result;
                Assert.Equal(true, response.IsSuccessStatusCode);
            }
        }
Esempio n. 5
0
        public void GetBlockCountWhenChainNew()
        {
            var Node = new BlockChainNode();

            Node.Initiate();
            var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node);

            HttpHost.Start();
            using (var client = new HttpClient())
            {
                var response = client.PostAsync("http://localhost:8080/count/", null).Result;
                var contents = response.Content.ReadAsStringAsync().Result;
                Assert.Equal("1", contents);
            }
        }
Esempio n. 6
0
        public void InitiateAndAddOneThousandBlocks()
        {
            foreach (IChainStorageProvider store in stores)
            {
                ResetStore(store);

                var Node = new BlockChainNode(new System.Security.Cryptography.SHA512Managed());
                Node.Initiate(null, store);

                for (int i = 1; i < 1001; i++)
                {
                    Node.SubmitData($"Block number {i}");
                }

                Assert.Equal(1001, Node.GetChainSize());
            }
        }
Esempio n. 7
0
        public void InitiateAndAddFiftyBlocksAndValidate()
        {
            foreach (IChainStorageProvider store in stores)
            {
                ResetStore(store);

                var Node = new BlockChainNode();
                Node.Initiate(null, store);

                for (int i = 1; i < 51; i++)
                {
                    Node.SubmitData($"Block number {i}");
                }


                Assert.Equal(true, Node.ValidateNode());
            }
        }
Esempio n. 8
0
        public void SubmitInvalidData()
        {
            var Node = new BlockChainNode();

            Node.Initiate();
            var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node);

            HttpHost.Start();
            using (var client = new HttpClient())
            {
                var myContent   = "";
                var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                var byteContent = new ByteArrayContent(buffer);

                var response = client.PostAsync("http://localhost:8080/add/", byteContent).Result;
                var contents = response.Content.ReadAsStringAsync().Result;
                Assert.Equal("No data found, cannot add block with no data, that's pointless!", contents);
            }
        }
Esempio n. 9
0
        public void SubmitValidData()
        {
            var Node = new BlockChainNode();

            Node.Initiate();
            var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node);

            HttpHost.Start();
            using (var client = new HttpClient())
            {
                var myContent   = "TestBlockData";
                var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                var byteContent = new ByteArrayContent(buffer);

                var response = client.PostAsync("http://localhost:8080/add/", byteContent).Result;
                var contents = response.Content.ReadAsStringAsync().Result;
                Assert.Equal("ADDED|2", contents);
            }
        }
Esempio n. 10
0
        public void InitiateAndAddOneHundredBlocksAndPersist()
        {
            foreach (IChainStorageProvider store in stores)
            {
                ResetStore(store);

                var Node = new BlockChainNode(new System.Security.Cryptography.SHA512Managed());
                Node.Initiate(null, store);

                for (int i = 1; i < 101; i++)
                {
                    Node.SubmitData($"Block number {i}");
                }

                var FileName = DateTime.Now.Ticks.ToString();
                Node.Persist(FileName);

                Assert.Equal(true, System.IO.File.Exists(FileName));
            }
        }
Esempio n. 11
0
        public void AddFiftyBlocksAndCheckIndividualRetrieval()
        {
            foreach (IChainStorageProvider store in stores)
            {
                ResetStore(store);

                var Node = new BlockChainNode(new System.Security.Cryptography.SHA512Managed());
                Node.Initiate(null, store);

                for (int i = 0; i < 50; i++)
                {
                    Node.SubmitData($"Block number {i+1}");
                }

                Block block = Node.RetrieveSingleBlock(22);


                // the reason we expect this to be block with data "21"
                //  is because of the additional geness block
                Assert.Equal("Block number 21", block.Data);
            }
        }
Esempio n. 12
0
        public void SubmitNewBlocksAndGetCount()
        {
            var Node = new BlockChainNode();

            Node.Initiate();
            var HttpHost = new BlockChainNodeHttpHost.HttpHost(Node);

            HttpHost.Start();
            using (var client = new HttpClient())
            {
                var myContent   = "TestBlockData";
                var buffer      = System.Text.Encoding.UTF8.GetBytes(myContent);
                var byteContent = new ByteArrayContent(buffer);

                for (int i = 0; i < 10; i++)
                {
                    client.PostAsync("http://localhost:8080/add/", byteContent).Wait();
                }

                var response = client.PostAsync("http://localhost:8080/count/", null).Result;
                var contents = response.Content.ReadAsStringAsync().Result;
                Assert.Equal("11", contents);
            }
        }