public void ConnectedBranchToBlockChain() { BlockBranch branch1 = new BlockBranch(); BlockBranch branch2 = new BlockBranch(); Block genesis = new Block(0, null); Block block1 = new Block(1, genesis.Hash); Block block2 = new Block(2, block1.Hash); Block block3 = new Block(3, block2.Hash); branch1.TryToAddFirst(genesis); branch1.TryToAddLast(block1); branch2.TryToAddLast(block2); branch2.TryToAddLast(block3); branch2.TryToConnect(branch1); BlockChain chain = branch2.ToBlockChain(2); Assert.IsNotNull(chain); Assert.AreEqual(2, chain.BestBlockNumber); Assert.AreEqual(genesis, chain.GetBlock(0)); Assert.AreEqual(block1, chain.GetBlock(1)); Assert.AreEqual(block2, chain.GetBlock(2)); }
public void AddBlockToLastInEmptyBranch() { BlockBranch branch = new BlockBranch(); Block block = new Block(42, new Hash()); Assert.IsTrue(branch.TryToAddLast(block)); Assert.AreEqual(block, branch.GetBlock(42)); }
public void ToBlockChain() { BlockBranch branch = new BlockBranch(); Block genesis = new Block(0, null); Block block1 = new Block(1, genesis.Hash); Block block2 = new Block(2, block1.Hash); branch.TryToAddFirst(genesis); branch.TryToAddLast(block1); branch.TryToAddLast(block2); BlockChain chain = branch.ToBlockChain(1); Assert.IsNotNull(chain); Assert.AreEqual(1, chain.BestBlockNumber); Assert.AreEqual(genesis, chain.GetBlock(0)); Assert.AreEqual(block1, chain.GetBlock(1)); }
public void AddBlockToLast() { BlockBranch branch = new BlockBranch(); Block block = new Block(42, new Hash()); Block block2 = new Block(43, block.Hash); Assert.IsTrue(branch.TryToAddFirst(block)); Assert.IsTrue(branch.TryToAddLast(block2)); Assert.AreEqual(block, branch.GetBlock(42)); Assert.AreEqual(block2, branch.GetBlock(43)); }
public void RejectBlockToLast() { BlockBranch branch = new BlockBranch(); Block block = new Block(42, new Hash()); Block block2 = new Block(43, new Hash()); Assert.IsTrue(branch.TryToAddFirst(block)); Assert.IsFalse(branch.TryToAddLast(block2)); Assert.AreEqual(block, branch.GetBlock(42)); Assert.IsNull(branch.GetBlock(43)); }