|
63 | 63 |
|
64 | 64 | expect($buffer->internalSize())->toBe(8); |
65 | 65 | }); |
| 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.'); |
0 commit comments