php-bitpay-client/tests/Bitpay/PrivateKeyTest.php

109 lines
3.4 KiB
PHP

<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2014 BitPay, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Bitpay;
class PrivateKeyTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
$this->assertInstanceOf('Bitpay\PrivateKey', PrivateKey::create());
}
public function testGenerate()
{
$priKey = new PrivateKey();
$this->assertNull($priKey->getHex());
$this->assertNull($priKey->getDec());
$priKey->generate();
$this->assertEquals(64, strlen($priKey->getHex()));
$this->assertGreaterThanOrEqual(76, strlen($priKey->getDec()));
}
public function testGetHex()
{
$priKey = new PrivateKey();
$this->assertNull($priKey->getHex());
$this->assertEquals(0, strlen($priKey->getHex()));
$priKey->generate();
$this->assertEquals(64, strlen($priKey->getHex()));
}
/**
* @depends testGetHex
* @depends testGenerate
*/
public function testToString()
{
$priKey = new PrivateKey();
// Make sure this is a string
$this->assertInternalType('string', $priKey->__toString());
$this->assertSame('', (string) $priKey);
$priKey->generate();
// make sure it's still a string after generating hex
$this->assertInternalType('string', $priKey->__toString());
}
public function testGetDec()
{
$priKey = new PrivateKey();
$this->assertNull($priKey->getDec());
$this->assertEquals(0, strlen($priKey->getDec()));
$priKey->generate();
$this->assertGreaterThanOrEqual(76, strlen($priKey->getDec()));
}
public function testIsValid()
{
$priKey = new PrivateKey();
$this->assertFalse($priKey->isValid());
$priKey->generate();
$this->assertTrue($priKey->isValid());
}
public function testSign()
{
//$priKey = PrivateKey::create()->generate();
//$signature = $priKey->sign('Hello');
}
public function testHasValidHex()
{
$pri = new PrivateKey();
$this->assertFalse($pri->hasValidHex());
$pri->generate();
$this->assertTrue($pri->hasValidHex());
}
public function testHasValidDec()
{
$pri = new PrivateKey();
$this->assertFalse($pri->hasValidDec());
$pri->generate();
$this->assertTrue($pri->hasValidDec());
}
}