Skip to content

Add Native Asset Support and Enhance Unit Testing#11

Merged
Crypto2099 merged 5 commits intomainfrom
develop
Jan 7, 2025
Merged

Add Native Asset Support and Enhance Unit Testing#11
Crypto2099 merged 5 commits intomainfrom
develop

Conversation

@Crypto2099
Copy link
Contributor

Add support and helper functions and unit tests for encoding and decoding Cardano Native Assets into an "Asset Fingerprint" which is a more human-friendly identifier defined in CIP-0014.

Signed-off-by: Adam Dean <adam@crypto2099.io>
- Adds the Test Vectors specified in CIP-0014 for Native Assets
- Adds helper functions for encoding and hashing Native Assets per CIP-0014

Signed-off-by: Adam Dean <adam@crypto2099.io>
- Add some constants to the top of the file to allow for easier re-use and future flexibility.
- Add a couple of checks to the encode function to validate HRP.
- Change a couple of hard-coded values to use new constants.
- Slightly change the language of some exceptions
- Remove some unused comments and variables

Signed-off-by: Adam Dean <adam@crypto2099.io>
- Add test vectors to bring new functions to 100% code coverage
- Add good and bad test vectors to test both expected behavior and unexpected data entry
- Add sanity checking and exception responses if data is malformed.

Signed-off-by: Adam Dean <adam@crypto2099.io>
- More unit tests specifically to complete code coverage around new checks placed on generic encode/decode functionality to bring alignment with original Bech32 specification in BIP-0173

Signed-off-by: Adam Dean <adam@crypto2099.io>
@Crypto2099 Crypto2099 added the enhancement New feature or request label Jan 5, 2025
@Crypto2099 Crypto2099 requested a review from latheesan-k January 5, 2025 03:20
@Crypto2099 Crypto2099 self-assigned this Jan 5, 2025
use PHPUnit\Framework\TestCase;

#[CoversClass(Bech32::class)]
class Bech32AssetTest extends TestCase

Choose a reason for hiding this comment

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

Minor recommendations:

  • Expand test coverage with unhappy path also
    • Add test that provide invalid input and edge cases (min/max input, zero lonth and other boundary conditions)
    • Use php unit's assertException helper to check expected exceptions are thrown for invalid inputs / edge cases

Choose a reason for hiding this comment

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

Ignore above recommendations, appears to be covered in the next test.

Copy link

@latheesan-k latheesan-k left a comment

Choose a reason for hiding this comment

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

LGTM

@Crypto2099 Crypto2099 merged commit 4d46b51 into main Jan 7, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Native Asset encoding/decoding Minor: decode does not validate HRP conformance to Bech32 character constraints

2 participants