Skip to content

fix M addresses, add tests #8

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

Merged
merged 1 commit into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
"psr-4": {
"Merkeleon\\PhpCryptocurrencyAddressValidation\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Nacho Test Suite">
<directory suffix=".php">./tests/</directory>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/Validation/LTC.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LTC extends Validation

protected $base58PrefixToHexVersion = [
'L' => '30',
'M' => '31',
'M' => '32',
'3' => '05'
];

Expand Down
8 changes: 6 additions & 2 deletions tests/BTCTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

namespace Tests;

use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation\BTC;
use PHPUnit_Framework_TestCase;

class BTCTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -14,8 +18,8 @@ public function testValidator()
];

foreach ($testData as $row) {
$validator = new BTC($row[0]);
$this->assertEquals($row[1], $validator->validate());
$validator = Validation::make('BTC');
$this->assertEquals($row[1], $validator->validate($row[0]));
}

}
Expand Down
8 changes: 6 additions & 2 deletions tests/DASHTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

namespace Tests;

use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation\DASH;
use PHPUnit_Framework_TestCase;

class DASHTest extends PHPUnit_Framework_TestCase
{
Expand All @@ -20,8 +24,8 @@ public function testValidator()
];

foreach ($testData as $row) {
$validator = new DASH($row[0]);
$this->assertEquals($row[1], $validator->validate());
$validator = Validation::make('DASH');
$this->assertEquals($row[1], $validator->validate($row[0]));
}

}
Expand Down
22 changes: 10 additions & 12 deletions tests/LTCTest.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
<?php

namespace Tests;

use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation\LTC;
use PHPUnit_Framework_TestCase;

class LTCTest extends PHPUnit_Framework_TestCase
{
public function testValidator()
{
/*
* There are many addresses in Litecoin blockchain which starts with 3.
* However, addresses starting with 3 are deprecated.
* Litecoin multisig addess should start with M.
*/

$testData = [
['1QLbGuc3WGKKKpLs4pBp9H6jiQ2MgPkXRp', false],
['3CDJNfdWX8m2NwuGUV3nhXHXEeLygMXoAj', false],
['3CDJNfdWX8m2NwuGUV3nhXHXEeLygMXoAj', true],
['LbTjMGN7gELw4KbeyQf6cTCq859hD18guE', true],
// @todo: add test case with M address
['MJRSgZ3UUFcTBTBAaN38XAXvZLwRe8WVw7', true],
];

foreach ($testData as $row) {
$validator = new LTC($row[0]);
$this->assertEquals($row[1], $validator->validate());
$validator = Validation::make('LTC');
$this->assertEquals($row[1], $validator->validate($row[0]));
}

}

public function testLitecoinDeprecatedMultisigAddress()
{
$validator = new LTC('3CDJNfdWX8m2NwuGUV3nhXHXEeLygMXoAj');
$validator = Validation::make('LTC');
$validator->setDeprecatedAllowed(true);
$this->assertEquals(true, $validator->validate());
$this->assertEquals(true, $validator->validate('3CDJNfdWX8m2NwuGUV3nhXHXEeLygMXoAj'));
}
}