From 9b58df39aa654311c920440d07bf05533600c37d Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 11 Jun 2025 17:20:54 +0100 Subject: [PATCH 01/15] handle hex2bin exception instead of relying on returning false --- src/Utils/Abi/ArgumentDecoder.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Utils/Abi/ArgumentDecoder.php b/src/Utils/Abi/ArgumentDecoder.php index eac3fbc1..3efc708e 100644 --- a/src/Utils/Abi/ArgumentDecoder.php +++ b/src/Utils/Abi/ArgumentDecoder.php @@ -12,7 +12,13 @@ final class ArgumentDecoder public function __construct(string $bytes) { - $bytes = hex2bin($bytes); + try { + $bytes = hex2bin($bytes); + } catch (\Throwable $e) { + // Handle the case where hex2bin fails, e.g., invalid hex string + $bytes = false; + } + if ($bytes === false) { $bytes = ''; } From fcb9b68e8db94b6d5b1bcf26f11ee813a526821e Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 11 Jun 2025 17:21:37 +0100 Subject: [PATCH 02/15] remove legacy message public key formatting & handling --- src/Utils/Message.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Utils/Message.php b/src/Utils/Message.php index 3e1ef91a..311f0dfb 100644 --- a/src/Utils/Message.php +++ b/src/Utils/Message.php @@ -44,16 +44,11 @@ class Message */ public function __construct(object $message) { - if (property_exists($message, 'publickey')) { - $this->publicKey = $message->publickey; - } elseif (property_exists($message, 'publicKey')) { - $this->publicKey = $message->publicKey; - } elseif (property_exists($message, 'signatory')) { - $this->publicKey = $message->signatory; - } else { + if (! property_exists($message, 'publicKey')) { throw new InvalidArgumentException('The given message did not contain a valid public key.'); } + $this->publicKey = $message->publicKey; $this->signature = $message->signature; $this->message = $message->message; } @@ -113,7 +108,7 @@ public static function sign(string $message, string $passphrase): self $v = dechex($signature->getRecoveryId() + 27); return static::new([ - 'publickey' => $privateKey->publicKey, + 'publicKey' => $privateKey->publicKey, 'signature' => $r.$s.$v, 'message' => $message, ]); @@ -144,7 +139,7 @@ public function verify(): bool public function toArray(): array { return [ - 'publickey' => $this->publicKey, + 'publicKey' => $this->publicKey, 'signature' => $this->signature, 'message' => $this->message, ]; From 70877d232e94ff41ef1f2053d3d63d270ed15b0e Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 11 Jun 2025 17:21:46 +0100 Subject: [PATCH 03/15] test: remaining utils coverage --- tests/Unit/Utils/Abi/ArgumentDecoderTest.php | 18 +++++ tests/Unit/Utils/AddressTest.php | 17 +++++ tests/Unit/Utils/MessageTest.php | 8 ++ tests/Unit/Utils/TransactionUtilsTest.php | 80 ++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 tests/Unit/Utils/TransactionUtilsTest.php diff --git a/tests/Unit/Utils/Abi/ArgumentDecoderTest.php b/tests/Unit/Utils/Abi/ArgumentDecoderTest.php index 0c388b50..638cc0dd 100644 --- a/tests/Unit/Utils/Abi/ArgumentDecoderTest.php +++ b/tests/Unit/Utils/Abi/ArgumentDecoderTest.php @@ -19,6 +19,15 @@ expect($decoder->decodeAddress())->toBe($expected); }); +it('should decode a string', function () { + $payload = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000474657374'; + $expected = 'test'; + + $decoder = new ArgumentDecoder($payload); + + expect($decoder->decodeString())->toBe($expected); +}); + it('should decode unsigned int', function () { $payload = '000000000000000000000000000000000000000000000000016345785d8a0000'; $expected = '100000000000000000'; @@ -54,3 +63,12 @@ expect($decoder->decodeBool())->toBe($expected); }); + +it('should handle issue converting hex to binary', function () { + $decoder = new ArgumentDecoder('invalid'); + + $reflectionProperty = new \ReflectionProperty(ArgumentDecoder::class, 'bytes'); + $reflectionProperty->setAccessible(true); + + expect($reflectionProperty->getValue($decoder))->toBe(''); +}); diff --git a/tests/Unit/Utils/AddressTest.php b/tests/Unit/Utils/AddressTest.php index 6f0ba7bb..b70e8daa 100644 --- a/tests/Unit/Utils/AddressTest.php +++ b/tests/Unit/Utils/AddressTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use ArkEcosystem\Crypto\ByteBuffer\ByteBuffer; use ArkEcosystem\Crypto\Utils\Address as TestClass; test('it should validate the address', function () { @@ -17,3 +18,19 @@ expect($actual)->toBeFalse(); }); + +it('should convert to hex string', function () { + $fixture = $this->getFixture('identity'); + + $actual = TestClass::toBufferHexString($fixture['data']['address']); + + expect($actual)->toBe(substr($fixture['data']['address'], 2)); +}); + +it('should extract address from a byte buffer', function () { + $fixture = $this->getFixture('identity'); + + $actual = TestClass::fromByteBuffer(ByteBuffer::fromHex(substr($fixture['data']['address'], 2))); + + expect($actual)->toBe($fixture['data']['address']); +}); diff --git a/tests/Unit/Utils/MessageTest.php b/tests/Unit/Utils/MessageTest.php index 2ce906b2..35093fee 100644 --- a/tests/Unit/Utils/MessageTest.php +++ b/tests/Unit/Utils/MessageTest.php @@ -34,6 +34,14 @@ expect($message->message)->toBe($fixture['message']); }); +test('it should throw if no public key is provided', function () { + $fixture = $this->getFixture('message-sign'); + + unset($fixture['publicKey']); + + Message::new($fixture); +})->throws(InvalidArgumentException::class, 'The given message did not contain a valid public key.'); + test('it should create a message from a string', function () { $fixture = $this->getFixture('message-sign'); diff --git a/tests/Unit/Utils/TransactionUtilsTest.php b/tests/Unit/Utils/TransactionUtilsTest.php new file mode 100644 index 00000000..eb59ce6a --- /dev/null +++ b/tests/Unit/Utils/TransactionUtilsTest.php @@ -0,0 +1,80 @@ +getTransactionFixture('evm_call', 'username-resignation'); + + $transaction = TransactionUtils::toBuffer($fixture['data']); + + expect($transaction->getHex())->toBe($fixture['serialized']); +}); + +it('should convert a transaction to a buffer when data starts with 0x', function () { + $fixture = $this->getTransactionFixture('evm_call', 'username-resignation'); + + $fixture['data']['data'] = '0x' . $fixture['data']['data']; + + $transaction = TransactionUtils::toBuffer($fixture['data']); + + expect($transaction->getHex())->toBe($fixture['serialized']); +}); + +it('should get the hash for a transaction', function () { + $fixture = $this->getTransactionFixture('evm_call', 'username-resignation'); + + $transaction = TransactionUtils::toHash($fixture['data']); + + expect($transaction->getHex())->toBe($fixture['data']['hash']); +}); + +it('should handle string data starting with 0x', function () { + $fixture = $this->getTransactionFixture('evm_call', 'username-resignation'); + + $fixture['data']['gasPrice'] = '0x'.dechex($fixture['data']['gasPrice']); + + $transaction = TransactionUtils::toBuffer($fixture['data']); + + expect($transaction->getHex())->toBe($fixture['serialized']); +}); + +it('should handle BigDecimal value', function () { + $fixture = $this->getTransactionFixture('evm_call', 'username-resignation'); + + $fixture['data']['gasPrice'] = BigDecimal::of($fixture['data']['gasPrice']); + + $transaction = TransactionUtils::toBuffer($fixture['data']); + + expect($transaction->getHex())->toBe($fixture['serialized']); +}); + +it('should handle zero BigDecimal value', function () { + $fixture = $this->getTransactionFixture('evm_call', 'username-resignation'); + + $fixture['data']['gasPrice'] = BigDecimal::zero(); + + $transaction = TransactionUtils::toBuffer($fixture['data'], true); + + $decoded = RlpDecoder::decode('0x'.substr($transaction->getHex(), 2)); + + expect($decoded[3])->toBe('0x'); +}); + +it('should handle unknown value value', function () { + $fixture = $this->getTransactionFixture('evm_call', 'username-resignation'); + + $fixture['data']['gasPrice'] = 123.456; + + $transaction = TransactionUtils::toBuffer($fixture['data'], true); + + $decoded = RlpDecoder::decode('0x'.substr($transaction->getHex(), 2)); + + expect($decoded[3])->toBe('0x'); +}); + +// toBuffer +// toHash From df46cb1981806bd870e5a201a73a023ee67c21b2 Mon Sep 17 00:00:00 2001 From: alexbarnsley Date: Wed, 11 Jun 2025 16:22:21 +0000 Subject: [PATCH 04/15] style: resolve style guide violations --- tests/Unit/Utils/Abi/ArgumentDecoderTest.php | 2 +- tests/Unit/Utils/TransactionUtilsTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Unit/Utils/Abi/ArgumentDecoderTest.php b/tests/Unit/Utils/Abi/ArgumentDecoderTest.php index 638cc0dd..df0d7cb7 100644 --- a/tests/Unit/Utils/Abi/ArgumentDecoderTest.php +++ b/tests/Unit/Utils/Abi/ArgumentDecoderTest.php @@ -20,7 +20,7 @@ }); it('should decode a string', function () { - $payload = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000474657374'; + $payload = '0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000474657374'; $expected = 'test'; $decoder = new ArgumentDecoder($payload); diff --git a/tests/Unit/Utils/TransactionUtilsTest.php b/tests/Unit/Utils/TransactionUtilsTest.php index eb59ce6a..c45005a7 100644 --- a/tests/Unit/Utils/TransactionUtilsTest.php +++ b/tests/Unit/Utils/TransactionUtilsTest.php @@ -1,10 +1,10 @@ getTransactionFixture('evm_call', 'username-resignation'); @@ -17,7 +17,7 @@ it('should convert a transaction to a buffer when data starts with 0x', function () { $fixture = $this->getTransactionFixture('evm_call', 'username-resignation'); - $fixture['data']['data'] = '0x' . $fixture['data']['data']; + $fixture['data']['data'] = '0x'.$fixture['data']['data']; $transaction = TransactionUtils::toBuffer($fixture['data']); From 6ae540a16e25211b885cb2cc86f613155f0577d1 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:22:04 +0100 Subject: [PATCH 05/15] remove string check for writing uint256 --- src/ByteBuffer/Concerns/Writes/UnsignedInteger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ByteBuffer/Concerns/Writes/UnsignedInteger.php b/src/ByteBuffer/Concerns/Writes/UnsignedInteger.php index db9f8d18..31d2b6d5 100644 --- a/src/ByteBuffer/Concerns/Writes/UnsignedInteger.php +++ b/src/ByteBuffer/Concerns/Writes/UnsignedInteger.php @@ -75,7 +75,7 @@ public function writeUInt64(int $value, int $offset = 0): self public function writeUInt256($value, int $offset = 0): self { // Convert the value to a GMP object for handling large numbers - if (is_numeric($value) || is_string($value)) { + if (is_numeric($value)) { $gmpValue = gmp_init($value); } elseif ($value instanceof \GMP) { $gmpValue = $value; From 45225ca6e9c2c222033f421a930103506e1fb824 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:22:32 +0100 Subject: [PATCH 06/15] remove unused network method --- src/Networks/AbstractNetwork.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Networks/AbstractNetwork.php b/src/Networks/AbstractNetwork.php index e1310cae..0d94bb39 100644 --- a/src/Networks/AbstractNetwork.php +++ b/src/Networks/AbstractNetwork.php @@ -14,17 +14,9 @@ abstract class AbstractNetwork extends Network implements NetworkInterface * @see Network::$base58PrefixMap */ protected $base58PrefixMap = [ - self::BASE58_WIF => 'aa', // 170 + self::BASE58_WIF => 'aa', // 170 ]; - /** - * {@inheritdoc} - */ - public static function __callStatic(string $method, array $args) - { - return static::factory()->{$method}(...$args); - } - /** * Create a new network instance. * From 56e75190d3c863d830502d76d50c4b7391fcf70b Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:22:46 +0100 Subject: [PATCH 07/15] bytebuffer tests --- tests/Unit/ByteBuffer/ByteBufferTest.php | 7 ++++ .../Concerns/Reads/UnsignedIntegerTest.php | 10 ++++++ .../Concerns/Writes/UnsignedIntegerTest.php | 32 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/tests/Unit/ByteBuffer/ByteBufferTest.php b/tests/Unit/ByteBuffer/ByteBufferTest.php index 5bebcecf..3d670635 100644 --- a/tests/Unit/ByteBuffer/ByteBufferTest.php +++ b/tests/Unit/ByteBuffer/ByteBufferTest.php @@ -177,6 +177,13 @@ expect($buffer->internalSize())->toBe(4 + 11); }); +it('should fill the buffer starting from a different start point', function () { + $buffer = ByteBuffer::new('hello'); + $buffer->fill(11, 4); + + expect($buffer->internalSize())->toBe(4 + 11); +}); + it('should flip the buffer contents', function () { $buffer = ByteBuffer::new('Hello World'); $buffer->flip(); diff --git a/tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php b/tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php index b86e4421..3acba409 100644 --- a/tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php +++ b/tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php @@ -71,3 +71,13 @@ expect($buffer->readULong())->toBe(64); }); + +test('it should read uint256', function () { + // 256-bit unsigned integer (32 bytes) + $value = '1157920892373161954235709850086879078532699846656405640323232344'; // max uint256 + $buffer = ByteBuffer::new(0); + $buffer->writeUInt256($value); + $buffer->position(0); + + expect($buffer->readUInt256())->toBe($value); +}); diff --git a/tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php b/tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php index 645797f6..458751c2 100644 --- a/tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php +++ b/tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php @@ -63,3 +63,35 @@ expect($buffer->internalSize())->toBe(8); }); + +test('it should write uint256', function () { + // 256-bit unsigned integer (32 bytes) + $value = '1157920892373161954235709850086879078532699846656405640323232344'; // max uint256 + $buffer = ByteBuffer::new(0); + $buffer->writeUInt256($value); + + expect($buffer->internalSize())->toBe(32); +}); + +test('it should write uint256 gmp value', function () { + // 256-bit unsigned integer (32 bytes) + $value = gmp_init('1157920892373161954235709850086879078532699846656405640323232344'); // max uint256 + $buffer = ByteBuffer::new(0); + $buffer->writeUInt256($value); + + expect($buffer->internalSize())->toBe(32); +}); + +test('it should throw exception when writing invalid uint256', function () { + // 256-bit unsigned integer (32 bytes) + $value = 'asd'; + $buffer = ByteBuffer::new(0); + $buffer->writeUInt256($value); +})->throws(InvalidArgumentException::class, 'The value must be a numeric string, integer, or GMP object.'); + +test('it should throw exception when writing uint256 which is too long', function () { + // 256-bit unsigned integer (32 bytes) + $value = '1157920892373161954235709850086879078532699846656405640323232344444411579208923731619542357098500868790785326998466564056403232323444444'; + $buffer = ByteBuffer::new(0); + $buffer->writeUInt256($value); +})->throws(InvalidArgumentException::class, 'The value must fit into 256 bits.'); From 8a6efa7c6c0d24451e734de2dc137178c6ea6b78 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:22:53 +0100 Subject: [PATCH 08/15] address validation tests --- tests/Unit/Identities/AddressTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Unit/Identities/AddressTest.php b/tests/Unit/Identities/AddressTest.php index 240d0c72..31bbf76b 100644 --- a/tests/Unit/Identities/AddressTest.php +++ b/tests/Unit/Identities/AddressTest.php @@ -38,3 +38,17 @@ expect($actual)->toBe($fixture['data']['address']); }); + +it('should validate an address', function () { + $fixture = $this->getFixture('identity'); + + $actual = Address::validate($fixture['data']['address']); + + expect($actual)->toBeTrue(); +}); + +it('should return false for invalid an address', function () { + $actual = Address::validate('invalid-address'); + + expect($actual)->toBeFalse(); +}); From 92c79187c0ff823f2f3ee60808a545069d450dd5 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:23:04 +0100 Subject: [PATCH 09/15] deserializer tests --- tests/Unit/Transactions/DeserializerTest.php | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/Unit/Transactions/DeserializerTest.php b/tests/Unit/Transactions/DeserializerTest.php index 11ef54f2..e9123e7b 100644 --- a/tests/Unit/Transactions/DeserializerTest.php +++ b/tests/Unit/Transactions/DeserializerTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use ArkEcosystem\Crypto\Transactions\Deserializer; use ArkEcosystem\Crypto\Transactions\Types\EvmCall; use ArkEcosystem\Crypto\Transactions\Types\Multipayment; use ArkEcosystem\Crypto\Transactions\Types\Transfer; @@ -88,3 +89,45 @@ expect($transaction)->toBeInstanceOf(Multipayment::class); }); + +it('should use ByteBuffer::fromHex when there is no null-byte in the string', function () { + // The string does not contain a null-byte + $hexString = 'abcdef1234567890'; + $deserializer = new Deserializer($hexString); + + // Use reflection to access the private buffer property + $reflection = new ReflectionClass($deserializer); + $bufferProperty = $reflection->getProperty('buffer'); + $bufferProperty->setAccessible(true); + $buffer = $bufferProperty->getValue($deserializer); + + // The buffer should be an instance of ByteBuffer + expect($buffer)->toBeInstanceOf(\ArkEcosystem\Crypto\ByteBuffer\ByteBuffer::class); + + // The buffer should contain the hex string (converted to binary) + expect($buffer->toString('hex'))->toContain($hexString); +}); + +it('should use ByteBuffer::fromBinary when there is a null-byte in the string', function () { + // The string contains a null-byte + $binaryString = "abc\0def"; // hex: 61626300646566 + $hexString = '61626300646566'; + $deserializer = new Deserializer($binaryString); + + // Use reflection to access the private buffer property + $reflection = new ReflectionClass($deserializer); + $bufferProperty = $reflection->getProperty('buffer'); + $bufferProperty->setAccessible(true); + $buffer = $bufferProperty->getValue($deserializer); + + // The buffer should be an instance of ByteBuffer + expect($buffer)->toBeInstanceOf(\ArkEcosystem\Crypto\ByteBuffer\ByteBuffer::class); + + // The buffer should contain the binary string + expect($buffer->toString('hex'))->toBe($hexString); +}); + +it('should return null if no data value in transaction data', function () { + expect(Deserializer::decodePayload([]))->toBeNull(); + expect(Deserializer::decodePayload(['data' => '']))->toBeNull(); +}); From 588afe61f9086a4dd612bc44cd9b300a3aa90605 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:23:13 +0100 Subject: [PATCH 10/15] abi function enum tests --- tests/Unit/Enums/AbiFunctionTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/Unit/Enums/AbiFunctionTest.php diff --git a/tests/Unit/Enums/AbiFunctionTest.php b/tests/Unit/Enums/AbiFunctionTest.php new file mode 100644 index 00000000..99647b22 --- /dev/null +++ b/tests/Unit/Enums/AbiFunctionTest.php @@ -0,0 +1,22 @@ +transactionClass())->toEqual($class); +})->with([ + 'Vote' => ['VOTE', Vote::class], + 'Unvote' => ['UNVOTE', Unvote::class], + 'ValidatorRegistration' => ['VALIDATOR_REGISTRATION', ValidatorRegistration::class], + 'ValidatorResignation' => ['VALIDATOR_RESIGNATION', ValidatorResignation::class], + 'UsernameRegistration' => ['USERNAME_REGISTRATION', UsernameRegistration::class], + 'UsernameResignation' => ['USERNAME_RESIGNATION', UsernameResignation::class], + 'Multipayment' => ['MULTIPAYMENT', Multipayment::class], +]); From c238821b65caad2a3ec36ef91108292d51814861 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:23:20 +0100 Subject: [PATCH 11/15] add coverage to tests --- .github/workflows/test.yml | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 28acd015..8fda1c98 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,10 +13,26 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} - - name: Install - run: composer update --no-interaction --no-suggest --ignore-platform-reqs + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.4" + extensions: mbstring, dom, fileinfo, intl, gd, imagick, bcmath, soap, zip, sqlite, pcov + coverage: pcov - - name: Unit tests - run: composer test + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.composer/cache/files + key: dependencies-composer-${{ hashFiles('composer.json') }} + + - name: Install Composer dependencies + run: composer install --no-ansi --no-interaction --no-suggest --no-progress --prefer-dist --optimize-autoloader + + - name: Run Tests + run: ./vendor/bin/pest --coverage --coverage-html=.coverage --coverage-clover=coverage.xml From a83bc22330637ecbedfbc039027d5aced0f36237 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:26:24 +0100 Subject: [PATCH 12/15] add phpunit xml --- .gitignore | 1 - phpunit.xml | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml diff --git a/.gitignore b/.gitignore index 9d8b2a4f..d5d2eba4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -phpunit.xml vendor clover.xml .php_cs.cache diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..7d0904f7 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./tests + + + + + ./app + ./src + + + From c3fa41d74499d801771cc39f9e41e459b2b3f69c Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:26:43 +0100 Subject: [PATCH 13/15] remove missing folder --- phpunit.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 7d0904f7..0c12bb9f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,7 +11,6 @@ - ./app ./src From 0f55d8435955cf08f017541aa4a3371acbbd91a9 Mon Sep 17 00:00:00 2001 From: alexbarnsley Date: Mon, 16 Jun 2025 13:31:49 +0000 Subject: [PATCH 14/15] style: resolve style guide violations --- .../Concerns/Reads/UnsignedIntegerTest.php | 2 +- .../Concerns/Writes/UnsignedIntegerTest.php | 8 ++++---- tests/Unit/Enums/AbiFunctionTest.php | 14 ++++++++------ tests/Unit/Transactions/DeserializerTest.php | 12 ++++++------ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php b/tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php index 3acba409..a5c3d7ff 100644 --- a/tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php +++ b/tests/Unit/ByteBuffer/Concerns/Reads/UnsignedIntegerTest.php @@ -74,7 +74,7 @@ test('it should read uint256', function () { // 256-bit unsigned integer (32 bytes) - $value = '1157920892373161954235709850086879078532699846656405640323232344'; // max uint256 + $value = '1157920892373161954235709850086879078532699846656405640323232344'; // max uint256 $buffer = ByteBuffer::new(0); $buffer->writeUInt256($value); $buffer->position(0); diff --git a/tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php b/tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php index 458751c2..b6db0e4c 100644 --- a/tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php +++ b/tests/Unit/ByteBuffer/Concerns/Writes/UnsignedIntegerTest.php @@ -66,7 +66,7 @@ test('it should write uint256', function () { // 256-bit unsigned integer (32 bytes) - $value = '1157920892373161954235709850086879078532699846656405640323232344'; // max uint256 + $value = '1157920892373161954235709850086879078532699846656405640323232344'; // max uint256 $buffer = ByteBuffer::new(0); $buffer->writeUInt256($value); @@ -75,7 +75,7 @@ test('it should write uint256 gmp value', function () { // 256-bit unsigned integer (32 bytes) - $value = gmp_init('1157920892373161954235709850086879078532699846656405640323232344'); // max uint256 + $value = gmp_init('1157920892373161954235709850086879078532699846656405640323232344'); // max uint256 $buffer = ByteBuffer::new(0); $buffer->writeUInt256($value); @@ -84,14 +84,14 @@ test('it should throw exception when writing invalid uint256', function () { // 256-bit unsigned integer (32 bytes) - $value = 'asd'; + $value = 'asd'; $buffer = ByteBuffer::new(0); $buffer->writeUInt256($value); })->throws(InvalidArgumentException::class, 'The value must be a numeric string, integer, or GMP object.'); test('it should throw exception when writing uint256 which is too long', function () { // 256-bit unsigned integer (32 bytes) - $value = '1157920892373161954235709850086879078532699846656405640323232344444411579208923731619542357098500868790785326998466564056403232323444444'; + $value = '1157920892373161954235709850086879078532699846656405640323232344444411579208923731619542357098500868790785326998466564056403232323444444'; $buffer = ByteBuffer::new(0); $buffer->writeUInt256($value); })->throws(InvalidArgumentException::class, 'The value must fit into 256 bits.'); diff --git a/tests/Unit/Enums/AbiFunctionTest.php b/tests/Unit/Enums/AbiFunctionTest.php index 99647b22..bc91bf3b 100644 --- a/tests/Unit/Enums/AbiFunctionTest.php +++ b/tests/Unit/Enums/AbiFunctionTest.php @@ -1,5 +1,7 @@ transactionClass())->toEqual($class); })->with([ - 'Vote' => ['VOTE', Vote::class], - 'Unvote' => ['UNVOTE', Unvote::class], + 'Vote' => ['VOTE', Vote::class], + 'Unvote' => ['UNVOTE', Unvote::class], 'ValidatorRegistration' => ['VALIDATOR_REGISTRATION', ValidatorRegistration::class], - 'ValidatorResignation' => ['VALIDATOR_RESIGNATION', ValidatorResignation::class], - 'UsernameRegistration' => ['USERNAME_REGISTRATION', UsernameRegistration::class], - 'UsernameResignation' => ['USERNAME_RESIGNATION', UsernameResignation::class], - 'Multipayment' => ['MULTIPAYMENT', Multipayment::class], + 'ValidatorResignation' => ['VALIDATOR_RESIGNATION', ValidatorResignation::class], + 'UsernameRegistration' => ['USERNAME_REGISTRATION', UsernameRegistration::class], + 'UsernameResignation' => ['USERNAME_RESIGNATION', UsernameResignation::class], + 'Multipayment' => ['MULTIPAYMENT', Multipayment::class], ]); diff --git a/tests/Unit/Transactions/DeserializerTest.php b/tests/Unit/Transactions/DeserializerTest.php index e9123e7b..93a4e374 100644 --- a/tests/Unit/Transactions/DeserializerTest.php +++ b/tests/Unit/Transactions/DeserializerTest.php @@ -92,17 +92,17 @@ it('should use ByteBuffer::fromHex when there is no null-byte in the string', function () { // The string does not contain a null-byte - $hexString = 'abcdef1234567890'; + $hexString = 'abcdef1234567890'; $deserializer = new Deserializer($hexString); // Use reflection to access the private buffer property - $reflection = new ReflectionClass($deserializer); + $reflection = new ReflectionClass($deserializer); $bufferProperty = $reflection->getProperty('buffer'); $bufferProperty->setAccessible(true); $buffer = $bufferProperty->getValue($deserializer); // The buffer should be an instance of ByteBuffer - expect($buffer)->toBeInstanceOf(\ArkEcosystem\Crypto\ByteBuffer\ByteBuffer::class); + expect($buffer)->toBeInstanceOf(ArkEcosystem\Crypto\ByteBuffer\ByteBuffer::class); // The buffer should contain the hex string (converted to binary) expect($buffer->toString('hex'))->toContain($hexString); @@ -111,17 +111,17 @@ it('should use ByteBuffer::fromBinary when there is a null-byte in the string', function () { // The string contains a null-byte $binaryString = "abc\0def"; // hex: 61626300646566 - $hexString = '61626300646566'; + $hexString = '61626300646566'; $deserializer = new Deserializer($binaryString); // Use reflection to access the private buffer property - $reflection = new ReflectionClass($deserializer); + $reflection = new ReflectionClass($deserializer); $bufferProperty = $reflection->getProperty('buffer'); $bufferProperty->setAccessible(true); $buffer = $bufferProperty->getValue($deserializer); // The buffer should be an instance of ByteBuffer - expect($buffer)->toBeInstanceOf(\ArkEcosystem\Crypto\ByteBuffer\ByteBuffer::class); + expect($buffer)->toBeInstanceOf(ArkEcosystem\Crypto\ByteBuffer\ByteBuffer::class); // The buffer should contain the binary string expect($buffer->toString('hex'))->toBe($hexString); From d8a988804f6f83a97f0f3c1a2cf944899c9b88e7 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:32:52 +0100 Subject: [PATCH 15/15] set minimum coverage --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index db4af42b..896bf1f5 100755 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "vendor/bin/php-cs-fixer fix" ], "test": [ - "./vendor/bin/pest --parallel" + "./vendor/bin/pest --coverage --min=100 --coverage-html=.coverage --coverage-clover=coverage.xml" ] }, "minimum-stability": "dev",