Skip to content

Bump murmurhash/phpunit, fix tests #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
99c0b5c
scrutinizer: bump minimum version to 7.3
afk11 Apr 17, 2021
63f6a5f
lastguest/murmurhash: support ^2.0
afk11 Apr 16, 2021
ee42dc6
phpunit: bump to 9.0
afk11 Apr 16, 2021
d78dc31
AddressTest: new usage of expectException
afk11 Apr 16, 2021
de4033d
BloomFilterTest: fix setUp signature
afk11 Apr 16, 2021
314437b
HierarchicalKeyTest: fix setUp signature
afk11 Apr 16, 2021
6a31a6c
AmountTest: [REVIEW] change amount fixtures since bcmath now seems to…
afk11 Apr 16, 2021
4fb5e9a
EnglishWordListTest: new usage of expectedException
afk11 Apr 16, 2021
ed54304
Base58Test: new usage of expectException
afk11 Apr 16, 2021
8ff86ab
BlockHeaderTest: assertInternalType deprecated, fix
afk11 Apr 16, 2021
4b10590
BlockHeaderTest: new usage of expectException
afk11 Apr 16, 2021
e1d95f1
BlockTest: assertInternalType deprecated, fix
afk11 Apr 16, 2021
58a1885
MerkleRootTest: new expectException usage
afk11 Apr 16, 2021
9214c93
ProofOfWorkTest: new expectException usage
afk11 Apr 16, 2021
0ea10fb
DifficultyTest: [REVIEW] tweak fixtures since bcmath scale behaviour …
afk11 Apr 16, 2021
40be493
StaticCollectionImplTest: new expectException usage
afk11 Apr 16, 2021
6e0719c
EcTest: new expectException usage
afk11 Apr 16, 2021
5b3df7a
HashTest: new expectException usage
afk11 Apr 16, 2021
25830f5
ElectrumKeyTest: new usage of expectException
afk11 Apr 16, 2021
76a0a81
HierarchicalKeySequenceTest: new expectException usage
afk11 Apr 16, 2021
a95e733
HierarchicalKeyTest: new usage of expectException
afk11 Apr 16, 2021
82471df
MultisigHDTest: new expectException usage
afk11 Apr 16, 2021
25600a3
PrefixRegistryTest: assertInternalType deprecated
afk11 Apr 16, 2021
081e681
PrivateKeyTest: new usage of expectException
afk11 Apr 16, 2021
f1c705e
PublicKeyTest: new usage for expectException
afk11 Apr 16, 2021
31d8c6a
LocktimeTest: [REVIEW] expectException usage, and discovered issue in…
afk11 Apr 16, 2021
934afa1
Bip39MnemonicTest: new usage for expectException
afk11 Apr 16, 2021
39d34ea
EnglishWordListTest: assertInternalType deprecated, and new expectExc…
afk11 Apr 16, 2021
4af6f3b
bip39 word list test: expectException usage
afk11 Apr 16, 2021
be5f6e6
PathTracerTest: assertInternalType deprecated, fix
afk11 Apr 16, 2021
eb93ac8
OutputClassifierTest: assertInternalArray deprecated
afk11 Apr 16, 2021
6214f7a
OutputScriptFactoryTest: new expectException usage
afk11 Apr 16, 2021
ad23c57
StackTest: new expectException usage
afk11 Apr 16, 2021
ff49a9b
OpcodesTest: new expectException usage
afk11 Apr 16, 2021
ace96f8
ScriptTest: new expectException usage and assertInternalType deprecat…
afk11 Apr 16, 2021
5f100dd
BitcoindBlockSerializerTest: new expectException usage
afk11 Apr 16, 2021
5c675f5
BlockHeaderSerializerTest: expectException usage
afk11 Apr 16, 2021
b8e2749
BlockSerializerTest: new expectException usage
afk11 Apr 16, 2021
17f2f86
ExtendedKeySerializerTest: new expectException usage
afk11 Apr 16, 2021
95f2618
CompactSignatureSerializerTest: new expectException usage
afk11 Apr 16, 2021
aa22cb1
DerSignatureSerializerTest: expectException usage
afk11 Apr 16, 2021
345ec80
TransactionSerializerTest: new expectException usage
afk11 Apr 16, 2021
fe10def
phpunit: remove deprecated filter (and unused)
afk11 Apr 16, 2021
2e38d72
SignDataTest: new expectException usage
afk11 Apr 16, 2021
b614e47
SignerTest: new expectException usage
afk11 Apr 16, 2021
ff920a0
Input/OutputCollectionMutatorTest: new expectException usage
afk11 Apr 16, 2021
a73d7e2
TransactionTest: new expectException usage
afk11 Apr 17, 2021
29ebaf1
UriTest: new expectException usage
afk11 Apr 17, 2021
bce0cb9
branch_test.json: remove stray whitespace from file, caused test fail…
afk11 Apr 23, 2021
983eb97
Script.php: nasty bug. use proper equality check, not assignment oper…
afk11 Apr 24, 2021
dbbd2a7
BloomFactor: refactor functions to avoid bcmath, because there were s…
afk11 Apr 24, 2021
244c851
ScriptCheckTestBase: compare strlen to 0, not empty string??
afk11 Apr 24, 2021
ba1f045
delete unused class WitnessCollectionMutator
afk11 Apr 24, 2021
6f7d4f2
AbstractCollectionMutator: refactor out SqlFixedArray which has had a…
afk11 Apr 24, 2021
77887b8
tests for InputCollectionMutator
afk11 Apr 24, 2021
4484c55
travis.yml: test 7.3/7.4/8.0
afk11 Apr 24, 2021
ef19212
travis.yml: bump dist to xenial
afk11 Apr 24, 2021
a7c56aa
rpc tests: assertInternalType deprecated fix
afk11 Apr 24, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build:
redis: false
postgresql: false
php:
version: 7.2
version: 7.3
ini:
'zend.assertions': '1'
'assert.exception': '1'
Expand Down
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0

