-
Notifications
You must be signed in to change notification settings - Fork 124
Add encode_mptoken_metadata and decode_mptoken_metadata utility functions #880
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c0b52ce
WIP commit
Patel-Raj11 023b891
WIP commit
Patel-Raj11 613dbfd
WIP commit
Patel-Raj11 75aa34f
WIP commit
Patel-Raj11 2268ee5
fix tests
Patel-Raj11 04f84f1
some refactors
Patel-Raj11 d3c4c6a
fix docstrings
Patel-Raj11 a25ea7a
update changelog
Patel-Raj11 ccad6c5
use dict over Dict
Patel-Raj11 6c118d3
add encode decode in IT
Patel-Raj11 81cc1f1
fix IT
Patel-Raj11 9c8ab6b
fix test
Patel-Raj11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
298 changes: 298 additions & 0 deletions
298
tests/unit/models/mptoken-metadata-encode-decode-fixtures.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,298 @@ | ||
| [ | ||
| { | ||
| "testName": "valid long MPTokenMetadata", | ||
| "mptMetadata": { | ||
| "ticker": "TBILL", | ||
| "name": "T-Bill Yield Token", | ||
| "desc": "A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.", | ||
| "icon": "https://example.org/tbill-icon.png", | ||
| "asset_class": "rwa", | ||
| "asset_subclass": "treasury", | ||
| "issuer_name": "Example Yield Co.", | ||
| "uris": [ | ||
| { | ||
| "uri": "https://exampleyield.co/tbill", | ||
| "category": "website", | ||
| "title": "Product Page" | ||
| }, | ||
| { | ||
| "uri": "https://exampleyield.co/docs", | ||
| "category": "docs", | ||
| "title": "Yield Token Docs" | ||
| } | ||
| ], | ||
| "additional_info": { | ||
| "interest_rate": "5.00%", | ||
| "interest_type": "variable", | ||
| "yield_source": "U.S. Treasury Bills", | ||
| "maturity_date": "2045-06-30", | ||
| "cusip": "912796RX0" | ||
| } | ||
| }, | ||
| "expectedLongForm": { | ||
| "ticker": "TBILL", | ||
| "name": "T-Bill Yield Token", | ||
| "desc": "A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.", | ||
| "icon": "https://example.org/tbill-icon.png", | ||
| "asset_class": "rwa", | ||
| "asset_subclass": "treasury", | ||
| "issuer_name": "Example Yield Co.", | ||
| "uris": [ | ||
| { | ||
| "uri": "https://exampleyield.co/tbill", | ||
| "category": "website", | ||
| "title": "Product Page" | ||
| }, | ||
| { | ||
| "uri": "https://exampleyield.co/docs", | ||
| "category": "docs", | ||
| "title": "Yield Token Docs" | ||
| } | ||
| ], | ||
| "additional_info": { | ||
| "interest_rate": "5.00%", | ||
| "interest_type": "variable", | ||
| "yield_source": "U.S. Treasury Bills", | ||
| "maturity_date": "2045-06-30", | ||
| "cusip": "912796RX0" | ||
| } | ||
| }, | ||
| "hex": "7B226163223A22727761222C226169223A7B226375736970223A22393132373936525830222C22696E7465726573745F72617465223A22352E303025222C22696E7465726573745F74797065223A227661726961626C65222C226D617475726974795F64617465223A22323034352D30362D3330222C227969656C645F736F75726365223A22552E532E2054726561737572792042696C6C73227D2C226173223A227472656173757279222C2264223A2241207969656C642D62656172696E6720737461626C65636F696E206261636B65642062792073686F72742D7465726D20552E532E205472656173757269657320616E64206D6F6E6579206D61726B657420696E737472756D656E74732E222C2269223A2268747470733A2F2F6578616D706C652E6F72672F7462696C6C2D69636F6E2E706E67222C22696E223A224578616D706C65205969656C6420436F2E222C226E223A22542D42696C6C205969656C6420546F6B656E222C2274223A225442494C4C222C227573223A5B7B2263223A2277656273697465222C2274223A2250726F647563742050616765222C2275223A2268747470733A2F2F6578616D706C657969656C642E636F2F7462696C6C227D2C7B2263223A22646F6373222C2274223A225969656C6420546F6B656E20446F6373222C2275223A2268747470733A2F2F6578616D706C657969656C642E636F2F646F6373227D5D7D" | ||
| }, | ||
| { | ||
| "testName": "valid MPTokenMetadata with all short field names", | ||
| "mptMetadata": { | ||
| "t": "TBILL", | ||
| "n": "T-Bill Yield Token", | ||
| "d": "A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.", | ||
| "i": "https://example.org/tbill-icon.png", | ||
| "ac": "rwa", | ||
| "as": "treasury", | ||
| "in": "Example Yield Co.", | ||
| "us": [ | ||
| { | ||
| "u": "https://exampleyield.co/tbill", | ||
| "c": "website", | ||
| "t": "Product Page" | ||
| }, | ||
| { | ||
| "u": "https://exampleyield.co/docs", | ||
| "c": "docs", | ||
| "t": "Yield Token Docs" | ||
| } | ||
| ], | ||
| "ai": { | ||
| "interest_rate": "5.00%", | ||
| "interest_type": "variable", | ||
| "yield_source": "U.S. Treasury Bills", | ||
| "maturity_date": "2045-06-30", | ||
| "cusip": "912796RX0" | ||
| } | ||
| }, | ||
| "expectedLongForm": { | ||
| "ticker": "TBILL", | ||
| "name": "T-Bill Yield Token", | ||
| "desc": "A yield-bearing stablecoin backed by short-term U.S. Treasuries and money market instruments.", | ||
| "icon": "https://example.org/tbill-icon.png", | ||
| "asset_class": "rwa", | ||
| "asset_subclass": "treasury", | ||
| "issuer_name": "Example Yield Co.", | ||
| "uris": [ | ||
| { | ||
| "uri": "https://exampleyield.co/tbill", | ||
| "category": "website", | ||
| "title": "Product Page" | ||
| }, | ||
| { | ||
| "uri": "https://exampleyield.co/docs", | ||
| "category": "docs", | ||
| "title": "Yield Token Docs" | ||
| } | ||
| ], | ||
| "additional_info": { | ||
| "interest_rate": "5.00%", | ||
| "interest_type": "variable", | ||
| "yield_source": "U.S. Treasury Bills", | ||
| "maturity_date": "2045-06-30", | ||
| "cusip": "912796RX0" | ||
| } | ||
| }, | ||
| "hex": "7B226163223A22727761222C226169223A7B226375736970223A22393132373936525830222C22696E7465726573745F72617465223A22352E303025222C22696E7465726573745F74797065223A227661726961626C65222C226D617475726974795F64617465223A22323034352D30362D3330222C227969656C645F736F75726365223A22552E532E2054726561737572792042696C6C73227D2C226173223A227472656173757279222C2264223A2241207969656C642D62656172696E6720737461626C65636F696E206261636B65642062792073686F72742D7465726D20552E532E205472656173757269657320616E64206D6F6E6579206D61726B657420696E737472756D656E74732E222C2269223A2268747470733A2F2F6578616D706C652E6F72672F7462696C6C2D69636F6E2E706E67222C22696E223A224578616D706C65205969656C6420436F2E222C226E223A22542D42696C6C205969656C6420546F6B656E222C2274223A225442494C4C222C227573223A5B7B2263223A2277656273697465222C2274223A2250726F647563742050616765222C2275223A2268747470733A2F2F6578616D706C657969656C642E636F2F7462696C6C227D2C7B2263223A22646F6373222C2274223A225969656C6420546F6B656E20446F6373222C2275223A2268747470733A2F2F6578616D706C657969656C642E636F2F646F6373227D5D7D" | ||
| }, | ||
| { | ||
| "testName": "valid MPTokenMetadata with mixed short and long field names", | ||
| "mptMetadata": { | ||
| "ticker": "CRYPTO", | ||
| "n": "Crypto Token", | ||
| "icon": "https://example.org/crypto-icon.png", | ||
| "asset_class": "gaming", | ||
| "d": "A gaming token for virtual worlds.", | ||
| "issuer_name": "Gaming Studios Inc.", | ||
| "as": "equity", | ||
| "uris": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "c": "website", | ||
| "title": "Main Website" | ||
| }, | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "t": "Main Website" | ||
| } | ||
| ], | ||
| "ai": "Gaming ecosystem token" | ||
| }, | ||
| "expectedLongForm": { | ||
| "ticker": "CRYPTO", | ||
| "name": "Crypto Token", | ||
| "icon": "https://example.org/crypto-icon.png", | ||
| "asset_class": "gaming", | ||
| "desc": "A gaming token for virtual worlds.", | ||
| "issuer_name": "Gaming Studios Inc.", | ||
| "asset_subclass": "equity", | ||
| "uris": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "title": "Main Website" | ||
| }, | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "title": "Main Website" | ||
| } | ||
| ], | ||
| "additional_info": "Gaming ecosystem token" | ||
| }, | ||
| "hex": "7B226163223A2267616D696E67222C226169223A2247616D696E672065636F73797374656D20746F6B656E222C226173223A22657175697479222C2264223A22412067616D696E6720746F6B656E20666F72207669727475616C20776F726C64732E222C2269223A2268747470733A2F2F6578616D706C652E6F72672F63727970746F2D69636F6E2E706E67222C22696E223A2247616D696E672053747564696F7320496E632E222C226E223A2243727970746F20546F6B656E222C2274223A2243525950544F222C227573223A5B7B2263223A2277656273697465222C2274223A224D61696E2057656273697465222C2275223A2268747470733A2F2F67616D696E6773747564696F732E636F6D227D2C7B2263223A2277656273697465222C2274223A224D61696E2057656273697465222C2275223A2268747470733A2F2F67616D696E6773747564696F732E636F6D227D5D7D" | ||
| }, | ||
| { | ||
| "testName": "with extra fields", | ||
| "mptMetadata": { | ||
| "ticker": "CRYPTO", | ||
| "n": "Crypto Token", | ||
| "icon": "https://example.org/crypto-icon.png", | ||
| "asset_class": "gaming", | ||
| "d": "A gaming token for virtual worlds.", | ||
| "issuer_name": "Gaming Studios Inc.", | ||
| "as": "equity", | ||
| "uris": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "c": "website", | ||
| "title": "Main Website" | ||
| }, | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "t": "Main Website" | ||
| } | ||
| ], | ||
| "ai": "Gaming ecosystem token", | ||
| "extra": { | ||
| "extra": "extra" | ||
| } | ||
| }, | ||
| "expectedLongForm": { | ||
| "ticker": "CRYPTO", | ||
| "name": "Crypto Token", | ||
| "icon": "https://example.org/crypto-icon.png", | ||
| "asset_class": "gaming", | ||
| "desc": "A gaming token for virtual worlds.", | ||
| "issuer_name": "Gaming Studios Inc.", | ||
| "asset_subclass": "equity", | ||
| "uris": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "title": "Main Website" | ||
| }, | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "title": "Main Website" | ||
| } | ||
| ], | ||
| "additional_info": "Gaming ecosystem token", | ||
| "extra": { | ||
| "extra": "extra" | ||
| } | ||
| }, | ||
| "hex": "7B226163223A2267616D696E67222C226169223A2247616D696E672065636F73797374656D20746F6B656E222C226173223A22657175697479222C2264223A22412067616D696E6720746F6B656E20666F72207669727475616C20776F726C64732E222C226578747261223A7B226578747261223A226578747261227D2C2269223A2268747470733A2F2F6578616D706C652E6F72672F63727970746F2D69636F6E2E706E67222C22696E223A2247616D696E672053747564696F7320496E632E222C226E223A2243727970746F20546F6B656E222C2274223A2243525950544F222C227573223A5B7B2263223A2277656273697465222C2274223A224D61696E2057656273697465222C2275223A2268747470733A2F2F67616D696E6773747564696F732E636F6D227D2C7B2263223A2277656273697465222C2274223A224D61696E2057656273697465222C2275223A2268747470733A2F2F67616D696E6773747564696F732E636F6D227D5D7D" | ||
| }, | ||
| { | ||
| "testName": "with unkown null fields", | ||
| "mptMetadata": { | ||
| "t": "CRYPTO", | ||
| "extra": null | ||
| }, | ||
| "expectedLongForm": { | ||
| "ticker": "CRYPTO", | ||
| "extra": null | ||
| }, | ||
| "hex": "7B226578747261223A6E756C6C2C2274223A2243525950544F227D" | ||
| }, | ||
| { | ||
| "testName": "multiple uris and us", | ||
| "mptMetadata": { | ||
| "t": "CRYPTO", | ||
| "uris": [ | ||
| { | ||
| "u": "https://gamingstudios.com", | ||
| "c": "website", | ||
| "t": "Main Website" | ||
| } | ||
| ], | ||
| "us": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "title": "Main Website" | ||
| } | ||
| ] | ||
| }, | ||
| "expectedLongForm": { | ||
| "ticker": "CRYPTO", | ||
| "uris": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "title": "Main Website" | ||
| } | ||
| ], | ||
| "us": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "category": "website", | ||
| "title": "Main Website" | ||
| } | ||
| ] | ||
| }, | ||
| "hex": "7B2274223A2243525950544F222C2275726973223A5B7B2263223A2277656273697465222C2274223A224D61696E2057656273697465222C2275223A2268747470733A2F2F67616D696E6773747564696F732E636F6D227D5D2C227573223A5B7B2263223A2277656273697465222C2274223A224D61696E2057656273697465222C2275223A2268747470733A2F2F67616D696E6773747564696F732E636F6D227D5D7D" | ||
| }, | ||
| { | ||
| "testName": "multiple keys in uri", | ||
| "mptMetadata": { | ||
| "us": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "u": "website", | ||
| "category": "Main Website", | ||
| "c": "Main Website" | ||
| } | ||
| ] | ||
| }, | ||
| "expectedLongForm": { | ||
| "uris": [ | ||
| { | ||
| "uri": "https://gamingstudios.com", | ||
| "u": "website", | ||
| "category": "Main Website", | ||
| "c": "Main Website" | ||
| } | ||
| ] | ||
| }, | ||
| "hex": "7B227573223A5B7B2263223A224D61696E2057656273697465222C2263617465676F7279223A224D61696E2057656273697465222C2275223A2277656273697465222C22757269223A2268747470733A2F2F67616D696E6773747564696F732E636F6D227D5D7D" | ||
| } | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explicit assertion for MPTokenMetadata field before accessing it.
The test directly accesses
mptoken_issuance_obj["MPTokenMetadata"]on line 69, which will raise aKeyErrorif the field is missing. While the field should be present since metadata was included in the transaction, an explicit assertion provides a clearer error message when debugging unexpected ledger behavior.Apply this diff to add an explicit assertion:
Alternatively, use safe dictionary access:
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetched object using
mpt_issuance_idfrom validated ledger. There is no wayMPTokenMetadatawon't exists.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Patel-Raj11, you're absolutely right. Since the object is retrieved using the
mpt_issuance_idfrom a validated ledger transaction that successfully included metadata, theMPTokenMetadatafield should indeed be present. If it's missing, that would indicate a fundamental issue with the ledger behavior itself rather than a test concern. Your current test flow is appropriate for this integration test scenario.🧠 Learnings used