private BlockChain CreateChainWithTransactions(int i) { var blockChain = new BlockChain($"transactionTest{i}.chain"); if (blockChain.Size() == 1) { var block1 = blockChain.GetNextBlock(); var transaction1 = new Transaction { To = "dillon", From = "", Amount = 23 }; block1.Alpha = 0; block1.TimeStamp = DateTime.Now; block1.Data = SerializeObject(new List <Transaction> { transaction1 }); blockChain.AddNextBlock(block1); } return(blockChain); }
public void TestVerifyChainFailure_BlockPrevHashModified() { var blockChain = new BlockChain(); var block1 = blockChain.GetNextBlock(); block1.Data = "eli snores"; block1.Alpha = 21; block1.TimeStamp = DateTime.Now; block1.PreviousHash = "ppop"; Assert.False(blockChain.AddNextBlock(block1)); }
public void TestVerifyChainFailure_BlockIndexModified() { var blockChain = new BlockChain(); var block1 = blockChain.GetNextBlock(); block1.Data = "eli snores"; block1.Alpha = 21; block1.TimeStamp = DateTime.Now; block1.Index = 0; Assert.Throws <ArgumentException>(() => blockChain.AddNextBlock(block1)); }
public void TestVerifyChainSuccess() { var blockChain = new BlockChain(); var block1 = blockChain.GetNextBlock(); block1.Data = "eli snores"; block1.Alpha = 21; block1.TimeStamp = DateTime.Now; blockChain.AddNextBlock(block1); var block2 = blockChain.GetNextBlock(); block2.Data = "eli sleep talks"; block2.Alpha = 2; block2.TimeStamp = DateTime.Now; blockChain.AddNextBlock(block2); Assert.True(blockChain.VerifyChain()); }
public void TestVerifyChain_UnloadinLoading() { var blockChain = new BlockChain(); var block = blockChain.GetNextBlock(); block.Data = "hi"; block.Alpha = 1; block.TimeStamp = DateTime.Now; blockChain.AddNextBlock(block); blockChain.Dispose(); var loadedChain = new BlockChain("dotcoin.chain"); Assert.True(loadedChain.Size() == 2); }