|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the daikon-cqrs/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 Daikon\Tests\Bitcoin\ValueObject; |
|
10
|
|
|
|
|
11
|
|
|
use Daikon\Bitcoin\ValueObject\Address; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
final class AddressTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
private const FIXED_REGTEST_ADDRESS = 'mwF1rmTrDH2pJNyRdQrWbWGv5UHeq5xUVq'; |
|
17
|
|
|
|
|
18
|
|
|
private Address $regtestAddress; |
|
19
|
|
|
|
|
20
|
1 |
|
public function testToNative(): void |
|
21
|
|
|
{ |
|
22
|
1 |
|
$this->assertEquals(self::FIXED_REGTEST_ADDRESS, $this->regtestAddress->toNative()); |
|
23
|
1 |
|
$this->assertEquals('', Address::makeEmpty()->toNative()); |
|
24
|
1 |
|
$this->assertEquals('', Address::fromNative(null)->toNative()); |
|
25
|
1 |
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function testEquals(): void |
|
28
|
|
|
{ |
|
29
|
1 |
|
$sameAddress = Address::fromNative(self::FIXED_REGTEST_ADDRESS); |
|
30
|
1 |
|
$this->assertTrue($this->regtestAddress->equals($sameAddress)); |
|
31
|
1 |
|
$differentAddress = Address::fromNative('xyz'); |
|
32
|
1 |
|
$this->assertFalse($this->regtestAddress->equals($differentAddress)); |
|
33
|
1 |
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public function testIsEmpty(): void |
|
36
|
|
|
{ |
|
37
|
1 |
|
$this->assertTrue(Address::makeEmpty()->isEmpty()); |
|
38
|
1 |
|
$this->assertTrue(Address::fromNative('')->isEmpty()); |
|
39
|
1 |
|
$this->assertTrue(Address::fromNative(null)->isEmpty()); |
|
40
|
1 |
|
$this->assertFalse(Address::fromNative('0')->isEmpty()); |
|
41
|
1 |
|
$this->assertFalse($this->regtestAddress->isEmpty()); |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
public function testToString(): void |
|
45
|
|
|
{ |
|
46
|
1 |
|
$this->assertEquals(self::FIXED_REGTEST_ADDRESS, (string)$this->regtestAddress); |
|
47
|
1 |
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
public function testMakeEmpty(): void |
|
50
|
|
|
{ |
|
51
|
1 |
|
$this->assertEquals('', Address::makeEmpty()->toNative()); |
|
52
|
1 |
|
$this->assertEquals('', (string)Address::makeEmpty()); |
|
53
|
1 |
|
$this->assertTrue(Address::makeEmpty()->isEmpty()); |
|
54
|
1 |
|
} |
|
55
|
|
|
|
|
56
|
5 |
|
protected function setUp(): void |
|
57
|
|
|
{ |
|
58
|
5 |
|
$this->regtestAddress = Address::fromNative(self::FIXED_REGTEST_ADDRESS); |
|
59
|
5 |
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|