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); } } }
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(); }
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 } }
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); } }
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); } }
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()); } }
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()); } }
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); } }
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); } }
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)); } }
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); } }
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); } }