Esempio n. 1
0
 public function testNetworkMessage()
 {
     $net = Bitcoin::getDefaultNetwork();
     $parser = new NetworkMessageSerializer($net);
     $factory = new Factory($net, new Random());
     $headers = $factory->headers([BlockHeaderFactory::fromHex('0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c')]);
     $serialized = $headers->getNetworkMessage()->getBuffer();
     $parsed = $parser->parse($serialized)->getPayload();
     $this->assertEquals($headers, $parsed);
 }
Esempio n. 2
0
 public function testBlockIndex()
 {
     $headerHex = '0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a29ab5f49ffff001d1dac2b7c';
     $header = BlockHeaderFactory::fromHex($headerHex);
     $hash = $header->getHash();
     $height = 0;
     $work = 0;
     $index = new BlockIndex($hash, $height, $work, $header);
     $this->assertEquals($hash, $index->getHash());
     $this->assertEquals($height, $index->getHeight());
     $this->assertEquals($work, $index->getWork());
     $this->assertSame($header, $index->getHeader());
 }
Esempio n. 3
0
 public function testCreateInstance()
 {
     $ecAdapter = Bitcoin::getEcAdapter();
     $params = new Params($ecAdapter->getMath());
     $consensus = new Consensus($ecAdapter->getMath(), $params);
     $proofOfWork = new ProofOfWork($ecAdapter->getMath(), $params);
     $check = new HeaderCheck($consensus, $ecAdapter, $proofOfWork);
     $header = BlockHeaderFactory::fromHex($this->getGenesisHex());
     $hash = $header->getHash();
     $this->assertNoException(function () use($check, $hash, $header) {
         $check->check($hash, $header, false);
     });
     $this->assertNoException(function () use($check, $hash, $header) {
         $check->check($hash, $header, true);
     });
     $badHeader = new BlockHeader($header->getVersion(), $header->getPrevBlock(), $header->getMerkleRoot(), $header->getTimestamp(), $header->getBits(), 1);
     $this->assertException(function () use($check, $badHeader) {
         $hash = $badHeader->getHash();
         $check->check($hash, $badHeader, true);
     });
 }