env:
- PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_COMMIT="cd329dbc3eaf096ae007e807b86b6f5947621ee3"

dist: trusty
dist: xenial
sudo: required

cache:
Expand All @@ -19,14 +18,14 @@ cache:

matrix:
exclude:
- php: 7.2
- php: 8.0
env: PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_COMMIT="cd329dbc3eaf096ae007e807b86b6f5947621ee3"

include:
# add extra test runs for php7: coverage, codestyle, examples, rpc tests
- php: 7.2
- php: 8.0
env: COVERAGE=true CODE_STYLE=true EXAMPLES=true PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_COMMIT="cd329dbc3eaf096ae007e807b86b6f5947621ee3"
- php: 7.0
- php: 7.3
env: RPC_TEST=true BITCOIN_VERSION="0.16.3" SECP256K1_COMMIT="cd329dbc3eaf096ae007e807b86b6f5947621ee3"

install:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"php-64bit": ">=7.0",
"pleonasm/merkle-tree": "1.0.0",
"composer/semver": "^1.4.0|^3.2.0",
"lastguest/murmurhash": "v2.0.0",
"lastguest/murmurhash": "^2.0",
"mdanter/ecc": "^0.5.0",
"bitwasp/buffertools": "^0.5.0",
"bitwasp/bech32": "^0.0.1"
Expand All @@ -37,7 +37,7 @@
},
"require-dev": {
"ext-json": "*",
"phpunit/phpunit": "^5.4.0",
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^2.0.0",
"nbobtc/bitcoind-php": "v2.0.2",
"bitwasp/secp256k1-php": "^v0.2.0",
Expand Down
7 changes: 0 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,4 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
<exclude>src/PaymentProtocol/Protobufs</exclude>
</whitelist>
</filter>

</phpunit>
67 changes: 17 additions & 50 deletions src/Bloom/BloomFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class BloomFilter extends Serializable
private $flags;

/**
* @param Math $math
* @param Math $math
* @param array $vFilter
* @param int $numHashFuncs
* @param int $nTweak
* @param int $flags
* @param int $numHashFuncs
* @param int $nTweak
* @param int $flags
*/
public function __construct(Math $math, array $vFilter, int $numHashFuncs, int $nTweak, int $flags)
{
Expand All @@ -91,11 +91,11 @@ public static function emptyFilter(int $size): array
* Create the Bloom Filter given the number of elements, a false positive rate,
* and the flags governing how the filter should be updated.
*
* @param Math $math
* @param int $nElements
* @param float $nFpRate
* @param int $nTweak
* @param int $flags
* @param Math $math
* @param int $nElements
* @param float $nFpRate
* @param int $nTweak
* @param int $flags
* @return BloomFilter
*/
public static function create(Math $math, int $nElements, float $nFpRate, int $nTweak, int $flags): BloomFilter
Expand Down Expand Up @@ -184,33 +184,15 @@ public function getFlags(): int
}

/**
* @param int $nElements
* @param int $nElements
* @param float $fpRate
* @return int
*/
public static function idealSize(int $nElements, float $fpRate): int
{
return (int) floor(
bcdiv(
min(
bcmul(
bcmul(
bcdiv(
'-1',
(string) self::LN2SQUARED
),
(string) $nElements
),
(string) log($fpRate)
),
bcmul(
(string) self::MAX_FILTER_SIZE,
'8'
)
),
'8'
)
);
$a = (-1/self::LN2SQUARED)*$nElements*log($fpRate);
$b = self::MAX_FILTER_SIZE*8;
return (int) floor(min($a, $b) / 8);
}

/**
Expand All @@ -220,28 +202,13 @@ public static function idealSize(int $nElements, float $fpRate): int
*/
public static function idealNumHashFuncs(int $filterSize, int $nElements)
{
return (int) floor(
min(
bcmul(
bcdiv(
bcmul(
(string) $filterSize,
'8'
),
(string) $nElements
),
(string) self::LN2
),
bcmul(
(string) self::MAX_FILTER_SIZE,
'8'
)
)
);
$a = (($filterSize*8)/$nElements)*self::LN2;
$b = self::MAX_FILTER_SIZE * 8;
return (int) floor(min($a, $b));
}

/**
* @param int $nHashNum
* @param int $nHashNum
* @param BufferInterface $data
* @return string
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Locktime.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Locktime
* Maximum block height that can be used in locktime, as beyond
* this is reserved for timestamp locktimes
*/
const BLOCK_MAX = 500000000;
const BLOCK_MAX = 500000000-1;

/**
* Maximum timestamp that can be encoded in locktime
Expand Down Expand Up @@ -98,8 +98,8 @@ public function fromBlockHeight(int $blockHeight): int
*/
public function toBlockHeight(int $lockTime): int
{
if ($lockTime >= self::BLOCK_MAX) {
throw new \Exception('This locktime is out of range for a block height');
if ($lockTime > self::BLOCK_MAX) {
throw new \Exception("This locktime is out of range for a block height");
}

return $lockTime;
Expand Down
2 changes: 1 addition & 1 deletion src/Mnemonic/Bip39/Wordlist/JapaneseWordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getIndex(string $word): int
}

if (!isset($this->wordsFlipped[$word])) {
throw new \InvalidArgumentException(__CLASS__ . ' does not contain word ' . $word);
throw new \InvalidArgumentException('Wordlist does not contain word ' . $word);
}

return $this->wordsFlipped[$word];
Expand Down
2 changes: 1 addition & 1 deletion src/Mnemonic/WordList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getWord(int $index): string
{
$words = $this->getWords();
if (!isset($words[$index])) {
throw new \InvalidArgumentException(__CLASS__ . " does not contain a word for index [{$index}]");
throw new \InvalidArgumentException("Wordlist does not contain a word for index [{$index}]");
}

return $words[$index];
Expand Down
20 changes: 17 additions & 3 deletions src/Script/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,24 @@ public function isWitness(& $program = null): bool
*/
public function isP2SH(& $scriptHash): bool
{
//
// if (strlen($this->script) == 23) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented debug code

// var_dump("{$this->script[0]} | ".ord($this->script[0])." ".Opcodes::OP_HASH160);
// var_dump(ord($this->script[0]) == Opcodes::OP_HASH160);
// var_dump("{$this->script[1]} | ".ord($this->script[1])." 20");
// var_dump(ord($this->script[1]) == 20);
// var_dump("{$this->script[22]} | ".ord($this->script[22])." ".Opcodes::OP_EQUAL);
// var_dump(ord($this->script[22]) == Opcodes::OP_EQUAL);
// }
// echo "isP2SH?\n";
// echo "script: ".bin2hex($this->script).PHP_EOL;
if (strlen($this->script) === 23
&& $this->script[0] = Opcodes::OP_HASH160
&& $this->script[1] = 20
&& $this->script[22] = Opcodes::OP_EQUAL
&& ord($this->script[0]) == Opcodes::OP_HASH160
&& ord($this->script[1]) == 20
&& ord($this->script[22]) == Opcodes::OP_EQUAL
// && $this->script[0] == Opcodes::OP_HASH160
// && $this->script[1] == 20
// && $this->script[22] == Opcodes::OP_EQUAL
) {
$scriptHash = new Buffer(substr($this->script, 2, 20));
return true;
Expand Down
55 changes: 24 additions & 31 deletions src/Transaction/Mutator/AbstractCollectionMutator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
abstract class AbstractCollectionMutator implements \Iterator, \ArrayAccess, \Countable
{
/**
* @var \SplFixedArray
* @var array
*/
protected $set;
protected $set = [];

private $position = 0;

/**
* @return array
*/
public function all(): array
{
return $this->set->toArray();
return $this->set;
}

/**
Expand All @@ -32,56 +34,44 @@ public function isNull(): bool
*/
public function count(): int
{
return $this->set->count();
return count($this->set);
}

/**
*
*/
public function rewind()
public function rewind(): void
{
$this->set->rewind();
$this->position = 0;
}

/**
* @return mixed
*/
public function current()
{
return $this->set->current();
return $this->set[$this->position];
}

/**
* @return int
*/
public function key()
public function key(): int
{
return $this->set->key();
return $this->position;
}

/**
*
*/
public function next()
public function next(): void
{
$this->set->next();
++$this->position;
}

/**
* @return bool
*/
public function valid()
public function valid(): bool
{
return $this->set->valid();
return array_key_exists($this->position, $this->set);
}

/**
* @param int $offset
* @return bool
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return $this->set->offsetExists($offset);
return array_key_exists($offset, $this->set);
}

/**
Expand All @@ -93,7 +83,7 @@ public function offsetUnset($offset)
throw new \InvalidArgumentException('Offset does not exist');
}

$this->set->offsetUnset($offset);
$this->set = array_slice($this->set, 0, $offset - 1) + array_slice($this->set, $offset + 1);
}

/**
Expand All @@ -102,10 +92,10 @@ public function offsetUnset($offset)
*/
public function offsetGet($offset)
{
if (!$this->set->offsetExists($offset)) {
if (!array_key_exists($offset, $this->set)) {
throw new \OutOfRangeException('Nothing found at this offset');
}
return $this->set->offsetGet($offset);
return $this->set[$offset];
}

/**
Expand All @@ -114,6 +104,9 @@ public function offsetGet($offset)
*/
public function offsetSet($offset, $value)
{
$this->set->offsetSet($offset, $value);
if ($offset > count($this->set)) {
throw new \InvalidArgumentException();
}
$this->set[$offset] = $value;
}
}
Loading