1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the ngutech/bitcoin-interop project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace NGUtech\Tests\Bitcoin\ValueObject; |
10
|
|
|
|
11
|
|
|
use Daikon\Interop\InvalidArgumentException; |
12
|
|
|
use NGUtech\Bitcoin\ValueObject\Address; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
final class AddressTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
private const FIXED_REGTEST_ADDRESS = 'mwF1rmTrDH2pJNyRdQrWbWGv5UHeq5xUVq'; |
18
|
|
|
|
19
|
|
|
private Address $regtestAddress; |
20
|
|
|
|
21
|
1 |
|
public function testFromNative(): void |
22
|
|
|
{ |
23
|
1 |
|
$this->expectException(InvalidArgumentException::class); |
24
|
1 |
|
Address::fromNative(''); |
25
|
|
|
} |
26
|
|
|
|
27
|
1 |
|
public function testToNative(): void |
28
|
|
|
{ |
29
|
1 |
|
$this->assertEquals(self::FIXED_REGTEST_ADDRESS, $this->regtestAddress->toNative()); |
30
|
1 |
|
$this->assertEquals('', Address::makeEmpty()->toNative()); |
31
|
1 |
|
$this->assertEquals('', Address::fromNative(null)->toNative()); |
32
|
1 |
|
} |
33
|
|
|
|
34
|
1 |
|
public function testEquals(): void |
35
|
|
|
{ |
36
|
1 |
|
$sameAddress = Address::fromNative(self::FIXED_REGTEST_ADDRESS); |
37
|
1 |
|
$this->assertTrue($this->regtestAddress->equals($sameAddress)); |
38
|
1 |
|
$differentAddress = Address::fromNative('xyz'); |
39
|
1 |
|
$this->assertFalse($this->regtestAddress->equals($differentAddress)); |
40
|
1 |
|
} |
41
|
|
|
|
42
|
1 |
|
public function testIsEmpty(): void |
43
|
|
|
{ |
44
|
1 |
|
$this->assertTrue(Address::makeEmpty()->isEmpty()); |
45
|
1 |
|
$this->assertTrue(Address::fromNative(null)->isEmpty()); |
46
|
1 |
|
$this->assertFalse(Address::fromNative('0')->isEmpty()); |
47
|
1 |
|
$this->assertFalse($this->regtestAddress->isEmpty()); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
1 |
|
public function testToString(): void |
51
|
|
|
{ |
52
|
1 |
|
$this->assertEquals(self::FIXED_REGTEST_ADDRESS, (string)$this->regtestAddress); |
53
|
1 |
|
} |
54
|
|
|
|
55
|
1 |
|
public function testMakeEmpty(): void |
56
|
|
|
{ |
57
|
1 |
|
$this->assertEquals('', Address::makeEmpty()->toNative()); |
58
|
1 |
|
$this->assertEquals('', (string)Address::makeEmpty()); |
59
|
1 |
|
$this->assertTrue(Address::makeEmpty()->isEmpty()); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
6 |
|
protected function setUp(): void |
63
|
|
|
{ |
64
|
6 |
|
$this->regtestAddress = Address::fromNative(self::FIXED_REGTEST_ADDRESS); |
65
|
6 |
|
} |
66
|
|
|
} |
67
|
|
|
|