1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Test\Bech32; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use function BitWasp\Bech32\decodeSegwit; |
|
|
|
|
7
|
|
|
use function BitWasp\Bech32\encodeSegwit; |
|
|
|
|
8
|
|
|
use BitWasp\Test\Bech32\Provider\ValidAddresses; |
9
|
|
|
|
10
|
|
|
class SegwitAddressTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @return array |
14
|
|
|
*/ |
15
|
|
|
public function validAddressProvider() |
16
|
|
|
{ |
17
|
|
|
return ValidAddresses::load(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* https://github.com/sipa/bech32/blob/master/ref/python/tests.py#L106 |
22
|
|
|
* @param string $hrp |
23
|
|
|
* @param string $bech32 |
24
|
|
|
* @param string $hexScript |
25
|
|
|
* @dataProvider validAddressProvider |
26
|
|
|
*/ |
27
|
|
|
public function testValidAddress($hrp, $bech32, $hexScript) |
28
|
|
|
{ |
29
|
|
|
list ($version, $program) = decodeSegwit($hrp, $bech32); |
30
|
|
|
$this->assertEquals($hexScript, Util::witnessProgram($version, $program)); |
31
|
|
|
|
32
|
|
|
$addr = encodeSegwit($hrp, $version, $program); |
33
|
|
|
$this->assertEquals(strtolower($bech32), strtolower($addr)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function invalidAddressProvider() { |
38
|
|
|
return [ |
39
|
|
|
["tc1qw508d6qejxtdg4y5r3zarvary0c5xw7kg3g4ty"], |
40
|
|
|
["bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5"], |
41
|
|
|
["BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2"], |
42
|
|
|
["bc1rw5uspcuh"], |
43
|
|
|
["bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kw5rljs90"], |
44
|
|
|
["BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P"], |
45
|
|
|
["tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7"], |
46
|
|
|
["tb1pw508d6qejxtdg4y5r3zarqfsj6c3"], |
47
|
|
|
["tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv"], |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $bech32 |
54
|
|
|
* @dataProvider invalidAddressProvider |
55
|
|
|
*/ |
56
|
|
|
public function testInvalidAddress($bech32) |
57
|
|
|
{ |
58
|
|
|
try { |
59
|
|
|
decodeSegwit("bc", $bech32); |
60
|
|
|
$threw = false; |
61
|
|
|
} catch (\Exception $e) { |
62
|
|
|
$threw = true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->assertTrue($threw, "expected mainnet hrp to fail"); |
66
|
|
|
|
67
|
|
|
try { |
68
|
|
|
decodeSegwit("tb", $bech32); |
69
|
|
|
$threw = false; |
70
|
|
|
} catch (\Exception $e) { |
71
|
|
|
$threw = true; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->assertTrue($threw, "expected testnet hrp to fail"); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths