From b7c9281033131cad8b178731ae7ed4e6c852c36c Mon Sep 17 00:00:00 2001 From: Thomas Kerin Date: Mon, 9 Jul 2018 19:54:35 +0200 Subject: [PATCH 1/2] php7 param and return types --- .travis.yml | 7 +- composer.json | 3 + composer.lock | 187 ++++++++++++++++++++--------- src/Exception/Bech32Exception.php | 2 + src/bech32.php | 26 ++-- test/Provider/InvalidAddresses.php | 2 + test/Provider/ValidAddresses.php | 2 + test/SegwitAddressTest.php | 2 + test/TestCase.php | 2 + test/Unit/ConvertBitsTest.php | 2 + test/Unit/DecodeTest.php | 2 + test/Unit/EncodeTest.php | 2 + test/Util.php | 8 +- 13 files changed, 168 insertions(+), 79 deletions(-) diff --git a/.travis.yml b/.travis.yml index 479a158..b329150 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ branches: - "master" php: - - 5.6 - 7.0 - 7.1 - 7.2 @@ -21,15 +20,15 @@ dist: trusty matrix: exclude: # dont want coverage on all runs, will include runs with just PHPUNIT - - php: 5.6 + - php: 7.2 env: PHPUNIT=true include: # add tests without coverage # add extra test runs for php7: coverage, codestyle - - php: 5.6 + - php: 7.2 env: PHPUNIT=true COVERAGE=true - - php: 7.0 + - php: 7.2 env: CODE_STYLE=true install: diff --git a/composer.json b/composer.json index b4a7258..946ec84 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,9 @@ "BitWasp\\Test\\Bech32\\": "test/" } }, + "require": { + "php": ">=7.0" + }, "require-dev": { "phpunit/phpunit": "^5.4.0", "squizlabs/php_codesniffer": "^2.0.0" diff --git a/composer.lock b/composer.lock index 21878c3..6cdcd28 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "2dc8e746d67e37ec73bbca4578ed5266", + "content-hash": "672a419d7cfb0ffaac52b6e190769a59", "packages": [], "packages-dev": [ { @@ -63,37 +63,43 @@ }, { "name": "myclabs/deep-copy", - "version": "1.6.1", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102" + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/8e6e04167378abf1ddb4d3522d8755c5fd90d102", - "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", "shasum": "" }, "require": { - "php": ">=5.4.0" + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" }, "require-dev": { - "doctrine/collections": "1.*", - "phpunit/phpunit": "~4.1" + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" }, "type": "library", "autoload": { "psr-4": { "DeepCopy\\": "src/DeepCopy/" - } + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], "description": "Create deep copies (clones) of your objects", - "homepage": "https://github.com/myclabs/DeepCopy", "keywords": [ "clone", "copy", @@ -101,7 +107,7 @@ "object", "object graph" ], - "time": "2017-04-12T18:52:22+00:00" + "time": "2018-06-11T23:09:50+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -159,29 +165,35 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.1.1", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2" + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/2d3d238c433cf69caeb4842e97a3223a116f94b2", - "reference": "2d3d238c433cf69caeb4842e97a3223a116f94b2", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/reflection-common": "^1.0.0", "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -200,7 +212,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-08-30T18:51:59+00:00" + "time": "2017-11-30T07:14:17+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -251,28 +263,28 @@ }, { "name": "phpspec/prophecy", - "version": "v1.7.2", + "version": "1.7.6", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6" + "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", - "reference": "c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712", + "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", - "sebastian/comparator": "^1.1|^2.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8 || ^5.6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" }, "type": "library", "extra": { @@ -310,7 +322,7 @@ "spy", "stub" ], - "time": "2017-09-04T11:05:03+00:00" + "time": "2018-04-18T13:57:24+00:00" }, { "name": "phpunit/php-code-coverage", @@ -377,16 +389,16 @@ }, { "name": "phpunit/php-file-iterator", - "version": "1.4.2", + "version": "1.4.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", "shasum": "" }, "require": { @@ -420,7 +432,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03T07:40:28+00:00" + "time": "2017-11-27T13:52:08+00:00" }, { "name": "phpunit/php-text-template", @@ -514,16 +526,16 @@ }, { "name": "phpunit/php-token-stream", - "version": "2.0.1", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0" + "reference": "791198a2c6254db10131eecfe8c06670700904db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/9a02332089ac48e704c70f6cefed30c224e3c0b0", - "reference": "9a02332089ac48e704c70f6cefed30c224e3c0b0", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", + "reference": "791198a2c6254db10131eecfe8c06670700904db", "shasum": "" }, "require": { @@ -559,20 +571,20 @@ "keywords": [ "tokenizer" ], - "time": "2017-08-20T05:47:52+00:00" + "time": "2017-11-27T05:48:46+00:00" }, { "name": "phpunit/phpunit", - "version": "5.7.22", + "version": "5.7.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "10df877596c9906d4110b5b905313829043f2ada" + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/10df877596c9906d4110b5b905313829043f2ada", - "reference": "10df877596c9906d4110b5b905313829043f2ada", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", "shasum": "" }, "require": { @@ -596,8 +608,8 @@ "sebastian/global-state": "^1.1", "sebastian/object-enumerator": "~2.0", "sebastian/resource-operations": "~1.0", - "sebastian/version": "~1.0.3|~2.0", - "symfony/yaml": "~2.1|~3.0" + "sebastian/version": "^1.0.6|^2.0.1", + "symfony/yaml": "~2.1|~3.0|~4.0" }, "conflict": { "phpdocumentor/reflection-docblock": "3.0.2" @@ -641,7 +653,7 @@ "testing", "xunit" ], - "time": "2017-09-24T07:23:38+00:00" + "time": "2018-02-01T05:50:59+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -1293,25 +1305,84 @@ ], "time": "2017-05-22T02:43:20+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-04-30T19:57:29+00:00" + }, { "name": "symfony/yaml", - "version": "v3.3.9", + "version": "v4.1.1", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "1d8c2a99c80862bdc3af94c1781bf70f86bccac0" + "reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/1d8c2a99c80862bdc3af94c1781bf70f86bccac0", - "reference": "1d8c2a99c80862bdc3af94c1781bf70f86bccac0", + "url": "https://api.github.com/repos/symfony/yaml/zipball/80e4bfa9685fc4a09acc4a857ec16974a9cd944e", + "reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e", "shasum": "" }, "require": { - "php": "^5.5.9|>=7.0.8" + "php": "^7.1.3", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "symfony/console": "<3.4" }, "require-dev": { - "symfony/console": "~2.8|~3.0" + "symfony/console": "~3.4|~4.0" }, "suggest": { "symfony/console": "For validating YAML files using the lint command" @@ -1319,7 +1390,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.3-dev" + "dev-master": "4.1-dev" } }, "autoload": { @@ -1346,20 +1417,20 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-07-29T21:54:42+00:00" + "time": "2018-05-30T07:26:09+00:00" }, { "name": "webmozart/assert", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + "reference": "0df1908962e7a3071564e857d86874dad1ef204a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a", "shasum": "" }, "require": { @@ -1396,7 +1467,7 @@ "check", "validate" ], - "time": "2016-11-23T20:04:58+00:00" + "time": "2018-01-29T19:49:41+00:00" } ], "aliases": [], @@ -1404,6 +1475,8 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "php": ">=7.0" + }, "platform-dev": [] } diff --git a/src/Exception/Bech32Exception.php b/src/Exception/Bech32Exception.php index 5413abd..298ebe5 100644 --- a/src/Exception/Bech32Exception.php +++ b/src/Exception/Bech32Exception.php @@ -1,5 +1,7 @@ 90) { @@ -245,7 +247,7 @@ function decode($sBech) * @param string $program * @throws Bech32Exception */ -function validateWitnessProgram($version, $program) +function validateWitnessProgram(int $version, string $program) { if ($version < 0 || $version > 16) { throw new Bech32Exception("Invalid witness version"); @@ -270,7 +272,7 @@ function validateWitnessProgram($version, $program) * @return string - the encoded address * @throws Bech32Exception */ -function encodeSegwit($hrp, $version, $program) +function encodeSegwit(string $hrp, int $version, string $program): string { $version = (int) $version; validateWitnessProgram($version, $program); @@ -288,7 +290,7 @@ function encodeSegwit($hrp, $version, $program) * @return array - [$version, $program] * @throws Bech32Exception */ -function decodeSegwit($hrp, $bech32) +function decodeSegwit(string $hrp, string $bech32): array { list ($hrpGot, $data) = decode($bech32); if ($hrpGot !== $hrp) { diff --git a/test/Provider/InvalidAddresses.php b/test/Provider/InvalidAddresses.php index 2cdb01b..ee98efd 100644 --- a/test/Provider/InvalidAddresses.php +++ b/test/Provider/InvalidAddresses.php @@ -1,5 +1,7 @@ Date: Mon, 9 Jul 2018 20:14:09 +0200 Subject: [PATCH 2/2] add new test fixture, and reorder fixtures against those from bip <3 --- src/bech32.php | 2 +- test/Provider/InvalidAddresses.php | 5 +++++ test/Unit/DecodeTest.php | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bech32.php b/src/bech32.php index 4d1fe94..5f67188 100644 --- a/src/bech32.php +++ b/src/bech32.php @@ -98,7 +98,7 @@ function convertBits(array $data, int $inLen, int $fromBits, int $toBits, bool $ $ret[] = ($acc << $toBits - $bits) & $maxv; } } else if ($bits >= $fromBits || ((($acc << ($toBits - $bits))) & $maxv)) { - throw new Bech32Exception('Invalid data'); + throw new Bech32Exception('Invalid data/padding'); } return $ret; diff --git a/test/Provider/InvalidAddresses.php b/test/Provider/InvalidAddresses.php index ee98efd..33958a3 100644 --- a/test/Provider/InvalidAddresses.php +++ b/test/Provider/InvalidAddresses.php @@ -55,6 +55,11 @@ class InvalidAddresses "bc1gmk9yu", "Invalid length for segwit address" ], + [ + "tb", + "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv", + "Invalid data/padding" + ], ]; /** diff --git a/test/Unit/DecodeTest.php b/test/Unit/DecodeTest.php index 59a3a64..8cc103d 100644 --- a/test/Unit/DecodeTest.php +++ b/test/Unit/DecodeTest.php @@ -16,14 +16,14 @@ public function failedDecodeFixtures() ["\x7f1axkwrx", "Out of range character in bech32 string"], ["\x801eym55h", "Out of range character in bech32 string"], ["an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx", "Bech32 string cannot exceed 90 characters in length"], - ["10a06t8", "Bech32 string is too short"], - ["1qzzfhee", "Empty HRP"], ["pzry9x0s0muk", "Missing separator character"], ["1pzry9x0s0muk", "Empty HRP"], ["x1b4n0q5v", "Invalid bech32 checksum"], + ["li1dgmt3", "Too short checksum"], ["de1lg7wt\xff", "Out of range character in bech32 string"], ["A1G7SGD8", "Invalid bech32 checksum"], - ["li1dgmt3", "Too short checksum"], + ["10a06t8", "Bech32 string is too short"], + ["1qzzfhee", "Empty HRP"], ["bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5", "Invalid bech32 checksum"], ]; }