Esempio n. 1
0
 public function testNetworkSerializer()
 {
     $network = Bitcoin::getDefaultNetwork();
     $parser = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
     $factory = new Factory($network, new Random());
     $version = '1';
     $relayUntil = '9999999';
     $expiration = '9898989';
     $id = '123';
     $cancel = '0';
     $minVer = '0';
     $maxVer = '0';
     $priority = '50';
     $comment = new Buffer('comment');
     $statusBar = new Buffer('statusBar');
     $setCancel = [1, 2];
     $setSubVer = [50, 99];
     $detail = new AlertDetail($version, $relayUntil, $expiration, $id, $cancel, $minVer, $maxVer, $priority, $comment, $statusBar, $setCancel, $setSubVer);
     $adapter = EcAdapterFactory::getPhpEcc(new Math(), EccFactory::getSecgCurves()->generator256k1());
     $sig = new Signature($adapter, '1', '1');
     $alert = $factory->alert($detail, $sig);
     $serialized = $alert->getNetworkMessage()->getBuffer();
     $parsed = $parser->parse($serialized)->getPayload();
     /** @var \BitWasp\Bitcoin\Networking\Messages\Alert $parsed */
     $this->assertEquals($alert->getDetail(), $parsed->getDetail());
     $this->assertEquals($alert->getSignature()->getR(), $parsed->getSignature()->getR());
     $this->assertEquals($alert->getSignature()->getS(), $parsed->getSignature()->getS());
 }
Esempio n. 2
0
 public function testNetworkSerializer()
 {
     $mem = new MemPool();
     $serializer = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
     $parsed = $serializer->parse($mem->getNetworkMessage()->getBuffer())->getPayload();
     $this->assertEquals($mem, $parsed);
 }
Esempio n. 3
0
 public function testNetworkSerializer()
 {
     $parser = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
     $getaddr = new GetAddr();
     $serialized = $getaddr->getNetworkMessage()->getBuffer();
     $parsed = $parser->parse($serialized)->getPayload();
     $this->assertEquals($getaddr, $parsed);
 }
Esempio n. 4
0
 public function testNetworkSerializer()
 {
     $array = [new Inventory(Inventory::MSG_TX, Buffer::hex('4141414141414141414141414141414141414141414141414141414141414141')), new Inventory(Inventory::MSG_TX, Buffer::hex('4141414141414141414141414141414141414141414141414141414141414142')), new Inventory(Inventory::MSG_TX, Buffer::hex('4141414141414141414141414141414141414141414141414141414141414143'))];
     $not = new NotFound($array);
     $serializer = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
     $serialized = $not->getNetworkMessage()->getBuffer();
     $parsed = $serializer->parse($serialized)->getPayload();
     $this->assertEquals($not, $parsed);
 }
Esempio n. 5
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. 6
0
 public function testNetworkSerializer()
 {
     $net = Bitcoin::getDefaultNetwork();
     $serializer = new NetworkMessageSerializer($net);
     $factory = new Factory($net, new Random());
     $reject = $factory->reject(new Buffer(), Reject::REJECT_INVALID, new Buffer(), new Buffer());
     $serialized = $reject->getNetworkMessage()->getBuffer();
     $parsed = $serializer->parse($serialized)->getPayload();
     $this->assertEquals($reject, $parsed);
 }
Esempio n. 7
0
 public function testNetworkSerializer()
 {
     $net = Bitcoin::getDefaultNetwork();
     $serializer = new NetworkMessageSerializer($net);
     $factory = new Factory($net, new Random());
     $ping = $factory->ping();
     $serialized = $ping->getNetworkMessage()->getBuffer();
     $parsed = $serializer->parse($serialized)->getPayload();
     $this->assertEquals($ping, $parsed);
 }
Esempio n. 8
0
 public function testNetworkSerializer()
 {
     $net = Bitcoin::getDefaultNetwork();
     $parser = new NetworkMessageSerializer($net);
     $factory = new Factory($net, new Random());
     $getdata = $factory->getdata([new Inventory(Inventory::MSG_BLOCK, Buffer::hex('4141414141414141414141414141414141414141414141414141414141414141'))]);
     $serialized = $getdata->getNetworkMessage()->getBuffer();
     $parsed = $parser->parse($serialized)->getPayload();
     $this->assertEquals($getdata, $parsed);
 }
Esempio n. 9
0
 public function testBlockSerializer()
 {
     $parser = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
     $txHex = '01000000' . '01' . '0000000000000000000000000000000000000000000000000000000000000000FFFFFFFF' . '4D' . '04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73' . 'FFFFFFFF' . '01' . '00F2052A01000000' . '43' . '4104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC' . '00000000';
     $blockHex = '01000000' . '0000000000000000000000000000000000000000000000000000000000000000' . '3BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A' . '29AB5F49' . 'FFFF001D' . '1DAC2B7C' . '01' . $txHex;
     $newBlock = BlockFactory::fromHex($blockHex);
     $block = new Block($newBlock);
     $serialized = $block->getNetworkMessage()->getBuffer();
     $parsed = $parser->parse($serialized)->getPayload();
     $this->assertEquals($block, $parsed);
 }
Esempio n. 10
0
 public function testNetworkSerializer()
 {
     list($hex, $tx) = $this->getTestTx();
     $net = Bitcoin::getDefaultNetwork();
     $serializer = new NetworkMessageSerializer($net);
     $factory = new Factory($net, new Random());
     $txMsg = $factory->tx($tx);
     $serialized = $txMsg->getNetworkMessage()->getBuffer();
     $parsed = $serializer->parse($serialized)->getPayload();
     $this->assertEquals($txMsg, $parsed);
 }
Esempio n. 11
0
 public function testNetworkSerializer()
 {
     $network = Bitcoin::getDefaultNetwork();
     $time = '9999999';
     $ip = '192.168.0.1';
     $port = '8333';
     $services = Buffer::hex('0000000000000000', 8);
     $add = new NetworkAddressTimestamp($time, $services, $ip, $port);
     $parser = new NetworkMessageSerializer(Bitcoin::getDefaultNetwork());
     $factory = new Factory($network, new Random());
     $addr = $factory->addr([$add]);
     $serialized = $addr->getNetworkMessage()->getBuffer();
     $parsed = $parser->parse($serialized)->getPayload();
     $this->assertEquals($addr, $parsed);
 }
Esempio n. 12
0
 public function testNetworkSerializer()
 {
     $v = '60002';
     $services = Buffer::hex('0000000000000001');
     $time = (string) time();
     $recipient = new NetworkAddress(Buffer::hex('0000000000000001'), '10.0.0.1', '8332');
     $sender = new NetworkAddress(Buffer::hex('0000000000000001'), '10.0.0.2', '8332');
     $userAgent = new Buffer("/Satoshi:0.7.2/");
     $lastBlock = '212672';
     $random = new Random();
     $nonce = $random->bytes(8)->getInt();
     $version = new Version($v, $services, $time, $recipient, $sender, $nonce, $userAgent, $lastBlock, true);
     $net = Bitcoin::getDefaultNetwork();
     $serializer = new NetworkMessageSerializer($net);
     $serialized = $version->getNetworkMessage()->getBuffer();
     $parsed = $serializer->parse($serialized)->getPayload();
     $this->assertEquals($version, $parsed);
 }
Esempio n. 13
0
 /**
  * @throws \BitWasp\Bitcoin\Exceptions\RandomBytesFailure
  * @expectedException \RuntimeException
  * @expectedExceptionMessage
  */
 public function testInvalidBytes()
 {
     $v = '60002';
     $services = Buffer::hex('0000000000000001');
     $time = '123456789';
     $recipient = new NetworkAddress(Buffer::hex('0000000000000001'), '10.0.0.1', '8332');
     $sender = new NetworkAddress(Buffer::hex('0000000000000001'), '10.0.0.2', '8332');
     $userAgent = new Buffer("/Satoshi:0.7.2/");
     $lastBlock = '212672';
     $random = new Random();
     $nonce = $random->bytes(8)->getInt();
     $version = new Version($v, $services, $time, $recipient, $sender, $nonce, $userAgent, $lastBlock, true);
     $bitcoin = new NetworkMessageSerializer(NetworkFactory::bitcoin());
     $serialized = $version->getNetworkMessage(NetworkFactory::viacoinTestnet())->getBuffer();
     $bitcoin->parse($serialized);
 }