Beispiel #1
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();
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
            }
        }