Skip to content

Commit d88de2a

Browse files
authored
refactor: remaining coverage (#178)
1 parent 92b95bf commit d88de2a

File tree

13 files changed

+168
-18
lines changed

13 files changed

+168
-18
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"vendor/bin/php-cs-fixer fix"
6464
],
6565
"test": [
66-
"./vendor/bin/pest --coverage --min=96 --coverage-html=.coverage --coverage-clover=coverage.xml"
66+
"./vendor/bin/pest --coverage --min=100 --coverage-html=.coverage --coverage-clover=coverage.xml"
6767
]
6868
},
6969
"minimum-stability": "dev",

phpunit.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
cacheDirectory=".phpunit.cache"
7+
>
38
<testsuites>
4-
<testsuite name="Analysis">
5-
<directory suffix="Test.php">./tests/Analysis</directory>
6-
</testsuite>
7-
<testsuite name="Unit">
8-
<directory suffix="Test.php">./tests/Unit</directory>
9+
<testsuite name="Test Suite">
10+
<directory suffix="Test.php">./tests</directory>
911
</testsuite>
1012
</testsuites>
1113
<source>

src/ByteBuffer/Concerns/Writes/UnsignedInteger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function writeUInt64(int $value, int $offset = 0): self
7575
public function writeUInt256($value, int $offset = 0): self
7676
{
7777
// Convert the value to a GMP object for handling large numbers
78-
if (is_numeric($value) || is_string($value)) {
78+
if (is_numeric($value)) {
7979
$gmpValue = gmp_init($value);
8080
} elseif ($value instanceof \GMP) {
8181
$gmpValue = $value;

src/Networks/AbstractNetwork.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,9 @@ abstract class AbstractNetwork extends Network implements NetworkInterface
1414
* @see Network::$base58PrefixMap
1515
*/
1616
protected $base58PrefixMap = [
17-
self::BASE58_WIF => 'aa', // 170
17+
self::BASE58_WIF => 'aa', // 170
1818
];
1919

20-
/**
21-
* {@inheritdoc}
22-
*/
23-
public static function __callStatic(string $method, array $args)
24-
{
25-
return static::factory()->{$method}(...$args);
26-
}
27-
2820
/**
2921
* Create a new network instance.
3022
*

tests/Unit/ByteBuffer/ByteBufferTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@
177177
expect($buffer->internalSize())->toBe(4 + 11);
178178
});
179179

180+
it('should fill the buffer starting from a different start point', function () {
181+
$buffer = ByteBuffer::new('hello');
182+
$buffer->fill(11, 4);
183+
184+
expect($buffer->internalSize())->toBe(4 + 11);
185+
});
186+
180187
it('should flip the buffer contents', function () {
181188
$buffer = ByteBuffer::new('Hello World');
182189
$buffer->flip();

tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,13 @@
7171

7272
expect($buffer->readULong())->toBe(64);
7373
});
74+
75+
test('it should read uint256', function () {
76+
// 256-bit unsigned integer (32 bytes)
77+
$value = '1157920892373161954235709850086879078532699846656405640323232344'; // max uint256
78+
$buffer = ByteBuffer::new(0);
79+
$buffer->writeUInt256($value);
80+
$buffer->position(0);
81+
82+
expect($buffer->readUInt256())->toBe($value);
83+
});

tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,35 @@
6363

6464
expect($buffer->internalSize())->toBe(8);
6565
});
66+
67+
test('it should write uint256', function () {
68+
// 256-bit unsigned integer (32 bytes)
69+
$value = '1157920892373161954235709850086879078532699846656405640323232344'; // max uint256
70+
$buffer = ByteBuffer::new(0);
71+
$buffer->writeUInt256($value);
72+
73+
expect($buffer->internalSize())->toBe(32);
74+
});
75+
76+
test('it should write uint256 gmp value', function () {
77+
// 256-bit unsigned integer (32 bytes)
78+
$value = gmp_init('1157920892373161954235709850086879078532699846656405640323232344'); // max uint256
79+
$buffer = ByteBuffer::new(0);
80+
$buffer->writeUInt256($value);
81+
82+
expect($buffer->internalSize())->toBe(32);
83+
});
84+
85+
test('it should throw exception when writing invalid uint256', function () {
86+
// 256-bit unsigned integer (32 bytes)
87+
$value = 'asd';
88+
$buffer = ByteBuffer::new(0);
89+
$buffer->writeUInt256($value);
90+
})->throws(InvalidArgumentException::class, 'The value must be a numeric string, integer, or GMP object.');
91+
92+
test('it should throw exception when writing uint256 which is too long', function () {
93+
// 256-bit unsigned integer (32 bytes)
94+
$value = '1157920892373161954235709850086879078532699846656405640323232344444411579208923731619542357098500868790785326998466564056403232323444444';
95+
$buffer = ByteBuffer::new(0);
96+
$buffer->writeUInt256($value);
97+
})->throws(InvalidArgumentException::class, 'The value must fit into 256 bits.');
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use ArkEcosystem\Crypto\Enums\AbiFunction;
6+
use ArkEcosystem\Crypto\Transactions\Types\Multipayment;
7+
use ArkEcosystem\Crypto\Transactions\Types\Unvote;
8+
use ArkEcosystem\Crypto\Transactions\Types\UsernameRegistration;
9+
use ArkEcosystem\Crypto\Transactions\Types\UsernameResignation;
10+
use ArkEcosystem\Crypto\Transactions\Types\ValidatorRegistration;
11+
use ArkEcosystem\Crypto\Transactions\Types\ValidatorResignation;
12+
use ArkEcosystem\Crypto\Transactions\Types\Vote;
13+
14+
it('should get transaction class', function ($type, $class) {
15+
expect(constant(AbiFunction::class.'::'.$type)->transactionClass())->toEqual($class);
16+
})->with([
17+
'Vote' => ['VOTE', Vote::class],
18+
'Unvote' => ['UNVOTE', Unvote::class],
19+
'ValidatorRegistration' => ['VALIDATOR_REGISTRATION', ValidatorRegistration::class],
20+
'ValidatorResignation' => ['VALIDATOR_RESIGNATION', ValidatorResignation::class],
21+
'UsernameRegistration' => ['USERNAME_REGISTRATION', UsernameRegistration::class],
22+
'UsernameResignation' => ['USERNAME_RESIGNATION', UsernameResignation::class],
23+
'Multipayment' => ['MULTIPAYMENT', Multipayment::class],
24+
]);

tests/Unit/Identities/AddressTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,17 @@
3838

3939
expect($actual)->toBe($fixture['data']['address']);
4040
});
41+
42+
it('should validate an address', function () {
43+
$fixture = $this->getFixture('identity');
44+
45+
$actual = Address::validate($fixture['data']['address']);
46+
47+
expect($actual)->toBeTrue();
48+
});
49+
50+
it('should return false for an invalid address', function () {
51+
$actual = Address::validate('invalid-address');
52+
53+
expect($actual)->toBeFalse();
54+
});

tests/Unit/Transactions/Builder/ValidatorRegistrationBuilderTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
expect((string) $builder)->toBe($builder->toJson());
4343
});
4444

45+
it('should set value on the transaction', function () {
46+
$builder = ValidatorRegistrationBuilder::new()
47+
->value(UnitConverter::parseUnits(10, 'ark'));
48+
49+
expect((string) $builder->transaction->data['value'])->toBe('10000000000000000000');
50+
});
51+
4552
it('should convert to an array', function () {
4653
$fixture = $this->getTransactionFixture('evm_call', 'unvote');
4754

0 commit comments

Comments
 (0)