/** * @expectedException \RuntimeException * @expectedExceptionMessage ChainCache: New BlockIndex does not refer to last */ public function testFailsAddingToCache() { $hash = str_pad("", 32, ""); $another = str_pad("", 32, "€"); $cache = new ChainCache([$hash]); $next = new BlockIndex(new Buffer(str_pad("", 32, "A")), 1, '1', new BlockHeader(1, new Buffer($another), new Buffer('', 32), 0, new Buffer(), 0)); $cache->add($next); }
/** * @param BlockIndex $index */ public function updateTip(BlockIndex $index) { if ($this->index->getHash() !== $index->getHeader()->getPrevBlock()) { throw new \RuntimeException('Header: Header does not extend this chain'); } if ($index->getHeight() - 1 != $this->index->getHeight()) { throw new \RuntimeException('Header: Incorrect chain height'); } $this->chainCache->add($index); $this->index = $index; }